attempt to run PHPCS on travis

This commit is contained in:
Aristeides Stathopoulos 2016-08-27 17:18:14 +03:00
parent 69e6b05205
commit c0b43e6370
3 changed files with 205 additions and 1 deletions

View File

@ -25,7 +25,24 @@ before_script:
- bash tests/bin/install.sh woocommerce_test root '' localhost $WP_VERSION
- bash tests/bin/travis.sh before
script: phpunit -c phpunit.xml.dist
script:
# Search for PHP syntax errors.
- find . \( -name '*.php' \) -exec php -lf {} \;
# Run PHPUnit tests.
- phpunit -c phpunit.xml.dist
# WordPress Coding Standards.
# @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards
# @link http://pear.php.net/package/PHP_CodeSniffer/
# -p flag: Show progress of the run.
# -s flag: Show sniff codes in all reports.
# -v flag: Print verbose output.
# -n flag: Do not print warnings. (shortcut for --warning-severity=0)
# --standard: Use WordPress as the standard.
# --extensions: Only sniff PHP files.
- /tmp/phpcs/scripts/phpcs -p -s -v -n ./*.php --standard=./phpcs.ruleset.xml --extensions=php
- /tmp/phpcs/scripts/phpcs -p -s -v -n ./**/*.php --standard=./phpcs.ruleset.xml --extensions=php
- /tmp/phpcs/scripts/phpcs -p -s -v -n ./**/**/*.php --standard=./phpcs.ruleset.xml --extensions=php
- /tmp/phpcs/scripts/phpcs -p -s -v -n ./**/**/**/*.php --standard=./phpcs.ruleset.xml --extensions=php
after_script:
- bash tests/bin/travis.sh after

174
phpcs.ruleset.xml Normal file
View File

