From a76525f4206e636dec72d75dd89410457b646403 Mon Sep 17 00:00:00 2001 From: David Binovec Date: Thu, 10 Aug 2017 14:54:44 +0000 Subject: [PATCH 01/31] PHPCS 3.x compatibility changes This commit makes changes necessary for succesffully runnig the WordPressVIPMinimum standard sniffs against both, PHPCS 2.x and 3.x. Due to the project's dependency on the WPCS, it is now loading the backward compatibility code from the upstream repository and enhances it for some missing parts from there. All tests are now also aliasing the `AbstractSniffUnitTest` if needed - when run against PHPCS 3.x. --- .../Classes/DeclarationCompatibilitySniff.php | 12 +++++---- .../Variables/VariableAnalysisSniff.php | 25 ++++--------------- .../Tests/Actions/PreGetPostsUnitTest.php | 5 ++++ .../Cache/CacheValueOverrideUnitTest.php | 5 ++++ .../DeclarationCompatibilityUnitTest.php | 5 ++++ .../ConstantRestrictionsUnitTest.php | 5 ++++ .../Tests/Files/IncludingFileUnitTest.php | 5 ++++ .../Functions/CheckReturnValueUnitTest.php | 5 ++++ .../Tests/VIP/ErrorControlUnitTest.php | 5 ++++ .../Tests/VIP/FlushRewriteRulesUnitTest.php | 5 ++++ .../Tests/VIP/RegexpCompareUnitTest.php | 5 ++++ .../VIP/RemoteRequestTimeoutUnitTest.php | 5 ++++ .../Tests/VIP/RestrictedFunctionsUnitTest.php | 5 ++++ .../Tests/VIP/StaticStrreplaceUnitTest.php | 5 ++++ WordPressVIPMinimum/autoload.php | 22 ++++++++++++++++ WordPressVIPMinimum/ruleset.xml | 2 ++ 16 files changed, 96 insertions(+), 25 deletions(-) create mode 100644 WordPressVIPMinimum/autoload.php diff --git a/WordPressVIPMinimum/Sniffs/Classes/DeclarationCompatibilitySniff.php b/WordPressVIPMinimum/Sniffs/Classes/DeclarationCompatibilitySniff.php index 9c797388..52b22b96 100644 --- a/WordPressVIPMinimum/Sniffs/Classes/DeclarationCompatibilitySniff.php +++ b/WordPressVIPMinimum/Sniffs/Classes/DeclarationCompatibilitySniff.php @@ -5,11 +5,6 @@ * @package VIPCS\WordPressVIPMinimum */ -if ( false === class_exists( 'PHP_CodeSniffer_Standards_AbstractScopeSniff', true ) ) { - $error = 'Class PHP_CodeSniffer_Standards_AbstractScopeSniff not found'; - throw new PHP_CodeSniffer_Exception( $error ); -} - /** * Class WordPressVIPMinimum_Sniffs_Classes_DeclarationCompatibilitySniff * @@ -361,4 +356,11 @@ protected function loadFunctionNamesInScope( PHP_CodeSniffer_File $phpcsFile, $c }//end loadFunctionNamesInScope() + /** + * Do nothing outside the scope. Has to be implemented accordingly to parent abstract class. + * + * @param File $phpcsFile + * @param $stackPtr + */ + public function processTokenOutsideScope( PHP_CodeSniffer_File $phpcsFile, $stackPtr) {} } diff --git a/WordPressVIPMinimum/Sniffs/Variables/VariableAnalysisSniff.php b/WordPressVIPMinimum/Sniffs/Variables/VariableAnalysisSniff.php index 016e5afc..f3aef2c2 100644 --- a/WordPressVIPMinimum/Sniffs/Variables/VariableAnalysisSniff.php +++ b/WordPressVIPMinimum/Sniffs/Variables/VariableAnalysisSniff.php @@ -679,7 +679,6 @@ protected function checkForFunctionPrototype( $currScope ) { $tokens = $phpcsFile->getTokens(); - $token = $tokens[$stackPtr]; // Are we a function or closure parameter? // It would be nice to get the list of function parameters from watching for @@ -744,7 +743,6 @@ protected function checkForCatchBlock( $currScope ) { $tokens = $phpcsFile->getTokens(); - $token = $tokens[$stackPtr]; // Are we a catch block parameter? if (($openPtr = $this->findContainingBrackets($phpcsFile, $stackPtr)) === false) { @@ -807,7 +805,6 @@ protected function checkForSuperGlobal( $currScope ) { $tokens = $phpcsFile->getTokens(); - $token = $tokens[$stackPtr]; // Are we a superglobal variable? if (in_array($varName, array( @@ -892,7 +889,6 @@ protected function checkForAssignment( $currScope ) { $tokens = $phpcsFile->getTokens(); - $token = $tokens[$stackPtr]; // Is the next non-whitespace an assignment? if (($assignPtr = $this->isNextThingAnAssign($phpcsFile, $stackPtr)) === false) { @@ -914,7 +910,6 @@ protected function checkForListAssignment( $currScope ) { $tokens = $phpcsFile->getTokens(); - $token = $tokens[$stackPtr]; // OK, are we within a list (...) construct? if (($openPtr = $this->findContainingBrackets($phpcsFile, $stackPtr)) === false) { @@ -945,7 +940,6 @@ protected function checkForGlobalDeclaration( $currScope ) { $tokens = $phpcsFile->getTokens(); - $token = $tokens[$stackPtr]; // Are we a global declaration? // Search backwards for first token that isn't whitespace, comma or variable. @@ -968,7 +962,6 @@ protected function checkForStaticDeclaration( $currScope ) { $tokens = $phpcsFile->getTokens(); - $token = $tokens[$stackPtr]; // Are we a static declaration? // Static declarations are a bit more complicated than globals, since they @@ -1032,7 +1025,6 @@ protected function checkForForeachLoopVar( $currScope ) { $tokens = $phpcsFile->getTokens(); - $token = $tokens[$stackPtr]; // Are we a foreach loopvar? if (($openPtr = $this->findContainingBrackets($phpcsFile, $stackPtr)) === false) { @@ -1055,7 +1047,6 @@ protected function checkForPassByReferenceFunctionCall( $currScope ) { $tokens = $phpcsFile->getTokens(); - $token = $tokens[$stackPtr]; // Are we pass-by-reference to known pass-by-reference function? if (($functionPtr = $this->findFunctionCall($phpcsFile, $stackPtr)) === false) { @@ -1148,8 +1139,6 @@ protected function processMemberVar( PHP_CodeSniffer_File $phpcsFile, $stackPtr ) { - $tokens = $phpcsFile->getTokens(); - $token = $tokens[$stackPtr]; // TODO: don't care for now } @@ -1307,14 +1296,13 @@ protected function processVariableInString( } protected function processCompactArguments( - PHP_CodeSniffer_File - $phpcsFile, + PHP_CodeSniffer_File $phpcsFile, $stackPtr, $arguments, $currScope ) { + $this->phpcsFile = $phpcsFile; $tokens = $phpcsFile->getTokens(); - $token = $tokens[$stackPtr]; foreach ($arguments as $argumentPtrs) { $argumentPtrs = array_values(array_filter($argumentPtrs, array( $this, 'filter_non_whitespace_tokens' ) )); @@ -1368,12 +1356,10 @@ protected function processCompactArguments( * @return void */ protected function processCompact( - PHP_CodeSniffer_File - $phpcsFile, + PHP_CodeSniffer_File $phpcsFile, $stackPtr ) { $tokens = $phpcsFile->getTokens(); - $token = $tokens[$stackPtr]; $currScope = $this->findVariableScope($phpcsFile, $stackPtr); @@ -1395,8 +1381,7 @@ protected function processCompact( * @return void */ protected function processScopeClose( - PHP_CodeSniffer_File - $phpcsFile, + PHP_CodeSniffer_File $phpcsFile, $stackPtr ) { $scopeInfo = $this->getScopeInfo($stackPtr, false); @@ -1443,7 +1428,7 @@ protected function processScopeClose( } function filter_non_whitespace_tokens($argumentPtr) { - $tokens = $phpcsFile->getTokens(); + $tokens = $this->phpcsFile->getTokens(); return $tokens[$argumentPtr]['code'] !== T_WHITESPACE; } }//end class diff --git a/WordPressVIPMinimum/Tests/Actions/PreGetPostsUnitTest.php b/WordPressVIPMinimum/Tests/Actions/PreGetPostsUnitTest.php index ca0dc433..45c53645 100644 --- a/WordPressVIPMinimum/Tests/Actions/PreGetPostsUnitTest.php +++ b/WordPressVIPMinimum/Tests/Actions/PreGetPostsUnitTest.php @@ -5,6 +5,11 @@ * @package VIPCS\WordPressVIPMinimum */ +// Cross version compatibility for PHPCS 2.x and 3.x. +if ( ! class_exists( '\AbstractSniffUnitTest' ) ) { + class_alias( '\PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest', '\AbstractSniffUnitTest' ); +} + /** * Unit test class for the PreGetPosts sniff. * diff --git a/WordPressVIPMinimum/Tests/Cache/CacheValueOverrideUnitTest.php b/WordPressVIPMinimum/Tests/Cache/CacheValueOverrideUnitTest.php index eef1e8fc..91c7b90d 100644 --- a/WordPressVIPMinimum/Tests/Cache/CacheValueOverrideUnitTest.php +++ b/WordPressVIPMinimum/Tests/Cache/CacheValueOverrideUnitTest.php @@ -5,6 +5,11 @@ * @package VIPCS\WordPressVIPMinimum */ +// Cross version compatibility for PHPCS 2.x and 3.x. +if ( ! class_exists( '\AbstractSniffUnitTest' ) ) { + class_alias( '\PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest', '\AbstractSniffUnitTest' ); +} + /** * Unit test class for the CacheValueOverride sniff. * diff --git a/WordPressVIPMinimum/Tests/Classes/DeclarationCompatibilityUnitTest.php b/WordPressVIPMinimum/Tests/Classes/DeclarationCompatibilityUnitTest.php index 2d99e5b6..fcacc44c 100644 --- a/WordPressVIPMinimum/Tests/Classes/DeclarationCompatibilityUnitTest.php +++ b/WordPressVIPMinimum/Tests/Classes/DeclarationCompatibilityUnitTest.php @@ -5,6 +5,11 @@ * @package VIPCS\WordPressVIPMinimum */ +// Cross version compatibility for PHPCS 2.x and 3.x. +if ( ! class_exists( '\AbstractSniffUnitTest' ) ) { + class_alias( '\PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest', '\AbstractSniffUnitTest' ); +} + /** * Unit test class for the DeclarationCompatibility sniff. * diff --git a/WordPressVIPMinimum/Tests/Constants/ConstantRestrictionsUnitTest.php b/WordPressVIPMinimum/Tests/Constants/ConstantRestrictionsUnitTest.php index 2ec599f4..9406deb0 100644 --- a/WordPressVIPMinimum/Tests/Constants/ConstantRestrictionsUnitTest.php +++ b/WordPressVIPMinimum/Tests/Constants/ConstantRestrictionsUnitTest.php @@ -5,6 +5,11 @@ * @package VIPCS\WordPressVIPMinimum */ +// Cross version compatibility for PHPCS 2.x and 3.x. +if ( ! class_exists( '\AbstractSniffUnitTest' ) ) { + class_alias( '\PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest', '\AbstractSniffUnitTest' ); +} + /** * Unit test class for the ConstantRestrictions sniff. * diff --git a/WordPressVIPMinimum/Tests/Files/IncludingFileUnitTest.php b/WordPressVIPMinimum/Tests/Files/IncludingFileUnitTest.php index 662162a5..c3a1af4d 100644 --- a/WordPressVIPMinimum/Tests/Files/IncludingFileUnitTest.php +++ b/WordPressVIPMinimum/Tests/Files/IncludingFileUnitTest.php @@ -5,6 +5,11 @@ * @package VIPCS\WordPressVIPMinimum */ +// Cross version compatibility for PHPCS 2.x and 3.x. +if ( ! class_exists( '\AbstractSniffUnitTest' ) ) { + class_alias( '\PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest', '\AbstractSniffUnitTest' ); +} + /** * Unit test class for the IncludingFile sniff. * diff --git a/WordPressVIPMinimum/Tests/Functions/CheckReturnValueUnitTest.php b/WordPressVIPMinimum/Tests/Functions/CheckReturnValueUnitTest.php index 6411342d..8295345c 100644 --- a/WordPressVIPMinimum/Tests/Functions/CheckReturnValueUnitTest.php +++ b/WordPressVIPMinimum/Tests/Functions/CheckReturnValueUnitTest.php @@ -5,6 +5,11 @@ * @package VIPCS\WordPressVIPMinimum */ +// Cross version compatibility for PHPCS 2.x and 3.x. +if ( ! class_exists( '\AbstractSniffUnitTest' ) ) { + class_alias( '\PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest', '\AbstractSniffUnitTest' ); +} + /** * Unit test class for the CheckReturnValue sniff. * diff --git a/WordPressVIPMinimum/Tests/VIP/ErrorControlUnitTest.php b/WordPressVIPMinimum/Tests/VIP/ErrorControlUnitTest.php index 7749caab..e740d2d4 100644 --- a/WordPressVIPMinimum/Tests/VIP/ErrorControlUnitTest.php +++ b/WordPressVIPMinimum/Tests/VIP/ErrorControlUnitTest.php @@ -5,6 +5,11 @@ * @package VIPCS\WordPressVIPMinimum */ +// Cross version compatibility for PHPCS 2.x and 3.x. +if ( ! class_exists( '\AbstractSniffUnitTest' ) ) { + class_alias( '\PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest', '\AbstractSniffUnitTest' ); +} + /** * Unit test class for the ErrorControl sniff. * diff --git a/WordPressVIPMinimum/Tests/VIP/FlushRewriteRulesUnitTest.php b/WordPressVIPMinimum/Tests/VIP/FlushRewriteRulesUnitTest.php index 210e1a7c..4cc081df 100644 --- a/WordPressVIPMinimum/Tests/VIP/FlushRewriteRulesUnitTest.php +++ b/WordPressVIPMinimum/Tests/VIP/FlushRewriteRulesUnitTest.php @@ -5,6 +5,11 @@ * @package VIPCS\WordPressVIPMinimum */ +// Cross version compatibility for PHPCS 2.x and 3.x. +if ( ! class_exists( '\AbstractSniffUnitTest' ) ) { + class_alias( '\PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest', '\AbstractSniffUnitTest' ); +} + /** * Unit test class for the FlushRewriteRules sniff. * diff --git a/WordPressVIPMinimum/Tests/VIP/RegexpCompareUnitTest.php b/WordPressVIPMinimum/Tests/VIP/RegexpCompareUnitTest.php index ff60b22b..d0789962 100644 --- a/WordPressVIPMinimum/Tests/VIP/RegexpCompareUnitTest.php +++ b/WordPressVIPMinimum/Tests/VIP/RegexpCompareUnitTest.php @@ -5,6 +5,11 @@ * @package VIPCS\WordPressVIPMinimum */ +// Cross version compatibility for PHPCS 2.x and 3.x. +if ( ! class_exists( '\AbstractSniffUnitTest' ) ) { + class_alias( '\PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest', '\AbstractSniffUnitTest' ); +} + /** * Unit test class for the RegexpCompare sniff. * diff --git a/WordPressVIPMinimum/Tests/VIP/RemoteRequestTimeoutUnitTest.php b/WordPressVIPMinimum/Tests/VIP/RemoteRequestTimeoutUnitTest.php index 37ebcf1e..70849614 100644 --- a/WordPressVIPMinimum/Tests/VIP/RemoteRequestTimeoutUnitTest.php +++ b/WordPressVIPMinimum/Tests/VIP/RemoteRequestTimeoutUnitTest.php @@ -5,6 +5,11 @@ * @package VIPCS\WordPressVIPMinimum */ +// Cross version compatibility for PHPCS 2.x and 3.x. +if ( ! class_exists( '\AbstractSniffUnitTest' ) ) { + class_alias( '\PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest', '\AbstractSniffUnitTest' ); +} + /** * Unit test class for the RemoteRequestTimeout sniff. * diff --git a/WordPressVIPMinimum/Tests/VIP/RestrictedFunctionsUnitTest.php b/WordPressVIPMinimum/Tests/VIP/RestrictedFunctionsUnitTest.php index 58742809..626020cc 100644 --- a/WordPressVIPMinimum/Tests/VIP/RestrictedFunctionsUnitTest.php +++ b/WordPressVIPMinimum/Tests/VIP/RestrictedFunctionsUnitTest.php @@ -5,6 +5,11 @@ * @package VIPCS\WordPressVIPMinimum */ +// Cross version compatibility for PHPCS 2.x and 3.x. +if ( ! class_exists( '\AbstractSniffUnitTest' ) ) { + class_alias( '\PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest', '\AbstractSniffUnitTest' ); +} + /** * Unit test class for the RestrictedFunctions sniff. * diff --git a/WordPressVIPMinimum/Tests/VIP/StaticStrreplaceUnitTest.php b/WordPressVIPMinimum/Tests/VIP/StaticStrreplaceUnitTest.php index 43b80b53..afb469e2 100644 --- a/WordPressVIPMinimum/Tests/VIP/StaticStrreplaceUnitTest.php +++ b/WordPressVIPMinimum/Tests/VIP/StaticStrreplaceUnitTest.php @@ -5,6 +5,11 @@ * @package VIPCS\WordPressVIPMinimum */ +// Cross version compatibility for PHPCS 2.x and 3.x. +if ( ! class_exists( '\AbstractSniffUnitTest' ) ) { + class_alias( '\PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest', '\AbstractSniffUnitTest' ); +} + /** * Unit test class for the StaticStrreplace sniff. * diff --git a/WordPressVIPMinimum/autoload.php b/WordPressVIPMinimum/autoload.php new file mode 100644 index 00000000..1659fbf5 --- /dev/null +++ b/WordPressVIPMinimum/autoload.php @@ -0,0 +1,22 @@ + $details ) { + if ( 'WordPress' === $standard ) { + require_once( $details['path'] . '/PHPCSAliases.php' ); + } + } + if ( ! class_exists( '\PHP_CodeSniffer_Standards_AbstractScopeSniff' ) ) { + class_alias( 'PHP_CodeSniffer\Sniffs\AbstractScopeSniff', '\PHP_CodeSniffer_Standards_AbstractScopeSniff' ); + } + if ( ! class_exists( '\WordPress_AbstractArrayAssignmentRestrictionsSniff' ) ) { + class_alias( '\WordPress\AbstractArrayAssignmentRestrictionsSniff', '\WordPress_AbstractArrayAssignmentRestrictionsSniff' ); + } + if ( ! class_exists( '\WordPress_Sniffs_VIP_RestrictedFunctionsSniff' ) ) { + class_alias( '\WordPress\Sniffs\VIP\RestrictedFunctionsSniff', '\WordPress_Sniffs_VIP_RestrictedFunctionsSniff' ); + } +} + +load_phpcs_helper_file(); \ No newline at end of file diff --git a/WordPressVIPMinimum/ruleset.xml b/WordPressVIPMinimum/ruleset.xml index 3c31ad15..27c22d6b 100644 --- a/WordPressVIPMinimum/ruleset.xml +++ b/WordPressVIPMinimum/ruleset.xml @@ -2,6 +2,8 @@ WordPress VIP Minimum Coding Standards + ./autoload.php + From c87ebc6c8e4a381247f8915c220c4d1a3da5c50e Mon Sep 17 00:00:00 2001 From: David Binovec Date: Thu, 10 Aug 2017 15:02:58 +0000 Subject: [PATCH 02/31] Dropping support for PHP 5.2 and 5.3 from Travis tests. Since the upstream repositories, both PHPCS and WPCS, have dropped support for PHP 5.2, we should as well. --- .travis.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index e9f260ed..8ed3f37a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,8 +4,6 @@ language: - php php: - - 5.2 - - 5.3 - 5.4 - 5.5 - 5.6 From 53c67f646b0ce3cf99b081c2288b88bc5fda3e85 Mon Sep 17 00:00:00 2001 From: David Binovec Date: Thu, 10 Aug 2017 15:43:06 +0000 Subject: [PATCH 03/31] Making the PHP_CS standards dir compatible across versions ( 2.9 vs. 3.0 ) --- .travis.yml | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/.travis.yml b/.travis.yml index 8ed3f37a..df8b5340 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,7 +12,7 @@ php: env: - PHPCS_BRANCH=master - - PHPCS_BRANCH=2.8.1 + - PHPCS_BRANCH=2.9 matrix: fast_finish: true @@ -45,14 +45,15 @@ before_script: - export PATH="$HOME/.composer/vendor/bin:$PATH" - export PHPCS_DIR=/tmp/phpcs - export WPCS_DIR=/tmp/wpcs + - export PHPCS_STANDARDS_DIR =$(if [[ $PHPCS_BRANCH == 2.9 ]]; then echo "src"; else echo "CodeSniffer"; fi) - export PHPCS_BIN=$(if [[ $PHPCS_BRANCH == 3.0 ]]; then echo $PHPCS_DIR/bin/phpcs; else echo $PHPCS_DIR/scripts/phpcs; fi) - mkdir -p $PHPCS_DIR && git clone --depth 1 https://github.com/squizlabs/PHP_CodeSniffer.git -b $PHPCS_BRANCH $PHPCS_DIR - mkdir -p $WPCS_DIR && git clone --depth 1 https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards.git -b master $WPCS_DIR - - ln -s $WPCS_DIR/WordPress $PHPCS_DIR/CodeSniffer/Standards/WordPress - - ln -s $WPCS_DIR/WordPress-Core $PHPCS_DIR/CodeSniffer/Standards/WordPress-Core - - ln -s $WPCS_DIR/WordPress-Docs $PHPCS_DIR/CodeSniffer/Standards/WordPress-Docs - - ln -s $WPCS_DIR/WordPress-Extra $PHPCS_DIR/CodeSniffer/Standards/WordPress-Extra - - ln -s $WPCS_DIR/WordPress-VIP $PHPCS_DIR/CodeSniffer/Standards/WordPress-VIP + - ln -s $WPCS_DIR/WordPress $PHPCS_DIR/$PHPCS_STANDARDS_DIR/Standards/WordPress + - ln -s $WPCS_DIR/WordPress-Core $PHPCS_DIR/$PHPCS_STANDARDS_DIR/Standards/WordPress-Core + - ln -s $WPCS_DIR/WordPress-Docs $PHPCS_DIR/$PHPCS_STANDARDS_DIR/Standards/WordPress-Docs + - ln -s $WPCS_DIR/WordPress-Extra $PHPCS_DIR/$PHPCS_STANDARDS_DIR/Standards/WordPress-Extra + - ln -s $WPCS_DIR/WordPress-VIP $PHPCS_DIR/$PHPCS_STANDARDS_DIR/Standards/WordPress-VIP - $PHPCS_BIN --config-set installed_paths $(pwd) - | if [[ ${TRAVIS_PHP_VERSION:0:2} == "7." ]]; then From 50e7066229c8b703f17015adbe7a24ae870ebf7c Mon Sep 17 00:00:00 2001 From: David Binovec Date: Thu, 10 Aug 2017 15:51:40 +0000 Subject: [PATCH 04/31] Fix the PHPCS_STANDARDS_DIR env variable command --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index df8b5340..1e3c3f1e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,7 +12,7 @@ php: env: - PHPCS_BRANCH=master - - PHPCS_BRANCH=2.9 + - PHPCS_BRANCH=2.9.0 matrix: fast_finish: true @@ -45,7 +45,7 @@ before_script: - export PATH="$HOME/.composer/vendor/bin:$PATH" - export PHPCS_DIR=/tmp/phpcs - export WPCS_DIR=/tmp/wpcs - - export PHPCS_STANDARDS_DIR =$(if [[ $PHPCS_BRANCH == 2.9 ]]; then echo "src"; else echo "CodeSniffer"; fi) + - export PHPCS_STANDARDS_DIR=$(if [[ ${PHPCS_BRANCH:0:2} == "2." ]]; then echo "src"; else echo "CodeSniffer"; fi) - export PHPCS_BIN=$(if [[ $PHPCS_BRANCH == 3.0 ]]; then echo $PHPCS_DIR/bin/phpcs; else echo $PHPCS_DIR/scripts/phpcs; fi) - mkdir -p $PHPCS_DIR && git clone --depth 1 https://github.com/squizlabs/PHP_CodeSniffer.git -b $PHPCS_BRANCH $PHPCS_DIR - mkdir -p $WPCS_DIR && git clone --depth 1 https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards.git -b master $WPCS_DIR From 6a963e14aa882b30bf18bd64b6a6be67ea18b7ca Mon Sep 17 00:00:00 2001 From: David Binovec Date: Thu, 10 Aug 2017 15:59:03 +0000 Subject: [PATCH 05/31] Moar changes to the travis config file --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 1e3c3f1e..dbafa1db 100644 --- a/.travis.yml +++ b/.travis.yml @@ -45,7 +45,7 @@ before_script: - export PATH="$HOME/.composer/vendor/bin:$PATH" - export PHPCS_DIR=/tmp/phpcs - export WPCS_DIR=/tmp/wpcs - - export PHPCS_STANDARDS_DIR=$(if [[ ${PHPCS_BRANCH:0:2} == "2." ]]; then echo "src"; else echo "CodeSniffer"; fi) + - export PHPCS_STANDARDS_DIR=$(if [[ ${PHPCS_BRANCH:0:2} == "2." ]]; then echo "CodeSniffer"; else echo "src"; fi) - export PHPCS_BIN=$(if [[ $PHPCS_BRANCH == 3.0 ]]; then echo $PHPCS_DIR/bin/phpcs; else echo $PHPCS_DIR/scripts/phpcs; fi) - mkdir -p $PHPCS_DIR && git clone --depth 1 https://github.com/squizlabs/PHP_CodeSniffer.git -b $PHPCS_BRANCH $PHPCS_DIR - mkdir -p $WPCS_DIR && git clone --depth 1 https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards.git -b master $WPCS_DIR From 05fe4ae6dcdc0500b1bd9d41727ea86011bdd062 Mon Sep 17 00:00:00 2001 From: David Binovec Date: Thu, 10 Aug 2017 16:05:30 +0000 Subject: [PATCH 06/31] Fixing PHPCS_BIN path for master branch of the PHPCS --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index dbafa1db..c81e3d42 100644 --- a/.travis.yml +++ b/.travis.yml @@ -46,7 +46,7 @@ before_script: - export PHPCS_DIR=/tmp/phpcs - export WPCS_DIR=/tmp/wpcs - export PHPCS_STANDARDS_DIR=$(if [[ ${PHPCS_BRANCH:0:2} == "2." ]]; then echo "CodeSniffer"; else echo "src"; fi) - - export PHPCS_BIN=$(if [[ $PHPCS_BRANCH == 3.0 ]]; then echo $PHPCS_DIR/bin/phpcs; else echo $PHPCS_DIR/scripts/phpcs; fi) + - export PHPCS_BIN=$(if [[ ${PHPCS_BRANCH:0:2} != 2. ]]; then echo $PHPCS_DIR/bin/phpcs; else echo $PHPCS_DIR/scripts/phpcs; fi) - mkdir -p $PHPCS_DIR && git clone --depth 1 https://github.com/squizlabs/PHP_CodeSniffer.git -b $PHPCS_BRANCH $PHPCS_DIR - mkdir -p $WPCS_DIR && git clone --depth 1 https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards.git -b master $WPCS_DIR - ln -s $WPCS_DIR/WordPress $PHPCS_DIR/$PHPCS_STANDARDS_DIR/Standards/WordPress From 54a23bde67866e9c4e98f4a625ac7897f74c7cc5 Mon Sep 17 00:00:00 2001 From: David Binovec Date: Thu, 10 Aug 2017 16:56:43 +0000 Subject: [PATCH 07/31] Fixing project's PHPCS styling issues --- .../Sniffs/Actions/PreGetPostsSniff.php | 4 ++-- .../Sniffs/Cache/CacheValueOverrideSniff.php | 4 ++-- .../Classes/DeclarationCompatibilitySniff.php | 20 +++++++++---------- .../Constants/ConstantRestrictionsSniff.php | 2 +- .../Sniffs/Files/IncludingFileSniff.php | 4 ++-- .../Functions/CheckReturnValueSniff.php | 2 +- .../Sniffs/VIP/ErrorControlSniff.php | 4 ++-- .../Sniffs/VIP/FlushRewriteRulesSniff.php | 2 +- .../Sniffs/VIP/RegexpCompareSniff.php | 14 ++++++------- .../Sniffs/VIP/RemoteRequestTimeoutSniff.php | 14 ++++++------- .../Sniffs/VIP/StaticStrreplaceSniff.php | 2 +- WordPressVIPMinimum/autoload.php | 17 ++++++++++++++-- 12 files changed, 51 insertions(+), 38 deletions(-) diff --git a/WordPressVIPMinimum/Sniffs/Actions/PreGetPostsSniff.php b/WordPressVIPMinimum/Sniffs/Actions/PreGetPostsSniff.php index 7563f683..3bd5372f 100644 --- a/WordPressVIPMinimum/Sniffs/Actions/PreGetPostsSniff.php +++ b/WordPressVIPMinimum/Sniffs/Actions/PreGetPostsSniff.php @@ -43,8 +43,8 @@ public function register() { * Processes the tokens that this sniff is interested in. * * @param PHP_CodeSniffer_File $phpcsFile The file where the token was found. - * @param int $stackPtr The position in the stack where - * the token was found. + * @param int $stackPtr The position in the stack where + * the token was found. * * @return void */ diff --git a/WordPressVIPMinimum/Sniffs/Cache/CacheValueOverrideSniff.php b/WordPressVIPMinimum/Sniffs/Cache/CacheValueOverrideSniff.php index c68342f4..c368004e 100644 --- a/WordPressVIPMinimum/Sniffs/Cache/CacheValueOverrideSniff.php +++ b/WordPressVIPMinimum/Sniffs/Cache/CacheValueOverrideSniff.php @@ -40,8 +40,8 @@ public function register() { * Processes the tokens that this sniff is interested in. * * @param PHP_CodeSniffer_File $phpcsFile The file where the token was found. - * @param int $stackPtr The position in the stack where - * the token was found. + * @param int $stackPtr The position in the stack where + * the token was found. * * @return void */ diff --git a/WordPressVIPMinimum/Sniffs/Classes/DeclarationCompatibilitySniff.php b/WordPressVIPMinimum/Sniffs/Classes/DeclarationCompatibilitySniff.php index 52b22b96..c4429321 100644 --- a/WordPressVIPMinimum/Sniffs/Classes/DeclarationCompatibilitySniff.php +++ b/WordPressVIPMinimum/Sniffs/Classes/DeclarationCompatibilitySniff.php @@ -99,7 +99,7 @@ class WordPressVIPMinimum_Sniffs_Classes_DeclarationCompatibilitySniff extends P ), 'args' => array( 'default' => 'array()', - ), + ), ), 'start_el' => array( 'output' => array( @@ -279,12 +279,12 @@ protected function processTokenWithinScope( PHP_CodeSniffer_File $phpcsFile, $st /** * Generates an error with nice current and parent class method notations * - * @param string $parentClassName The name of the extended (parent) class. - * @param string $methodName The name of the method currently being examined. - * @param array $currentMethodSignature The list of params and their options of the method which is being examined. - * @param array $parentMethodSignature The list of params and their options of the parent class method. - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token in the stack. + * @param string $parentClassName The name of the extended (parent) class. + * @param string $methodName The name of the method currently being examined. + * @param array $currentMethodSignature The list of params and their options of the method which is being examined. + * @param array $parentMethodSignature The list of params and their options of the parent class method. + * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. + * @param int $stackPtr The position of the current token in the stack. * * @return void */ @@ -359,8 +359,8 @@ protected function loadFunctionNamesInScope( PHP_CodeSniffer_File $phpcsFile, $c /** * Do nothing outside the scope. Has to be implemented accordingly to parent abstract class. * - * @param File $phpcsFile - * @param $stackPtr + * @param PHP_CodeSniffer_File $phpcsFile PHPCS File. + * @param int $stackPtr Stack position. */ - public function processTokenOutsideScope( PHP_CodeSniffer_File $phpcsFile, $stackPtr) {} + public function processTokenOutsideScope( PHP_CodeSniffer_File $phpcsFile, $stackPtr ) {} } diff --git a/WordPressVIPMinimum/Sniffs/Constants/ConstantRestrictionsSniff.php b/WordPressVIPMinimum/Sniffs/Constants/ConstantRestrictionsSniff.php index 2de9bcbb..9be7501a 100644 --- a/WordPressVIPMinimum/Sniffs/Constants/ConstantRestrictionsSniff.php +++ b/WordPressVIPMinimum/Sniffs/Constants/ConstantRestrictionsSniff.php @@ -38,7 +38,7 @@ public function register() { * Process this test when one of its tokens is encoutnered * * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token in the stack passed in $tokens. + * @param int $stackPtr The position of the current token in the stack passed in $tokens. * * @return void */ diff --git a/WordPressVIPMinimum/Sniffs/Files/IncludingFileSniff.php b/WordPressVIPMinimum/Sniffs/Files/IncludingFileSniff.php index b963a78d..40dee8da 100644 --- a/WordPressVIPMinimum/Sniffs/Files/IncludingFileSniff.php +++ b/WordPressVIPMinimum/Sniffs/Files/IncludingFileSniff.php @@ -74,8 +74,8 @@ public function register() { * Processes this test, when one of its tokens is encountered. * * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token in the - * stack passed in $tokens. + * @param int $stackPtr The position of the current token in the + * stack passed in $tokens. * * @return void */ diff --git a/WordPressVIPMinimum/Sniffs/Functions/CheckReturnValueSniff.php b/WordPressVIPMinimum/Sniffs/Functions/CheckReturnValueSniff.php index de10313e..6d167005 100644 --- a/WordPressVIPMinimum/Sniffs/Functions/CheckReturnValueSniff.php +++ b/WordPressVIPMinimum/Sniffs/Functions/CheckReturnValueSniff.php @@ -73,7 +73,7 @@ public function register() { * * @param PHP_CodeSniffer_File $phpcsFile The file where the token was found. * @param int $stackPtr The position in the stack where - * the token was found. + * the token was found. * * @return void */ diff --git a/WordPressVIPMinimum/Sniffs/VIP/ErrorControlSniff.php b/WordPressVIPMinimum/Sniffs/VIP/ErrorControlSniff.php index d50f004f..3b578770 100644 --- a/WordPressVIPMinimum/Sniffs/VIP/ErrorControlSniff.php +++ b/WordPressVIPMinimum/Sniffs/VIP/ErrorControlSniff.php @@ -20,7 +20,7 @@ class WordPressVIPMinimum_Sniffs_VIP_ErrorControlSniff implements PHP_CodeSniffe */ public function register() { return array( - T_ASPERAND + T_ASPERAND, ); } @@ -28,7 +28,7 @@ public function register() { * Process this test when one of its tokens is encoutered * * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token in the stack passed in $tokens. + * @param int $stackPtr The position of the current token in the stack passed in $tokens. * * @return void */ diff --git a/WordPressVIPMinimum/Sniffs/VIP/FlushRewriteRulesSniff.php b/WordPressVIPMinimum/Sniffs/VIP/FlushRewriteRulesSniff.php index 3a73d868..50ffbc5e 100644 --- a/WordPressVIPMinimum/Sniffs/VIP/FlushRewriteRulesSniff.php +++ b/WordPressVIPMinimum/Sniffs/VIP/FlushRewriteRulesSniff.php @@ -26,7 +26,7 @@ public function register() { * Process this test when one of its tokens is encountered. * * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token in the stack passed in $tokens. + * @param int $stackPtr The position of the current token in the stack passed in $tokens. * * @return void */ diff --git a/WordPressVIPMinimum/Sniffs/VIP/RegexpCompareSniff.php b/WordPressVIPMinimum/Sniffs/VIP/RegexpCompareSniff.php index 3415015b..3c05078e 100644 --- a/WordPressVIPMinimum/Sniffs/VIP/RegexpCompareSniff.php +++ b/WordPressVIPMinimum/Sniffs/VIP/RegexpCompareSniff.php @@ -17,13 +17,13 @@ class WordPressVIPMinimum_Sniffs_VIP_RegexpCompareSniff extends WordPress_Abstra * This should be overridden in extending classes. * * Example: groups => array( - * 'wpdb' => array( - * 'type' => 'error' | 'warning', - * 'message' => 'Dont use this one please!', - * 'variables' => array( '$val', '$var' ), - * 'object_vars' => array( '$foo->bar', .. ), - * 'array_members' => array( '$foo['bar']', .. ), - * ) + * 'wpdb' => array( + * 'type' => 'error' | 'warning', + * 'message' => 'Dont use this one please!', + * 'variables' => array( '$val', '$var' ), + * 'object_vars' => array( '$foo->bar', .. ), + * 'array_members' => array( '$foo['bar']', .. ), + * ) * ) * * @return array diff --git a/WordPressVIPMinimum/Sniffs/VIP/RemoteRequestTimeoutSniff.php b/WordPressVIPMinimum/Sniffs/VIP/RemoteRequestTimeoutSniff.php index a63adfb5..8c60236e 100644 --- a/WordPressVIPMinimum/Sniffs/VIP/RemoteRequestTimeoutSniff.php +++ b/WordPressVIPMinimum/Sniffs/VIP/RemoteRequestTimeoutSniff.php @@ -17,13 +17,13 @@ class WordPressVIPMinimum_Sniffs_VIP_RemoteRequestTimeoutSniff extends WordPress * This should be overridden in extending classes. * * Example: groups => array( - * 'wpdb' => array( - * 'type' => 'error' | 'warning', - * 'message' => 'Dont use this one please!', - * 'variables' => array( '$val', '$var' ), - * 'object_vars' => array( '$foo->bar', .. ), - * 'array_members' => array( '$foo['bar']', .. ), - * ) + * 'wpdb' => array( + * 'type' => 'error' | 'warning', + * 'message' => 'Dont use this one please!', + * 'variables' => array( '$val', '$var' ), + * 'object_vars' => array( '$foo->bar', .. ), + * 'array_members' => array( '$foo['bar']', .. ), + * ) * ) * * @return array diff --git a/WordPressVIPMinimum/Sniffs/VIP/StaticStrreplaceSniff.php b/WordPressVIPMinimum/Sniffs/VIP/StaticStrreplaceSniff.php index 303a8c76..5fc69312 100644 --- a/WordPressVIPMinimum/Sniffs/VIP/StaticStrreplaceSniff.php +++ b/WordPressVIPMinimum/Sniffs/VIP/StaticStrreplaceSniff.php @@ -26,7 +26,7 @@ public function register() { * Process this test when one of its tokens is encountered * * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token in the stack passed in $tokens. + * @param int $stackPtr The position of the current token in the stack passed in $tokens. * * @return void */ diff --git a/WordPressVIPMinimum/autoload.php b/WordPressVIPMinimum/autoload.php index 1659fbf5..3890f394 100644 --- a/WordPressVIPMinimum/autoload.php +++ b/WordPressVIPMinimum/autoload.php @@ -1,9 +1,21 @@ $details ) { + + foreach ( \PHP_CodeSniffer\Util\Standards::getInstalledStandardDetails( 'WordPress' ) as $standard => $details ) { if ( 'WordPress' === $standard ) { require_once( $details['path'] . '/PHPCSAliases.php' ); } @@ -19,4 +31,5 @@ class_alias( '\WordPress\Sniffs\VIP\RestrictedFunctionsSniff', '\WordPress_Sniff } } -load_phpcs_helper_file(); \ No newline at end of file +load_phpcs_helper_file(); + From b2dff91c95072fdd2f436668e985034dc08b400b Mon Sep 17 00:00:00 2001 From: David Binovec Date: Thu, 10 Aug 2017 17:16:03 +0000 Subject: [PATCH 08/31] Make the phpcs' binary path compatible for both, 2.x and 3.x branch --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index c81e3d42..0439ea4b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -75,5 +75,5 @@ script: # -n flag: Do not print warnings. (shortcut for --warning-severity=0) # --standard: Use WordPress as the standard. # --extensions: Only sniff PHP files. - - if [[ "$SNIFF" == "1" ]]; then $PHPCS_DIR/scripts/phpcs -p -s -n . --standard=./bin/phpcs.xml --extensions=php; fi + - if [[ "$SNIFF" == "1" ]]; then $PHPCS_DIR/$( if [[ ${PHPCS_BRANCH:0:2} == "2." ]]; then echo "scripts"; else echo "bin"; fi; )/phpcs -p -s -n . --standard=./bin/phpcs.xml --extensions=php; fi - if [[ "$INTEGRATION_TEST" == "1" ]]; then php ./ruleset_test.php; fi From 1f16e9ec62b7901bee7330d905b38b13de5c45d7 Mon Sep 17 00:00:00 2001 From: David Binovec Date: Fri, 11 Aug 2017 08:52:38 +0000 Subject: [PATCH 09/31] Using slightly modified Travis configuration from the upstream repository (WPCS). The modifications contain: * Adding both, VIPCS and WPCS to the PHPCS installed pats config * Running phpunit with loaded AllTests.php from WPCS * Adjusting the paths of XML files which are being linted --- .travis.yml | 90 +++++++++++++++++++++++++++++++---------------------- 1 file changed, 53 insertions(+), 37 deletions(-) diff --git a/.travis.yml b/.travis.yml index 0439ea4b..af1b68e6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,10 @@ sudo: false +dist: trusty + +cache: + apt: true + language: - php @@ -9,63 +14,69 @@ php: - 5.6 - 7.0 - 7.1 + - nightly env: - - PHPCS_BRANCH=master - - PHPCS_BRANCH=2.9.0 + # `master` is now 3.x. + - PHPCS_BRANCH=master LINT=1 + # Lowest tagged release in the 2.x series with which WPCS is compatible. + - PHPCS_BRANCH=2.9.0 matrix: fast_finish: true include: - # Run PHPCS against WPCS. I just picked to run it against 5.5. - - php: 5.5 + # Run PHPCS against WPCS. I just picked to run it against 7.0. + - php: 7.0 env: PHPCS_BRANCH=master SNIFF=1 - # Run against PHPCS 3.0. I just picked to run it against 5.6. - - php: 5.6 - env: PHPCS_BRANCH=3.0 + addons: + apt: + packages: + - libxml2-utils + # Run against HHVM and PHP nightly. - php: hhvm sudo: required dist: trusty group: edge - env: PHPCS_BRANCH=master - - php: nightly - env: PHPCS_BRANCH=master - # Run custom integration test. I just picked to run it against 7.0. - - php: 7.0 - env: PHPCS_BRANCH=master INTEGRATION_TEST=1 + env: PHPCS_BRANCH=master LINT=1 + + # Test PHP 5.3 only against PHPCS 2.x as PHPCS 3.x has a minimum requirement of PHP 5.4. + - php: 5.3 + env: PHPCS_BRANCH=2.9 LINT=1 + dist: precise + # Test PHP 5.3 with short_open_tags set to On (is Off by default) + - php: 5.3 + env: PHPCS_BRANCH=2.9.0 SHORT_OPEN_TAGS=true + dist: precise + allow_failures: # Allow failures for unstable builds. - php: nightly - php: hhvm - - env: PHPCS_BRANCH=3.0 - -before_script: - - export PATH="$HOME/.composer/vendor/bin:$PATH" +before_install: + - export XMLLINT_INDENT=" " - export PHPCS_DIR=/tmp/phpcs - - export WPCS_DIR=/tmp/wpcs - - export PHPCS_STANDARDS_DIR=$(if [[ ${PHPCS_BRANCH:0:2} == "2." ]]; then echo "CodeSniffer"; else echo "src"; fi) - - export PHPCS_BIN=$(if [[ ${PHPCS_BRANCH:0:2} != 2. ]]; then echo $PHPCS_DIR/bin/phpcs; else echo $PHPCS_DIR/scripts/phpcs; fi) + - export PHPUNIT_DIR=/tmp/phpunit + - export PHPCS_BIN=$(if [[ $PHPCS_BRANCH == master ]]; then echo $PHPCS_DIR/bin/phpcs; else echo $PHPCS_DIR/scripts/phpcs; fi) - mkdir -p $PHPCS_DIR && git clone --depth 1 https://github.com/squizlabs/PHP_CodeSniffer.git -b $PHPCS_BRANCH $PHPCS_DIR - mkdir -p $WPCS_DIR && git clone --depth 1 https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards.git -b master $WPCS_DIR - - ln -s $WPCS_DIR/WordPress $PHPCS_DIR/$PHPCS_STANDARDS_DIR/Standards/WordPress - - ln -s $WPCS_DIR/WordPress-Core $PHPCS_DIR/$PHPCS_STANDARDS_DIR/Standards/WordPress-Core - - ln -s $WPCS_DIR/WordPress-Docs $PHPCS_DIR/$PHPCS_STANDARDS_DIR/Standards/WordPress-Docs - - ln -s $WPCS_DIR/WordPress-Extra $PHPCS_DIR/$PHPCS_STANDARDS_DIR/Standards/WordPress-Extra - - ln -s $WPCS_DIR/WordPress-VIP $PHPCS_DIR/$PHPCS_STANDARDS_DIR/Standards/WordPress-VIP - - $PHPCS_BIN --config-set installed_paths $(pwd) - - | - if [[ ${TRAVIS_PHP_VERSION:0:2} == "7." ]]; then - composer global require "phpunit/phpunit=5.7.*" - elif [[ ${TRAVIS_PHP_VERSION:0:3} != "5.2" ]]; then - composer global require "phpunit/phpunit=4.8.*" - fi; - - phpunit --version + - $PHPCS_BIN --config-set installed_paths $(pwd),$(WPCS_DIR) + # Download PHPUnit 5.x for builds on PHP 7, nightly and HHVM as the PHPCS + # test suite is currently not compatible with PHPUnit 6.x. + # Fixed at a very specific PHPUnit version which is also compatible with HHVM. + - if [[ ${TRAVIS_PHP_VERSION:0:2} != "5." ]]; then wget -P $PHPUNIT_DIR https://phar.phpunit.de/phpunit-5.7.17.phar && chmod +x $PHPUNIT_DIR/phpunit-5.7.17.phar; fi + # Selectively adjust the ini values for the build image to test ini value dependent sniff features. + - if [[ "$SHORT_OPEN_TAGS" == "true" ]]; then echo "short_open_tag = On" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini; fi script: - - if find . -name "*.php" -exec php -l {} \; | grep "^[Parse error|Fatal error]"; then exit 1; fi; - - phpunit --filter WordPressVIPMinimum /tmp/phpcs/tests/AllTests.php + # Lint the PHP files against parse errors. + - if [[ "$LINT" == "1" ]]; then if find . -name "*.php" -exec php -l {} \; | grep "^[Parse error|Fatal error]"; then exit 1; fi; fi + # Run the unit tests. + - if [[ ${TRAVIS_PHP_VERSION:0:2} == "5." && ${PHPCS_BRANCH:0:2} == "2." ]]; then phpunit --filter WordPressVIPMinimum $(WPCS_DIR)/Test/AllTests.php; fi + - if [[ ${TRAVIS_PHP_VERSION:0:2} == "5." && ${PHPCS_BRANCH:0:2} != "2." ]]; then phpunit --filter WordPressVIPMinimum $PHPCS_DIR/tests/AllTests.php; fi + - if [[ ${TRAVIS_PHP_VERSION:0:2} != "5." && ${PHPCS_BRANCH:0:2} == "2." ]]; then php $PHPUNIT_DIR/phpunit-5.7.17.phar --filter WordPressVIPMinimum $(pwd)/Test/AllTests.php; fi + - if [[ ${TRAVIS_PHP_VERSION:0:2} != "5." && ${PHPCS_BRANCH:0:2} != "2." ]]; then php $PHPUNIT_DIR/phpunit-5.7.17.phar --filter WordPressVIPMinumum $PHPCS_DIR/tests/AllTests.php; fi # WordPress Coding Standards. # @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards # @link http://pear.php.net/package/PHP_CodeSniffer/ @@ -75,5 +86,10 @@ script: # -n flag: Do not print warnings. (shortcut for --warning-severity=0) # --standard: Use WordPress as the standard. # --extensions: Only sniff PHP files. - - if [[ "$SNIFF" == "1" ]]; then $PHPCS_DIR/$( if [[ ${PHPCS_BRANCH:0:2} == "2." ]]; then echo "scripts"; else echo "bin"; fi; )/phpcs -p -s -n . --standard=./bin/phpcs.xml --extensions=php; fi - - if [[ "$INTEGRATION_TEST" == "1" ]]; then php ./ruleset_test.php; fi + - if [[ "$SNIFF" == "1" ]]; then $PHPCS_BIN . --standard=./bin/phpcs.xml --runtime-set ignore_warnings_on_exit 1; fi + # Validate the xml files. + # @link http://xmlsoft.org/xmllint.html + - if [[ "$SNIFF" == "1" ]]; then xmllint --noout ./*/ruleset.xml; fi + # Check the code-style consistency of the xml files. + - if [[ "$SNIFF" == "1" ]]; then diff -B --tabsize=4 ./WordPressVIPMinimum/ruleset.xml <(xmllint --format "./WordPressVIPMinimum/ruleset.xml"); fi + From 915bacf2822a05fb6013e3c86a42dcb235dfe53e Mon Sep 17 00:00:00 2001 From: David Binovec Date: Fri, 11 Aug 2017 08:57:38 +0000 Subject: [PATCH 10/31] Re-adding the custom integration test back to Travis configuration --- .travis.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index af1b68e6..ca1f57dc 100644 --- a/.travis.yml +++ b/.travis.yml @@ -48,6 +48,9 @@ matrix: - php: 5.3 env: PHPCS_BRANCH=2.9.0 SHORT_OPEN_TAGS=true dist: precise + # Run custom integration test. I just picked to it agains PHP 7.0. + - php: 7.0 + env: PHPCS_BRANCH=master INTEGRATION_TEST=1 allow_failures: # Allow failures for unstable builds. @@ -92,4 +95,4 @@ script: - if [[ "$SNIFF" == "1" ]]; then xmllint --noout ./*/ruleset.xml; fi # Check the code-style consistency of the xml files. - if [[ "$SNIFF" == "1" ]]; then diff -B --tabsize=4 ./WordPressVIPMinimum/ruleset.xml <(xmllint --format "./WordPressVIPMinimum/ruleset.xml"); fi - + - if [[ "$INTEGRATION_TEST" == "1" ]]; then php ./ruleset_test.php; fi From df04e334174aaec222ff205a4d08d6bd65637598 Mon Sep 17 00:00:00 2001 From: David Binovec Date: Fri, 11 Aug 2017 09:00:45 +0000 Subject: [PATCH 11/31] Defining the WPCS_DIR environment variable for Travis --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index ca1f57dc..f9ad9862 100644 --- a/.travis.yml +++ b/.travis.yml @@ -60,6 +60,7 @@ matrix: before_install: - export XMLLINT_INDENT=" " - export PHPCS_DIR=/tmp/phpcs + - export WPCS_DIR=/tmp/wpcs - export PHPUNIT_DIR=/tmp/phpunit - export PHPCS_BIN=$(if [[ $PHPCS_BRANCH == master ]]; then echo $PHPCS_DIR/bin/phpcs; else echo $PHPCS_DIR/scripts/phpcs; fi) - mkdir -p $PHPCS_DIR && git clone --depth 1 https://github.com/squizlabs/PHP_CodeSniffer.git -b $PHPCS_BRANCH $PHPCS_DIR From 20951466155b72481af45fa6d424527bee721de0 Mon Sep 17 00:00:00 2001 From: David Binovec Date: Fri, 11 Aug 2017 09:07:39 +0000 Subject: [PATCH 12/31] Properly reference the WPCS AllTests.php file --- .travis.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index f9ad9862..439bc5b6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -65,7 +65,7 @@ before_install: - export PHPCS_BIN=$(if [[ $PHPCS_BRANCH == master ]]; then echo $PHPCS_DIR/bin/phpcs; else echo $PHPCS_DIR/scripts/phpcs; fi) - mkdir -p $PHPCS_DIR && git clone --depth 1 https://github.com/squizlabs/PHP_CodeSniffer.git -b $PHPCS_BRANCH $PHPCS_DIR - mkdir -p $WPCS_DIR && git clone --depth 1 https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards.git -b master $WPCS_DIR - - $PHPCS_BIN --config-set installed_paths $(pwd),$(WPCS_DIR) + - $PHPCS_BIN --config-set installed_paths $(pwd),$WPCS_DIR # Download PHPUnit 5.x for builds on PHP 7, nightly and HHVM as the PHPCS # test suite is currently not compatible with PHPUnit 6.x. # Fixed at a very specific PHPUnit version which is also compatible with HHVM. @@ -77,9 +77,9 @@ script: # Lint the PHP files against parse errors. - if [[ "$LINT" == "1" ]]; then if find . -name "*.php" -exec php -l {} \; | grep "^[Parse error|Fatal error]"; then exit 1; fi; fi # Run the unit tests. - - if [[ ${TRAVIS_PHP_VERSION:0:2} == "5." && ${PHPCS_BRANCH:0:2} == "2." ]]; then phpunit --filter WordPressVIPMinimum $(WPCS_DIR)/Test/AllTests.php; fi + - if [[ ${TRAVIS_PHP_VERSION:0:2} == "5." && ${PHPCS_BRANCH:0:2} == "2." ]]; then phpunit --filter WordPressVIPMinimum $WPCS_DIR/Test/AllTests.php; fi - if [[ ${TRAVIS_PHP_VERSION:0:2} == "5." && ${PHPCS_BRANCH:0:2} != "2." ]]; then phpunit --filter WordPressVIPMinimum $PHPCS_DIR/tests/AllTests.php; fi - - if [[ ${TRAVIS_PHP_VERSION:0:2} != "5." && ${PHPCS_BRANCH:0:2} == "2." ]]; then php $PHPUNIT_DIR/phpunit-5.7.17.phar --filter WordPressVIPMinimum $(pwd)/Test/AllTests.php; fi + - if [[ ${TRAVIS_PHP_VERSION:0:2} != "5." && ${PHPCS_BRANCH:0:2} == "2." ]]; then php $PHPUNIT_DIR/phpunit-5.7.17.phar --filter WordPressVIPMinimum $WPCS_DIR/Test/AllTests.php; fi - if [[ ${TRAVIS_PHP_VERSION:0:2} != "5." && ${PHPCS_BRANCH:0:2} != "2." ]]; then php $PHPUNIT_DIR/phpunit-5.7.17.phar --filter WordPressVIPMinumum $PHPCS_DIR/tests/AllTests.php; fi # WordPress Coding Standards. # @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards From 962199d20f9f5f0385382e964510c045e3cd25a0 Mon Sep 17 00:00:00 2001 From: David Binovec Date: Fri, 11 Aug 2017 09:13:40 +0000 Subject: [PATCH 13/31] Fixing PHPCS Standards violation in WordPressVIPMinimum/Sniffs/Actions/PreGetPostsSniff.php sniff --- .../Sniffs/Actions/PreGetPostsSniff.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/WordPressVIPMinimum/Sniffs/Actions/PreGetPostsSniff.php b/WordPressVIPMinimum/Sniffs/Actions/PreGetPostsSniff.php index 3bd5372f..4eae0211 100644 --- a/WordPressVIPMinimum/Sniffs/Actions/PreGetPostsSniff.php +++ b/WordPressVIPMinimum/Sniffs/Actions/PreGetPostsSniff.php @@ -96,9 +96,9 @@ public function process( PHP_CodeSniffer_File $phpcsFile, $stackPtr ) { if ( 'PHPCS_T_CLOSURE' === $this->_tokens[ $callbackPtr ]['code'] ) { $this->processClosure( $callbackPtr ); - } else if ( 'T_ARRAY' === $this->_tokens[ $callbackPtr ]['type'] ) { + } elseif ( 'T_ARRAY' === $this->_tokens[ $callbackPtr ]['type'] ) { $this->processArray( $callbackPtr ); - } else if ( true === in_array( $this->_tokens[ $callbackPtr ]['code'], PHP_CodeSniffer_Tokens::$stringTokens ) ) { + } elseif ( true === in_array( $this->_tokens[ $callbackPtr ]['code'], PHP_CodeSniffer_Tokens::$stringTokens, true ) ) { $this->processString( $callbackPtr ); } @@ -242,11 +242,11 @@ private function processFunctionBody( $stackPtr, $variableName ) { if ( $this->isEarlyMainQueryCheck( $wpQueryVarUsed ) ) { return; } - } else if ( $this->isInsideIfConditonal( $wpQueryVarUsed ) ) { + } elseif ( $this->isInsideIfConditonal( $wpQueryVarUsed ) ) { if ( ! $this->isParentConditionalCheckingMainQuery( $wpQueryVarUsed ) ) { $this->_phpcsFile->addWarning( 'Main WP_Query is being modified without $query->is_main_query() check. Needs manual inspection.', $wpQueryVarUsed ); } - } else if ( $this->isWPQueryMethodCall( $wpQueryVarUsed, 'set' ) ) { + } elseif ( $this->isWPQueryMethodCall( $wpQueryVarUsed, 'set' ) ) { $this->_phpcsFile->addWarning( 'Main WP_Query is being modified without $query->is_main_query() check. Needs manual inspection.', $wpQueryVarUsed ); } $findStart = $wpQueryVarUsed + 1; @@ -316,7 +316,7 @@ private function isEarlyMainQueryCheck( $stackPtr ) { } $nestedParenthesisEnd = array_shift( $this->_tokens[ $stackPtr ]['nested_parenthesis'] ); - if ( true === in_array( 'PHPCS_T_CLOSURE', $this->_tokens[ $stackPtr ]['conditions'] ) ) { + if ( true === in_array( 'PHPCS_T_CLOSURE', $this->_tokens[ $stackPtr ]['conditions'], true ) ) { $nestedParenthesisEnd = array_shift( $this->_tokens[ $stackPtr ]['nested_parenthesis'] ); } From 5a22dda938444a5990bda3bd5feef772faf585bb Mon Sep 17 00:00:00 2001 From: David Binovec Date: Fri, 11 Aug 2017 09:19:08 +0000 Subject: [PATCH 14/31] Fixing PHPCS validation errors in Sniffs and integration test files. --- .../Sniffs/Cache/CacheValueOverrideSniff.php | 2 +- .../Sniffs/Functions/CheckReturnValueSniff.php | 4 ++-- .../Sniffs/VIP/StaticStrreplaceSniff.php | 2 +- ruleset_test.php | 10 ++++++---- 4 files changed, 10 insertions(+), 8 deletions(-) diff --git a/WordPressVIPMinimum/Sniffs/Cache/CacheValueOverrideSniff.php b/WordPressVIPMinimum/Sniffs/Cache/CacheValueOverrideSniff.php index c368004e..b5840fae 100644 --- a/WordPressVIPMinimum/Sniffs/Cache/CacheValueOverrideSniff.php +++ b/WordPressVIPMinimum/Sniffs/Cache/CacheValueOverrideSniff.php @@ -108,7 +108,7 @@ private function isFunctionCall( $stackPtr ) { $tokens = $this->_tokens; $phpcsFile = $this->_phpcsFile; - if ( false === in_array( $tokens[ $stackPtr ]['code'], PHP_CodeSniffer_Tokens::$functionNameTokens ) ) { + if ( false === in_array( $tokens[ $stackPtr ]['code'], PHP_CodeSniffer_Tokens::$functionNameTokens, true ) ) { return false; } diff --git a/WordPressVIPMinimum/Sniffs/Functions/CheckReturnValueSniff.php b/WordPressVIPMinimum/Sniffs/Functions/CheckReturnValueSniff.php index 6d167005..2b03bf4e 100644 --- a/WordPressVIPMinimum/Sniffs/Functions/CheckReturnValueSniff.php +++ b/WordPressVIPMinimum/Sniffs/Functions/CheckReturnValueSniff.php @@ -98,7 +98,7 @@ private function isFunctionCall( $stackPtr ) { $tokens = $this->_tokens; $phpcsFile = $this->_phpcsFile; - if ( false === in_array( $tokens[ $stackPtr ]['code'], PHP_CodeSniffer_Tokens::$functionNameTokens ) ) { + if ( false === in_array( $tokens[ $stackPtr ]['code'], PHP_CodeSniffer_Tokens::$functionNameTokens, true ) ) { return false; } @@ -214,7 +214,7 @@ public function findNonCheckedVariables( $stackPtr ) { $callees = array(); foreach ( $this->catch as $callee => $checkReturnArray ) { - if ( true === in_array( $functionName, $checkReturnArray ) ) { + if ( true === in_array( $functionName, $checkReturnArray, true ) ) { $isFunctionWeLookFor = true; $callees[] = $callee; } diff --git a/WordPressVIPMinimum/Sniffs/VIP/StaticStrreplaceSniff.php b/WordPressVIPMinimum/Sniffs/VIP/StaticStrreplaceSniff.php index 5fc69312..c9457e85 100644 --- a/WordPressVIPMinimum/Sniffs/VIP/StaticStrreplaceSniff.php +++ b/WordPressVIPMinimum/Sniffs/VIP/StaticStrreplaceSniff.php @@ -69,7 +69,7 @@ public function process( PHP_CodeSniffer_File $phpcsFile, $stackPtr ) { $next_start_ptr = $closeBracket + 1; continue; - } else if ( T_CONSTANT_ENCAPSED_STRING !== $tokens[ $param_ptr ]['code'] ) { + } elseif ( T_CONSTANT_ENCAPSED_STRING !== $tokens[ $param_ptr ]['code'] ) { return; } diff --git a/ruleset_test.php b/ruleset_test.php index 6dc0b22b..74e1a134 100644 --- a/ruleset_test.php +++ b/ruleset_test.php @@ -119,10 +119,12 @@ public function __construct( $expected = array() ) { // Travis support. if ( false === getenv( 'PHPCS_BIN' ) ) { + // @codingStandardsIgnoreLine putenv( 'PHPCS_BIN=phpcs' ); } // Collect the PHPCS result. + // @codingStandardsIgnoreLine $output = shell_exec( '$PHPCS_BIN --standard=WordPressVIPMinimum --report=json ./ruleset_test.inc' ); $output = json_decode( $output, true ); @@ -172,7 +174,7 @@ private function check_missing_expected_values() { if ( false === isset( $this->$type[ $line ] ) ) { $this->error_warning_message( $number, $type, 0, $line ); $this->total_issues ++; - } else if ( $this->$type[ $line ] !== $number ) { + } elseif ( $this->$type[ $line ] !== $number ) { $this->error_warning_message( $number, $type, $this->$type[ $line ], $line ); $this->total_issues ++; } @@ -190,7 +192,7 @@ private function check_unexpected_values() { if ( false === isset( $expected[ $type ][ $line ] ) ) { $this->error_warning_message( 0, $type, $number, $line ); $this->total_issues ++; - } else if ( $number !== $expected[ $type ][ $line ] ) { + } elseif ( $number !== $expected[ $type ][ $line ] ) { $this->error_warning_message( $expected[ $type ][ $line ], $type, $number, $line ); $this->total_issues ++; } @@ -209,7 +211,7 @@ private function check_messages() { if ( false === isset( $this->messages[ $line ] ) ) { printf( 'Expected "%s" but found no message for line %d' . PHP_EOL, $message, $line ); // XSS OK. $this->total_issues ++; - } else if ( false === in_array( $message, $this->messages[ $line ] ) ) { + } elseif ( false === in_array( $message, $this->messages[ $line ], true ) ) { printf( 'Expected message "%s" was not found for line %d' . PHP_EOL, $message, $line ); // XSS OK. $this->total_issues ++; } @@ -218,7 +220,7 @@ private function check_messages() { foreach ( $this->messages as $line => $messages ) { foreach ( $messages as $message ) { if ( true === isset( $this->expected['messages'][ $line ] ) ) { - if ( false === in_array( $message, $this->expected['messages'][ $line ] ) ) { + if ( false === in_array( $message, $this->expected['messages'][ $line ], true ) ) { printf( 'Unexpected message "%s" was found for line %d' . PHP_EOL, $message, $line ); // XSS OK. $this->total_issues ++; } From 18f65120880ad0210a93104c4a209b72c4ba3a57 Mon Sep 17 00:00:00 2001 From: David Binovec Date: Fri, 11 Aug 2017 09:20:35 +0000 Subject: [PATCH 15/31] Fixing XML lint violations in the ruleset.xml file. --- WordPressVIPMinimum/ruleset.xml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/WordPressVIPMinimum/ruleset.xml b/WordPressVIPMinimum/ruleset.xml index 27c22d6b..c0e31b20 100644 --- a/WordPressVIPMinimum/ruleset.xml +++ b/WordPressVIPMinimum/ruleset.xml @@ -10,17 +10,17 @@ - + - - - - + + + + - - + + From da2227aea1d6ff7cbcfd904ff9e057a0c2ff6fb0 Mon Sep 17 00:00:00 2001 From: David Binovec Date: Fri, 11 Aug 2017 09:25:57 +0000 Subject: [PATCH 16/31] Updating the coding standard for the project itself. Those changes copy the improvements done in the upstream repository (WPCS). --- bin/phpcs.xml | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/bin/phpcs.xml b/bin/phpcs.xml index 9852ad6c..7c03fbda 100644 --- a/bin/phpcs.xml +++ b/bin/phpcs.xml @@ -1,17 +1,25 @@ - The Coding standard for the WordPress Coding Standards itself. + The Coding standard for the WordPress Coding Standards itself. - - /WordPress/Sniffs/Arrays/ArrayDeclarationSniff.php + + - - - - + + /Test/AllTests.php + /Test/Standards/*.php - + + */vendor/* - \ No newline at end of file + + + + + + + + + + + From 540978d22cff33a2e50f8ae89a5cb54b797cb66f Mon Sep 17 00:00:00 2001 From: David Binovec Date: Fri, 11 Aug 2017 09:30:58 +0000 Subject: [PATCH 17/31] Temporarily disable the PSR1 Class Declaration Sniff for this project. We'll have to address those issues in near future (in order to be on par with the upstream standards), but it does not feel necessary in terms of making sure the VIPCS supports both PHPCS 2.x and 3.x --- bin/phpcs.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/phpcs.xml b/bin/phpcs.xml index 7c03fbda..1823352d 100644 --- a/bin/phpcs.xml +++ b/bin/phpcs.xml @@ -20,6 +20,6 @@ - + From 63c65b0d4a5d81a10c7e1bbf58e5159f6825ec89 Mon Sep 17 00:00:00 2001 From: David Binovec Date: Fri, 11 Aug 2017 09:36:10 +0000 Subject: [PATCH 18/31] Load the WPCS bootstrap file when running phpunit --- .travis.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 439bc5b6..13f27f34 100644 --- a/.travis.yml +++ b/.travis.yml @@ -77,10 +77,10 @@ script: # Lint the PHP files against parse errors. - if [[ "$LINT" == "1" ]]; then if find . -name "*.php" -exec php -l {} \; | grep "^[Parse error|Fatal error]"; then exit 1; fi; fi # Run the unit tests. - - if [[ ${TRAVIS_PHP_VERSION:0:2} == "5." && ${PHPCS_BRANCH:0:2} == "2." ]]; then phpunit --filter WordPressVIPMinimum $WPCS_DIR/Test/AllTests.php; fi - - if [[ ${TRAVIS_PHP_VERSION:0:2} == "5." && ${PHPCS_BRANCH:0:2} != "2." ]]; then phpunit --filter WordPressVIPMinimum $PHPCS_DIR/tests/AllTests.php; fi - - if [[ ${TRAVIS_PHP_VERSION:0:2} != "5." && ${PHPCS_BRANCH:0:2} == "2." ]]; then php $PHPUNIT_DIR/phpunit-5.7.17.phar --filter WordPressVIPMinimum $WPCS_DIR/Test/AllTests.php; fi - - if [[ ${TRAVIS_PHP_VERSION:0:2} != "5." && ${PHPCS_BRANCH:0:2} != "2." ]]; then php $PHPUNIT_DIR/phpunit-5.7.17.phar --filter WordPressVIPMinumum $PHPCS_DIR/tests/AllTests.php; fi + - if [[ ${TRAVIS_PHP_VERSION:0:2} == "5." && ${PHPCS_BRANCH:0:2} == "2." ]]; then phpunit --botstrap $WPCS_DIR/Test/bootstrap.php --filter WordPressVIPMinimum $WPCS_DIR/Test/AllTests.php; fi + - if [[ ${TRAVIS_PHP_VERSION:0:2} == "5." && ${PHPCS_BRANCH:0:2} != "2." ]]; then phpunit --botstrap $WPCS_DIR/Test/bootstrap.php --filter WordPressVIPMinimum $PHPCS_DIR/tests/AllTests.php; fi + - if [[ ${TRAVIS_PHP_VERSION:0:2} != "5." && ${PHPCS_BRANCH:0:2} == "2." ]]; then php $PHPUNIT_DIR/phpunit-5.7.17.phar --botstrap $WPCS_DIR/Test/bootstrap.php --filter WordPressVIPMinimum $WPCS_DIR/Test/AllTests.php; fi + - if [[ ${TRAVIS_PHP_VERSION:0:2} != "5." && ${PHPCS_BRANCH:0:2} != "2." ]]; then php $PHPUNIT_DIR/phpunit-5.7.17.phar --botstrap $WPCS_DIR/Test/bootstrap.php --filter WordPressVIPMinumum $PHPCS_DIR/tests/AllTests.php; fi # WordPress Coding Standards. # @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards # @link http://pear.php.net/package/PHP_CodeSniffer/ From fd524ab009136987d6cd588fc2b2b87b3f79c5d6 Mon Sep 17 00:00:00 2001 From: David Binovec Date: Fri, 11 Aug 2017 09:38:48 +0000 Subject: [PATCH 19/31] Fix a typo in the --bootstrap param of the phpunit /s/botstrap/bootstrap --- .travis.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 13f27f34..f1c2c60b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -77,10 +77,10 @@ script: # Lint the PHP files against parse errors. - if [[ "$LINT" == "1" ]]; then if find . -name "*.php" -exec php -l {} \; | grep "^[Parse error|Fatal error]"; then exit 1; fi; fi # Run the unit tests. - - if [[ ${TRAVIS_PHP_VERSION:0:2} == "5." && ${PHPCS_BRANCH:0:2} == "2." ]]; then phpunit --botstrap $WPCS_DIR/Test/bootstrap.php --filter WordPressVIPMinimum $WPCS_DIR/Test/AllTests.php; fi - - if [[ ${TRAVIS_PHP_VERSION:0:2} == "5." && ${PHPCS_BRANCH:0:2} != "2." ]]; then phpunit --botstrap $WPCS_DIR/Test/bootstrap.php --filter WordPressVIPMinimum $PHPCS_DIR/tests/AllTests.php; fi - - if [[ ${TRAVIS_PHP_VERSION:0:2} != "5." && ${PHPCS_BRANCH:0:2} == "2." ]]; then php $PHPUNIT_DIR/phpunit-5.7.17.phar --botstrap $WPCS_DIR/Test/bootstrap.php --filter WordPressVIPMinimum $WPCS_DIR/Test/AllTests.php; fi - - if [[ ${TRAVIS_PHP_VERSION:0:2} != "5." && ${PHPCS_BRANCH:0:2} != "2." ]]; then php $PHPUNIT_DIR/phpunit-5.7.17.phar --botstrap $WPCS_DIR/Test/bootstrap.php --filter WordPressVIPMinumum $PHPCS_DIR/tests/AllTests.php; fi + - if [[ ${TRAVIS_PHP_VERSION:0:2} == "5." && ${PHPCS_BRANCH:0:2} == "2." ]]; then phpunit --bootstrap $WPCS_DIR/Test/bootstrap.php --filter WordPressVIPMinimum $WPCS_DIR/Test/AllTests.php; fi + - if [[ ${TRAVIS_PHP_VERSION:0:2} == "5." && ${PHPCS_BRANCH:0:2} != "2." ]]; then phpunit --bootstrap $WPCS_DIR/Test/bootstrap.php --filter WordPressVIPMinimum $PHPCS_DIR/tests/AllTests.php; fi + - if [[ ${TRAVIS_PHP_VERSION:0:2} != "5." && ${PHPCS_BRANCH:0:2} == "2." ]]; then php $PHPUNIT_DIR/phpunit-5.7.17.phar --bootstrap $WPCS_DIR/Test/bootstrap.php --filter WordPressVIPMinimum $WPCS_DIR/Test/AllTests.php; fi + - if [[ ${TRAVIS_PHP_VERSION:0:2} != "5." && ${PHPCS_BRANCH:0:2} != "2." ]]; then php $PHPUNIT_DIR/phpunit-5.7.17.phar --bootstrap $WPCS_DIR/Test/bootstrap.php --filter WordPressVIPMinumum $PHPCS_DIR/tests/AllTests.php; fi # WordPress Coding Standards. # @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards # @link http://pear.php.net/package/PHP_CodeSniffer/ From ee111d223d8a7ec5cc7221fc503808581293c167 Mon Sep 17 00:00:00 2001 From: David Binovec Date: Fri, 11 Aug 2017 09:53:22 +0000 Subject: [PATCH 20/31] Hotfix Fatal Fatal error: Class 'WordPress_AbstractArrayAssignmentRestrictionsSniff' not found in /home/travis/build/Automattic/VIP-Coding-Standards/WordPressVIPMinimum/Sniffs/VIP/RegexpCompareSniff.php on line 13 --- WordPressVIPMinimum/Sniffs/VIP/RegexpCompareSniff.php | 4 ++++ WordPressVIPMinimum/Sniffs/VIP/RemoteRequestTimeoutSniff.php | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/WordPressVIPMinimum/Sniffs/VIP/RegexpCompareSniff.php b/WordPressVIPMinimum/Sniffs/VIP/RegexpCompareSniff.php index 3c05078e..88792759 100644 --- a/WordPressVIPMinimum/Sniffs/VIP/RegexpCompareSniff.php +++ b/WordPressVIPMinimum/Sniffs/VIP/RegexpCompareSniff.php @@ -5,6 +5,10 @@ * @package VIPCS\WordPressVIPMinimum */ +if ( false === class_exists( '\WordPress_AbstractArrayAssignmentRestrictionsSniff' ) ) { + class_alias( '\WordPress\AbstractArrayAssignmentRestrictionsSniff', '\WordPress_AbstractArrayAssignmentRestrictionsSniff' ); +} + /** * Flag REGEXP and NOT REGEXP in meta compare * diff --git a/WordPressVIPMinimum/Sniffs/VIP/RemoteRequestTimeoutSniff.php b/WordPressVIPMinimum/Sniffs/VIP/RemoteRequestTimeoutSniff.php index 8c60236e..bea7ade7 100644 --- a/WordPressVIPMinimum/Sniffs/VIP/RemoteRequestTimeoutSniff.php +++ b/WordPressVIPMinimum/Sniffs/VIP/RemoteRequestTimeoutSniff.php @@ -5,6 +5,10 @@ * @package VIPCS\WordPressVIPMinimum */ +if ( false === class_exists( '\WordPress_AbstractArrayAssignmentRestrictionsSniff' ) ) { + class_alias( '\WordPress\AbstractArrayAssignmentRestrictionsSniff', '\WordPress_AbstractArrayAssignmentRestrictionsSniff' ); +} + /** * Flag REGEXP and NOT REGEXP in meta compare * From 026914e7bfba60de79d9c09454f1dc961428767c Mon Sep 17 00:00:00 2001 From: David Binovec Date: Fri, 11 Aug 2017 10:01:20 +0000 Subject: [PATCH 21/31] Making sure the VIP Coding standard works even on combo of PHPCS 2.x and WPCS > 0.1.3 (thus the autoloading is not taking effect) --- .../Sniffs/Classes/DeclarationCompatibilitySniff.php | 5 +++++ WordPressVIPMinimum/Sniffs/VIP/RegexpCompareSniff.php | 1 + .../Sniffs/VIP/RemoteRequestTimeoutSniff.php | 1 + .../Sniffs/VIP/RestrictedFunctionsSniff.php | 5 +++++ WordPressVIPMinimum/autoload.php | 10 +--------- 5 files changed, 13 insertions(+), 9 deletions(-) diff --git a/WordPressVIPMinimum/Sniffs/Classes/DeclarationCompatibilitySniff.php b/WordPressVIPMinimum/Sniffs/Classes/DeclarationCompatibilitySniff.php index c4429321..e03f5960 100644 --- a/WordPressVIPMinimum/Sniffs/Classes/DeclarationCompatibilitySniff.php +++ b/WordPressVIPMinimum/Sniffs/Classes/DeclarationCompatibilitySniff.php @@ -5,6 +5,11 @@ * @package VIPCS\WordPressVIPMinimum */ +// WPCS pre 0.1.3 backwardcompatibility. +if ( ! class_exists( '\PHP_CodeSniffer_Standards_AbstractScopeSniff' ) ) { + class_alias( 'PHP_CodeSniffer\Sniffs\AbstractScopeSniff', '\PHP_CodeSniffer_Standards_AbstractScopeSniff' ); +} + /** * Class WordPressVIPMinimum_Sniffs_Classes_DeclarationCompatibilitySniff * diff --git a/WordPressVIPMinimum/Sniffs/VIP/RegexpCompareSniff.php b/WordPressVIPMinimum/Sniffs/VIP/RegexpCompareSniff.php index 88792759..b53c9ad8 100644 --- a/WordPressVIPMinimum/Sniffs/VIP/RegexpCompareSniff.php +++ b/WordPressVIPMinimum/Sniffs/VIP/RegexpCompareSniff.php @@ -5,6 +5,7 @@ * @package VIPCS\WordPressVIPMinimum */ +// WPCS pre 0.1.3 backwardcompatibility. if ( false === class_exists( '\WordPress_AbstractArrayAssignmentRestrictionsSniff' ) ) { class_alias( '\WordPress\AbstractArrayAssignmentRestrictionsSniff', '\WordPress_AbstractArrayAssignmentRestrictionsSniff' ); } diff --git a/WordPressVIPMinimum/Sniffs/VIP/RemoteRequestTimeoutSniff.php b/WordPressVIPMinimum/Sniffs/VIP/RemoteRequestTimeoutSniff.php index bea7ade7..620856fd 100644 --- a/WordPressVIPMinimum/Sniffs/VIP/RemoteRequestTimeoutSniff.php +++ b/WordPressVIPMinimum/Sniffs/VIP/RemoteRequestTimeoutSniff.php @@ -5,6 +5,7 @@ * @package VIPCS\WordPressVIPMinimum */ +// WPCS pre 0.1.3 backwardcompatibility. if ( false === class_exists( '\WordPress_AbstractArrayAssignmentRestrictionsSniff' ) ) { class_alias( '\WordPress\AbstractArrayAssignmentRestrictionsSniff', '\WordPress_AbstractArrayAssignmentRestrictionsSniff' ); } diff --git a/WordPressVIPMinimum/Sniffs/VIP/RestrictedFunctionsSniff.php b/WordPressVIPMinimum/Sniffs/VIP/RestrictedFunctionsSniff.php index 0e118687..ef4f016c 100644 --- a/WordPressVIPMinimum/Sniffs/VIP/RestrictedFunctionsSniff.php +++ b/WordPressVIPMinimum/Sniffs/VIP/RestrictedFunctionsSniff.php @@ -5,6 +5,11 @@ * @package VIPCS\WordPressVIPMinimum */ +// WPCS pre 0.1.3 backwardcompatibility. +if ( ! class_exists( '\WordPress_Sniffs_VIP_RestrictedFunctionsSniff' ) ) { + class_alias( '\WordPress\Sniffs\VIP\RestrictedFunctionsSniff', '\WordPress_Sniffs_VIP_RestrictedFunctionsSniff' ); +} + /** * Restricts usage of some functions in VIP context. * diff --git a/WordPressVIPMinimum/autoload.php b/WordPressVIPMinimum/autoload.php index 3890f394..6dbc5052 100644 --- a/WordPressVIPMinimum/autoload.php +++ b/WordPressVIPMinimum/autoload.php @@ -18,17 +18,9 @@ function load_phpcs_helper_file() { foreach ( \PHP_CodeSniffer\Util\Standards::getInstalledStandardDetails( 'WordPress' ) as $standard => $details ) { if ( 'WordPress' === $standard ) { require_once( $details['path'] . '/PHPCSAliases.php' ); + return; } } - if ( ! class_exists( '\PHP_CodeSniffer_Standards_AbstractScopeSniff' ) ) { - class_alias( 'PHP_CodeSniffer\Sniffs\AbstractScopeSniff', '\PHP_CodeSniffer_Standards_AbstractScopeSniff' ); - } - if ( ! class_exists( '\WordPress_AbstractArrayAssignmentRestrictionsSniff' ) ) { - class_alias( '\WordPress\AbstractArrayAssignmentRestrictionsSniff', '\WordPress_AbstractArrayAssignmentRestrictionsSniff' ); - } - if ( ! class_exists( '\WordPress_Sniffs_VIP_RestrictedFunctionsSniff' ) ) { - class_alias( '\WordPress\Sniffs\VIP\RestrictedFunctionsSniff', '\WordPress_Sniffs_VIP_RestrictedFunctionsSniff' ); - } } load_phpcs_helper_file(); From 34b156ac5164ecabab03459e846f586692f68e18 Mon Sep 17 00:00:00 2001 From: David Binovec Date: Fri, 11 Aug 2017 13:59:10 +0000 Subject: [PATCH 22/31] Referencing the new namespaced classes in WPCS 0.1.3 There is no simple path for supporting WPCS prior to 0.1.3 --- WordPressVIPMinimum/Sniffs/VIP/RegexpCompareSniff.php | 7 +------ .../Sniffs/VIP/RemoteRequestTimeoutSniff.php | 7 +------ .../Sniffs/VIP/RestrictedFunctionsSniff.php | 7 +------ 3 files changed, 3 insertions(+), 18 deletions(-) diff --git a/WordPressVIPMinimum/Sniffs/VIP/RegexpCompareSniff.php b/WordPressVIPMinimum/Sniffs/VIP/RegexpCompareSniff.php index b53c9ad8..cef76d1b 100644 --- a/WordPressVIPMinimum/Sniffs/VIP/RegexpCompareSniff.php +++ b/WordPressVIPMinimum/Sniffs/VIP/RegexpCompareSniff.php @@ -5,17 +5,12 @@ * @package VIPCS\WordPressVIPMinimum */ -// WPCS pre 0.1.3 backwardcompatibility. -if ( false === class_exists( '\WordPress_AbstractArrayAssignmentRestrictionsSniff' ) ) { - class_alias( '\WordPress\AbstractArrayAssignmentRestrictionsSniff', '\WordPress_AbstractArrayAssignmentRestrictionsSniff' ); -} - /** * Flag REGEXP and NOT REGEXP in meta compare * * @package VIPCS\WordPressVIPMinimum */ -class WordPressVIPMinimum_Sniffs_VIP_RegexpCompareSniff extends WordPress_AbstractArrayAssignmentRestrictionsSniff { +class WordPressVIPMinimum_Sniffs_VIP_RegexpCompareSniff extends WordPress\AbstractArrayAssignmentRestrictionsSniff { /** * Groups of variables to restrict. diff --git a/WordPressVIPMinimum/Sniffs/VIP/RemoteRequestTimeoutSniff.php b/WordPressVIPMinimum/Sniffs/VIP/RemoteRequestTimeoutSniff.php index 620856fd..ba89a775 100644 --- a/WordPressVIPMinimum/Sniffs/VIP/RemoteRequestTimeoutSniff.php +++ b/WordPressVIPMinimum/Sniffs/VIP/RemoteRequestTimeoutSniff.php @@ -5,17 +5,12 @@ * @package VIPCS\WordPressVIPMinimum */ -// WPCS pre 0.1.3 backwardcompatibility. -if ( false === class_exists( '\WordPress_AbstractArrayAssignmentRestrictionsSniff' ) ) { - class_alias( '\WordPress\AbstractArrayAssignmentRestrictionsSniff', '\WordPress_AbstractArrayAssignmentRestrictionsSniff' ); -} - /** * Flag REGEXP and NOT REGEXP in meta compare * * @package VIPCS\WordPressVIPMinimum */ -class WordPressVIPMinimum_Sniffs_VIP_RemoteRequestTimeoutSniff extends WordPress_AbstractArrayAssignmentRestrictionsSniff { +class WordPressVIPMinimum_Sniffs_VIP_RemoteRequestTimeoutSniff extends WordPress\AbstractArrayAssignmentRestrictionsSniff { /** * Groups of variables to restrict. diff --git a/WordPressVIPMinimum/Sniffs/VIP/RestrictedFunctionsSniff.php b/WordPressVIPMinimum/Sniffs/VIP/RestrictedFunctionsSniff.php index ef4f016c..ba95c60e 100644 --- a/WordPressVIPMinimum/Sniffs/VIP/RestrictedFunctionsSniff.php +++ b/WordPressVIPMinimum/Sniffs/VIP/RestrictedFunctionsSniff.php @@ -5,17 +5,12 @@ * @package VIPCS\WordPressVIPMinimum */ -// WPCS pre 0.1.3 backwardcompatibility. -if ( ! class_exists( '\WordPress_Sniffs_VIP_RestrictedFunctionsSniff' ) ) { - class_alias( '\WordPress\Sniffs\VIP\RestrictedFunctionsSniff', '\WordPress_Sniffs_VIP_RestrictedFunctionsSniff' ); -} - /** * Restricts usage of some functions in VIP context. * * @package VIPCS\WordPressVIPMinimum */ -class WordPressVIPMinimum_Sniffs_VIP_RestrictedFunctionsSniff extends WordPress_Sniffs_VIP_RestrictedFunctionsSniff { +class WordPressVIPMinimum_Sniffs_VIP_RestrictedFunctionsSniff extends WordPress\Sniffs\VIP\RestrictedFunctionsSniff { /** * Groups of functions to restrict. From 0b76919776fad1267fb6df5b8b68feef3cb59148 Mon Sep 17 00:00:00 2001 From: David Binovec Date: Fri, 11 Aug 2017 14:52:51 +0000 Subject: [PATCH 23/31] Fixing missing 3rd param for addError and addWarning methods --- .../Sniffs/Actions/PreGetPostsSniff.php | 4 ++-- .../Sniffs/Cache/CacheValueOverrideSniff.php | 2 +- .../Classes/DeclarationCompatibilitySniff.php | 2 +- .../Constants/ConstantRestrictionsSniff.php | 6 +++--- .../Sniffs/Files/IncludingFileSniff.php | 12 ++++++------ .../Sniffs/Functions/CheckReturnValueSniff.php | 6 +++--- .../Sniffs/VIP/ErrorControlSniff.php | 2 +- .../Sniffs/VIP/FlushRewriteRulesSniff.php | 2 +- .../Sniffs/VIP/StaticStrreplaceSniff.php | 2 +- .../Sniffs/Variables/VariableAnalysisSniff.php | 16 ++++++++++++---- ruleset_test.inc | 2 +- 11 files changed, 32 insertions(+), 24 deletions(-) diff --git a/WordPressVIPMinimum/Sniffs/Actions/PreGetPostsSniff.php b/WordPressVIPMinimum/Sniffs/Actions/PreGetPostsSniff.php index 4eae0211..9f115471 100644 --- a/WordPressVIPMinimum/Sniffs/Actions/PreGetPostsSniff.php +++ b/WordPressVIPMinimum/Sniffs/Actions/PreGetPostsSniff.php @@ -244,10 +244,10 @@ private function processFunctionBody( $stackPtr, $variableName ) { } } elseif ( $this->isInsideIfConditonal( $wpQueryVarUsed ) ) { if ( ! $this->isParentConditionalCheckingMainQuery( $wpQueryVarUsed ) ) { - $this->_phpcsFile->addWarning( 'Main WP_Query is being modified without $query->is_main_query() check. Needs manual inspection.', $wpQueryVarUsed ); + $this->_phpcsFile->addWarning( 'Main WP_Query is being modified without $query->is_main_query() check. Needs manual inspection.', $wpQueryVarUsed, 'WordPressVIPMinimum.Actions.PreGetPosts' ); } } elseif ( $this->isWPQueryMethodCall( $wpQueryVarUsed, 'set' ) ) { - $this->_phpcsFile->addWarning( 'Main WP_Query is being modified without $query->is_main_query() check. Needs manual inspection.', $wpQueryVarUsed ); + $this->_phpcsFile->addWarning( 'Main WP_Query is being modified without $query->is_main_query() check. Needs manual inspection.', $wpQueryVarUsed, 'WordPressVIPMinimum.Actions.PreGetPosts' ); } $findStart = $wpQueryVarUsed + 1; } diff --git a/WordPressVIPMinimum/Sniffs/Cache/CacheValueOverrideSniff.php b/WordPressVIPMinimum/Sniffs/Cache/CacheValueOverrideSniff.php index b5840fae..50b051b9 100644 --- a/WordPressVIPMinimum/Sniffs/Cache/CacheValueOverrideSniff.php +++ b/WordPressVIPMinimum/Sniffs/Cache/CacheValueOverrideSniff.php @@ -91,7 +91,7 @@ public function process( PHP_CodeSniffer_File $phpcsFile, $stackPtr ) { $valueAfterEqualSign = $phpcsFile->findNext( PHP_CodeSniffer_Tokens::$emptyTokens, ($rightAfterNextVariableOccurence + 1), null, true, null, true ); if ( T_FALSE === $tokens[ $valueAfterEqualSign ]['code'] ) { - $phpcsFile->addError( sprintf( 'Obtained cached value in %s is being overriden. Disabling caching?', $variableName ), $nextVariableOccurrence ); + $phpcsFile->addError( sprintf( 'Obtained cached value in %s is being overriden. Disabling caching?', $variableName ), $nextVariableOccurrence, 'WordPressVIPMinimum.Cache.CacheValueOverride' ); } } //end Process() diff --git a/WordPressVIPMinimum/Sniffs/Classes/DeclarationCompatibilitySniff.php b/WordPressVIPMinimum/Sniffs/Classes/DeclarationCompatibilitySniff.php index e03f5960..c826f56d 100644 --- a/WordPressVIPMinimum/Sniffs/Classes/DeclarationCompatibilitySniff.php +++ b/WordPressVIPMinimum/Sniffs/Classes/DeclarationCompatibilitySniff.php @@ -299,7 +299,7 @@ private function addError( $parentClassName, $methodName, $currentMethodSignatur $parentSignature = sprintf( '%s::%s(%s)', $parentClassName, $methodName, implode( ', ', $this->generateParamList( $parentMethodSignature ) ) ); - $phpcsFile->addError( sprintf( 'Declaration of %s should be compatible with %s', $currentSignature, $parentSignature ), $stackPtr ); + $phpcsFile->addError( sprintf( 'Declaration of %s should be compatible with %s', $currentSignature, $parentSignature ), $stackPtr, 'WordPressVIPMinimum.Classes.DeclarationCompatibility' ); }//end addError() /** diff --git a/WordPressVIPMinimum/Sniffs/Constants/ConstantRestrictionsSniff.php b/WordPressVIPMinimum/Sniffs/Constants/ConstantRestrictionsSniff.php index 9be7501a..17a4215f 100644 --- a/WordPressVIPMinimum/Sniffs/Constants/ConstantRestrictionsSniff.php +++ b/WordPressVIPMinimum/Sniffs/Constants/ConstantRestrictionsSniff.php @@ -58,7 +58,7 @@ public function process( PHP_CodeSniffer_File $phpcsFile, $stackPtr ) { } if ( T_STRING === $tokens[ $stackPtr ]['code'] ) { - $phpcsFile->addWarning( sprintf( 'Code is touching the %s constant. Make sure it\'s used appropriately.', $constantName ), $stackPtr ); + $phpcsFile->addWarning( sprintf( 'Code is touching the %s constant. Make sure it\'s used appropriately.', $constantName ), $stackPtr, 'WordPressVIPMinimum.Constants.ConstantRestrictions' ); return; } @@ -86,9 +86,9 @@ public function process( PHP_CodeSniffer_File $phpcsFile, $stackPtr ) { if ( true === in_array( $tokens[ $previous ]['code'], PHP_CodeSniffer_Tokens::$functionNameTokens, true ) ) { if ( 'define' === $tokens[ $previous ]['content'] ) { - $phpcsFile->addError( sprintf( 'The definition of %s constant is prohibited. Please use a different name.', $constantName ), $previous ); + $phpcsFile->addError( sprintf( 'The definition of %s constant is prohibited. Please use a different name.', $constantName ), $previous, 'WordPressVIPMinimum.Constants.ConstantRestrictions' ); } else { - $phpcsFile->addWarning( sprintf( 'Code is touching the %s constant. Make sure it\'s used appropriately.', $constantName ), $previous ); + $phpcsFile->addWarning( sprintf( 'Code is touching the %s constant. Make sure it\'s used appropriately.', $constantName ), $previous, 'WordPressVIPMinimum.Constants.ConstantRestrictions' ); } } } diff --git a/WordPressVIPMinimum/Sniffs/Files/IncludingFileSniff.php b/WordPressVIPMinimum/Sniffs/Files/IncludingFileSniff.php index 40dee8da..733d4530 100644 --- a/WordPressVIPMinimum/Sniffs/Files/IncludingFileSniff.php +++ b/WordPressVIPMinimum/Sniffs/Files/IncludingFileSniff.php @@ -95,7 +95,7 @@ public function process( PHP_CodeSniffer_File $phpcsFile, $stackPtr ) { } if ( T_VARIABLE === $tokens[ $nextToken ]['code'] ) { - $phpcsFile->addWarning( sprintf( 'File inclusion using variable (%s). Probably needs manual inspection.', $tokens[ $nextToken ]['content'] ), $nextToken ); + $phpcsFile->addWarning( sprintf( 'File inclusion using variable (%s). Probably needs manual inspection.', $tokens[ $nextToken ]['content'] ), $nextToken, 'WordPressVIPMinimum.Files.IncludingFile' ); return; } @@ -119,12 +119,12 @@ public function process( PHP_CodeSniffer_File $phpcsFile, $stackPtr ) { if ( 1 === preg_match( '/^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*$/', $tokens[ $nextToken ]['content'] ) ) { // The construct is using custom constant, which needs manula inspection. - $phpcsFile->addWarning( sprintf( 'File inclusion using custom constant (%s). Probably needs manual inspection.', $tokens[ $nextToken ]['content'] ), $nextToken ); + $phpcsFile->addWarning( sprintf( 'File inclusion using custom constant (%s). Probably needs manual inspection.', $tokens[ $nextToken ]['content'] ), $nextToken, 'WordPressVIPMinimum.Files.IncludingFile' ); return; } if ( 0 === strpos( $tokens[ $nextToken ]['content'], '$' ) ) { - $phpcsFile->addWarning( sprintf( 'File inclusion using variable (%s). Probably needs manual inspection.', $tokens[ $nextToken ]['content'] ), $nextToken ); + $phpcsFile->addWarning( sprintf( 'File inclusion using variable (%s). Probably needs manual inspection.', $tokens[ $nextToken ]['content'] ), $nextToken, 'WordPressVIPMinimum.Files.IncludingFile' ); return; } @@ -135,14 +135,14 @@ public function process( PHP_CodeSniffer_File $phpcsFile, $stackPtr ) { $nextNextToken = $phpcsFile->findNext( PHP_CodeSniffer_Tokens::$emptyTokens, ($nextToken + 1), null, true, null, true ); if ( T_OPEN_PARENTHESIS === $tokens[ $nextNextToken ]['code'] ) { - $phpcsFile->addWarning( sprintf( 'File inclusion using custom function ( %s() ). Probably needs manual inspection.', $tokens[ $nextToken ]['content'] ), $nextToken ); + $phpcsFile->addWarning( sprintf( 'File inclusion using custom function ( %s() ). Probably needs manual inspection.', $tokens[ $nextToken ]['content'] ), $nextToken, 'WordPressVIPMinimum.Files.IncludingFile' ); return; } - $phpcsFile->addError( 'Absolute include path must be used. Use get_template_directory, get_stylesheet_directory or plugin_dir_path.', $nextToken ); + $phpcsFile->addError( 'Absolute include path must be used. Use get_template_directory, get_stylesheet_directory or plugin_dir_path.', $nextToken, 'WordPressVIPMinimum.Files.IncludingFile' ); return; } else { - $phpcsFile->addError( 'Absolute include path must be used. Use get_template_directory, get_stylesheet_directory or plugin_dir_path.', $nextToken ); + $phpcsFile->addError( 'Absolute include path must be used. Use get_template_directory, get_stylesheet_directory or plugin_dir_path.', $nextToken, 'WordPressVIPMinimum.Files.IncludingFile' ); return; }// End if(). diff --git a/WordPressVIPMinimum/Sniffs/Functions/CheckReturnValueSniff.php b/WordPressVIPMinimum/Sniffs/Functions/CheckReturnValueSniff.php index 2b03bf4e..e09f9b3e 100644 --- a/WordPressVIPMinimum/Sniffs/Functions/CheckReturnValueSniff.php +++ b/WordPressVIPMinimum/Sniffs/Functions/CheckReturnValueSniff.php @@ -185,7 +185,7 @@ public function findDirectFunctionCalls( $stackPtr ) { $startNext = $openBracket + 1; while ( $next = $phpcsFile->findNext( PHP_CodeSniffer_Tokens::$functionNameTokens, $startNext, $closeBracket, false, null, true ) ) { if ( true === in_array( $tokens[ $next ]['content'], $this->catch[ $functionName ], true ) ) { - $phpcsFile->addError( sprintf( "%s's return type must be checked before calling %s using that value", $tokens[ $next ]['content'], $functionName ), $next ); + $phpcsFile->addError( sprintf( "%s's return type must be checked before calling %s using that value", $tokens[ $next ]['content'], $functionName ), $next, 'WordPressVIPMinimum.Functions.CheckReturnValue' ); } $startNext = $next + 1; } @@ -293,7 +293,7 @@ public function findNonCheckedVariables( $stackPtr ) { if ( true === in_array( $tokens[ $nextFunctionCallWithVariable ]['code'], array_merge( PHP_CodeSniffer_Tokens::$functionNameTokens, $notFunctionsCallee ), true ) && $tokens[ $nextFunctionCallWithVariable ]['content'] === $callee ) { - $phpcsFile->addError( sprintf( 'Type of %s must be checked before calling %s using that variable', $variableName, $callee ), $nextFunctionCallWithVariable ); + $phpcsFile->addError( sprintf( 'Type of %s must be checked before calling %s using that variable', $variableName, $callee ), $nextFunctionCallWithVariable, 'WordPressVIPMinimum.Functions.CheckReturnValue' ); return; } @@ -302,7 +302,7 @@ public function findNonCheckedVariables( $stackPtr ) { if ( true === in_array( $tokens[ $next ]['code'], PHP_CodeSniffer_Tokens::$functionNameTokens, true ) && $tokens[ $next ]['content'] === $callee ) { - $phpcsFile->addError( sprintf( 'Type of %s must be checked before calling %s using that variable', $variableName, $callee ), $next ); + $phpcsFile->addError( sprintf( 'Type of %s must be checked before calling %s using that variable', $variableName, $callee ), $next, 'WordPressVIPMinimum.Functions.CheckReturnValue' ); return; } } diff --git a/WordPressVIPMinimum/Sniffs/VIP/ErrorControlSniff.php b/WordPressVIPMinimum/Sniffs/VIP/ErrorControlSniff.php index 3b578770..7a773f34 100644 --- a/WordPressVIPMinimum/Sniffs/VIP/ErrorControlSniff.php +++ b/WordPressVIPMinimum/Sniffs/VIP/ErrorControlSniff.php @@ -36,7 +36,7 @@ public function process( PHP_CodeSniffer_File $phpcsFile, $stackPtr ) { $tokens = $phpcsFile->getTokens(); - $phpcsFile->addError( sprintf( 'The code shouldn\'t use error control operators (%s). The call should be wrapped in appropriate checks.', $tokens[ $stackPtr ]['content'] ), $stackPtr ); + $phpcsFile->addError( sprintf( 'The code shouldn\'t use error control operators (%s). The call should be wrapped in appropriate checks.', $tokens[ $stackPtr ]['content'] ), $stackPtr, 'WordPressVIPMinimum.VIP.ErrorControl' ); } } diff --git a/WordPressVIPMinimum/Sniffs/VIP/FlushRewriteRulesSniff.php b/WordPressVIPMinimum/Sniffs/VIP/FlushRewriteRulesSniff.php index 50ffbc5e..800b5ec6 100644 --- a/WordPressVIPMinimum/Sniffs/VIP/FlushRewriteRulesSniff.php +++ b/WordPressVIPMinimum/Sniffs/VIP/FlushRewriteRulesSniff.php @@ -84,7 +84,7 @@ public function process( PHP_CodeSniffer_File $phpcsFile, $stackPtr ) { return; } - $phpcsFile->addError( sprintf( '%s should not be used in any normal circumstances in the theme code.', $tokens[ $stackPtr ]['content'] ), $stackPtr ); + $phpcsFile->addError( sprintf( '%s should not be used in any normal circumstances in the theme code.', $tokens[ $stackPtr ]['content'] ), $stackPtr, 'WordPressVIPMinimum.VIP.FlushRewriteRules' ); } } diff --git a/WordPressVIPMinimum/Sniffs/VIP/StaticStrreplaceSniff.php b/WordPressVIPMinimum/Sniffs/VIP/StaticStrreplaceSniff.php index c9457e85..e50013dd 100644 --- a/WordPressVIPMinimum/Sniffs/VIP/StaticStrreplaceSniff.php +++ b/WordPressVIPMinimum/Sniffs/VIP/StaticStrreplaceSniff.php @@ -77,6 +77,6 @@ public function process( PHP_CodeSniffer_File $phpcsFile, $stackPtr ) { } - $phpcsFile->addError( sprintf( 'This code pattern is often used to run a very dangerous shell programs on your server. The code in these files needs to be reviewed, and possibly cleaned.', $tokens[ $stackPtr ]['content'] ), $stackPtr ); + $phpcsFile->addError( sprintf( 'This code pattern is often used to run a very dangerous shell programs on your server. The code in these files needs to be reviewed, and possibly cleaned.', $tokens[ $stackPtr ]['content'] ), $stackPtr, 'WordPressVIPMinimum.VIP.StaticStrreplace' ); }//end process() } diff --git a/WordPressVIPMinimum/Sniffs/Variables/VariableAnalysisSniff.php b/WordPressVIPMinimum/Sniffs/Variables/VariableAnalysisSniff.php index f3aef2c2..6eaa5639 100644 --- a/WordPressVIPMinimum/Sniffs/Variables/VariableAnalysisSniff.php +++ b/WordPressVIPMinimum/Sniffs/Variables/VariableAnalysisSniff.php @@ -487,7 +487,9 @@ function markVariableReadAndWarnIfUndefined($phpcsFile, $varName, $stackPtr, $cu // We haven't been defined by this point. $phpcsFile->addWarning("Variable %s is undefined.", $stackPtr, 'UndefinedVariable', - array("\${$varName}")); + array("\${$varName}"), + 'WordPressVIPMinimum.Variables.VariableAnalysis' + ); } return true; } @@ -720,7 +722,9 @@ protected function checkForFunctionPrototype( // We haven't been defined by this point. $phpcsFile->addWarning("Variable %s is undefined.", $stackPtr, 'UndefinedVariable', - array("\${$varName}")); + array("\${$varName}"), + 'WordPressVIPMinimum.Variables.VariableAnalysis' + ); return true; } // $functionPtr is at the use, we need the function keyword for start of scope. @@ -865,7 +869,9 @@ protected function checkForStaticMember( if ($tokens[$scopePtr]['code'] === T_CLOSURE) { $phpcsFile->addError("Use of {$err_desc}%s inside closure.", $stackPtr, $err_class, - array("\${$varName}")); + array("\${$varName}"), + 'WordPressVIPMinimum.Variables.VariableAnalysis' + ); return true; } if ($scopeCode === T_CLASS) { @@ -875,7 +881,9 @@ protected function checkForStaticMember( } $phpcsFile->addError("Use of {$err_desc}%s outside class definition.", $stackPtr, $err_class, - array("\${$varName}")); + array("\${$varName}"), + 'WordPressVIPMinimum.Variables.VariableAnalysis' + ); return true; } diff --git a/ruleset_test.inc b/ruleset_test.inc index efd20808..4faeb2c5 100644 --- a/ruleset_test.inc +++ b/ruleset_test.inc @@ -130,4 +130,4 @@ get_children(); // Bad. Warning. Message. attachment_url_to_postid(); // Bad. Error. -str_replace( 'foo', 'bar', 'foobar' ); // Bad. Error. \ No newline at end of file +str_replace( 'foo', 'bar', 'foobar' ); // Bad. Error. From fb5643d80037fe96b74e0559dbea6250bb8bc192 Mon Sep 17 00:00:00 2001 From: David Binovec Date: Mon, 14 Aug 2017 14:21:08 +0000 Subject: [PATCH 24/31] Fix PHPCS 2.x unit tests --- .../Sniffs/Variables/VariableAnalysisSniff.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/WordPressVIPMinimum/Sniffs/Variables/VariableAnalysisSniff.php b/WordPressVIPMinimum/Sniffs/Variables/VariableAnalysisSniff.php index f02b2cc2..7cdbf685 100644 --- a/WordPressVIPMinimum/Sniffs/Variables/VariableAnalysisSniff.php +++ b/WordPressVIPMinimum/Sniffs/Variables/VariableAnalysisSniff.php @@ -481,14 +481,16 @@ function isVariableUndefined($varName, $stackPtr, $currScope) { } function markVariableReadAndWarnIfUndefined($phpcsFile, $varName, $stackPtr, $currScope) { + echo $varName . "\n"; $this->markVariableRead($varName, $stackPtr, $currScope); if ($this->isVariableUndefined($varName, $stackPtr, $currScope) === true) { // We haven't been defined by this point. - $phpcsFile->addWarning("Variable %s is undefined.", $stackPtr, + $phpcsFile->addWarning( + "Variable %s is undefined.", + $stackPtr, 'UndefinedVariable', - array("\${$varName}"), - 'WordPressVIPMinimum.Variables.VariableAnalysis' + array("\${$varName}") ); } return true; From 78456b881540f9e062942b952009fb2224b4f47f Mon Sep 17 00:00:00 2001 From: David Binovec Date: Mon, 14 Aug 2017 15:24:21 +0000 Subject: [PATCH 25/31] Remove "echo" introduced for debugging purposes as it's breaking the ruleset test --- WordPressVIPMinimum/Sniffs/Variables/VariableAnalysisSniff.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WordPressVIPMinimum/Sniffs/Variables/VariableAnalysisSniff.php b/WordPressVIPMinimum/Sniffs/Variables/VariableAnalysisSniff.php index 7cdbf685..0d0b0892 100644 --- a/WordPressVIPMinimum/Sniffs/Variables/VariableAnalysisSniff.php +++ b/WordPressVIPMinimum/Sniffs/Variables/VariableAnalysisSniff.php @@ -481,7 +481,7 @@ function isVariableUndefined($varName, $stackPtr, $currScope) { } function markVariableReadAndWarnIfUndefined($phpcsFile, $varName, $stackPtr, $currScope) { - echo $varName . "\n"; + $this->markVariableRead($varName, $stackPtr, $currScope); if ($this->isVariableUndefined($varName, $stackPtr, $currScope) === true) { From 1c38087e0b2b9e84b0535fe6a54db05792221786 Mon Sep 17 00:00:00 2001 From: David Binovec Date: Mon, 14 Aug 2017 15:24:57 +0000 Subject: [PATCH 26/31] Use namespace in WordPressVIPMinimum/Sniffs/VIP/RestrictedFunctionsSniff accordingly to the parent theme, as not using one is breaking the identifications of individual sniffs on ruleset.xml level and thus breaking message escallation and overriding. --- WordPressVIPMinimum/Sniffs/VIP/RestrictedFunctionsSniff.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/WordPressVIPMinimum/Sniffs/VIP/RestrictedFunctionsSniff.php b/WordPressVIPMinimum/Sniffs/VIP/RestrictedFunctionsSniff.php index ba95c60e..128d3c05 100644 --- a/WordPressVIPMinimum/Sniffs/VIP/RestrictedFunctionsSniff.php +++ b/WordPressVIPMinimum/Sniffs/VIP/RestrictedFunctionsSniff.php @@ -5,12 +5,14 @@ * @package VIPCS\WordPressVIPMinimum */ +namespace WordPressVIPMinimum\Sniffs\VIP; + /** * Restricts usage of some functions in VIP context. * * @package VIPCS\WordPressVIPMinimum */ -class WordPressVIPMinimum_Sniffs_VIP_RestrictedFunctionsSniff extends WordPress\Sniffs\VIP\RestrictedFunctionsSniff { +class RestrictedFunctionsSniff extends \WordPress\Sniffs\VIP\RestrictedFunctionsSniff { /** * Groups of functions to restrict. From 262f7837d5ef46a742d2a91a24f9bf1095fd550c Mon Sep 17 00:00:00 2001 From: David Binovec Date: Mon, 14 Aug 2017 15:56:43 +0000 Subject: [PATCH 27/31] Use appropriate namespaces in all Sniffs in the WordPressVIPMinimum standard. Re-enable the PSR1 Class Declaration sniff for the code style of the project itself. --- .../Sniffs/Actions/PreGetPostsSniff.php | 33 ++++--- .../Sniffs/Cache/CacheValueOverrideSniff.php | 31 +++--- .../Classes/DeclarationCompatibilitySniff.php | 30 +++--- .../Constants/ConstantRestrictionsSniff.php | 19 ++-- .../Sniffs/Files/IncludingFileSniff.php | 23 +++-- .../Functions/CheckReturnValueSniff.php | 39 ++++---- .../Sniffs/VIP/ErrorControlSniff.php | 12 ++- .../Sniffs/VIP/FlushRewriteRulesSniff.php | 21 ++-- .../Sniffs/VIP/RegexpCompareSniff.php | 4 +- .../Sniffs/VIP/RemoteRequestTimeoutSniff.php | 4 +- .../Sniffs/VIP/StaticStrreplaceSniff.php | 25 +++-- .../Variables/VariableAnalysisHelper.php | 2 + .../Variables/VariableAnalysisSniff.php | 96 ++++++++++--------- bin/phpcs.xml | 6 +- 14 files changed, 199 insertions(+), 146 deletions(-) diff --git a/WordPressVIPMinimum/Sniffs/Actions/PreGetPostsSniff.php b/WordPressVIPMinimum/Sniffs/Actions/PreGetPostsSniff.php index 9f115471..c624ba6b 100644 --- a/WordPressVIPMinimum/Sniffs/Actions/PreGetPostsSniff.php +++ b/WordPressVIPMinimum/Sniffs/Actions/PreGetPostsSniff.php @@ -5,6 +5,11 @@ * @package VIPCS\WordPressVIPMinimum */ +namespace WordPressVIPMinimum\Sniffs\Actions; + +use PHP_CodeSniffer_File as File; +use PHP_CodeSniffer_Tokens as Tokens; + /** * This sniff validates a propper usage of pre_get_posts action callback * @@ -12,7 +17,7 @@ * * @package VIPCS\WordPressVIPMinimum */ -class WordPressVIPminimum_Sniffs_Actions_PreGetPostsSniff implements PHP_CodeSniffer_Sniff { +class Actions_PreGetPostsSniff implements \PHP_CodeSniffer_Sniff { /** * The tokens of the phpcsFile. @@ -34,7 +39,7 @@ class WordPressVIPminimum_Sniffs_Actions_PreGetPostsSniff implements PHP_CodeSni * @return array(int) */ public function register() { - return PHP_CodeSniffer_Tokens::$functionNameTokens; + return Tokens::$functionNameTokens; }//end register() @@ -42,13 +47,13 @@ public function register() { /** * Processes the tokens that this sniff is interested in. * - * @param PHP_CodeSniffer_File $phpcsFile The file where the token was found. - * @param int $stackPtr The position in the stack where - * the token was found. + * @param \PHP_CodeSniffer\Files\File $phpcsFile The file where the token was found. + * @param int $stackPtr The position in the stack where + * the token was found. * * @return void */ - public function process( PHP_CodeSniffer_File $phpcsFile, $stackPtr ) { + public function process( File $phpcsFile, $stackPtr ) { $this->_tokens = $phpcsFile->getTokens(); @@ -62,7 +67,7 @@ public function process( PHP_CodeSniffer_File $phpcsFile, $stackPtr ) { } $actionNamePtr = $this->_phpcsFile->findNext( - array_merge( PHP_CodeSniffer_Tokens::$emptyTokens, array( T_OPEN_PARENTHESIS ) ), // types. + array_merge( Tokens::$emptyTokens, array( T_OPEN_PARENTHESIS ) ), // types. $stackPtr + 1, // start. null, // end. true, // exclude. @@ -81,7 +86,7 @@ public function process( PHP_CodeSniffer_File $phpcsFile, $stackPtr ) { } $callbackPtr = $this->_phpcsFile->findNext( - array_merge( PHP_CodeSniffer_Tokens::$emptyTokens, array( T_COMMA ) ), // types. + array_merge( Tokens::$emptyTokens, array( T_COMMA ) ), // types. $actionNamePtr + 1, // start. null, // end. true, // exclude. @@ -98,7 +103,7 @@ public function process( PHP_CodeSniffer_File $phpcsFile, $stackPtr ) { $this->processClosure( $callbackPtr ); } elseif ( 'T_ARRAY' === $this->_tokens[ $callbackPtr ]['type'] ) { $this->processArray( $callbackPtr ); - } elseif ( true === in_array( $this->_tokens[ $callbackPtr ]['code'], PHP_CodeSniffer_Tokens::$stringTokens, true ) ) { + } elseif ( true === in_array( $this->_tokens[ $callbackPtr ]['code'], Tokens::$stringTokens, true ) ) { $this->processString( $callbackPtr ); } @@ -112,7 +117,7 @@ public function process( PHP_CodeSniffer_File $phpcsFile, $stackPtr ) { private function processArray( $stackPtr ) { $previous = $this->_phpcsFile->findPrevious( - PHP_CodeSniffer_Tokens::$emptyTokens, // types + Tokens::$emptyTokens, // types $this->_tokens[ $stackPtr ]['parenthesis_closer'] - 1, // start. null, // end. true, // exclude. @@ -134,7 +139,7 @@ private function processString( $stackPtr ) { $callbackFunctionName = substr( $this->_tokens[ $stackPtr ]['content'], 1, -1 ); $callbackFunctionPtr = $this->_phpcsFile->findNext( - PHP_CodeSniffer_Tokens::$functionNameTokens, // types. + Tokens::$functionNameTokens, // types. 0, // start. null, // end. false, // exclude. @@ -346,7 +351,7 @@ private function isEarlyMainQueryCheck( $stackPtr ) { */ private function isWPQueryMethodCall( $stackPtr, $method = null ) { $next = $this->_phpcsFile->findNext( - PHP_CodeSniffer_Tokens::$emptyTokens, // types. + Tokens::$emptyTokens, // types. $stackPtr + 1, // start. null, // end. true, // exclude. @@ -363,7 +368,7 @@ private function isWPQueryMethodCall( $stackPtr, $method = null ) { } $next = $this->_phpcsFile->findNext( - PHP_CodeSniffer_Tokens::$emptyTokens, // types. + Tokens::$emptyTokens, // types. $next + 1, // start. null, // end. true, // exclude. @@ -372,7 +377,7 @@ private function isWPQueryMethodCall( $stackPtr, $method = null ) { ); if ( $next && - true === in_array( $this->_tokens[ $next ]['code'], PHP_CodeSniffer_Tokens::$functionNameTokens, true ) && + true === in_array( $this->_tokens[ $next ]['code'], Tokens::$functionNameTokens, true ) && $method === $this->_tokens[ $next ]['content'] ) { return true; diff --git a/WordPressVIPMinimum/Sniffs/Cache/CacheValueOverrideSniff.php b/WordPressVIPMinimum/Sniffs/Cache/CacheValueOverrideSniff.php index 50b051b9..10f55a26 100644 --- a/WordPressVIPMinimum/Sniffs/Cache/CacheValueOverrideSniff.php +++ b/WordPressVIPMinimum/Sniffs/Cache/CacheValueOverrideSniff.php @@ -5,6 +5,11 @@ * @package VIPCS\WordPressVIPMinimum */ +namespace WordPressVIPMinimum\Sniffs\Cache; + +use PHP_CodeSniffer_File as File; +use PHP_CodeSniffer_Tokens as Tokens; + /** * This sniff enforces checking the return value of a function before passing it to anoher one. * @@ -16,7 +21,7 @@ * * @package VIPCS\WordPressVIPMinimum */ -class WordPressVIPminimum_Sniffs_Cache_CacheValueOverrideSniff implements PHP_CodeSniffer_Sniff { +class CacheValueOverrideSniff implements \PHP_CodeSniffer_Sniff { /** * Tokens of the file. @@ -31,7 +36,7 @@ class WordPressVIPminimum_Sniffs_Cache_CacheValueOverrideSniff implements PHP_Co * @return array(int) */ public function register() { - return PHP_CodeSniffer_Tokens::$functionNameTokens; + return Tokens::$functionNameTokens; }//end register() @@ -39,13 +44,13 @@ public function register() { /** * Processes the tokens that this sniff is interested in. * - * @param PHP_CodeSniffer_File $phpcsFile The file where the token was found. - * @param int $stackPtr The position in the stack where - * the token was found. + * @param \PHP_CodeSniffer\Files\File $phpcsFile The file where the token was found. + * @param int $stackPtr The position in the stack where + * the token was found. * * @return void */ - public function process( PHP_CodeSniffer_File $phpcsFile, $stackPtr ) { + public function process( File $phpcsFile, $stackPtr ) { $this->_tokens = $phpcsFile->getTokens(); $tokens = $phpcsFile->getTokens(); @@ -74,21 +79,21 @@ public function process( PHP_CodeSniffer_File $phpcsFile, $stackPtr ) { $variableName = $variableToken['content']; // Find the next non-empty token. - $openBracket = $phpcsFile->findNext( PHP_CodeSniffer_Tokens::$emptyTokens, ($stackPtr + 1), null, true ); + $openBracket = $phpcsFile->findNext( Tokens::$emptyTokens, ($stackPtr + 1), null, true ); // Find the closing bracket. $closeBracket = $tokens[ $openBracket ]['parenthesis_closer']; $nextVariableOccurrence = $phpcsFile->findNext( T_VARIABLE, ($closeBracket + 1), null, false, $variableName, false ); - $rightAfterNextVariableOccurence = $phpcsFile->findNext( PHP_CodeSniffer_Tokens::$emptyTokens, ($nextVariableOccurrence + 1), null, true, null, true ); + $rightAfterNextVariableOccurence = $phpcsFile->findNext( Tokens::$emptyTokens, ($nextVariableOccurrence + 1), null, true, null, true ); if ( T_EQUAL !== $tokens[ $rightAfterNextVariableOccurence ]['code'] ) { // Not a value override. return; } - $valueAfterEqualSign = $phpcsFile->findNext( PHP_CodeSniffer_Tokens::$emptyTokens, ($rightAfterNextVariableOccurence + 1), null, true, null, true ); + $valueAfterEqualSign = $phpcsFile->findNext( Tokens::$emptyTokens, ($rightAfterNextVariableOccurence + 1), null, true, null, true ); if ( T_FALSE === $tokens[ $valueAfterEqualSign ]['code'] ) { $phpcsFile->addError( sprintf( 'Obtained cached value in %s is being overriden. Disabling caching?', $variableName ), $nextVariableOccurrence, 'WordPressVIPMinimum.Cache.CacheValueOverride' ); @@ -108,12 +113,12 @@ private function isFunctionCall( $stackPtr ) { $tokens = $this->_tokens; $phpcsFile = $this->_phpcsFile; - if ( false === in_array( $tokens[ $stackPtr ]['code'], PHP_CodeSniffer_Tokens::$functionNameTokens, true ) ) { + if ( false === in_array( $tokens[ $stackPtr ]['code'], Tokens::$functionNameTokens, true ) ) { return false; } // Find the next non-empty token. - $openBracket = $phpcsFile->findNext( PHP_CodeSniffer_Tokens::$emptyTokens, ($stackPtr + 1), null, true ); + $openBracket = $phpcsFile->findNext( Tokens::$emptyTokens, ($stackPtr + 1), null, true ); if ( T_OPEN_PARENTHESIS !== $tokens[ $openBracket ]['code'] ) { // Not a function call. @@ -121,7 +126,7 @@ private function isFunctionCall( $stackPtr ) { } // Find the previous non-empty token. - $search = PHP_CodeSniffer_Tokens::$emptyTokens; + $search = Tokens::$emptyTokens; $search[] = T_BITWISE_AND; $previous = $phpcsFile->findPrevious( $search, ($stackPtr - 1), null, true ); if ( T_FUNCTION === $tokens[ $previous ]['code'] ) { @@ -145,7 +150,7 @@ private function isVariableAssignment( $stackPtr ) { $phpcsFile = $this->_phpcsFile; // Find the previous non-empty token. - $search = PHP_CodeSniffer_Tokens::$emptyTokens; + $search = Tokens::$emptyTokens; $search[] = T_BITWISE_AND; $previous = $phpcsFile->findPrevious( $search, ($stackPtr - 1), null, true ); diff --git a/WordPressVIPMinimum/Sniffs/Classes/DeclarationCompatibilitySniff.php b/WordPressVIPMinimum/Sniffs/Classes/DeclarationCompatibilitySniff.php index c826f56d..81d15400 100644 --- a/WordPressVIPMinimum/Sniffs/Classes/DeclarationCompatibilitySniff.php +++ b/WordPressVIPMinimum/Sniffs/Classes/DeclarationCompatibilitySniff.php @@ -5,6 +5,10 @@ * @package VIPCS\WordPressVIPMinimum */ +namespace WordPressVIPMinimum\Sniffs\Classes; + +use PHP_CodeSniffer_File as File; + // WPCS pre 0.1.3 backwardcompatibility. if ( ! class_exists( '\PHP_CodeSniffer_Standards_AbstractScopeSniff' ) ) { class_alias( 'PHP_CodeSniffer\Sniffs\AbstractScopeSniff', '\PHP_CodeSniffer_Standards_AbstractScopeSniff' ); @@ -15,7 +19,7 @@ class_alias( 'PHP_CodeSniffer\Sniffs\AbstractScopeSniff', '\PHP_CodeSniffer_Stan * * @package VIPCS\WordPressVIPMinimum */ -class WordPressVIPMinimum_Sniffs_Classes_DeclarationCompatibilitySniff extends PHP_CodeSniffer_Standards_AbstractScopeSniff { +class DeclarationCompatibilitySniff extends \PHP_CodeSniffer_Standards_AbstractScopeSniff { /** * The name of the class we are currently checking. @@ -194,14 +198,14 @@ public function __construct() { /** * Processes this test when one of its tokens is encountered. * - * @param PHP_CodeSniffer_File $phpcsFile The current file being scanned. - * @param int $stackPtr The position of the current token - * in the stack passed in $tokens. - * @param int $currScope A pointer to the start of the scope. + * @param \PHP_CodeSniffer\Files\File $phpcsFile The current file being scanned. + * @param int $stackPtr The position of the current token + * in the stack passed in $tokens. + * @param int $currScope A pointer to the start of the scope. * * @return void */ - protected function processTokenWithinScope( PHP_CodeSniffer_File $phpcsFile, $stackPtr, $currScope ) { + protected function processTokenWithinScope( File $phpcsFile, $stackPtr, $currScope ) { $className = $phpcsFile->getDeclarationName( $currScope ); @@ -288,7 +292,7 @@ protected function processTokenWithinScope( PHP_CodeSniffer_File $phpcsFile, $st * @param string $methodName The name of the method currently being examined. * @param array $currentMethodSignature The list of params and their options of the method which is being examined. * @param array $parentMethodSignature The list of params and their options of the parent class method. - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. + * @param File $phpcsFile The file being scanned. * @param int $stackPtr The position of the current token in the stack. * * @return void @@ -341,12 +345,12 @@ private function generateParamList( $methodSignature ) { /** * Extracts all the function names found in the given scope. * - * @param PHP_CodeSniffer_File $phpcsFile The current file being scanned. - * @param int $currScope A pointer to the start of the scope. + * @param File $phpcsFile The current file being scanned. + * @param int $currScope A pointer to the start of the scope. * * @return void */ - protected function loadFunctionNamesInScope( PHP_CodeSniffer_File $phpcsFile, $currScope ) { + protected function loadFunctionNamesInScope( File $phpcsFile, $currScope ) { $this->_functionList = array(); $tokens = $phpcsFile->getTokens(); @@ -364,8 +368,8 @@ protected function loadFunctionNamesInScope( PHP_CodeSniffer_File $phpcsFile, $c /** * Do nothing outside the scope. Has to be implemented accordingly to parent abstract class. * - * @param PHP_CodeSniffer_File $phpcsFile PHPCS File. - * @param int $stackPtr Stack position. + * @param File $phpcsFile PHPCS File. + * @param int $stackPtr Stack position. */ - public function processTokenOutsideScope( PHP_CodeSniffer_File $phpcsFile, $stackPtr ) {} + public function processTokenOutsideScope( File $phpcsFile, $stackPtr ) {} } diff --git a/WordPressVIPMinimum/Sniffs/Constants/ConstantRestrictionsSniff.php b/WordPressVIPMinimum/Sniffs/Constants/ConstantRestrictionsSniff.php index 17a4215f..bab2d034 100644 --- a/WordPressVIPMinimum/Sniffs/Constants/ConstantRestrictionsSniff.php +++ b/WordPressVIPMinimum/Sniffs/Constants/ConstantRestrictionsSniff.php @@ -6,12 +6,17 @@ * @link https://github.com/Automattic/VIP-Coding-Standards */ +namespace WordPressVIPMinimum\Sniffs\Constants; + +use PHP_CodeSniffer_File as File; +use PHP_CodeSniffer_Tokens as Tokens; + /** * Restricts usage of some constants. * * @package VIPCS\WordPressVIPMinimum */ -class WordPressVIPMinimum_Sniffs_Constants_ConstantRestrictionsSniff implements PHP_CodeSniffer_Sniff { +class ConstantRestrictionsSniff implements \PHP_CodeSniffer_Sniff { /** * List of restricted constant names. @@ -37,12 +42,12 @@ public function register() { /** * Process this test when one of its tokens is encoutnered * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token in the stack passed in $tokens. + * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned. + * @param int $stackPtr The position of the current token in the stack passed in $tokens. * * @return void */ - public function process( PHP_CodeSniffer_File $phpcsFile, $stackPtr ) { + public function process( File $phpcsFile, $stackPtr ) { $tokens = $phpcsFile->getTokens(); @@ -63,7 +68,7 @@ public function process( PHP_CodeSniffer_File $phpcsFile, $stackPtr ) { } // Find the previous non-empty token. - $openBracket = $phpcsFile->findPrevious( PHP_CodeSniffer_Tokens::$emptyTokens, ($stackPtr - 1), null, true, null, true ); + $openBracket = $phpcsFile->findPrevious( Tokens::$emptyTokens, ($stackPtr - 1), null, true, null, true ); if ( T_OPEN_PARENTHESIS !== $tokens[ $openBracket ]['code'] ) { // Not a function call. @@ -76,7 +81,7 @@ public function process( PHP_CodeSniffer_File $phpcsFile, $stackPtr ) { } // Find the previous non-empty token. - $search = PHP_CodeSniffer_Tokens::$emptyTokens; + $search = Tokens::$emptyTokens; $search[] = T_BITWISE_AND; $previous = $phpcsFile->findPrevious( $search, ($openBracket - 1), null, true ); if ( T_FUNCTION === $tokens[ $previous ]['code'] ) { @@ -84,7 +89,7 @@ public function process( PHP_CodeSniffer_File $phpcsFile, $stackPtr ) { return; } - if ( true === in_array( $tokens[ $previous ]['code'], PHP_CodeSniffer_Tokens::$functionNameTokens, true ) ) { + if ( true === in_array( $tokens[ $previous ]['code'], Tokens::$functionNameTokens, true ) ) { if ( 'define' === $tokens[ $previous ]['content'] ) { $phpcsFile->addError( sprintf( 'The definition of %s constant is prohibited. Please use a different name.', $constantName ), $previous, 'WordPressVIPMinimum.Constants.ConstantRestrictions' ); } else { diff --git a/WordPressVIPMinimum/Sniffs/Files/IncludingFileSniff.php b/WordPressVIPMinimum/Sniffs/Files/IncludingFileSniff.php index 733d4530..576fed97 100644 --- a/WordPressVIPMinimum/Sniffs/Files/IncludingFileSniff.php +++ b/WordPressVIPMinimum/Sniffs/Files/IncludingFileSniff.php @@ -5,6 +5,11 @@ * @package VIPCS\WordPressVIPMinimum */ +namespace WordPressVIPMinimum\Sniffs\Files; + +use PHP_CodeSniffer_File as File; +use PHP_CodeSniffer_Tokens as Tokens; + /** * WordPressVIPMinimum_Sniffs_Files_IncludingFileSniff. * @@ -13,7 +18,7 @@ * * @package VIPCS\WordPressVIPMinimum */ -class WordPressVIPMinimum_Sniffs_Files_IncludingFileSniff implements PHP_CodeSniffer_Sniff { +class IncludingFileSniff implements \PHP_CodeSniffer_Sniff { /** * List of function used for getting paths. @@ -65,7 +70,7 @@ class WordPressVIPMinimum_Sniffs_Files_IncludingFileSniff implements PHP_CodeSni * @return array */ public function register() { - return PHP_CodeSniffer_Tokens::$includeTokens; + return Tokens::$includeTokens; }//end register() @@ -73,20 +78,20 @@ public function register() { /** * Processes this test, when one of its tokens is encountered. * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token in the - * stack passed in $tokens. + * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned. + * @param int $stackPtr The position of the current token in the + * stack passed in $tokens. * * @return void */ - public function process( PHP_CodeSniffer_File $phpcsFile, $stackPtr ) { + public function process( File $phpcsFile, $stackPtr ) { $tokens = $phpcsFile->getTokens(); - $nextToken = $phpcsFile->findNext( PHP_CodeSniffer_Tokens::$emptyTokens, ($stackPtr + 1), null, true, null, true ); + $nextToken = $phpcsFile->findNext( Tokens::$emptyTokens, ($stackPtr + 1), null, true, null, true ); if ( T_OPEN_PARENTHESIS === $tokens[ $nextToken ]['code'] ) { // The construct is using parenthesis, grab the next non empty token. - $nextToken = $phpcsFile->findNext( PHP_CodeSniffer_Tokens::$emptyTokens, ($nextToken + 1), null, true, null, true ); + $nextToken = $phpcsFile->findNext( Tokens::$emptyTokens, ($nextToken + 1), null, true, null, true ); } if ( T_DIR === $tokens[ $nextToken ]['code'] || '__DIR__' === $tokens[ $nextToken ]['content'] ) { @@ -133,7 +138,7 @@ public function process( PHP_CodeSniffer_File $phpcsFile, $stackPtr ) { return; } - $nextNextToken = $phpcsFile->findNext( PHP_CodeSniffer_Tokens::$emptyTokens, ($nextToken + 1), null, true, null, true ); + $nextNextToken = $phpcsFile->findNext( Tokens::$emptyTokens, ($nextToken + 1), null, true, null, true ); if ( T_OPEN_PARENTHESIS === $tokens[ $nextNextToken ]['code'] ) { $phpcsFile->addWarning( sprintf( 'File inclusion using custom function ( %s() ). Probably needs manual inspection.', $tokens[ $nextToken ]['content'] ), $nextToken, 'WordPressVIPMinimum.Files.IncludingFile' ); return; diff --git a/WordPressVIPMinimum/Sniffs/Functions/CheckReturnValueSniff.php b/WordPressVIPMinimum/Sniffs/Functions/CheckReturnValueSniff.php index e09f9b3e..df5b8870 100644 --- a/WordPressVIPMinimum/Sniffs/Functions/CheckReturnValueSniff.php +++ b/WordPressVIPMinimum/Sniffs/Functions/CheckReturnValueSniff.php @@ -5,6 +5,11 @@ * @package VIPCS\WordPressVIPMinimum */ +namespace WordPressVIPMinimum\Sniffs\Functions; + +use PHP_CodeSniffer_File as File; +use PHP_CodeSniffer_Tokens as Tokens; + /** * This sniff enforces checking the return value of a function before passing it to another one. * @@ -14,7 +19,7 @@ * echo esc_url( wpcom_vip_get_term_link( $term ) ); * */ -class WordPressVIPminimum_Sniffs_Functions_CheckReturnValueSniff implements PHP_CodeSniffer_Sniff { +class CheckReturnValueSniff implements \PHP_CodeSniffer_Sniff { /** * Tokens of the whole file. @@ -63,7 +68,7 @@ class WordPressVIPminimum_Sniffs_Functions_CheckReturnValueSniff implements PHP_ * @return array(int) */ public function register() { - return PHP_CodeSniffer_Tokens::$functionNameTokens; + return Tokens::$functionNameTokens; }//end register() @@ -71,13 +76,13 @@ public function register() { /** * Processes the tokens that this sniff is interested in. * - * @param PHP_CodeSniffer_File $phpcsFile The file where the token was found. - * @param int $stackPtr The position in the stack where - * the token was found. + * @param \PHP_CodeSniffer\Files\File $phpcsFile The file where the token was found. + * @param int $stackPtr The position in the stack where + * the token was found. * * @return void */ - public function process( PHP_CodeSniffer_File $phpcsFile, $stackPtr ) { + public function process( File $phpcsFile, $stackPtr ) { $this->_tokens = $phpcsFile->getTokens(); $this->_phpcsFile = $phpcsFile; @@ -98,12 +103,12 @@ private function isFunctionCall( $stackPtr ) { $tokens = $this->_tokens; $phpcsFile = $this->_phpcsFile; - if ( false === in_array( $tokens[ $stackPtr ]['code'], PHP_CodeSniffer_Tokens::$functionNameTokens, true ) ) { + if ( false === in_array( $tokens[ $stackPtr ]['code'], Tokens::$functionNameTokens, true ) ) { return false; } // Find the next non-empty token. - $openBracket = $phpcsFile->findNext( PHP_CodeSniffer_Tokens::$emptyTokens, ($stackPtr + 1), null, true ); + $openBracket = $phpcsFile->findNext( Tokens::$emptyTokens, ($stackPtr + 1), null, true ); if ( T_OPEN_PARENTHESIS !== $tokens[ $openBracket ]['code'] ) { // Not a function call. @@ -111,7 +116,7 @@ private function isFunctionCall( $stackPtr ) { } // Find the previous non-empty token. - $search = PHP_CodeSniffer_Tokens::$emptyTokens; + $search = Tokens::$emptyTokens; $search[] = T_BITWISE_AND; $previous = $phpcsFile->findPrevious( $search, ($stackPtr - 1), null, true ); if ( T_FUNCTION === $tokens[ $previous ]['code'] ) { @@ -135,7 +140,7 @@ private function isVariableAssignment( $stackPtr ) { $phpcsFile = $this->_phpcsFile; // Find the previous non-empty token. - $search = PHP_CodeSniffer_Tokens::$emptyTokens; + $search = Tokens::$emptyTokens; $search[] = T_BITWISE_AND; $previous = $phpcsFile->findPrevious( $search, ($stackPtr - 1), null, true ); @@ -177,13 +182,13 @@ public function findDirectFunctionCalls( $stackPtr ) { } // Find the next non-empty token. - $openBracket = $phpcsFile->findNext( PHP_CodeSniffer_Tokens::$emptyTokens, ($stackPtr + 1), null, true ); + $openBracket = $phpcsFile->findNext( Tokens::$emptyTokens, ($stackPtr + 1), null, true ); // Find the closing bracket. $closeBracket = $tokens[ $openBracket ]['parenthesis_closer']; $startNext = $openBracket + 1; - while ( $next = $phpcsFile->findNext( PHP_CodeSniffer_Tokens::$functionNameTokens, $startNext, $closeBracket, false, null, true ) ) { + while ( $next = $phpcsFile->findNext( Tokens::$functionNameTokens, $startNext, $closeBracket, false, null, true ) ) { if ( true === in_array( $tokens[ $next ]['content'], $this->catch[ $functionName ], true ) ) { $phpcsFile->addError( sprintf( "%s's return type must be checked before calling %s using that value", $tokens[ $next ]['content'], $functionName ), $next, 'WordPressVIPMinimum.Functions.CheckReturnValue' ); } @@ -241,7 +246,7 @@ public function findNonCheckedVariables( $stackPtr ) { $variableName = $variableToken['content']; // Find the next non-empty token. - $openBracket = $phpcsFile->findNext( PHP_CodeSniffer_Tokens::$emptyTokens, ($stackPtr + 1), null, true ); + $openBracket = $phpcsFile->findNext( Tokens::$emptyTokens, ($stackPtr + 1), null, true ); // Find the closing bracket. $closeBracket = $tokens[ $openBracket ]['parenthesis_closer']; @@ -279,7 +284,7 @@ public function findNonCheckedVariables( $stackPtr ) { $nextVariableOccurrence = $phpcsFile->findNext( T_VARIABLE, ($closeBracket + 1), null, false, $variableName, false ); // Find previous non-empty token, which is not an open parenthesis, comma nor variable. - $search = PHP_CodeSniffer_Tokens::$emptyTokens; + $search = Tokens::$emptyTokens; $search[] = T_OPEN_PARENTHESIS; // This allows us to check for variables which are passed as second paramt of a function. Eg.: array_key_exists. $search[] = T_COMMA; @@ -290,16 +295,16 @@ public function findNonCheckedVariables( $stackPtr ) { foreach ( $callees as $callee ) { $notFunctionsCallee = array_key_exists( $callee, $this->notFunctions ) ? (array) $this->notFunctions[ $callee ] : array(); // Check whether the found token is one of the function calls (or foreach call) we are interested in. - if ( true === in_array( $tokens[ $nextFunctionCallWithVariable ]['code'], array_merge( PHP_CodeSniffer_Tokens::$functionNameTokens, $notFunctionsCallee ), true ) + if ( true === in_array( $tokens[ $nextFunctionCallWithVariable ]['code'], array_merge( Tokens::$functionNameTokens, $notFunctionsCallee ), true ) && $tokens[ $nextFunctionCallWithVariable ]['content'] === $callee ) { $phpcsFile->addError( sprintf( 'Type of %s must be checked before calling %s using that variable', $variableName, $callee ), $nextFunctionCallWithVariable, 'WordPressVIPMinimum.Functions.CheckReturnValue' ); return; } - $search = array_merge( PHP_CodeSniffer_Tokens::$emptyTokens, array( T_EQUAL ) ); + $search = array_merge( Tokens::$emptyTokens, array( T_EQUAL ) ); $next = $phpcsFile->findNext( $search, $nextVariableOccurrence + 1, null, true, null, false ); - if ( true === in_array( $tokens[ $next ]['code'], PHP_CodeSniffer_Tokens::$functionNameTokens, true ) + if ( true === in_array( $tokens[ $next ]['code'], Tokens::$functionNameTokens, true ) && $tokens[ $next ]['content'] === $callee ) { $phpcsFile->addError( sprintf( 'Type of %s must be checked before calling %s using that variable', $variableName, $callee ), $next, 'WordPressVIPMinimum.Functions.CheckReturnValue' ); diff --git a/WordPressVIPMinimum/Sniffs/VIP/ErrorControlSniff.php b/WordPressVIPMinimum/Sniffs/VIP/ErrorControlSniff.php index 7a773f34..1935c7b0 100644 --- a/WordPressVIPMinimum/Sniffs/VIP/ErrorControlSniff.php +++ b/WordPressVIPMinimum/Sniffs/VIP/ErrorControlSniff.php @@ -6,12 +6,16 @@ * @link https://github.com/Automattic/VIP-Coding-Standards */ +namespace WordPressVIPMinimum\Sniffs\VIP; + +use PHP_CodeSniffer_File as File; + /** * Restricts usage of error control operators. Currently only the at sign. * * @package VIPCS\WordPressVIPMinimum */ -class WordPressVIPMinimum_Sniffs_VIP_ErrorControlSniff implements PHP_CodeSniffer_Sniff { +class ErrorControlSniff implements \PHP_CodeSniffer_Sniff { /** * Returns an array of tokens this test wants to listen for. @@ -27,12 +31,12 @@ public function register() { /** * Process this test when one of its tokens is encoutered * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token in the stack passed in $tokens. + * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned. + * @param int $stackPtr The position of the current token in the stack passed in $tokens. * * @return void */ - public function process( PHP_CodeSniffer_File $phpcsFile, $stackPtr ) { + public function process( File $phpcsFile, $stackPtr ) { $tokens = $phpcsFile->getTokens(); diff --git a/WordPressVIPMinimum/Sniffs/VIP/FlushRewriteRulesSniff.php b/WordPressVIPMinimum/Sniffs/VIP/FlushRewriteRulesSniff.php index 800b5ec6..6543f1e2 100644 --- a/WordPressVIPMinimum/Sniffs/VIP/FlushRewriteRulesSniff.php +++ b/WordPressVIPMinimum/Sniffs/VIP/FlushRewriteRulesSniff.php @@ -6,12 +6,17 @@ * @link https://github.com/Automattic/VIP-Coding-Standards */ +namespace WordPressVIPMinimum\Sniffs\VIP; + +use PHP_CodeSniffer_File as File; +use PHP_CodeSniffer_Tokens as Tokens; + /** * Restricts usage of rewrite rules flushing * * @package VIPCS\WordPressVIPMinimum */ -class WordPressVIPMinimum_Sniffs_VIP_FlushRewriteRulesSniff implements PHP_CodeSniffer_Sniff { +class FlushRewriteRulesSniff implements \PHP_CodeSniffer_Sniff { /** * Returns an array of tokens this test wants to listen for. @@ -19,18 +24,18 @@ class WordPressVIPMinimum_Sniffs_VIP_FlushRewriteRulesSniff implements PHP_CodeS * @return array */ public function register() { - return PHP_CodeSniffer_Tokens::$functionNameTokens; + return Tokens::$functionNameTokens; } /** * Process this test when one of its tokens is encountered. * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token in the stack passed in $tokens. + * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned. + * @param int $stackPtr The position of the current token in the stack passed in $tokens. * * @return void */ - public function process( PHP_CodeSniffer_File $phpcsFile, $stackPtr ) { + public function process( File $phpcsFile, $stackPtr ) { $tokens = $phpcsFile->getTokens(); @@ -41,7 +46,7 @@ public function process( PHP_CodeSniffer_File $phpcsFile, $stackPtr ) { } $previousPtr = $phpcsFile->findPrevious( - array_merge( PHP_CodeSniffer_Tokens::$emptyTokens ), // types. + array_merge( Tokens::$emptyTokens ), // types. $stackPtr - 1, // start. null, // end. true, // exclude. @@ -54,7 +59,7 @@ public function process( PHP_CodeSniffer_File $phpcsFile, $stackPtr ) { } $previousPtr = $phpcsFile->findPrevious( - array_merge( PHP_CodeSniffer_Tokens::$emptyTokens ), // types. + array_merge( Tokens::$emptyTokens ), // types. $previousPtr - 1, // start. null, // end. true, // exclude. @@ -68,7 +73,7 @@ public function process( PHP_CodeSniffer_File $phpcsFile, $stackPtr ) { if ( 'PHPCS_T_CLOSE_SQUARE_BRACKET' === $tokens[ $previousPtr ]['code'] ) { $previousPtr = $phpcsFile->findPrevious( - array_merge( PHP_CodeSniffer_Tokens::$emptyTokens ), // types. + array_merge( Tokens::$emptyTokens ), // types. $previousPtr - 1, // start. null, // end. true, // exclude. diff --git a/WordPressVIPMinimum/Sniffs/VIP/RegexpCompareSniff.php b/WordPressVIPMinimum/Sniffs/VIP/RegexpCompareSniff.php index cef76d1b..91db7368 100644 --- a/WordPressVIPMinimum/Sniffs/VIP/RegexpCompareSniff.php +++ b/WordPressVIPMinimum/Sniffs/VIP/RegexpCompareSniff.php @@ -5,12 +5,14 @@ * @package VIPCS\WordPressVIPMinimum */ +namespace WordPressVIPMinimum\Sniffs\VIP; + /** * Flag REGEXP and NOT REGEXP in meta compare * * @package VIPCS\WordPressVIPMinimum */ -class WordPressVIPMinimum_Sniffs_VIP_RegexpCompareSniff extends WordPress\AbstractArrayAssignmentRestrictionsSniff { +class RegexpCompareSniff extends \WordPress\AbstractArrayAssignmentRestrictionsSniff { /** * Groups of variables to restrict. diff --git a/WordPressVIPMinimum/Sniffs/VIP/RemoteRequestTimeoutSniff.php b/WordPressVIPMinimum/Sniffs/VIP/RemoteRequestTimeoutSniff.php index ba89a775..4df10bd9 100644 --- a/WordPressVIPMinimum/Sniffs/VIP/RemoteRequestTimeoutSniff.php +++ b/WordPressVIPMinimum/Sniffs/VIP/RemoteRequestTimeoutSniff.php @@ -5,12 +5,14 @@ * @package VIPCS\WordPressVIPMinimum */ +namespace WordPressVIPMinimum\Sniffs\VIP; + /** * Flag REGEXP and NOT REGEXP in meta compare * * @package VIPCS\WordPressVIPMinimum */ -class WordPressVIPMinimum_Sniffs_VIP_RemoteRequestTimeoutSniff extends WordPress\AbstractArrayAssignmentRestrictionsSniff { +class RemoteRequestTimeoutSniff extends \WordPress\AbstractArrayAssignmentRestrictionsSniff { /** * Groups of variables to restrict. diff --git a/WordPressVIPMinimum/Sniffs/VIP/StaticStrreplaceSniff.php b/WordPressVIPMinimum/Sniffs/VIP/StaticStrreplaceSniff.php index e50013dd..840007e9 100644 --- a/WordPressVIPMinimum/Sniffs/VIP/StaticStrreplaceSniff.php +++ b/WordPressVIPMinimum/Sniffs/VIP/StaticStrreplaceSniff.php @@ -6,12 +6,17 @@ * @link https://github.com/Automattic/VIP-Coding-Standards */ +namespace WordPressVIPMinimum\Sniffs\VIP; + +use PHP_CodeSniffer_File as File; +use PHP_CodeSniffer_Tokens as Tokens; + /** * Restricts usage of str_replace with all 3 params being static. * * @package VIPCS\WordPressVIPMinimum */ -class WordPressVIPMinimum_Sniffs_VIP_StaticStrreplaceSniff implements PHP_CodeSniffer_Sniff { +class StaticStrreplaceSniff implements \PHP_CodeSniffer_Sniff { /** * Returns an array of tokens this test wants to listen for. @@ -19,18 +24,18 @@ class WordPressVIPMinimum_Sniffs_VIP_StaticStrreplaceSniff implements PHP_CodeSn * @return array */ public function register() { - return PHP_CodeSniffer_Tokens::$functionNameTokens; + return Tokens::$functionNameTokens; } /** * Process this test when one of its tokens is encountered * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token in the stack passed in $tokens. + * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned. + * @param int $stackPtr The position of the current token in the stack passed in $tokens. * * @return void */ - public function process( PHP_CodeSniffer_File $phpcsFile, $stackPtr ) { + public function process( File $phpcsFile, $stackPtr ) { $tokens = $phpcsFile->getTokens(); @@ -38,7 +43,7 @@ public function process( PHP_CodeSniffer_File $phpcsFile, $stackPtr ) { return; } - $openBracket = $phpcsFile->findNext( PHP_CodeSniffer_Tokens::$emptyTokens, ($stackPtr + 1), null, true ); + $openBracket = $phpcsFile->findNext( Tokens::$emptyTokens, ($stackPtr + 1), null, true ); if ( T_OPEN_PARENTHESIS !== $tokens[ $openBracket ]['code'] ) { return; @@ -46,10 +51,10 @@ public function process( PHP_CodeSniffer_File $phpcsFile, $stackPtr ) { $next_start_ptr = $openBracket + 1; for ( $i = 0; $i < 3; $i++ ) { - $param_ptr = $phpcsFile->findNext( array_merge( PHP_CodeSniffer_Tokens::$emptyTokens, array( T_COMMA ) ), $next_start_ptr, null, true ); + $param_ptr = $phpcsFile->findNext( array_merge( Tokens::$emptyTokens, array( T_COMMA ) ), $next_start_ptr, null, true ); if ( T_ARRAY === $tokens[ $param_ptr ]['code'] ) { - $openBracket = $phpcsFile->findNext( PHP_CodeSniffer_Tokens::$emptyTokens, ($param_ptr + 1), null, true ); + $openBracket = $phpcsFile->findNext( Tokens::$emptyTokens, ($param_ptr + 1), null, true ); if ( T_OPEN_PARENTHESIS !== $tokens[ $openBracket ]['code'] ) { return; } @@ -57,13 +62,13 @@ public function process( PHP_CodeSniffer_File $phpcsFile, $stackPtr ) { // Find the closing bracket. $closeBracket = $tokens[ $openBracket ]['parenthesis_closer']; - $array_item_ptr = $phpcsFile->findNext( array_merge( PHP_CodeSniffer_Tokens::$emptyTokens, array( T_COMMA ) ), ( $openBracket + 1 ), $closeBracket, true ); + $array_item_ptr = $phpcsFile->findNext( array_merge( Tokens::$emptyTokens, array( T_COMMA ) ), ( $openBracket + 1 ), $closeBracket, true ); while ( false !== $array_item_ptr ) { if ( T_CONSTANT_ENCAPSED_STRING !== $tokens[ $array_item_ptr ]['code'] ) { return; } - $array_item_ptr = $phpcsFile->findNext( array_merge( PHP_CodeSniffer_Tokens::$emptyTokens, array( T_COMMA ) ), ( $array_item_ptr + 1 ), $closeBracket, true ); + $array_item_ptr = $phpcsFile->findNext( array_merge( Tokens::$emptyTokens, array( T_COMMA ) ), ( $array_item_ptr + 1 ), $closeBracket, true ); } $next_start_ptr = $closeBracket + 1; diff --git a/WordPressVIPMinimum/Sniffs/Variables/VariableAnalysisHelper.php b/WordPressVIPMinimum/Sniffs/Variables/VariableAnalysisHelper.php index 06258a88..5974b284 100644 --- a/WordPressVIPMinimum/Sniffs/Variables/VariableAnalysisHelper.php +++ b/WordPressVIPMinimum/Sniffs/Variables/VariableAnalysisHelper.php @@ -13,6 +13,8 @@ * @link http://pear.php.net/package/PHP_CodeSniffer */ +namespace WordPressVIPMinimum\Sniffs\Variables; + /** * Holds details of a scope. * diff --git a/WordPressVIPMinimum/Sniffs/Variables/VariableAnalysisSniff.php b/WordPressVIPMinimum/Sniffs/Variables/VariableAnalysisSniff.php index 0d0b0892..cdbfbcd6 100644 --- a/WordPressVIPMinimum/Sniffs/Variables/VariableAnalysisSniff.php +++ b/WordPressVIPMinimum/Sniffs/Variables/VariableAnalysisSniff.php @@ -13,6 +13,10 @@ * @link http://pear.php.net/package/PHP_CodeSniffer */ +namespace WordPressVIPMinimum\Sniffs\Variables; + +use PHP_CodeSniffer_File as File; + /** * Checks the for undefined function variables. * @@ -25,7 +29,7 @@ * @copyright 2011 Sam Graham * @link http://pear.php.net/package/PHP_CodeSniffer */ -class WordPressVIPMinimum_Sniffs_Variables_VariableAnalysisSniff implements PHP_CodeSniffer_Sniff +class VariableAnalysisSniff implements \PHP_CodeSniffer_Sniff { /** * The current phpcsFile being checked. @@ -330,13 +334,13 @@ public function register() { /** * Processes this test, when one of its tokens is encountered. * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token - * in the stack passed in $tokens. + * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned. + * @param int $stackPtr The position of the current token + * in the stack passed in $tokens. * * @return void */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) { + public function process(File $phpcsFile, $stackPtr) { $tokens = $phpcsFile->getTokens(); $token = $tokens[$stackPtr]; @@ -497,7 +501,7 @@ function markVariableReadAndWarnIfUndefined($phpcsFile, $varName, $stackPtr, $cu } function findFunctionPrototype( - PHP_CodeSniffer_File $phpcsFile, + File $phpcsFile, $stackPtr ) { $tokens = $phpcsFile->getTokens(); @@ -520,7 +524,7 @@ function findFunctionPrototype( } function findVariableScope( - PHP_CodeSniffer_File $phpcsFile, + File $phpcsFile, $stackPtr ) { $tokens = $phpcsFile->getTokens(); @@ -552,7 +556,7 @@ function findVariableScope( } function isNextThingAnAssign( - PHP_CodeSniffer_File $phpcsFile, + File $phpcsFile, $stackPtr ) { $tokens = $phpcsFile->getTokens(); @@ -568,7 +572,7 @@ function isNextThingAnAssign( } function findWhereAssignExecuted( - PHP_CodeSniffer_File $phpcsFile, + File $phpcsFile, $stackPtr ) { $tokens = $phpcsFile->getTokens(); @@ -603,7 +607,7 @@ function findWhereAssignExecuted( } function findContainingBrackets( - PHP_CodeSniffer_File $phpcsFile, + File $phpcsFile, $stackPtr ) { $tokens = $phpcsFile->getTokens(); @@ -617,7 +621,7 @@ function findContainingBrackets( function findFunctionCall( - PHP_CodeSniffer_File $phpcsFile, + File $phpcsFile, $stackPtr ) { $tokens = $phpcsFile->getTokens(); @@ -634,7 +638,7 @@ function findFunctionCall( } function findFunctionCallArguments( - PHP_CodeSniffer_File $phpcsFile, + File $phpcsFile, $stackPtr ) { $tokens = $phpcsFile->getTokens(); @@ -677,7 +681,7 @@ function findFunctionCallArguments( } protected function checkForFunctionPrototype( - PHP_CodeSniffer_File $phpcsFile, + File $phpcsFile, $stackPtr, $varName, $currScope @@ -743,7 +747,7 @@ protected function checkForFunctionPrototype( } protected function checkForCatchBlock( - PHP_CodeSniffer_File $phpcsFile, + File $phpcsFile, $stackPtr, $varName, $currScope @@ -777,7 +781,7 @@ protected function checkForCatchBlock( } protected function checkForThisWithinClass( - PHP_CodeSniffer_File $phpcsFile, + File $phpcsFile, $stackPtr, $varName, $currScope @@ -805,7 +809,7 @@ protected function checkForThisWithinClass( } protected function checkForSuperGlobal( - PHP_CodeSniffer_File $phpcsFile, + File $phpcsFile, $stackPtr, $varName, $currScope @@ -833,7 +837,7 @@ protected function checkForSuperGlobal( } protected function checkForStaticMember( - PHP_CodeSniffer_File $phpcsFile, + File $phpcsFile, $stackPtr, $varName, $currScope @@ -893,7 +897,7 @@ protected function checkForStaticMember( } protected function checkForAssignment( - PHP_CodeSniffer_File $phpcsFile, + File $phpcsFile, $stackPtr, $varName, $currScope @@ -914,7 +918,7 @@ protected function checkForAssignment( } protected function checkForListAssignment( - PHP_CodeSniffer_File $phpcsFile, + File $phpcsFile, $stackPtr, $varName, $currScope @@ -944,7 +948,7 @@ protected function checkForListAssignment( } protected function checkForGlobalDeclaration( - PHP_CodeSniffer_File $phpcsFile, + File $phpcsFile, $stackPtr, $varName, $currScope @@ -966,7 +970,7 @@ protected function checkForGlobalDeclaration( } protected function checkForStaticDeclaration( - PHP_CodeSniffer_File $phpcsFile, + File $phpcsFile, $stackPtr, $varName, $currScope @@ -1029,7 +1033,7 @@ protected function checkForStaticDeclaration( } protected function checkForForeachLoopVar( - PHP_CodeSniffer_File $phpcsFile, + File $phpcsFile, $stackPtr, $varName, $currScope @@ -1051,7 +1055,7 @@ protected function checkForForeachLoopVar( } protected function checkForPassByReferenceFunctionCall( - PHP_CodeSniffer_File $phpcsFile, + File $phpcsFile, $stackPtr, $varName, $currScope @@ -1115,7 +1119,7 @@ protected function checkForPassByReferenceFunctionCall( } protected function checkForSymbolicObjectProperty( - PHP_CodeSniffer_File $phpcsFile, + File $phpcsFile, $stackPtr, $varName, $currScope @@ -1139,14 +1143,14 @@ protected function checkForSymbolicObjectProperty( /** * Called to process class member vars. * - * @param PHP_CodeSniffer_File $phpcsFile The PHP_CodeSniffer file where this - * token was found. - * @param int $stackPtr The position where the token was found. + * @param \PHP_CodeSniffer\Files\File $phpcsFile The PHP_CodeSniffer file where this + * token was found. + * @param int $stackPtr The position where the token was found. * * @return void */ protected function processMemberVar( - PHP_CodeSniffer_File $phpcsFile, + File $phpcsFile, $stackPtr ) { // TODO: don't care for now @@ -1155,14 +1159,14 @@ protected function processMemberVar( /** * Called to process normal member vars. * - * @param PHP_CodeSniffer_File $phpcsFile The PHP_CodeSniffer file where this - * token was found. - * @param int $stackPtr The position where the token was found. + * @param \PHP_CodeSniffer\Files\File $phpcsFile The PHP_CodeSniffer file where this + * token was found. + * @param int $stackPtr The position where the token was found. * * @return void */ protected function processVariable( - PHP_CodeSniffer_File $phpcsFile, + File $phpcsFile, $stackPtr ) { $tokens = $phpcsFile->getTokens(); @@ -1272,15 +1276,15 @@ protected function processVariable( * Note that there may be more than one variable in the string, which will * result only in one call for the string. * - * @param PHP_CodeSniffer_File $phpcsFile The PHP_CodeSniffer file where this - * token was found. - * @param int $stackPtr The position where the double quoted - * string was found. + * @param \PHP_CodeSniffer\Files\File $phpcsFile The PHP_CodeSniffer file where this + * token was found. + * @param int $stackPtr The position where the double quoted + * string was found. * * @return void */ protected function processVariableInString( - PHP_CodeSniffer_File + File $phpcsFile, $stackPtr ) { @@ -1306,7 +1310,7 @@ protected function processVariableInString( } protected function processCompactArguments( - PHP_CodeSniffer_File $phpcsFile, + File $phpcsFile, $stackPtr, $arguments, $currScope @@ -1358,15 +1362,15 @@ protected function processCompactArguments( /** * Called to process variables named in a call to compact(). * - * @param PHP_CodeSniffer_File $phpcsFile The PHP_CodeSniffer file where this - * token was found. - * @param int $stackPtr The position where the call to compact() - * was found. + * @param \PHP_CodeSniffer\Files\File $phpcsFile The PHP_CodeSniffer file where this + * token was found. + * @param int $stackPtr The position where the call to compact() + * was found. * * @return void */ protected function processCompact( - PHP_CodeSniffer_File $phpcsFile, + File $phpcsFile, $stackPtr ) { $tokens = $phpcsFile->getTokens(); @@ -1384,14 +1388,14 @@ protected function processCompact( * Note that although triggered by the closing curly brace of the scope, $stackPtr is * the scope conditional, not the closing curly brace. * - * @param PHP_CodeSniffer_File $phpcsFile The PHP_CodeSniffer file where this + * @param \PHP_CodeSniffer\Files\File $phpcsFile The PHP_CodeSniffer file where this * token was found. - * @param int $stackPtr The position of the scope conditional. + * @param int $stackPtr The position of the scope conditional. * * @return void */ protected function processScopeClose( - PHP_CodeSniffer_File $phpcsFile, + File $phpcsFile, $stackPtr ) { $scopeInfo = $this->getScopeInfo($stackPtr, false); diff --git a/bin/phpcs.xml b/bin/phpcs.xml index 1823352d..346f1ec4 100644 --- a/bin/phpcs.xml +++ b/bin/phpcs.xml @@ -13,13 +13,13 @@ */vendor/* - - + + - + From 5929f50dab7012033572d3686d38167bda52c234 Mon Sep 17 00:00:00 2001 From: David Binovec Date: Mon, 14 Aug 2017 16:01:23 +0000 Subject: [PATCH 28/31] Fix typo in PreGetPostsSniff class name /s/Actions_PreGetPostsSniff/PreGetPostsSniff/ --- WordPressVIPMinimum/Sniffs/Actions/PreGetPostsSniff.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WordPressVIPMinimum/Sniffs/Actions/PreGetPostsSniff.php b/WordPressVIPMinimum/Sniffs/Actions/PreGetPostsSniff.php index c624ba6b..018fd8f3 100644 --- a/WordPressVIPMinimum/Sniffs/Actions/PreGetPostsSniff.php +++ b/WordPressVIPMinimum/Sniffs/Actions/PreGetPostsSniff.php @@ -17,7 +17,7 @@ * * @package VIPCS\WordPressVIPMinimum */ -class Actions_PreGetPostsSniff implements \PHP_CodeSniffer_Sniff { +class PreGetPostsSniff implements \PHP_CodeSniffer_Sniff { /** * The tokens of the phpcsFile. From 4a3363b1f9e12fdbdd997a312c196d22fb8ee121 Mon Sep 17 00:00:00 2001 From: David Binovec Date: Mon, 14 Aug 2017 16:23:46 +0000 Subject: [PATCH 29/31] Adding namespaces to Test classes --- .../Sniffs/Cache/CacheValueOverrideSniff.php | 3 ++- .../Sniffs/Classes/DeclarationCompatibilitySniff.php | 12 ++++++------ .../Tests/Actions/PreGetPostsUnitTest.php | 4 ++++ .../Tests/Cache/CacheValueOverrideUnitTest.php | 6 +++++- .../Classes/DeclarationCompatibilityUnitTest.php | 6 +++++- .../Tests/Constants/ConstantRestrictionsUnitTest.php | 6 +++++- .../Tests/Files/IncludingFileUnitTest.php | 6 +++++- .../Tests/Functions/CheckReturnValueUnitTest.php | 6 +++++- .../Tests/VIP/ErrorControlUnitTest.php | 6 +++++- .../Tests/VIP/FlushRewriteRulesUnitTest.php | 6 +++++- .../Tests/VIP/RegexpCompareUnitTest.php | 6 +++++- .../Tests/VIP/RemoteRequestTimeoutUnitTest.php | 6 +++++- .../Tests/VIP/RestrictedFunctionsUnitTest.php | 6 +++++- .../Tests/VIP/StaticStrreplaceUnitTest.php | 6 +++++- .../Tests/Variables/VariableAnalysisUnitTest.php | 6 +++++- ruleset_test.php | 2 ++ 16 files changed, 74 insertions(+), 19 deletions(-) diff --git a/WordPressVIPMinimum/Sniffs/Cache/CacheValueOverrideSniff.php b/WordPressVIPMinimum/Sniffs/Cache/CacheValueOverrideSniff.php index 10f55a26..68d1b855 100644 --- a/WordPressVIPMinimum/Sniffs/Cache/CacheValueOverrideSniff.php +++ b/WordPressVIPMinimum/Sniffs/Cache/CacheValueOverrideSniff.php @@ -7,6 +7,7 @@ namespace WordPressVIPMinimum\Sniffs\Cache; +use PHP_CodeSniffer_Sniff as PHPCS_Sniff; use PHP_CodeSniffer_File as File; use PHP_CodeSniffer_Tokens as Tokens; @@ -21,7 +22,7 @@ * * @package VIPCS\WordPressVIPMinimum */ -class CacheValueOverrideSniff implements \PHP_CodeSniffer_Sniff { +class CacheValueOverrideSniff implements PHPCS_Sniff { /** * Tokens of the file. diff --git a/WordPressVIPMinimum/Sniffs/Classes/DeclarationCompatibilitySniff.php b/WordPressVIPMinimum/Sniffs/Classes/DeclarationCompatibilitySniff.php index 81d15400..0d6af8bc 100644 --- a/WordPressVIPMinimum/Sniffs/Classes/DeclarationCompatibilitySniff.php +++ b/WordPressVIPMinimum/Sniffs/Classes/DeclarationCompatibilitySniff.php @@ -288,12 +288,12 @@ protected function processTokenWithinScope( File $phpcsFile, $stackPtr, $currSco /** * Generates an error with nice current and parent class method notations * - * @param string $parentClassName The name of the extended (parent) class. - * @param string $methodName The name of the method currently being examined. - * @param array $currentMethodSignature The list of params and their options of the method which is being examined. - * @param array $parentMethodSignature The list of params and their options of the parent class method. - * @param File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token in the stack. + * @param string $parentClassName The name of the extended (parent) class. + * @param string $methodName The name of the method currently being examined. + * @param array $currentMethodSignature The list of params and their options of the method which is being examined. + * @param array $parentMethodSignature The list of params and their options of the parent class method. + * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned. + * @param int $stackPtr The position of the current token in the stack. * * @return void */ diff --git a/WordPressVIPMinimum/Tests/Actions/PreGetPostsUnitTest.php b/WordPressVIPMinimum/Tests/Actions/PreGetPostsUnitTest.php index 45c53645..8c6883e0 100644 --- a/WordPressVIPMinimum/Tests/Actions/PreGetPostsUnitTest.php +++ b/WordPressVIPMinimum/Tests/Actions/PreGetPostsUnitTest.php @@ -5,6 +5,10 @@ * @package VIPCS\WordPressVIPMinimum */ +namespace WordPressVIPMinimum\Tests\Actions; + +use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; + // Cross version compatibility for PHPCS 2.x and 3.x. if ( ! class_exists( '\AbstractSniffUnitTest' ) ) { class_alias( '\PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest', '\AbstractSniffUnitTest' ); diff --git a/WordPressVIPMinimum/Tests/Cache/CacheValueOverrideUnitTest.php b/WordPressVIPMinimum/Tests/Cache/CacheValueOverrideUnitTest.php index 91c7b90d..b907e4a2 100644 --- a/WordPressVIPMinimum/Tests/Cache/CacheValueOverrideUnitTest.php +++ b/WordPressVIPMinimum/Tests/Cache/CacheValueOverrideUnitTest.php @@ -5,6 +5,10 @@ * @package VIPCS\WordPressVIPMinimum */ +namespace WordPressVIPMinimum\Tests\Cache; + +use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; + // Cross version compatibility for PHPCS 2.x and 3.x. if ( ! class_exists( '\AbstractSniffUnitTest' ) ) { class_alias( '\PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest', '\AbstractSniffUnitTest' ); @@ -15,7 +19,7 @@ class_alias( '\PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest', '\Abstrac * * @package VIPCS\WordPressVIPMinimum */ -class WordPressVIPMinimum_Tests_Cache_CacheValueOverrideUnitTest extends AbstractSniffUnitTest { +class CacheValueOverrideUnitTest extends AbstractSniffUnitTest { /** * Returns the lines where errors should occur. diff --git a/WordPressVIPMinimum/Tests/Classes/DeclarationCompatibilityUnitTest.php b/WordPressVIPMinimum/Tests/Classes/DeclarationCompatibilityUnitTest.php index fcacc44c..76f5a62d 100644 --- a/WordPressVIPMinimum/Tests/Classes/DeclarationCompatibilityUnitTest.php +++ b/WordPressVIPMinimum/Tests/Classes/DeclarationCompatibilityUnitTest.php @@ -5,6 +5,10 @@ * @package VIPCS\WordPressVIPMinimum */ +namespace WordPressVIPMinimum\Tests\Classes; + +use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; + // Cross version compatibility for PHPCS 2.x and 3.x. if ( ! class_exists( '\AbstractSniffUnitTest' ) ) { class_alias( '\PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest', '\AbstractSniffUnitTest' ); @@ -15,7 +19,7 @@ class_alias( '\PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest', '\Abstrac * * @package VIPCS\WordPressVIPMinimum */ -class WordPressVIPMinimum_Tests_Classes_DeclarationCompatibilityUnitTest extends AbstractSniffUnitTest { +class DeclarationCompatibilityUnitTest extends AbstractSniffUnitTest { /** * Returns the lines where errors should occur. diff --git a/WordPressVIPMinimum/Tests/Constants/ConstantRestrictionsUnitTest.php b/WordPressVIPMinimum/Tests/Constants/ConstantRestrictionsUnitTest.php index 9406deb0..cc910aee 100644 --- a/WordPressVIPMinimum/Tests/Constants/ConstantRestrictionsUnitTest.php +++ b/WordPressVIPMinimum/Tests/Constants/ConstantRestrictionsUnitTest.php @@ -5,6 +5,10 @@ * @package VIPCS\WordPressVIPMinimum */ +namespace WordPressVIPMinimum\Tests\Constants; + +use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; + // Cross version compatibility for PHPCS 2.x and 3.x. if ( ! class_exists( '\AbstractSniffUnitTest' ) ) { class_alias( '\PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest', '\AbstractSniffUnitTest' ); @@ -15,7 +19,7 @@ class_alias( '\PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest', '\Abstrac * * @package VIPCS\WordPressVIPMinimum */ -class WordPressVIPMinimum_Tests_Constants_ConstantRestrictionsUnitTest extends AbstractSniffUnitTest { +class ConstantRestrictionsUnitTest extends AbstractSniffUnitTest { /** * Returns the lines where errors should occur. diff --git a/WordPressVIPMinimum/Tests/Files/IncludingFileUnitTest.php b/WordPressVIPMinimum/Tests/Files/IncludingFileUnitTest.php index c3a1af4d..ddb9b67c 100644 --- a/WordPressVIPMinimum/Tests/Files/IncludingFileUnitTest.php +++ b/WordPressVIPMinimum/Tests/Files/IncludingFileUnitTest.php @@ -5,6 +5,10 @@ * @package VIPCS\WordPressVIPMinimum */ +namespace WordPressVIPMinimum\Tests\Files; + +use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; + // Cross version compatibility for PHPCS 2.x and 3.x. if ( ! class_exists( '\AbstractSniffUnitTest' ) ) { class_alias( '\PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest', '\AbstractSniffUnitTest' ); @@ -15,7 +19,7 @@ class_alias( '\PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest', '\Abstrac * * @package VIPCS\WordPressVIPMinimum */ -class WordPressVIPMinimum_Tests_Files_IncludingFileUnitTest extends AbstractSniffUnitTest { +class IncludingFileUnitTest extends AbstractSniffUnitTest { /** * Returns the lines where errors should occur. diff --git a/WordPressVIPMinimum/Tests/Functions/CheckReturnValueUnitTest.php b/WordPressVIPMinimum/Tests/Functions/CheckReturnValueUnitTest.php index 8295345c..fd10b777 100644 --- a/WordPressVIPMinimum/Tests/Functions/CheckReturnValueUnitTest.php +++ b/WordPressVIPMinimum/Tests/Functions/CheckReturnValueUnitTest.php @@ -5,6 +5,10 @@ * @package VIPCS\WordPressVIPMinimum */ +namespace WordPressVIPMinimum\Tests\Functions; + +use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; + // Cross version compatibility for PHPCS 2.x and 3.x. if ( ! class_exists( '\AbstractSniffUnitTest' ) ) { class_alias( '\PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest', '\AbstractSniffUnitTest' ); @@ -15,7 +19,7 @@ class_alias( '\PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest', '\Abstrac * * @package VIPCS\WordPressVIPMinimum */ -class WordPressVIPMinimum_Tests_Functions_CheckReturnValueUnitTest extends AbstractSniffUnitTest { +class CheckReturnValueUnitTest extends AbstractSniffUnitTest { /** * Returns the lines where errors should occur. diff --git a/WordPressVIPMinimum/Tests/VIP/ErrorControlUnitTest.php b/WordPressVIPMinimum/Tests/VIP/ErrorControlUnitTest.php index e740d2d4..3543eed4 100644 --- a/WordPressVIPMinimum/Tests/VIP/ErrorControlUnitTest.php +++ b/WordPressVIPMinimum/Tests/VIP/ErrorControlUnitTest.php @@ -5,6 +5,10 @@ * @package VIPCS\WordPressVIPMinimum */ +namespace WordPressVIPMinimum\Tests\VIP; + +use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; + // Cross version compatibility for PHPCS 2.x and 3.x. if ( ! class_exists( '\AbstractSniffUnitTest' ) ) { class_alias( '\PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest', '\AbstractSniffUnitTest' ); @@ -15,7 +19,7 @@ class_alias( '\PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest', '\Abstrac * * @package VIPCS\WordPressVIPMinimum */ -class WordPressVIPMinimum_Tests_VIP_ErrorControlUnitTest extends AbstractSniffUnitTest { +class ErrorControlUnitTest extends AbstractSniffUnitTest { /** * Returns the lines where errors should occur. diff --git a/WordPressVIPMinimum/Tests/VIP/FlushRewriteRulesUnitTest.php b/WordPressVIPMinimum/Tests/VIP/FlushRewriteRulesUnitTest.php index 4cc081df..d495a3b5 100644 --- a/WordPressVIPMinimum/Tests/VIP/FlushRewriteRulesUnitTest.php +++ b/WordPressVIPMinimum/Tests/VIP/FlushRewriteRulesUnitTest.php @@ -5,6 +5,10 @@ * @package VIPCS\WordPressVIPMinimum */ +namespace WordPressVIPMinimum\Tests\VIP; + +use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; + // Cross version compatibility for PHPCS 2.x and 3.x. if ( ! class_exists( '\AbstractSniffUnitTest' ) ) { class_alias( '\PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest', '\AbstractSniffUnitTest' ); @@ -15,7 +19,7 @@ class_alias( '\PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest', '\Abstrac * * @package VIPCS\WordPressVIPMinimum */ -class WordPressVIPMinimum_Tests_VIP_FlushRewriteRulesUnitTest extends AbstractSniffUnitTest { +class FlushRewriteRulesUnitTest extends AbstractSniffUnitTest { /** * Returns the lines where errors should occur. diff --git a/WordPressVIPMinimum/Tests/VIP/RegexpCompareUnitTest.php b/WordPressVIPMinimum/Tests/VIP/RegexpCompareUnitTest.php index d0789962..7e52e112 100644 --- a/WordPressVIPMinimum/Tests/VIP/RegexpCompareUnitTest.php +++ b/WordPressVIPMinimum/Tests/VIP/RegexpCompareUnitTest.php @@ -5,6 +5,10 @@ * @package VIPCS\WordPressVIPMinimum */ +namespace WordPressVIPMinimum\Tests\VIP; + +use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; + // Cross version compatibility for PHPCS 2.x and 3.x. if ( ! class_exists( '\AbstractSniffUnitTest' ) ) { class_alias( '\PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest', '\AbstractSniffUnitTest' ); @@ -15,7 +19,7 @@ class_alias( '\PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest', '\Abstrac * * @package VIPCS\WordPressVIPMinimum */ -class WordPressVIPMinimum_Tests_VIP_RegexpCompareUnitTest extends AbstractSniffUnitTest { +class RegexpCompareUnitTest extends AbstractSniffUnitTest { /** * Returns the lines where errors should occur. diff --git a/WordPressVIPMinimum/Tests/VIP/RemoteRequestTimeoutUnitTest.php b/WordPressVIPMinimum/Tests/VIP/RemoteRequestTimeoutUnitTest.php index 70849614..84255930 100644 --- a/WordPressVIPMinimum/Tests/VIP/RemoteRequestTimeoutUnitTest.php +++ b/WordPressVIPMinimum/Tests/VIP/RemoteRequestTimeoutUnitTest.php @@ -5,6 +5,10 @@ * @package VIPCS\WordPressVIPMinimum */ +namespace WordPressVIPMinimum\Tests\VIP; + +use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; + // Cross version compatibility for PHPCS 2.x and 3.x. if ( ! class_exists( '\AbstractSniffUnitTest' ) ) { class_alias( '\PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest', '\AbstractSniffUnitTest' ); @@ -15,7 +19,7 @@ class_alias( '\PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest', '\Abstrac * * @package VIPCS\WordPressVIPMinimum */ -class WordPressVIPMinimum_Tests_VIP_RemoteRequestTimeoutUnitTest extends AbstractSniffUnitTest { +class RemoteRequestTimeoutUnitTest extends AbstractSniffUnitTest { /** * Returns the lines where errors should occur. diff --git a/WordPressVIPMinimum/Tests/VIP/RestrictedFunctionsUnitTest.php b/WordPressVIPMinimum/Tests/VIP/RestrictedFunctionsUnitTest.php index 626020cc..6fac9687 100644 --- a/WordPressVIPMinimum/Tests/VIP/RestrictedFunctionsUnitTest.php +++ b/WordPressVIPMinimum/Tests/VIP/RestrictedFunctionsUnitTest.php @@ -5,6 +5,10 @@ * @package VIPCS\WordPressVIPMinimum */ +namespace WordPressVIPMinimum\Tests\VIP; + +use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; + // Cross version compatibility for PHPCS 2.x and 3.x. if ( ! class_exists( '\AbstractSniffUnitTest' ) ) { class_alias( '\PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest', '\AbstractSniffUnitTest' ); @@ -15,7 +19,7 @@ class_alias( '\PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest', '\Abstrac * * @package VIPCS\WordPressVIPMinimum */ -class WordPressVIPMinimum_Tests_VIP_RestrictedFunctionsUnitTest extends AbstractSniffUnitTest { +class RestrictedFunctionsUnitTest extends AbstractSniffUnitTest { /** * Returns the lines where errors should occur. diff --git a/WordPressVIPMinimum/Tests/VIP/StaticStrreplaceUnitTest.php b/WordPressVIPMinimum/Tests/VIP/StaticStrreplaceUnitTest.php index afb469e2..77d91804 100644 --- a/WordPressVIPMinimum/Tests/VIP/StaticStrreplaceUnitTest.php +++ b/WordPressVIPMinimum/Tests/VIP/StaticStrreplaceUnitTest.php @@ -5,6 +5,10 @@ * @package VIPCS\WordPressVIPMinimum */ +namespace WordPressVIPMinimum\Tests\VIP; + +use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; + // Cross version compatibility for PHPCS 2.x and 3.x. if ( ! class_exists( '\AbstractSniffUnitTest' ) ) { class_alias( '\PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest', '\AbstractSniffUnitTest' ); @@ -15,7 +19,7 @@ class_alias( '\PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest', '\Abstrac * * @package VIPCS\WordPressVIPMinimum */ -class WordPressVIPMinimum_Tests_VIP_StaticStrreplaceUnitTest extends AbstractSniffUnitTest { +class StaticStrreplaceUnitTest extends AbstractSniffUnitTest { /** * Returns the lines where errors should occur. diff --git a/WordPressVIPMinimum/Tests/Variables/VariableAnalysisUnitTest.php b/WordPressVIPMinimum/Tests/Variables/VariableAnalysisUnitTest.php index 8f520ffa..ef8d0072 100644 --- a/WordPressVIPMinimum/Tests/Variables/VariableAnalysisUnitTest.php +++ b/WordPressVIPMinimum/Tests/Variables/VariableAnalysisUnitTest.php @@ -5,12 +5,16 @@ * @package VIPCS\WordPressVIPMinimum */ +namespace WordPressVIPMinimum\Tests\Variables; + +use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; + /** * Unit test class for the Variable Analysis sniff. * * @package VIPCS\WordPressVIPMinimum */ -class WordPressVIPMinimum_Tests_Variables_VariableAnalysisUnitTest extends AbstractSniffUnitTest { +class VariableAnalysisUnitTest extends AbstractSniffUnitTest { /** * Returns the lines where errors should occur. diff --git a/ruleset_test.php b/ruleset_test.php index 74e1a134..ec3772fc 100644 --- a/ruleset_test.php +++ b/ruleset_test.php @@ -15,6 +15,8 @@ * @package VIPCS\WordPressVIPMinimum */ +namespace WordPressVIPMinimum; + // Expected values. $expected = array( 'errors' => array( From 5610c587d9a7a26291c69bebcf8a27808e769a09 Mon Sep 17 00:00:00 2001 From: David Binovec Date: Mon, 14 Aug 2017 17:11:35 +0000 Subject: [PATCH 30/31] Adjusting Warning and Error names in Sniffs in order to make namespaced tests working --- .../Sniffs/Actions/PreGetPostsSniff.php | 4 ++-- .../Sniffs/Cache/CacheValueOverrideSniff.php | 2 +- .../Sniffs/Classes/DeclarationCompatibilitySniff.php | 2 +- .../Sniffs/Constants/ConstantRestrictionsSniff.php | 6 +++--- .../Sniffs/Files/IncludingFileSniff.php | 12 ++++++------ .../Sniffs/Functions/CheckReturnValueSniff.php | 6 +++--- WordPressVIPMinimum/Sniffs/VIP/ErrorControlSniff.php | 2 +- .../Sniffs/VIP/FlushRewriteRulesSniff.php | 2 +- .../Sniffs/VIP/StaticStrreplaceSniff.php | 2 +- .../Tests/Actions/PreGetPostsUnitTest.php | 7 +------ .../Tests/Cache/CacheValueOverrideUnitTest.php | 5 ----- .../Classes/DeclarationCompatibilityUnitTest.php | 5 ----- .../Tests/Constants/ConstantRestrictionsUnitTest.php | 5 ----- .../Tests/Files/IncludingFileUnitTest.php | 6 ------ .../Tests/Functions/CheckReturnValueUnitTest.php | 5 ----- .../Tests/VIP/ErrorControlUnitTest.php | 5 ----- .../Tests/VIP/FlushRewriteRulesUnitTest.php | 5 ----- .../Tests/VIP/RegexpCompareUnitTest.php | 5 ----- .../Tests/VIP/RemoteRequestTimeoutUnitTest.php | 5 ----- .../Tests/VIP/RestrictedFunctionsUnitTest.php | 5 ----- .../Tests/VIP/StaticStrreplaceUnitTest.php | 5 ----- 21 files changed, 20 insertions(+), 81 deletions(-) diff --git a/WordPressVIPMinimum/Sniffs/Actions/PreGetPostsSniff.php b/WordPressVIPMinimum/Sniffs/Actions/PreGetPostsSniff.php index 018fd8f3..790dd9f2 100644 --- a/WordPressVIPMinimum/Sniffs/Actions/PreGetPostsSniff.php +++ b/WordPressVIPMinimum/Sniffs/Actions/PreGetPostsSniff.php @@ -249,10 +249,10 @@ private function processFunctionBody( $stackPtr, $variableName ) { } } elseif ( $this->isInsideIfConditonal( $wpQueryVarUsed ) ) { if ( ! $this->isParentConditionalCheckingMainQuery( $wpQueryVarUsed ) ) { - $this->_phpcsFile->addWarning( 'Main WP_Query is being modified without $query->is_main_query() check. Needs manual inspection.', $wpQueryVarUsed, 'WordPressVIPMinimum.Actions.PreGetPosts' ); + $this->_phpcsFile->addWarning( 'Main WP_Query is being modified without $query->is_main_query() check. Needs manual inspection.', $wpQueryVarUsed, 'PreGetPosts' ); } } elseif ( $this->isWPQueryMethodCall( $wpQueryVarUsed, 'set' ) ) { - $this->_phpcsFile->addWarning( 'Main WP_Query is being modified without $query->is_main_query() check. Needs manual inspection.', $wpQueryVarUsed, 'WordPressVIPMinimum.Actions.PreGetPosts' ); + $this->_phpcsFile->addWarning( 'Main WP_Query is being modified without $query->is_main_query() check. Needs manual inspection.', $wpQueryVarUsed, 'PreGetPosts' ); } $findStart = $wpQueryVarUsed + 1; } diff --git a/WordPressVIPMinimum/Sniffs/Cache/CacheValueOverrideSniff.php b/WordPressVIPMinimum/Sniffs/Cache/CacheValueOverrideSniff.php index 68d1b855..8b6d9ab2 100644 --- a/WordPressVIPMinimum/Sniffs/Cache/CacheValueOverrideSniff.php +++ b/WordPressVIPMinimum/Sniffs/Cache/CacheValueOverrideSniff.php @@ -97,7 +97,7 @@ public function process( File $phpcsFile, $stackPtr ) { $valueAfterEqualSign = $phpcsFile->findNext( Tokens::$emptyTokens, ($rightAfterNextVariableOccurence + 1), null, true, null, true ); if ( T_FALSE === $tokens[ $valueAfterEqualSign ]['code'] ) { - $phpcsFile->addError( sprintf( 'Obtained cached value in %s is being overriden. Disabling caching?', $variableName ), $nextVariableOccurrence, 'WordPressVIPMinimum.Cache.CacheValueOverride' ); + $phpcsFile->addError( sprintf( 'Obtained cached value in %s is being overriden. Disabling caching?', $variableName ), $nextVariableOccurrence, 'CacheValueOverride' ); } } //end Process() diff --git a/WordPressVIPMinimum/Sniffs/Classes/DeclarationCompatibilitySniff.php b/WordPressVIPMinimum/Sniffs/Classes/DeclarationCompatibilitySniff.php index 0d6af8bc..adf6d267 100644 --- a/WordPressVIPMinimum/Sniffs/Classes/DeclarationCompatibilitySniff.php +++ b/WordPressVIPMinimum/Sniffs/Classes/DeclarationCompatibilitySniff.php @@ -303,7 +303,7 @@ private function addError( $parentClassName, $methodName, $currentMethodSignatur $parentSignature = sprintf( '%s::%s(%s)', $parentClassName, $methodName, implode( ', ', $this->generateParamList( $parentMethodSignature ) ) ); - $phpcsFile->addError( sprintf( 'Declaration of %s should be compatible with %s', $currentSignature, $parentSignature ), $stackPtr, 'WordPressVIPMinimum.Classes.DeclarationCompatibility' ); + $phpcsFile->addError( sprintf( 'Declaration of %s should be compatible with %s', $currentSignature, $parentSignature ), $stackPtr, 'DeclarationCompatibility' ); }//end addError() /** diff --git a/WordPressVIPMinimum/Sniffs/Constants/ConstantRestrictionsSniff.php b/WordPressVIPMinimum/Sniffs/Constants/ConstantRestrictionsSniff.php index bab2d034..c389b54b 100644 --- a/WordPressVIPMinimum/Sniffs/Constants/ConstantRestrictionsSniff.php +++ b/WordPressVIPMinimum/Sniffs/Constants/ConstantRestrictionsSniff.php @@ -63,7 +63,7 @@ public function process( File $phpcsFile, $stackPtr ) { } if ( T_STRING === $tokens[ $stackPtr ]['code'] ) { - $phpcsFile->addWarning( sprintf( 'Code is touching the %s constant. Make sure it\'s used appropriately.', $constantName ), $stackPtr, 'WordPressVIPMinimum.Constants.ConstantRestrictions' ); + $phpcsFile->addWarning( sprintf( 'Code is touching the %s constant. Make sure it\'s used appropriately.', $constantName ), $stackPtr, 'ConstantRestrictions' ); return; } @@ -91,9 +91,9 @@ public function process( File $phpcsFile, $stackPtr ) { if ( true === in_array( $tokens[ $previous ]['code'], Tokens::$functionNameTokens, true ) ) { if ( 'define' === $tokens[ $previous ]['content'] ) { - $phpcsFile->addError( sprintf( 'The definition of %s constant is prohibited. Please use a different name.', $constantName ), $previous, 'WordPressVIPMinimum.Constants.ConstantRestrictions' ); + $phpcsFile->addError( sprintf( 'The definition of %s constant is prohibited. Please use a different name.', $constantName ), $previous, 'ConstantRestrictions' ); } else { - $phpcsFile->addWarning( sprintf( 'Code is touching the %s constant. Make sure it\'s used appropriately.', $constantName ), $previous, 'WordPressVIPMinimum.Constants.ConstantRestrictions' ); + $phpcsFile->addWarning( sprintf( 'Code is touching the %s constant. Make sure it\'s used appropriately.', $constantName ), $previous, 'ConstantRestrictions' ); } } } diff --git a/WordPressVIPMinimum/Sniffs/Files/IncludingFileSniff.php b/WordPressVIPMinimum/Sniffs/Files/IncludingFileSniff.php index 576fed97..a2eee545 100644 --- a/WordPressVIPMinimum/Sniffs/Files/IncludingFileSniff.php +++ b/WordPressVIPMinimum/Sniffs/Files/IncludingFileSniff.php @@ -100,7 +100,7 @@ public function process( File $phpcsFile, $stackPtr ) { } if ( T_VARIABLE === $tokens[ $nextToken ]['code'] ) { - $phpcsFile->addWarning( sprintf( 'File inclusion using variable (%s). Probably needs manual inspection.', $tokens[ $nextToken ]['content'] ), $nextToken, 'WordPressVIPMinimum.Files.IncludingFile' ); + $phpcsFile->addWarning( sprintf( 'File inclusion using variable (%s). Probably needs manual inspection.', $tokens[ $nextToken ]['content'] ), $nextToken, 'IncludingFile' ); return; } @@ -124,12 +124,12 @@ public function process( File $phpcsFile, $stackPtr ) { if ( 1 === preg_match( '/^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*$/', $tokens[ $nextToken ]['content'] ) ) { // The construct is using custom constant, which needs manula inspection. - $phpcsFile->addWarning( sprintf( 'File inclusion using custom constant (%s). Probably needs manual inspection.', $tokens[ $nextToken ]['content'] ), $nextToken, 'WordPressVIPMinimum.Files.IncludingFile' ); + $phpcsFile->addWarning( sprintf( 'File inclusion using custom constant (%s). Probably needs manual inspection.', $tokens[ $nextToken ]['content'] ), $nextToken, 'IncludingFile' ); return; } if ( 0 === strpos( $tokens[ $nextToken ]['content'], '$' ) ) { - $phpcsFile->addWarning( sprintf( 'File inclusion using variable (%s). Probably needs manual inspection.', $tokens[ $nextToken ]['content'] ), $nextToken, 'WordPressVIPMinimum.Files.IncludingFile' ); + $phpcsFile->addWarning( sprintf( 'File inclusion using variable (%s). Probably needs manual inspection.', $tokens[ $nextToken ]['content'] ), $nextToken, 'IncludingFile' ); return; } @@ -140,14 +140,14 @@ public function process( File $phpcsFile, $stackPtr ) { $nextNextToken = $phpcsFile->findNext( Tokens::$emptyTokens, ($nextToken + 1), null, true, null, true ); if ( T_OPEN_PARENTHESIS === $tokens[ $nextNextToken ]['code'] ) { - $phpcsFile->addWarning( sprintf( 'File inclusion using custom function ( %s() ). Probably needs manual inspection.', $tokens[ $nextToken ]['content'] ), $nextToken, 'WordPressVIPMinimum.Files.IncludingFile' ); + $phpcsFile->addWarning( sprintf( 'File inclusion using custom function ( %s() ). Probably needs manual inspection.', $tokens[ $nextToken ]['content'] ), $nextToken, 'IncludingFile' ); return; } - $phpcsFile->addError( 'Absolute include path must be used. Use get_template_directory, get_stylesheet_directory or plugin_dir_path.', $nextToken, 'WordPressVIPMinimum.Files.IncludingFile' ); + $phpcsFile->addError( 'Absolute include path must be used. Use get_template_directory, get_stylesheet_directory or plugin_dir_path.', $nextToken, 'IncludingFile' ); return; } else { - $phpcsFile->addError( 'Absolute include path must be used. Use get_template_directory, get_stylesheet_directory or plugin_dir_path.', $nextToken, 'WordPressVIPMinimum.Files.IncludingFile' ); + $phpcsFile->addError( 'Absolute include path must be used. Use get_template_directory, get_stylesheet_directory or plugin_dir_path.', $nextToken, 'IncludingFile' ); return; }// End if(). diff --git a/WordPressVIPMinimum/Sniffs/Functions/CheckReturnValueSniff.php b/WordPressVIPMinimum/Sniffs/Functions/CheckReturnValueSniff.php index df5b8870..e20a401a 100644 --- a/WordPressVIPMinimum/Sniffs/Functions/CheckReturnValueSniff.php +++ b/WordPressVIPMinimum/Sniffs/Functions/CheckReturnValueSniff.php @@ -190,7 +190,7 @@ public function findDirectFunctionCalls( $stackPtr ) { $startNext = $openBracket + 1; while ( $next = $phpcsFile->findNext( Tokens::$functionNameTokens, $startNext, $closeBracket, false, null, true ) ) { if ( true === in_array( $tokens[ $next ]['content'], $this->catch[ $functionName ], true ) ) { - $phpcsFile->addError( sprintf( "%s's return type must be checked before calling %s using that value", $tokens[ $next ]['content'], $functionName ), $next, 'WordPressVIPMinimum.Functions.CheckReturnValue' ); + $phpcsFile->addError( sprintf( "%s's return type must be checked before calling %s using that value", $tokens[ $next ]['content'], $functionName ), $next, 'CheckReturnValue' ); } $startNext = $next + 1; } @@ -298,7 +298,7 @@ public function findNonCheckedVariables( $stackPtr ) { if ( true === in_array( $tokens[ $nextFunctionCallWithVariable ]['code'], array_merge( Tokens::$functionNameTokens, $notFunctionsCallee ), true ) && $tokens[ $nextFunctionCallWithVariable ]['content'] === $callee ) { - $phpcsFile->addError( sprintf( 'Type of %s must be checked before calling %s using that variable', $variableName, $callee ), $nextFunctionCallWithVariable, 'WordPressVIPMinimum.Functions.CheckReturnValue' ); + $phpcsFile->addError( sprintf( 'Type of %s must be checked before calling %s using that variable', $variableName, $callee ), $nextFunctionCallWithVariable, 'CheckReturnValue' ); return; } @@ -307,7 +307,7 @@ public function findNonCheckedVariables( $stackPtr ) { if ( true === in_array( $tokens[ $next ]['code'], Tokens::$functionNameTokens, true ) && $tokens[ $next ]['content'] === $callee ) { - $phpcsFile->addError( sprintf( 'Type of %s must be checked before calling %s using that variable', $variableName, $callee ), $next, 'WordPressVIPMinimum.Functions.CheckReturnValue' ); + $phpcsFile->addError( sprintf( 'Type of %s must be checked before calling %s using that variable', $variableName, $callee ), $next, 'CheckReturnValue' ); return; } } diff --git a/WordPressVIPMinimum/Sniffs/VIP/ErrorControlSniff.php b/WordPressVIPMinimum/Sniffs/VIP/ErrorControlSniff.php index 1935c7b0..e2750159 100644 --- a/WordPressVIPMinimum/Sniffs/VIP/ErrorControlSniff.php +++ b/WordPressVIPMinimum/Sniffs/VIP/ErrorControlSniff.php @@ -40,7 +40,7 @@ public function process( File $phpcsFile, $stackPtr ) { $tokens = $phpcsFile->getTokens(); - $phpcsFile->addError( sprintf( 'The code shouldn\'t use error control operators (%s). The call should be wrapped in appropriate checks.', $tokens[ $stackPtr ]['content'] ), $stackPtr, 'WordPressVIPMinimum.VIP.ErrorControl' ); + $phpcsFile->addError( sprintf( 'The code shouldn\'t use error control operators (%s). The call should be wrapped in appropriate checks.', $tokens[ $stackPtr ]['content'] ), $stackPtr, 'ErrorControl' ); } } diff --git a/WordPressVIPMinimum/Sniffs/VIP/FlushRewriteRulesSniff.php b/WordPressVIPMinimum/Sniffs/VIP/FlushRewriteRulesSniff.php index 6543f1e2..ffbde47f 100644 --- a/WordPressVIPMinimum/Sniffs/VIP/FlushRewriteRulesSniff.php +++ b/WordPressVIPMinimum/Sniffs/VIP/FlushRewriteRulesSniff.php @@ -89,7 +89,7 @@ public function process( File $phpcsFile, $stackPtr ) { return; } - $phpcsFile->addError( sprintf( '%s should not be used in any normal circumstances in the theme code.', $tokens[ $stackPtr ]['content'] ), $stackPtr, 'WordPressVIPMinimum.VIP.FlushRewriteRules' ); + $phpcsFile->addError( sprintf( '%s should not be used in any normal circumstances in the theme code.', $tokens[ $stackPtr ]['content'] ), $stackPtr, 'FlushRewriteRules' ); } } diff --git a/WordPressVIPMinimum/Sniffs/VIP/StaticStrreplaceSniff.php b/WordPressVIPMinimum/Sniffs/VIP/StaticStrreplaceSniff.php index 840007e9..dd26ccdc 100644 --- a/WordPressVIPMinimum/Sniffs/VIP/StaticStrreplaceSniff.php +++ b/WordPressVIPMinimum/Sniffs/VIP/StaticStrreplaceSniff.php @@ -82,6 +82,6 @@ public function process( File $phpcsFile, $stackPtr ) { } - $phpcsFile->addError( sprintf( 'This code pattern is often used to run a very dangerous shell programs on your server. The code in these files needs to be reviewed, and possibly cleaned.', $tokens[ $stackPtr ]['content'] ), $stackPtr, 'WordPressVIPMinimum.VIP.StaticStrreplace' ); + $phpcsFile->addError( sprintf( 'This code pattern is often used to run a very dangerous shell programs on your server. The code in these files needs to be reviewed, and possibly cleaned.', $tokens[ $stackPtr ]['content'] ), $stackPtr, 'StaticStrreplace' ); }//end process() } diff --git a/WordPressVIPMinimum/Tests/Actions/PreGetPostsUnitTest.php b/WordPressVIPMinimum/Tests/Actions/PreGetPostsUnitTest.php index 8c6883e0..91ecc48d 100644 --- a/WordPressVIPMinimum/Tests/Actions/PreGetPostsUnitTest.php +++ b/WordPressVIPMinimum/Tests/Actions/PreGetPostsUnitTest.php @@ -9,17 +9,12 @@ use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; -// Cross version compatibility for PHPCS 2.x and 3.x. -if ( ! class_exists( '\AbstractSniffUnitTest' ) ) { - class_alias( '\PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest', '\AbstractSniffUnitTest' ); -} - /** * Unit test class for the PreGetPosts sniff. * * @package VIPCS\WordPressVIPMinimum */ -class WordPressVIPMinimum_Tests_Actions_PreGetPostsUnitTest extends AbstractSniffUnitTest { +class PreGetPostsUnitTest extends AbstractSniffUnitTest { /** * Returns the lines where errors should occur. diff --git a/WordPressVIPMinimum/Tests/Cache/CacheValueOverrideUnitTest.php b/WordPressVIPMinimum/Tests/Cache/CacheValueOverrideUnitTest.php index b907e4a2..37097e97 100644 --- a/WordPressVIPMinimum/Tests/Cache/CacheValueOverrideUnitTest.php +++ b/WordPressVIPMinimum/Tests/Cache/CacheValueOverrideUnitTest.php @@ -9,11 +9,6 @@ use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; -// Cross version compatibility for PHPCS 2.x and 3.x. -if ( ! class_exists( '\AbstractSniffUnitTest' ) ) { - class_alias( '\PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest', '\AbstractSniffUnitTest' ); -} - /** * Unit test class for the CacheValueOverride sniff. * diff --git a/WordPressVIPMinimum/Tests/Classes/DeclarationCompatibilityUnitTest.php b/WordPressVIPMinimum/Tests/Classes/DeclarationCompatibilityUnitTest.php index 76f5a62d..99026700 100644 --- a/WordPressVIPMinimum/Tests/Classes/DeclarationCompatibilityUnitTest.php +++ b/WordPressVIPMinimum/Tests/Classes/DeclarationCompatibilityUnitTest.php @@ -9,11 +9,6 @@ use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; -// Cross version compatibility for PHPCS 2.x and 3.x. -if ( ! class_exists( '\AbstractSniffUnitTest' ) ) { - class_alias( '\PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest', '\AbstractSniffUnitTest' ); -} - /** * Unit test class for the DeclarationCompatibility sniff. * diff --git a/WordPressVIPMinimum/Tests/Constants/ConstantRestrictionsUnitTest.php b/WordPressVIPMinimum/Tests/Constants/ConstantRestrictionsUnitTest.php index cc910aee..015d9f37 100644 --- a/WordPressVIPMinimum/Tests/Constants/ConstantRestrictionsUnitTest.php +++ b/WordPressVIPMinimum/Tests/Constants/ConstantRestrictionsUnitTest.php @@ -9,11 +9,6 @@ use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; -// Cross version compatibility for PHPCS 2.x and 3.x. -if ( ! class_exists( '\AbstractSniffUnitTest' ) ) { - class_alias( '\PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest', '\AbstractSniffUnitTest' ); -} - /** * Unit test class for the ConstantRestrictions sniff. * diff --git a/WordPressVIPMinimum/Tests/Files/IncludingFileUnitTest.php b/WordPressVIPMinimum/Tests/Files/IncludingFileUnitTest.php index ddb9b67c..e31be4a7 100644 --- a/WordPressVIPMinimum/Tests/Files/IncludingFileUnitTest.php +++ b/WordPressVIPMinimum/Tests/Files/IncludingFileUnitTest.php @@ -8,12 +8,6 @@ namespace WordPressVIPMinimum\Tests\Files; use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; - -// Cross version compatibility for PHPCS 2.x and 3.x. -if ( ! class_exists( '\AbstractSniffUnitTest' ) ) { - class_alias( '\PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest', '\AbstractSniffUnitTest' ); -} - /** * Unit test class for the IncludingFile sniff. * diff --git a/WordPressVIPMinimum/Tests/Functions/CheckReturnValueUnitTest.php b/WordPressVIPMinimum/Tests/Functions/CheckReturnValueUnitTest.php index fd10b777..d06491e9 100644 --- a/WordPressVIPMinimum/Tests/Functions/CheckReturnValueUnitTest.php +++ b/WordPressVIPMinimum/Tests/Functions/CheckReturnValueUnitTest.php @@ -9,11 +9,6 @@ use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; -// Cross version compatibility for PHPCS 2.x and 3.x. -if ( ! class_exists( '\AbstractSniffUnitTest' ) ) { - class_alias( '\PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest', '\AbstractSniffUnitTest' ); -} - /** * Unit test class for the CheckReturnValue sniff. * diff --git a/WordPressVIPMinimum/Tests/VIP/ErrorControlUnitTest.php b/WordPressVIPMinimum/Tests/VIP/ErrorControlUnitTest.php index 3543eed4..2ba94c57 100644 --- a/WordPressVIPMinimum/Tests/VIP/ErrorControlUnitTest.php +++ b/WordPressVIPMinimum/Tests/VIP/ErrorControlUnitTest.php @@ -9,11 +9,6 @@ use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; -// Cross version compatibility for PHPCS 2.x and 3.x. -if ( ! class_exists( '\AbstractSniffUnitTest' ) ) { - class_alias( '\PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest', '\AbstractSniffUnitTest' ); -} - /** * Unit test class for the ErrorControl sniff. * diff --git a/WordPressVIPMinimum/Tests/VIP/FlushRewriteRulesUnitTest.php b/WordPressVIPMinimum/Tests/VIP/FlushRewriteRulesUnitTest.php index d495a3b5..cd71d391 100644 --- a/WordPressVIPMinimum/Tests/VIP/FlushRewriteRulesUnitTest.php +++ b/WordPressVIPMinimum/Tests/VIP/FlushRewriteRulesUnitTest.php @@ -9,11 +9,6 @@ use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; -// Cross version compatibility for PHPCS 2.x and 3.x. -if ( ! class_exists( '\AbstractSniffUnitTest' ) ) { - class_alias( '\PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest', '\AbstractSniffUnitTest' ); -} - /** * Unit test class for the FlushRewriteRules sniff. * diff --git a/WordPressVIPMinimum/Tests/VIP/RegexpCompareUnitTest.php b/WordPressVIPMinimum/Tests/VIP/RegexpCompareUnitTest.php index 7e52e112..b4e015b2 100644 --- a/WordPressVIPMinimum/Tests/VIP/RegexpCompareUnitTest.php +++ b/WordPressVIPMinimum/Tests/VIP/RegexpCompareUnitTest.php @@ -9,11 +9,6 @@ use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; -// Cross version compatibility for PHPCS 2.x and 3.x. -if ( ! class_exists( '\AbstractSniffUnitTest' ) ) { - class_alias( '\PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest', '\AbstractSniffUnitTest' ); -} - /** * Unit test class for the RegexpCompare sniff. * diff --git a/WordPressVIPMinimum/Tests/VIP/RemoteRequestTimeoutUnitTest.php b/WordPressVIPMinimum/Tests/VIP/RemoteRequestTimeoutUnitTest.php index 84255930..6139c080 100644 --- a/WordPressVIPMinimum/Tests/VIP/RemoteRequestTimeoutUnitTest.php +++ b/WordPressVIPMinimum/Tests/VIP/RemoteRequestTimeoutUnitTest.php @@ -9,11 +9,6 @@ use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; -// Cross version compatibility for PHPCS 2.x and 3.x. -if ( ! class_exists( '\AbstractSniffUnitTest' ) ) { - class_alias( '\PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest', '\AbstractSniffUnitTest' ); -} - /** * Unit test class for the RemoteRequestTimeout sniff. * diff --git a/WordPressVIPMinimum/Tests/VIP/RestrictedFunctionsUnitTest.php b/WordPressVIPMinimum/Tests/VIP/RestrictedFunctionsUnitTest.php index 6fac9687..777b6029 100644 --- a/WordPressVIPMinimum/Tests/VIP/RestrictedFunctionsUnitTest.php +++ b/WordPressVIPMinimum/Tests/VIP/RestrictedFunctionsUnitTest.php @@ -9,11 +9,6 @@ use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; -// Cross version compatibility for PHPCS 2.x and 3.x. -if ( ! class_exists( '\AbstractSniffUnitTest' ) ) { - class_alias( '\PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest', '\AbstractSniffUnitTest' ); -} - /** * Unit test class for the RestrictedFunctions sniff. * diff --git a/WordPressVIPMinimum/Tests/VIP/StaticStrreplaceUnitTest.php b/WordPressVIPMinimum/Tests/VIP/StaticStrreplaceUnitTest.php index 77d91804..4f00379e 100644 --- a/WordPressVIPMinimum/Tests/VIP/StaticStrreplaceUnitTest.php +++ b/WordPressVIPMinimum/Tests/VIP/StaticStrreplaceUnitTest.php @@ -9,11 +9,6 @@ use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; -// Cross version compatibility for PHPCS 2.x and 3.x. -if ( ! class_exists( '\AbstractSniffUnitTest' ) ) { - class_alias( '\PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest', '\AbstractSniffUnitTest' ); -} - /** * Unit test class for the StaticStrreplace sniff. * From c75381f3d48d3de270dce1f7d6279b7ef657f6c6 Mon Sep 17 00:00:00 2001 From: David Binovec Date: Tue, 15 Aug 2017 10:33:17 +0000 Subject: [PATCH 31/31] Using proper WPCS version in backward compatibility comment /s/0.1.3/0.13.1 --- .../Sniffs/Classes/DeclarationCompatibilitySniff.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WordPressVIPMinimum/Sniffs/Classes/DeclarationCompatibilitySniff.php b/WordPressVIPMinimum/Sniffs/Classes/DeclarationCompatibilitySniff.php index adf6d267..0625ef63 100644 --- a/WordPressVIPMinimum/Sniffs/Classes/DeclarationCompatibilitySniff.php +++ b/WordPressVIPMinimum/Sniffs/Classes/DeclarationCompatibilitySniff.php @@ -9,7 +9,7 @@ use PHP_CodeSniffer_File as File; -// WPCS pre 0.1.3 backwardcompatibility. +// WPCS pre 0.13.1 backwardcompatibility. if ( ! class_exists( '\PHP_CodeSniffer_Standards_AbstractScopeSniff' ) ) { class_alias( 'PHP_CodeSniffer\Sniffs\AbstractScopeSniff', '\PHP_CodeSniffer_Standards_AbstractScopeSniff' ); }