@ -0,0 +1,174 @@
<?xml version="1.0"?>
<ruleset name="WordPress Coding Standards">
<!-- See https://github.com/squizlabs/PHP_CodeSniffer/wiki/Annotated-ruleset.xml -->
<!-- See https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/blob/develop/WordPress-Core/ruleset.xml -->
<!-- Set a description for this ruleset. -->
<description>A custom set of code standard rules to check for WordPress themes and plugins.</description>
<!-- Include the WordPress ruleset, with exclusions. -->
<rule ref="WordPress">
<exclude name="Generic.CodeAnalysis.EmptyStatement.DetectedCATCH" />
<exclude name="Generic.CodeAnalysis.EmptyStatement.DetectedIF" />
<exclude name="Generic.CodeAnalysis.EmptyStatement.DetectedELSE" />
<exclude name="Generic.Commenting.DocComment.LongNotCapital" />
<exclude name="Generic.Commenting.DocComment.MissingShort" />
<exclude name="Generic.Commenting.DocComment.ShortNotCapital" />
<exclude name="Generic.Commenting.DocComment.SpacingAfter" />
<exclude name="Generic.Commenting.DocComment.SpacingBeforeTags" />
<exclude name="Generic.ControlStructures.InlineControlStructure.NotAllowed" />
<exclude name="Generic.Files.EndFileNewline.NotFound" />
<exclude name="Generic.Files.LineEndings.InvalidEOLChar" />
<exclude name="Generic.Files.LowercasedFilename.NotFound" />
<exclude name="Generic.Formatting.DisallowMultipleStatements.SameLine" />
<exclude name="Generic.Formatting.SpaceAfterCast.NoSpace" />
<exclude name="Generic.Functions.OpeningFunctionBraceKernighanRitchie.BraceOnNewLine" />
<exclude name="Generic.Functions.OpeningFunctionBraceKernighanRitchie.ContentAfterBrace" />
<exclude name="Generic.Functions.OpeningFunctionBraceKernighanRitchie.SpaceBeforeBrace" />
<exclude name="Generic.PHP.ForbiddenFunctions.FoundWithAlternative" />
<exclude name="Generic.PHP.LowerCaseKeyword.Found" />
<exclude name="Generic.PHP.NoSilencedErrors.Discouraged" />
<exclude name="Generic.Strings.UnnecessaryStringConcat.Found" />
<exclude name="Generic.WhiteSpace.DisallowSpaceIndent.SpacesUsed" />
<exclude name="Generic.WhiteSpace.ScopeIndent.Incorrect" />
<exclude name="Generic.WhiteSpace.ScopeIndent.IncorrectExact" />
<exclude name="PEAR.Functions.FunctionCallSignature.Indent" />
<exclude name="PEAR.Functions.FunctionCallSignature.SpaceAfterCloseBracket" />
<exclude name="PEAR.Functions.FunctionCallSignature.SpaceAfterOpenBracket" />
<exclude name="PEAR.Functions.FunctionCallSignature.SpaceBeforeCloseBracket" />
<exclude name="PEAR.Functions.FunctionCallSignature.SpaceBeforeOpenBracket" />
<exclude name="Squiz.Commenting.BlockComment.NoEmptyLineBefore" />
<exclude name="Squiz.Commenting.BlockComment.NoNewLine" />
<exclude name="Squiz.Commenting.BlockComment.WrongEnd" />
<exclude name="Squiz.Commenting.ClassComment.SpacingAfter" />
<exclude name="Squiz.Commenting.ClassComment.Missing" />
<exclude name="Squiz.Commenting.DocCommentAlignment.SpaceBeforeStar" />
<exclude name="Squiz.Commenting.EmptyCatchComment.Missing" />
<exclude name="Squiz.Commenting.FileComment.Missing" />
<exclude name="Squiz.Commenting.FileComment.MissingPackageTag" />
<exclude name="Squiz.Commenting.FileComment.SpacingAfterComment" />
<exclude name="Squiz.Commenting.FileComment.SpacingAfterOpen" />
<exclude name="Squiz.Commenting.FileComment.WrongStyle" />
<exclude name="Squiz.Commenting.FunctionComment.EmptyThrows" />
<exclude name="Squiz.Commenting.FunctionComment.ExtraParamComment" />
<exclude name="Squiz.Commenting.FunctionComment.InvalidNoReturn" />
<exclude name="Squiz.Commenting.FunctionComment.InvalidReturnVoid" />
<exclude name="Squiz.Commenting.FunctionComment.Missing" />
<exclude name="Squiz.Commenting.FunctionComment.MissingParamComment" />
<exclude name="Squiz.Commenting.FunctionComment.MissingParamName" />
<exclude name="Squiz.Commenting.FunctionComment.MissingParamTag" />
<exclude name="Squiz.Commenting.FunctionComment.ParamCommentFullStop" />
<exclude name="Squiz.Commenting.FunctionComment.ParamNameNoCaseMatch" />
<exclude name="Squiz.Commenting.FunctionComment.ParamNameNoMatch" />
<exclude name="Squiz.Commenting.FunctionComment.ScalarTypeHintMissing" />
<exclude name="Squiz.Commenting.FunctionComment.SpacingAfter" />
<exclude name="Squiz.Commenting.FunctionComment.SpacingAfterParamType" />
<exclude name="Squiz.Commenting.FunctionComment.ThrowsNoFullStop" />
<exclude name="Squiz.Commenting.FunctionComment.ThrowsNotCapital" />
<exclude name="Squiz.Commenting.FunctionCommentThrowTag.Missing" />
<exclude name="Squiz.Commenting.FunctionCommentThrowTag.WrongNumber" />
<exclude name="Squiz.Commenting.FunctionComment.WrongStyle" />
<exclude name="Squiz.Commenting.InlineComment.Empty" />
<exclude name="Squiz.Commenting.InlineComment.InvalidEndChar" />
<exclude name="Squiz.Commenting.InlineComment.NoSpaceBefore" />
<exclude name="Squiz.Commenting.InlineComment.NotCapital" />
<exclude name="Squiz.Commenting.InlineComment.SpacingAfter" />
<exclude name="Squiz.Commenting.InlineComment.SpacingBefore" />
<exclude name="Squiz.Commenting.InlineComment.WrongStyle" />
<exclude name="Squiz.Commenting.VariableComment.Missing" />
<exclude name="Squiz.Commenting.VariableComment.MissingVar" />
<exclude name="Squiz.Commenting.VariableComment.WrongStyle" />
<exclude name="Squiz.ControlStructures.ControlSignature.SpaceAfterCloseBrace" />
<exclude name="Squiz.ControlStructures.ControlSignature.SpaceAfterCloseParenthesis" />
<exclude name="Squiz.ControlStructures.ControlSignature.SpaceAfterKeyword" />
<exclude name="Squiz.Functions.FunctionDeclarationArgumentSpacing.SpaceAfterDefault" />
<exclude name="Squiz.Functions.FunctionDeclarationArgumentSpacing.SpacingAfterOpen" />
<exclude name="Squiz.Functions.FunctionDeclarationArgumentSpacing.SpacingAfterOpenHint" />
<exclude name="Squiz.Functions.FunctionDeclarationArgumentSpacing.SpaceBeforeEquals" />
<exclude name="Squiz.Functions.FunctionDeclarationArgumentSpacing.SpacingBeforeClose" />
<exclude name="Squiz.PHP.CommentedOutCode.Found" />
<exclude name="Squiz.Strings.DoubleQuoteUsage.NotRequired" />
<!-- <exclude name="Squiz.WhiteSpace.SuperfluousWhitespace.EmptyLines" /> -->
<!-- <exclude name="Squiz.WhiteSpace.SuperfluousWhitespace.EndLine" /> -->
<!-- <exclude name="WordPress.Arrays.ArrayDeclaration.CloseBraceNewLine" /> -->
<!-- <exclude name="WordPress.Arrays.ArrayDeclaration.FirstIndexNoNewline" /> -->
<!-- <exclude name="WordPress.Arrays.ArrayDeclaration.FirstValueNoNewline" /> -->
<!-- <exclude name="WordPress.Arrays.ArrayDeclaration.IndexNoNewline" /> -->
<!-- <exclude name="WordPress.Arrays.ArrayDeclaration.NoComma" /> -->
<!-- <exclude name="WordPress.Arrays.ArrayDeclaration.NoCommaAfterLast" /> -->
<!-- <exclude name="WordPress.Arrays.ArrayDeclaration.NoSpaceAfterComma" /> -->
<!-- <exclude name="WordPress.Arrays.ArrayDeclaration.NoSpaceAfterDoubleArrow" /> -->
<!-- <exclude name="WordPress.Arrays.ArrayDeclaration.NoSpaceAfterOpenParenthesis" /> -->
<!-- <exclude name="WordPress.Arrays.ArrayDeclaration.NoSpaceBeforeDoubleArrow" /> -->
<!-- <exclude name="WordPress.Arrays.ArrayDeclaration.SpaceAfterArrayOpener" /> -->
<!-- <exclude name="WordPress.Arrays.ArrayDeclaration.SpaceAfterDoubleArrow" /> -->
<!-- <exclude name="WordPress.Arrays.ArrayDeclaration.SpaceAfterKeyword" /> -->
<!-- <exclude name="WordPress.Arrays.ArrayDeclaration.SpaceBeforeComma" /> -->
<!-- <exclude name="WordPress.Arrays.ArrayDeclaration.SpaceInEmptyArray" /> -->
<!-- <exclude name="WordPress.Arrays.ArrayDeclaration.ValueNoNewline" /> -->
<!-- <exclude name="WordPress.Arrays.ArrayKeySpacingRestrictions.NoSpacesAroundArrayKeys" /> -->
<!-- <exclude name="WordPress.Arrays.ArrayKeySpacingRestrictions.SpacesAroundArrayKeys" /> -->
<exclude name="WordPress.CSRF.NonceVerification.NoNonceVerification" />
<exclude name="WordPress.Files.FileName.UnderscoresNotAllowed" />
<exclude name="WordPress.NamingConventions.ValidFunctionName.FunctionNameInvalid" />
<exclude name="WordPress.NamingConventions.ValidVariableName.MemberNotSnakeCase" />
<exclude name="WordPress.NamingConventions.ValidVariableName.NotSnakeCase" />
<exclude name="WordPress.NamingConventions.ValidVariableName.NotSnakeCaseMemberVar" />
<exclude name="WordPress.NamingConventions.ValidVariableName.StringNotSnakeCase" />
<exclude name="WordPress.PHP.DiscouragedFunctions.Discouraged" />
<exclude name="WordPress.PHP.DiscouragedFunctions.DiscouragedWithAlternative" />
<exclude name="WordPress.PHP.StrictComparisons.LooseComparison" />
<exclude name="WordPress.PHP.StrictInArray.MissingTrueStrict" />
<exclude name="WordPress.PHP.YodaConditions.NotYoda" />
<exclude name="WordPress.VIP.AdminBarRemoval.RemovalDetected" />
<exclude name="WordPress.VIP.DirectDatabaseQuery.DirectQuery" />
<exclude name="WordPress.VIP.DirectDatabaseQuery.NoCaching" />
<exclude name="WordPress.VIP.DirectDatabaseQuery.SchemaChange" />
<exclude name="WordPress.VIP.FileSystemWritesDisallow.FileWriteDetected" />
<exclude name="WordPress.VIP.OrderByRand.orderby" />
<exclude name="WordPress.VIP.PostsPerPage.posts_per_page" />
<exclude name="WordPress.VIP.RestrictedFunctions.count_user_posts" />
<exclude name="WordPress.VIP.RestrictedFunctions.custom_role" />
<exclude name="WordPress.VIP.RestrictedFunctions.cookies" />
<exclude name="WordPress.VIP.RestrictedFunctions.curl" />
<exclude name="WordPress.VIP.RestrictedFunctions.extract" />
<exclude name="WordPress.VIP.RestrictedFunctions.file_get_contents" />
<exclude name="WordPress.VIP.RestrictedFunctions.get_pages" />
<exclude name="WordPress.VIP.RestrictedFunctions.get_posts" />
<exclude name="WordPress.VIP.RestrictedFunctions.get_term_by" />
<exclude name="WordPress.VIP.RestrictedFunctions.get_term_link" />
<exclude name="WordPress.VIP.RestrictedFunctions.parse_url" />
<exclude name="WordPress.VIP.RestrictedFunctions.url_to_postid" />
<exclude name="WordPress.VIP.RestrictedFunctions.user_meta" />
<exclude name="WordPress.VIP.RestrictedFunctions.wp_get_post_terms" />
<exclude name="WordPress.VIP.RestrictedFunctions.wp_remote_get" />
<exclude name="WordPress.VIP.RestrictedVariables.user_meta" />
<exclude name="WordPress.VIP.RestrictedVariables.cache_constraints" />
<exclude name="WordPress.VIP.SessionFunctionsUsage.session_write_close" />
<exclude name="WordPress.VIP.SlowDBQuery.slow_db_query" />
<exclude name="WordPress.VIP.SuperGlobalInputUsage.AccessDetected" />
<exclude name="WordPress.VIP.ValidatedSanitizedInput.InputNotSanitized" />
<exclude name="WordPress.VIP.ValidatedSanitizedInput.InputNotValidated" />
<exclude name="WordPress.VIP.ValidatedSanitizedInput.MissingUnslash" />
<exclude name="WordPress.Variables.GlobalVariables.OverrideProhibited" />
<exclude name="WordPress.WP.EnqueuedResources.NonEnqueuedScript" />
<exclude name="WordPress.WP.EnqueuedResources.NonEnqueuedStylesheet" />
<exclude name="WordPress.WP.PreparedSQL.NotPrepared" />
<!-- <exclude name="WordPress.WhiteSpace.ControlStructureSpacing.BlankLineAfterEnd" /> -->
<!-- <exclude name="WordPress.WhiteSpace.ControlStructureSpacing.ExtraSpaceAfterCloseParenthesis" /> -->
<!-- <exclude name="WordPress.WhiteSpace.ControlStructureSpacing.NoSpaceAfterCloseParenthesis" /> -->
<!-- <exclude name="WordPress.WhiteSpace.ControlStructureSpacing.NoSpaceAfterOpenParenthesis" /> -->
<!-- <exclude name="WordPress.WhiteSpace.ControlStructureSpacing.NoSpaceAfterStructureOpen" /> -->
<!-- <exclude name="WordPress.WhiteSpace.ControlStructureSpacing.NoSpaceBetweenStructureColon" /> -->
<!-- <exclude name="WordPress.WhiteSpace.ControlStructureSpacing.NoSpaceBeforeCloseParenthesis" /> -->
<!-- <exclude name="WordPress.WhiteSpace.ControlStructureSpacing.NoSpaceBeforeOpenParenthesis" /> -->
<!-- <exclude name="WordPress.WhiteSpace.ControlStructureSpacing.OpenBraceNotSameLine" /> -->
<!-- <exclude name="WordPress.WhiteSpace.ControlStructureSpacing.SpaceBeforeFunctionOpenParenthesis" /> -->
<!-- <exclude name="WordPress.WhiteSpace.OperatorSpacing.NoSpaceAfter" /> -->
<!-- <exclude name="WordPress.WhiteSpace.OperatorSpacing.NoSpaceBefore" /> -->
<!-- <exclude name="WordPress.WhiteSpace.OperatorSpacing.SpacingAfter" /> -->
<!-- <exclude name="WordPress.WhiteSpace.OperatorSpacing.SpacingBefore" /> -->
<exclude name="WordPress.XSS.EscapeOutput.OutputNotEscaped" />
<exclude name="WordPress.XSS.EscapeOutput.UnsafePrintingFunction" />
</rule>
</ruleset>

View File

@ -12,6 +12,19 @@ if [ $1 == 'before' ]; then
composer init --require=satooshi/php-coveralls:0.7.0 -n
composer install --no-interaction
# Install CodeSniffer for WordPress Coding Standards checks.
git clone -b master --depth 1 https://github.com/squizlabs/PHP_CodeSniffer.git /tmp/phpcs
# Install WordPress Coding Standards.
git clone -b master --depth 1 https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards.git /tmp/sniffs
# Install PHP Compatibility sniffs.
git clone -b master --depth 1 https://github.com/wimg/PHPCompatibility.git /tmp/sniffs/PHPCompatibility
# Set install path for PHPCS sniffs.
# @link https://github.com/squizlabs/PHP_CodeSniffer/blob/4237c2fc98cc838730b76ee9cee316f99286a2a7/CodeSniffer.php#L1941
/tmp/phpcs/scripts/phpcs --config-set installed_paths /tmp/sniffs
# After CodeSniffer install you should refresh your path.
phpenv rehash
elif [ $1 == 'after' ]; then
# no Xdebug and therefore no coverage in PHP 5.2