From 4e56f47f820515b41678c36d0b457cafb9b78eab Mon Sep 17 00:00:00 2001 From: Keshav Mishra Date: Wed, 24 May 2023 18:14:04 +0530 Subject: [PATCH 1/6] Upgrade support to php 8 --- composer.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index afae0d7..ece71a8 100644 --- a/composer.json +++ b/composer.json @@ -24,11 +24,11 @@ "sort-packages": true }, "require": { - "php": "^5.6 || ^7.0", - "squizlabs/php_codesniffer": "^2.6" + "php": "^7.0 || ^8.0", + "squizlabs/php_codesniffer": "^3.6" }, "require-dev": { "php-coveralls/php-coveralls": "^1.0", - "phpunit/phpunit": "^5.5" + "phpunit/phpunit": ">=6.5" } } From 2c165adcd3ef170a9d6126a672a96b03e6cd2eec Mon Sep 17 00:00:00 2001 From: Keshav Mishra Date: Wed, 24 May 2023 18:24:58 +0530 Subject: [PATCH 2/6] Update php libraries --- composer.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index ece71a8..90be242 100644 --- a/composer.json +++ b/composer.json @@ -25,10 +25,10 @@ }, "require": { "php": "^7.0 || ^8.0", - "squizlabs/php_codesniffer": "^3.6" + "squizlabs/php_codesniffer": "3.*" }, "require-dev": { - "php-coveralls/php-coveralls": "^1.0", + "php-coveralls/php-coveralls": "^2.5", "phpunit/phpunit": ">=6.5" } } From 254c8d0a8902acf42fb369ce711d392d05e97764 Mon Sep 17 00:00:00 2001 From: Christopher Ryan Date: Tue, 13 Jun 2023 10:22:40 -0400 Subject: [PATCH 3/6] Add build steps for PHP 8 versions. --- .github/workflows/php.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index 24897d8..91b6f0c 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -11,7 +11,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - php-versions: ['7.0', '7.1', '7.2', '7.3', '7.4'] + php-versions: ['7.0', '7.1', '7.2', '7.3', '7.4', '8.0', '8.1', '8.2'] steps: - name: Checkout uses: actions/checkout@v2 From b1e5203e44817cc8367f667bb06793ec6196fe0b Mon Sep 17 00:00:00 2001 From: Christopher Ryan Date: Tue, 13 Jun 2023 10:33:45 -0400 Subject: [PATCH 4/6] Revert codesniffer back to previous version. --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 2fbe276..d10a813 100644 --- a/composer.json +++ b/composer.json @@ -25,7 +25,7 @@ }, "require": { "php": "^7.0 || ^8.0", - "squizlabs/php_codesniffer": "3.*" + "squizlabs/php_codesniffer": "^2.6" }, "require-dev": { "php-coveralls/php-coveralls": "^2.5", From 1003b66a16ac62d277ac9bc1c14c4013bc2c8eaf Mon Sep 17 00:00:00 2001 From: Christopher Ryan Date: Tue, 13 Jun 2023 12:33:52 -0400 Subject: [PATCH 5/6] Upgrade PHP_CodeSniffer to support version 3. --- DWS/Helpers/{Array.php => Arrays.php} | 12 ++++--- DWS/Helpers/Bracket.php | 14 ++++++--- DWS/Helpers/Operator.php | 17 ++++++---- DWS/Helpers/WhiteSpace.php | 10 ++++-- DWS/Sniffs/Arrays/ArrayDeclarationSniff.php | 16 +++++++--- DWS/Sniffs/Arrays/ArrowSpacingSniff.php | 11 +++++-- DWS/Sniffs/Arrays/CommaSpacingSniff.php | 18 +++++++---- DWS/Sniffs/Arrays/TrailingCommaSniff.php | 23 +++++++++----- .../ControlSignatureSniff.php | 6 +++- ...ultilineBracketedExpressionIndentSniff.php | 23 +++++++++----- DWS/Sniffs/Scope/VariableScopeSniff.php | 24 ++++++++------ DWS/Sniffs/Strings/DoubleQuoteUsageSniff.php | 11 +++++-- DWS/Sniffs/Strings/EmbeddedVariablesSniff.php | 11 +++++-- .../Strings/UnnecessaryStringConcatSniff.php | 14 ++++++--- .../ControlStructureInteriorSpacingSniff.php | 11 +++++-- .../ControlStructureTrailingSpacingSniff.php | 11 +++++-- .../WhiteSpace/OperatorSpacingSniff.php | 23 +++++++++----- .../WhiteSpace/SuperfluousWhitespaceSniff.php | 16 +++++++--- composer.json | 5 ++- tests/AbstractSniffUnitTest.php | 31 +++++++------------ .../Arrays/ArrayDeclarationSniffTest.php | 1 - .../Sniffs/Arrays/ArrowSpacingSniffTest.php | 1 - .../Sniffs/Arrays/CommaSpacingSniffTest.php | 1 - .../Sniffs/Arrays/TrailingCommaSniffTest.php | 1 - .../ControlSignatureSniffTest.php | 1 + ...lineBracketedExpressionIndentSniffTest.php | 1 - .../Sniffs/Scope/VariableScopeSniffTest.php | 1 + .../Strings/DoubleQuoteUsageSniffTest.php | 1 + .../Strings/EmbeddedVariablesSniffTest.php | 1 + .../UnnecessaryStringConcatSniffTest.php | 1 + ...ntrolStructureInteriorSpacingSniffTest.php | 1 + ...ntrolStructureTrailingSpacingSniffTest.php | 1 + .../WhiteSpace/OperatorSpacingSniffTest.php | 1 + ...fluousWhitespaceSniffGoodBeginningTest.php | 1 + .../SuperfluousWhitespaceSniffTest.php | 1 + tests/bootstrap.php | 1 + 36 files changed, 211 insertions(+), 112 deletions(-) rename DWS/Helpers/{Array.php => Arrays.php} (78%) diff --git a/DWS/Helpers/Array.php b/DWS/Helpers/Arrays.php similarity index 78% rename from DWS/Helpers/Array.php rename to DWS/Helpers/Arrays.php index 0993c2a..8d873c6 100644 --- a/DWS/Helpers/Array.php +++ b/DWS/Helpers/Arrays.php @@ -6,26 +6,30 @@ * @subpackage Helpers */ +namespace DWS\Helpers; + +use PHP_CodeSniffer\Files\File; + /** * A collection of helper methods for arrays. * * @package DWS * @subpackage Helpers */ -final class DWS_Helpers_Array +final class Arrays { /** * Returns the positions of all of the commas that belong to the array beginning at $arrayStart. * - * @param PHP_CodeSniffer_File $phpcsFile The file where the array is declared. + * @param PHP_CodeSniffer\Files\File $phpcsFile The file where the array is declared. * @param int $arrayStart The position of the opening parenthesis or bracket for the array in the file. * * @return array The stack pointers for all of the commas in the array (excluding commas in nested arrays, functions, etc.). */ - public static function commaPositions(PHP_CodeSniffer_File $phpcsFile, $arrayStart) + public static function commaPositions(File $phpcsFile, $arrayStart) { $tokens = $phpcsFile->getTokens(); - $arrayEnd = DWS_Helpers_Bracket::bracketEnd($phpcsFile, $arrayStart); + $arrayEnd = Bracket::bracketEnd($phpcsFile, $arrayStart); $commas = []; for ($i = $arrayStart + 1; $i <= $arrayEnd; $i++) { diff --git a/DWS/Helpers/Bracket.php b/DWS/Helpers/Bracket.php index fc08cd2..1fc258f 100644 --- a/DWS/Helpers/Bracket.php +++ b/DWS/Helpers/Bracket.php @@ -6,23 +6,27 @@ * @subpackage Helpers */ +namespace DWS\Helpers; + +use PHP_CodeSniffer\Files\File; + /** * A collection of helper methods for bracketed expressions. * * @package DWS * @subpackage Helpers */ -final class DWS_Helpers_Bracket +final class Bracket { /** * Given a pointer to a bracketed expression (such as T_ARRAY or T_OPEN_SHORT_ARRAY), returns the stack pointer for the opening bracket. * - * @param PHP_CodeSniffer_File $phpcsFile The file where the bracketed expression is declared. + * @param PHP_CodeSniffer\Files\File $phpcsFile The file where the bracketed expression is declared. * @param int $stackPtr The position of the expression element in the stack in $phpcsFile. * * @return int The position of the opening bracket, or if not found, the given $stackPtr. */ - public static function bracketStart(PHP_CodeSniffer_File $phpcsFile, $stackPtr) + public static function bracketStart(File $phpcsFile, $stackPtr) { $tokens = $phpcsFile->getTokens(); if (array_key_exists('parenthesis_opener', $tokens[$stackPtr])) { @@ -37,12 +41,12 @@ public static function bracketStart(PHP_CodeSniffer_File $phpcsFile, $stackPtr) /** * Given a pointer to a bracketed expression (such as T_ARRAY or T_OPEN_SHORT_ARRAY), returns the stack pointer for the ending bracket. * - * @param PHP_CodeSniffer_File $phpcsFile The file where the bracketed expression is declared. + * @param PHP_CodeSniffer\Files\File $phpcsFile The file where the bracketed expression is declared. * @param int $stackPtr The position of the expression element in the stack in $phpcsFile. * * @return int The position of the ending bracket, or if not found, the given $stackPtr. */ - public static function bracketEnd(PHP_CodeSniffer_File $phpcsFile, $stackPtr) + public static function bracketEnd(File $phpcsFile, $stackPtr) { $tokens = $phpcsFile->getTokens(); if (array_key_exists('parenthesis_closer', $tokens[$stackPtr])) { diff --git a/DWS/Helpers/Operator.php b/DWS/Helpers/Operator.php index 36860e6..6173e2e 100644 --- a/DWS/Helpers/Operator.php +++ b/DWS/Helpers/Operator.php @@ -6,23 +6,28 @@ * @subpackage Helpers */ +namespace DWS\Helpers; + +use PHP_CodeSniffer\Files\File; +use PHP_CodeSniffer\Util\Tokens; + /** * A collection of helper methods for operators. * * @package DWS * @subpackage Helpers */ -final class DWS_Helpers_Operator +final class Operator { /** * Given a pointer to a bracketed expression (such as T_ARRAY or T_OPEN_SHORT_ARRAY), returns the stack pointer for the opening bracket. * - * @param PHP_CodeSniffer_File $phpcsFile The file where the bracketed expression is declared. + * @param PHP_CodeSniffer\Files\File $phpcsFile The file where the bracketed expression is declared. * @param int $stackPtr The position of the expression element in the stack in $phpcsFile. * * @return int The position of the opening bracket, or if not found, the given $stackPtr. */ - public static function isUnary(PHP_CodeSniffer_File $phpcsFile, $stackPtr) + public static function isUnary(File $phpcsFile, $stackPtr) { $tokens = $phpcsFile->getTokens(); @@ -38,9 +43,9 @@ public static function isUnary(PHP_CodeSniffer_File $phpcsFile, $stackPtr) $prev = $phpcsFile->findPrevious(T_WHITESPACE, $stackPtr - 1, null, true); $unaryHints = array_unique( array_merge( - PHP_CodeSniffer_Tokens::$comparisonTokens, - PHP_CodeSniffer_Tokens::$operators, - PHP_CodeSniffer_Tokens::$assignmentTokens, + Tokens::$comparisonTokens, + Tokens::$operators, + Tokens::$assignmentTokens, [ T_RETURN, T_COMMA, diff --git a/DWS/Helpers/WhiteSpace.php b/DWS/Helpers/WhiteSpace.php index 14b4911..ad8f2b4 100644 --- a/DWS/Helpers/WhiteSpace.php +++ b/DWS/Helpers/WhiteSpace.php @@ -6,23 +6,27 @@ * @subpackage Helpers */ +namespace DWS\Helpers; + +use PHP_CodeSniffer\Files\File; + /** * A collection of helper methods for whitespace. * * @package DWS * @subpackage Helpers */ -final class DWS_Helpers_Whitespace +final class Whitespace { /** * Returns the indentation level of the requested line. * - * @param PHP_CodeSniffer_File $phpcsFile The file in question. + * @param PHP_CodeSniffer\Files\File $phpcsFile The file in question. * @param int $stackPtr The stack pointer to the element on the line in question. * * @return int The normalized column number for the initial non-whitespace token on the line. */ - public static function indentOfLine(PHP_CodeSniffer_File $phpcsFile, $stackPtr) + public static function indentOfLine(File $phpcsFile, $stackPtr) { $tokens = $phpcsFile->getTokens(); $beginningElement = $stackPtr; diff --git a/DWS/Sniffs/Arrays/ArrayDeclarationSniff.php b/DWS/Sniffs/Arrays/ArrayDeclarationSniff.php index aebab06..21f8e43 100644 --- a/DWS/Sniffs/Arrays/ArrayDeclarationSniff.php +++ b/DWS/Sniffs/Arrays/ArrayDeclarationSniff.php @@ -6,13 +6,19 @@ * @subpackage Sniffs */ +namespace DWS\Sniffs\Arrays; + +use DWS\Helpers\Bracket; +use PHP_CodeSniffer\Sniffs\Sniff; +use PHP_CodeSniffer\Files\File; + /** * A test to ensure that arrays conform to the array coding standard. * * @package DWS * @subpackage Sniffs */ -final class DWS_Sniffs_Arrays_ArrayDeclarationSniff implements PHP_CodeSniffer_Sniff +final class ArrayDeclarationSniff implements Sniff { /** * Returns an array of tokens this test wants to listen for. @@ -27,16 +33,16 @@ public function register() /** * Processes this sniff, when one of its tokens is encountered. * - * @param PHP_CodeSniffer_File $phpcsFile The current file being checked. + * @param PHP_CodeSniffer\Files\File $phpcsFile The current file being checked. * @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(); - $arrayStart = DWS_Helpers_Bracket::bracketStart($phpcsFile, $stackPtr); - $arrayEnd = DWS_Helpers_Bracket::bracketEnd($phpcsFile, $stackPtr); + $arrayStart = Bracket::bracketStart($phpcsFile, $stackPtr); + $arrayEnd = Bracket::bracketEnd($phpcsFile, $stackPtr); if (!in_array($arrayStart, [$stackPtr, $stackPtr + 1])) { $phpcsFile->addError('No whitespace allowed between the array keyword and the opening parenthesis', $stackPtr, 'SpaceAfterKeyword'); diff --git a/DWS/Sniffs/Arrays/ArrowSpacingSniff.php b/DWS/Sniffs/Arrays/ArrowSpacingSniff.php index 3814600..8cc9216 100644 --- a/DWS/Sniffs/Arrays/ArrowSpacingSniff.php +++ b/DWS/Sniffs/Arrays/ArrowSpacingSniff.php @@ -6,13 +6,18 @@ * @subpackage Sniffs */ +namespace DWS\Sniffs\Arrays; + +use PHP_CodeSniffer\Sniffs\Sniff; +use PHP_CodeSniffer\Files\File; + /** * A test to ensure that arrows in arrays are set with proper whitespace. * * @package DWS * @subpackage Sniffs */ -final class DWS_Sniffs_Arrays_ArrowSpacingSniff implements PHP_CodeSniffer_Sniff +final class ArrowSpacingSniff implements Sniff { /** * Returns an array of tokens this test wants to listen for. @@ -27,12 +32,12 @@ public function register() /** * Processes this sniff, when one of its tokens is encountered. * - * @param PHP_CodeSniffer_File $phpcsFile The current file being checked. + * @param PHP_CodeSniffer\Files\File $phpcsFile The current file being checked. * @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/DWS/Sniffs/Arrays/CommaSpacingSniff.php b/DWS/Sniffs/Arrays/CommaSpacingSniff.php index 0c5b0c6..d4e5294 100644 --- a/DWS/Sniffs/Arrays/CommaSpacingSniff.php +++ b/DWS/Sniffs/Arrays/CommaSpacingSniff.php @@ -6,13 +6,19 @@ * @subpackage Sniffs */ +namespace DWS\Sniffs\Arrays; + +use DWS\Helpers; +use PHP_CodeSniffer\Sniffs\Sniff; +use PHP_CodeSniffer\Files\File; + /** * A test to ensure that commas in arrays are set with proper whitespace. * * @package DWS * @subpackage Sniffs */ -final class DWS_Sniffs_Arrays_CommaSpacingSniff implements PHP_CodeSniffer_Sniff +final class CommaSpacingSniff implements Sniff { /** * Returns an array of tokens this test wants to listen for. @@ -27,20 +33,20 @@ public function register() /** * Processes this sniff, when one of its tokens is encountered. * - * @param PHP_CodeSniffer_File $phpcsFile The current file being checked. + * @param PHP_CodeSniffer\Files\File $phpcsFile The current file being checked. * @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(); - $arrayStart = DWS_Helpers_Bracket::bracketStart($phpcsFile, $stackPtr); - $arrayEnd = DWS_Helpers_Bracket::bracketEnd($phpcsFile, $stackPtr); + $arrayStart = Helpers\Bracket::bracketStart($phpcsFile, $stackPtr); + $arrayEnd = Helpers\Bracket::bracketEnd($phpcsFile, $stackPtr); $isSingleLine = $tokens[$arrayStart]['line'] === $tokens[$arrayEnd]['line']; - foreach (DWS_Helpers_Array::commaPositions($phpcsFile, $arrayStart) as $comma) { + foreach (Helpers\Arrays::commaPositions($phpcsFile, $arrayStart) as $comma) { if ($tokens[$comma - 1]['code'] === T_WHITESPACE) { $phpcsFile->addError('No whitespace allowed before commas in an array', $comma, 'SpaceBeforeComma'); } diff --git a/DWS/Sniffs/Arrays/TrailingCommaSniff.php b/DWS/Sniffs/Arrays/TrailingCommaSniff.php index 9ef1a11..e3b66f2 100644 --- a/DWS/Sniffs/Arrays/TrailingCommaSniff.php +++ b/DWS/Sniffs/Arrays/TrailingCommaSniff.php @@ -6,13 +6,20 @@ * @subpackage Sniffs */ +namespace DWS\Sniffs\Arrays; + +use DWS\Helpers; +use PHP_CodeSniffer\Sniffs\Sniff; +use PHP_CodeSniffer\Files\File; +use PHP_CodeSniffer\Util\Tokens; + /** * A test to ensure that trailing commas are included for multi-line arrays only. * * @package DWS * @subpackage Sniffs */ -final class DWS_Sniffs_Arrays_TrailingCommaSniff implements PHP_CodeSniffer_Sniff +final class TrailingCommaSniff implements Sniff { /** * Returns an array of tokens this test wants to listen for. @@ -27,30 +34,30 @@ public function register() /** * Processes this sniff, when one of its tokens is encountered. * - * @param PHP_CodeSniffer_File $phpcsFile The current file being checked. + * @param PHP_CodeSniffer\Files\File $phpcsFile The current file being checked. * @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(); - $arrayStart = DWS_Helpers_Bracket::bracketStart($phpcsFile, $stackPtr); - $arrayEnd = DWS_Helpers_Bracket::bracketEnd($phpcsFile, $stackPtr); + $arrayStart = Helpers\Bracket::bracketStart($phpcsFile, $stackPtr); + $arrayEnd = Helpers\Bracket::bracketEnd($phpcsFile, $stackPtr); $isSingleLine = $tokens[$arrayStart]['line'] === $tokens[$arrayEnd]['line']; - $commas = DWS_Helpers_Array::commaPositions($phpcsFile, $arrayStart); + $commas = Helpers\Arrays::commaPositions($phpcsFile, $arrayStart); $lastComma = array_pop($commas); - $trailingComma = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, $lastComma + 1, $arrayEnd, true) === false; + $trailingComma = $phpcsFile->findNext(Tokens::$emptyTokens, $lastComma + 1, $arrayEnd, true) === false; if ($isSingleLine) { if ($trailingComma) { $phpcsFile->addError('No trailing comma allowed on single-line arrays', $lastComma, 'SingleLineTrailingComma'); } } elseif (!$trailingComma) { - $previousItem = $phpcsFile->findPrevious(PHP_CodeSniffer_Tokens::$emptyTokens, $arrayEnd - 1, $arrayStart, true); + $previousItem = $phpcsFile->findPrevious(Tokens::$emptyTokens, $arrayEnd - 1, $arrayStart, true); $phpcsFile->addError('Trailing comma required for multi-line arrays', $previousItem, 'MultiLineTrailingComma'); } } diff --git a/DWS/Sniffs/ControlStructures/ControlSignatureSniff.php b/DWS/Sniffs/ControlStructures/ControlSignatureSniff.php index 33d32dd..0fe551a 100644 --- a/DWS/Sniffs/ControlStructures/ControlSignatureSniff.php +++ b/DWS/Sniffs/ControlStructures/ControlSignatureSniff.php @@ -6,13 +6,17 @@ * @subpackage Sniffs */ +namespace DWS\Sniffs\ControlStructures; + +use PHP_CodeSniffer\Sniffs\AbstractPatternSniff; + /** * Verifies that control statements conform to their coding standards. * * @package DWS * @subpackage Sniffs */ -final class DWS_Sniffs_ControlStructures_ControlSignatureSniff extends PHP_CodeSniffer_Standards_AbstractPatternSniff +final class ControlSignatureSniff extends AbstractPatternSniff { /** * Initialze the parent AbstractPatternSniff to ignore comments diff --git a/DWS/Sniffs/Formatting/MultilineBracketedExpressionIndentSniff.php b/DWS/Sniffs/Formatting/MultilineBracketedExpressionIndentSniff.php index 94bcb1b..fb85dbb 100644 --- a/DWS/Sniffs/Formatting/MultilineBracketedExpressionIndentSniff.php +++ b/DWS/Sniffs/Formatting/MultilineBracketedExpressionIndentSniff.php @@ -7,6 +7,13 @@ * @subpackage Sniffs */ +namespace DWS\Sniffs\Formatting; + +use DWS\Helpers; +use PHP_CodeSniffer\Sniffs\Sniff; +use PHP_CodeSniffer\Files\File; +use PHP_CodeSniffer\Util\Tokens; + /** * A test to ensure that multi-line bracketed expressions (arrays, function definitions, function calls, control structure conditions, etc.) are * indented correctly. @@ -14,7 +21,7 @@ * @package DWS * @subpackage Sniffs */ -final class DWS_Sniffs_Formatting_MultilineBracketedExpressionIndentSniff implements PHP_CodeSniffer_Sniff +final class MultilineBracketedExpressionIndentSniff implements Sniff { /** * Returns an array of tokens this test wants to listen for. @@ -29,29 +36,29 @@ public function register() /** * Processes this sniff, when one of its tokens is encountered. * - * @param PHP_CodeSniffer_File $phpcsFile The current file being checked. + * @param PHP_CodeSniffer\Files\File $phpcsFile The current file being checked. * @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(); - $bracketStart = DWS_Helpers_Bracket::bracketStart($phpcsFile, $stackPtr); - $bracketEnd = DWS_Helpers_Bracket::bracketEnd($phpcsFile, $stackPtr); + $bracketStart = Helpers\Bracket::bracketStart($phpcsFile, $stackPtr); + $bracketEnd = Helpers\Bracket::bracketEnd($phpcsFile, $stackPtr); if ($tokens[$bracketStart]['line'] === $tokens[$bracketEnd]['line']) { return; // Single-line expressions don't have indentation to worry about. } - $beginningIndent = DWS_Helpers_WhiteSpace::indentOfLine($phpcsFile, $bracketStart); + $beginningIndent = Helpers\WhiteSpace::indentOfLine($phpcsFile, $bracketStart); if ($tokens[$bracketEnd]['column'] !== $beginningIndent) { $data = [$beginningIndent - 1, $tokens[$bracketEnd]['column'] - 1, $tokens[$bracketEnd]['content']]; $phpcsFile->addError('Expected indentation of %s spaces, %s found for ending bracket "%s"', $bracketEnd, 'EndIndent', $data); } - $nextToken = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, $bracketStart + 1, $bracketEnd, true); + $nextToken = $phpcsFile->findNext(Tokens::$emptyTokens, $bracketStart + 1, $bracketEnd, true); if ($nextToken !== false && $tokens[$nextToken]['line'] === $tokens[$bracketStart]['line']) { $data = [$tokens[$bracketStart]['content']]; $phpcsFile->addError('Expected first item after opening "%s" to be indented on a new line', $nextToken, 'OpeningIndent', $data); @@ -59,7 +66,7 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) $firstOnLine = $bracketStart + 1; for ($line = $tokens[$bracketStart]['line'] + 1; $line < $tokens[$bracketEnd]['line']; $line++) { - while ($tokens[$firstOnLine]['line'] < $line || in_array($tokens[$firstOnLine]['code'], PHP_CodeSniffer_Tokens::$emptyTokens)) { + while ($tokens[$firstOnLine]['line'] < $line || in_array($tokens[$firstOnLine]['code'], Tokens::$emptyTokens)) { if (array_key_exists('parenthesis_closer', $tokens[$firstOnLine])) { $firstOnLine = $tokens[$firstOnLine]['parenthesis_closer'] + 1; $line = $tokens[$firstOnLine]['line']; diff --git a/DWS/Sniffs/Scope/VariableScopeSniff.php b/DWS/Sniffs/Scope/VariableScopeSniff.php index 3bb9357..0e2fd03 100644 --- a/DWS/Sniffs/Scope/VariableScopeSniff.php +++ b/DWS/Sniffs/Scope/VariableScopeSniff.php @@ -6,13 +6,19 @@ * @subpackage Sniffs */ +namespace DWS\Sniffs\Scope; + +use PHP_CodeSniffer\Sniffs\AbstractVariableSniff; +use PHP_CodeSniffer\Files\File; +use PHP_CodeSniffer\Util\Tokens; + /** * Verifies that all variables are declared in the proper scope. * * @package DWS * @subpackage Sniffs */ -final class DWS_Sniffs_Scope_VariableScopeSniff extends PHP_CodeSniffer_Standards_AbstractVariableSniff +final class VariableScopeSniff extends AbstractVariableSniff { /** * This stores the first scope level that a variable is encountered @@ -22,24 +28,24 @@ final class DWS_Sniffs_Scope_VariableScopeSniff extends PHP_CodeSniffer_Standard /** * Processes normal variables. * - * @param PHP_CodeSniffer_File $phpcsFile The file where this token was found. + * @param PHP_CodeSniffer\Files\File $phpcsFile The 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, $stackPtr) + protected function processVariable(File $phpcsFile, $stackPtr) { $tokens = $phpcsFile->getTokens(); $variableName = $tokens[$stackPtr]['content']; $scopeIdentifier = $phpcsFile->getFilename() . $variableName; $level = $tokens[$stackPtr]['level']; $functionIndex = $phpcsFile->findPrevious(T_FUNCTION, $stackPtr); - $lastScopeOpen = $phpcsFile->findPrevious(PHP_CodeSniffer_Tokens::$scopeOpeners, $stackPtr); + $lastScopeOpen = $phpcsFile->findPrevious(Tokens::$scopeOpeners, $stackPtr); //Inline scope openers do not increment the level value $scopeOpenDistance = $tokens[$stackPtr]['line'] - $tokens[$lastScopeOpen]['line']; if ( - in_array($tokens[$lastScopeOpen]['code'], PHP_CodeSniffer_Tokens::$scopeOpeners) === true + in_array($tokens[$lastScopeOpen]['code'], Tokens::$scopeOpeners) === true && ($scopeOpenDistance === 1 || $scopeOpenDistance === 0)//Include the variables in the condition && $tokens[$stackPtr]['level'] === $tokens[$lastScopeOpen]['level'] ) { @@ -77,12 +83,12 @@ protected function processVariable(PHP_CodeSniffer_File $phpcsFile, $stackPtr) /** * Processes the function tokens within the class. * - * @param PHP_CodeSniffer_File $phpcsFile The file where this token was found. + * @param PHP_CodeSniffer\Files\File $phpcsFile The 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, $stackPtr) + protected function processMemberVar(File $phpcsFile, $stackPtr) { //Do Nothing } @@ -90,12 +96,12 @@ protected function processMemberVar(PHP_CodeSniffer_File $phpcsFile, $stackPtr) /** * Processes variables in double quoted strings. * - * @param PHP_CodeSniffer_File $phpcsFile The file where this token was found. + * @param PHP_CodeSniffer\Files\File $phpcsFile The file where this token was found. * @param int $stackPtr The position where the token was found. * * @return void */ - protected function processVariableInString(PHP_CodeSniffer_File $phpcsFile, $stackPtr) + protected function processVariableInString(File $phpcsFile, $stackPtr) { //Do Nothing } diff --git a/DWS/Sniffs/Strings/DoubleQuoteUsageSniff.php b/DWS/Sniffs/Strings/DoubleQuoteUsageSniff.php index bf6ec35..466d72a 100644 --- a/DWS/Sniffs/Strings/DoubleQuoteUsageSniff.php +++ b/DWS/Sniffs/Strings/DoubleQuoteUsageSniff.php @@ -6,13 +6,18 @@ * @subpackage Sniffs */ +namespace DWS\Sniffs\Strings; + +use PHP_CodeSniffer\Sniffs\Sniff; +use PHP_CodeSniffer\Files\File; + /** * Makes sure that any use of Double Quotes are warranted. * * @package DWS * @subpackage Sniffs */ -final class DWS_Sniffs_Strings_DoubleQuoteUsageSniff implements PHP_CodeSniffer_Sniff +final class DoubleQuoteUsageSniff implements Sniff { /** * Returns an array of tokens this test wants to listen for. @@ -27,12 +32,12 @@ public function register() /** * Processes this test, when one of its tokens is encountered. * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. + * @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/DWS/Sniffs/Strings/EmbeddedVariablesSniff.php b/DWS/Sniffs/Strings/EmbeddedVariablesSniff.php index 75850e7..f6949ff 100644 --- a/DWS/Sniffs/Strings/EmbeddedVariablesSniff.php +++ b/DWS/Sniffs/Strings/EmbeddedVariablesSniff.php @@ -6,13 +6,18 @@ * @subpackage Sniffs */ +namespace DWS\Sniffs\Strings; + +use PHP_CodeSniffer\Sniffs\Sniff; +use PHP_CodeSniffer\Files\File; + /** * Makes sure that all variables embedded in strings are enclosed in braces. * * @package DWS * @subpackage Sniffs */ -final class DWS_Sniffs_Strings_EmbeddedVariablesSniff implements PHP_CodeSniffer_Sniff +final class EmbeddedVariablesSniff implements Sniff { /** * Returns an array of tokens this test wants to listen for. @@ -27,12 +32,12 @@ public function register() /** * Processes this test, when one of its tokens is encountered. * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. + * @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/DWS/Sniffs/Strings/UnnecessaryStringConcatSniff.php b/DWS/Sniffs/Strings/UnnecessaryStringConcatSniff.php index f1aa27f..5002828 100644 --- a/DWS/Sniffs/Strings/UnnecessaryStringConcatSniff.php +++ b/DWS/Sniffs/Strings/UnnecessaryStringConcatSniff.php @@ -7,6 +7,12 @@ * @subpackage Sniffs */ +namespace DWS\Sniffs\Strings; + +use PHP_CodeSniffer\Sniffs\Sniff; +use PHP_CodeSniffer\Files\File; +use PHP_CodeSniffer\Util\Tokens; + /** * Checks that two strings are not concatenated together; suggests * using one string instead. @@ -14,7 +20,7 @@ * @package DWS * @subpackage Sniffs */ -final class DWS_Sniffs_Strings_UnnecessaryStringConcatSniff implements PHP_CodeSniffer_Sniff +final class UnnecessaryStringConcatSniff implements Sniff { /** * The limit that the length of a line should not exceed. @@ -43,12 +49,12 @@ public function register() /** * Processes this test, when one of its tokens is encountered. * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. + * @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) { // Work out which type of file this is for. $tokens = $phpcsFile->getTokens(); @@ -60,7 +66,7 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) $prev = $phpcsFile->findPrevious(T_WHITESPACE, $stackPtr - 1, null, true); $next = $phpcsFile->findNext(T_WHITESPACE, $stackPtr + 1, null, true); - $stringTokens = PHP_CodeSniffer_Tokens::$stringTokens; + $stringTokens = Tokens::$stringTokens; //See if the characters before and after the concatenation are quotes if ( in_array($tokens[$prev]['code'], $stringTokens) !== true || diff --git a/DWS/Sniffs/WhiteSpace/ControlStructureInteriorSpacingSniff.php b/DWS/Sniffs/WhiteSpace/ControlStructureInteriorSpacingSniff.php index 298517f..84cd7da 100644 --- a/DWS/Sniffs/WhiteSpace/ControlStructureInteriorSpacingSniff.php +++ b/DWS/Sniffs/WhiteSpace/ControlStructureInteriorSpacingSniff.php @@ -6,13 +6,18 @@ * @subpackage Sniffs */ +namespace DWS\Sniffs\WhiteSpace; + +use PHP_CodeSniffer\Sniffs\Sniff; +use PHP_CodeSniffer\Files\File; + /** * Verifies that there are no blank lines at the beginning or end of control structures. * * @package DWS * @subpackage Sniffs */ -final class DWS_Sniffs_WhiteSpace_ControlStructureInteriorSpacingSniff implements PHP_CodeSniffer_Sniff +final class ControlStructureInteriorSpacingSniff implements Sniff { /** * Returns an array of tokens this test wants to listen for. @@ -27,12 +32,12 @@ public function register() /** * Processes this test, when one of its tokens is encountered. * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. + * @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]; diff --git a/DWS/Sniffs/WhiteSpace/ControlStructureTrailingSpacingSniff.php b/DWS/Sniffs/WhiteSpace/ControlStructureTrailingSpacingSniff.php index 4809d9a..f00078c 100644 --- a/DWS/Sniffs/WhiteSpace/ControlStructureTrailingSpacingSniff.php +++ b/DWS/Sniffs/WhiteSpace/ControlStructureTrailingSpacingSniff.php @@ -8,6 +8,11 @@ * @subpackage Sniffs */ +namespace DWS\Sniffs\WhiteSpace; + +use PHP_CodeSniffer\Sniffs\Sniff; +use PHP_CodeSniffer\Files\File; + /** * Verifies that no whitespace proceeds the first content of the file, that there is * no whitespace at the end of a line, that there are no extra new lines before or after @@ -16,7 +21,7 @@ * @package DWS * @subpackage Sniffs */ -final class DWS_Sniffs_WhiteSpace_ControlStructureTrailingSpacingSniff implements PHP_CodeSniffer_Sniff +final class ControlStructureTrailingSpacingSniff implements Sniff { /** * Returns an array of tokens this test wants to listen for. @@ -31,12 +36,12 @@ public function register() /** * Processes this test, when one of its tokens is encountered. * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. + * @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]; diff --git a/DWS/Sniffs/WhiteSpace/OperatorSpacingSniff.php b/DWS/Sniffs/WhiteSpace/OperatorSpacingSniff.php index 8c0eb8f..6ac8c1d 100644 --- a/DWS/Sniffs/WhiteSpace/OperatorSpacingSniff.php +++ b/DWS/Sniffs/WhiteSpace/OperatorSpacingSniff.php @@ -6,13 +6,20 @@ * @subpackage Sniffs */ +namespace DWS\Sniffs\WhiteSpace; + +use DWS\Helpers; +use PHP_CodeSniffer\Sniffs\Sniff; +use PHP_CodeSniffer\Files\File; +use PHP_CodeSniffer\Util\Tokens; + /** * Verifies that there is one space around operators. * * @package DWS * @subpackage Sniffs */ -final class DWS_Sniffs_WhiteSpace_OperatorSpacingSniff implements PHP_CodeSniffer_Sniff +final class OperatorSpacingSniff implements Sniff { /** * Returns an array of tokens this test wants to listen for. @@ -23,10 +30,10 @@ public function register() { return array_unique( array_merge( - PHP_CodeSniffer_Tokens::$comparisonTokens, - PHP_CodeSniffer_Tokens::$operators, - PHP_CodeSniffer_Tokens::$assignmentTokens, - PHP_CodeSniffer_Tokens::$booleanOperators, + Tokens::$comparisonTokens, + Tokens::$operators, + Tokens::$assignmentTokens, + Tokens::$booleanOperators, [T_INLINE_THEN, T_INLINE_ELSE, T_BOOLEAN_NOT, T_STRING_CONCAT] ) ); @@ -36,12 +43,12 @@ public function register() /** * Processes this test, when one of its tokens is encountered. * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. + * @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(); $operator = $tokens[$stackPtr]['content']; @@ -57,7 +64,7 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) $nextNonEmpty = $phpcsFile->findNext(T_WHITESPACE, $stackPtr + 1, null, true); $nextSplitsLine = $tokens[$nextNonEmpty]['line'] !== $tokens[$stackPtr]['line']; - if (DWS_Helpers_Operator::isUnary($phpcsFile, $stackPtr)) { + if (Helpers\Operator::isUnary($phpcsFile, $stackPtr)) { if ( !$previousSplitsLine && $previousSpaces !== 1 && diff --git a/DWS/Sniffs/WhiteSpace/SuperfluousWhitespaceSniff.php b/DWS/Sniffs/WhiteSpace/SuperfluousWhitespaceSniff.php index 00e2559..2efc9c3 100644 --- a/DWS/Sniffs/WhiteSpace/SuperfluousWhitespaceSniff.php +++ b/DWS/Sniffs/WhiteSpace/SuperfluousWhitespaceSniff.php @@ -8,6 +8,12 @@ * @subpackage Sniffs */ +namespace DWS\Sniffs\WhiteSpace; + +use PHP_CodeSniffer\Sniffs\Sniff; +use PHP_CodeSniffer\Files\File; +use PHP_CodeSniffer\Util\Tokens; + /** * Verifies that no whitespace proceeds the first content of the file, that there is * no whitespace at the end of a line, that there are no extra new lines before or after @@ -16,7 +22,7 @@ * @package DWS * @subpackage Sniffs */ -final class DWS_Sniffs_WhiteSpace_SuperfluousWhitespaceSniff implements PHP_CodeSniffer_Sniff +final class SuperfluousWhitespaceSniff implements Sniff { /** * Returns an array of tokens this test wants to listen for. @@ -25,7 +31,7 @@ final class DWS_Sniffs_WhiteSpace_SuperfluousWhitespaceSniff implements PHP_Code */ public function register() { - $tokens = PHP_CodeSniffer_Tokens::$scopeOpeners; + $tokens = Tokens::$scopeOpeners; $tokens[] = T_OPEN_TAG; $tokens[] = T_WHITESPACE; $tokens[] = T_COMMENT; @@ -35,12 +41,12 @@ public function register() /** * Processes this sniff, when one of its tokens is encountered. * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. + * @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(); $tokenContent = null; @@ -61,7 +67,7 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) $phpcsFile->addError('Additional whitespace found at start of file', $stackPtr, 'StartFile'); } elseif ( - in_array($tokens[$stackPtr]['code'], PHP_CodeSniffer_Tokens::$scopeOpeners) + in_array($tokens[$stackPtr]['code'], Tokens::$scopeOpeners) && array_key_exists('scope_opener', $tokens[$stackPtr]) ) { $classOpen = $tokens[$stackPtr]['scope_opener']; diff --git a/composer.json b/composer.json index d10a813..2887bc6 100644 --- a/composer.json +++ b/composer.json @@ -25,12 +25,15 @@ }, "require": { "php": "^7.0 || ^8.0", - "squizlabs/php_codesniffer": "^2.6" + "squizlabs/php_codesniffer": "^3" }, "require-dev": { "php-coveralls/php-coveralls": "^2.5", "phpunit/phpunit": ">=6.5" }, + "autoload": { + "psr-4": { "DWS\\": "src" } + }, "scripts": { "lint": "vendor/bin/phpcs", "test": "vendor/bin/phpunit" diff --git a/tests/AbstractSniffUnitTest.php b/tests/AbstractSniffUnitTest.php index 0a7c00a..4cd2337 100644 --- a/tests/AbstractSniffUnitTest.php +++ b/tests/AbstractSniffUnitTest.php @@ -20,13 +20,6 @@ */ abstract class AbstractSniffUnitTest extends TestCase { - /** - * The PHP_CodeSniffer object used for testing. - * - * @var PHP_CodeSniffer - */ - protected static $_phpcs = null; - /** * Tests the extending classes Sniff class. * @@ -36,13 +29,12 @@ abstract class AbstractSniffUnitTest extends TestCase */ public final function runTest() { - if (self::$_phpcs === null) { - self::$_phpcs = new PHP_CodeSniffer(); - self::$_phpcs->cli->setCommandLineValues(['-s']); - } + $config = new \PHP_CodeSniffer\Config(); + $ruleset = new \PHP_CodeSniffer\Ruleset($config); + $ruleset->registerSniffs([$this->_getSniffName()], [], []); + $ruleset->populateTokenListeners(); - self::$_phpcs->process([], 'DWS', [$this->_getSniffName()]); - self::$_phpcs->setIgnorePatterns([]); + //self::$_phpcs->cli->setCommandLineValues(['-s']); $testFile = dirname(__DIR__) . '/tests/' . str_replace('_', '/', get_class($this)) . '.inc'; if (!file_exists($testFile)) { @@ -52,7 +44,8 @@ public final function runTest() $phpcsFile = null; try { - $phpcsFile = self::$_phpcs->processFile($testFile); + $phpcsFile = new \PHP_CodeSniffer\Files\LocalFile($testFile, $ruleset, $config); + $phpcsFile->process(); } catch (Exception $e) { $this->fail("An unexpected exception has been caught: {$e->getMessage()}"); } @@ -73,12 +66,12 @@ public final function runTest() /** * Generate a list of test failures for a given sniffed file. * - * @param PHP_CodeSniffer_File $file The file being tested. + * @param PHP_CodeSniffer\Files\File $file The file being tested. * * @return array - * @throws PHP_CodeSniffer_Exception + * @throws \PHP_CodeSniffer\Exception\RuntimeException */ - public function generateFailureMessages(PHP_CodeSniffer_File $file) + public function generateFailureMessages(\PHP_CodeSniffer\Files\File $file) { $testFile = $file->getFilename(); $foundErrors = $file->getErrors(); @@ -87,11 +80,11 @@ public function generateFailureMessages(PHP_CodeSniffer_File $file) $expectedWarnings = $this->getWarningList(basename($testFile)); if (!is_array($expectedErrors)) { - throw new PHP_CodeSniffer_Exception('getErrorList() must return an array'); + throw new \PHP_CodeSniffer\Exception\RuntimeException('getErrorList() must return an array'); } if (!is_array($expectedWarnings)) { - throw new PHP_CodeSniffer_Exception('getWarningList() must return an array'); + throw new \PHP_CodeSniffer\Exception\RuntimeException('getWarningList() must return an array'); } /* diff --git a/tests/DWS/Sniffs/Arrays/ArrayDeclarationSniffTest.php b/tests/DWS/Sniffs/Arrays/ArrayDeclarationSniffTest.php index aae9abc..5972f16 100644 --- a/tests/DWS/Sniffs/Arrays/ArrayDeclarationSniffTest.php +++ b/tests/DWS/Sniffs/Arrays/ArrayDeclarationSniffTest.php @@ -1,5 +1,4 @@ add('', __DIR__); From f2566f36b6163c88312eb1c2d2ee9fe714151080 Mon Sep 17 00:00:00 2001 From: Christopher Ryan Date: Thu, 15 Jun 2023 11:06:27 -0400 Subject: [PATCH 6/6] Fix unit tests to work correctly with upgraded phpcs. --- composer.json | 6 ++++-- tests/AbstractSniffUnitTest.php | 4 +--- tests/DWS/Sniffs/Arrays/ArrayDeclarationSniffTest.php | 2 +- tests/DWS/Sniffs/Arrays/ArrowSpacingSniffTest.php | 2 +- tests/DWS/Sniffs/Arrays/CommaSpacingSniffTest.php | 2 +- tests/DWS/Sniffs/Arrays/TrailingCommaSniffTest.php | 2 +- .../Sniffs/ControlStructures/ControlSignatureSniffTest.php | 2 +- .../MultilineBracketedExpressionIndentSniffTest.php | 2 +- tests/DWS/Sniffs/Scope/VariableScopeSniffTest.php | 2 +- tests/DWS/Sniffs/Strings/DoubleQuoteUsageSniffTest.php | 2 +- tests/DWS/Sniffs/Strings/EmbeddedVariablesSniffTest.php | 2 +- .../DWS/Sniffs/Strings/UnnecessaryStringConcatSniffTest.php | 2 +- .../WhiteSpace/ControlStructureInteriorSpacingSniffTest.php | 2 +- .../WhiteSpace/ControlStructureTrailingSpacingSniffTest.php | 2 +- tests/DWS/Sniffs/WhiteSpace/OperatorSpacingSniffTest.php | 2 +- .../SuperfluousWhitespaceSniffGoodBeginningTest.php | 2 +- .../Sniffs/WhiteSpace/SuperfluousWhitespaceSniffTest.php | 2 +- tests/bootstrap.php | 2 ++ 18 files changed, 22 insertions(+), 20 deletions(-) diff --git a/composer.json b/composer.json index 2887bc6..8ac7822 100644 --- a/composer.json +++ b/composer.json @@ -29,10 +29,12 @@ }, "require-dev": { "php-coveralls/php-coveralls": "^2.5", - "phpunit/phpunit": ">=6.5" + "phpunit/phpunit": "^6.5 || ^9" }, "autoload": { - "psr-4": { "DWS\\": "src" } + "psr-4": { + "DWS\\": "src" + } }, "scripts": { "lint": "vendor/bin/phpcs", diff --git a/tests/AbstractSniffUnitTest.php b/tests/AbstractSniffUnitTest.php index 4cd2337..1b7df25 100644 --- a/tests/AbstractSniffUnitTest.php +++ b/tests/AbstractSniffUnitTest.php @@ -31,11 +31,9 @@ public final function runTest() { $config = new \PHP_CodeSniffer\Config(); $ruleset = new \PHP_CodeSniffer\Ruleset($config); - $ruleset->registerSniffs([$this->_getSniffName()], [], []); + $ruleset->registerSniffs([dirname(__DIR__) . $this->_getSniffName()], [], []); $ruleset->populateTokenListeners(); - //self::$_phpcs->cli->setCommandLineValues(['-s']); - $testFile = dirname(__DIR__) . '/tests/' . str_replace('_', '/', get_class($this)) . '.inc'; if (!file_exists($testFile)) { $this->markTestSkipped(); diff --git a/tests/DWS/Sniffs/Arrays/ArrayDeclarationSniffTest.php b/tests/DWS/Sniffs/Arrays/ArrayDeclarationSniffTest.php index 5972f16..31ad003 100644 --- a/tests/DWS/Sniffs/Arrays/ArrayDeclarationSniffTest.php +++ b/tests/DWS/Sniffs/Arrays/ArrayDeclarationSniffTest.php @@ -14,6 +14,6 @@ public function getWarningList() protected function _getSniffName() { - return 'DWS.Arrays.ArrayDeclaration'; + return '/DWS/Sniffs/Arrays/ArrayDeclarationSniff.php'; } } diff --git a/tests/DWS/Sniffs/Arrays/ArrowSpacingSniffTest.php b/tests/DWS/Sniffs/Arrays/ArrowSpacingSniffTest.php index 993fd76..7fb98c7 100644 --- a/tests/DWS/Sniffs/Arrays/ArrowSpacingSniffTest.php +++ b/tests/DWS/Sniffs/Arrays/ArrowSpacingSniffTest.php @@ -14,6 +14,6 @@ public function getWarningList() protected function _getSniffName() { - return 'DWS.Arrays.ArrowSpacing'; + return '/DWS/Sniffs/Arrays/ArrowSpacingSniff.php'; } } diff --git a/tests/DWS/Sniffs/Arrays/CommaSpacingSniffTest.php b/tests/DWS/Sniffs/Arrays/CommaSpacingSniffTest.php index c4eca4e..d9e371c 100644 --- a/tests/DWS/Sniffs/Arrays/CommaSpacingSniffTest.php +++ b/tests/DWS/Sniffs/Arrays/CommaSpacingSniffTest.php @@ -14,6 +14,6 @@ public function getWarningList() protected function _getSniffName() { - return 'DWS.Arrays.CommaSpacing'; + return '/DWS/Sniffs/Arrays/CommaSpacingSniff.php'; } } diff --git a/tests/DWS/Sniffs/Arrays/TrailingCommaSniffTest.php b/tests/DWS/Sniffs/Arrays/TrailingCommaSniffTest.php index 9cd5858..a4ddc56 100644 --- a/tests/DWS/Sniffs/Arrays/TrailingCommaSniffTest.php +++ b/tests/DWS/Sniffs/Arrays/TrailingCommaSniffTest.php @@ -14,6 +14,6 @@ public function getWarningList() protected function _getSniffName() { - return 'DWS.Arrays.TrailingComma'; + return '/DWS/Sniffs/Arrays/TrailingCommaSniff.php'; } } diff --git a/tests/DWS/Sniffs/ControlStructures/ControlSignatureSniffTest.php b/tests/DWS/Sniffs/ControlStructures/ControlSignatureSniffTest.php index 043efea..07e0fcb 100644 --- a/tests/DWS/Sniffs/ControlStructures/ControlSignatureSniffTest.php +++ b/tests/DWS/Sniffs/ControlStructures/ControlSignatureSniffTest.php @@ -14,6 +14,6 @@ public function getWarningList() protected function _getSniffName() { - return 'DWS.ControlStructures.ControlSignature'; + return '/DWS/Sniffs/ControlStructures/ControlSignatureSniff.php'; } } diff --git a/tests/DWS/Sniffs/Formatting/MultilineBracketedExpressionIndentSniffTest.php b/tests/DWS/Sniffs/Formatting/MultilineBracketedExpressionIndentSniffTest.php index 2765fe5..2d503f7 100644 --- a/tests/DWS/Sniffs/Formatting/MultilineBracketedExpressionIndentSniffTest.php +++ b/tests/DWS/Sniffs/Formatting/MultilineBracketedExpressionIndentSniffTest.php @@ -14,6 +14,6 @@ public function getWarningList() protected function _getSniffName() { - return 'DWS.Formatting.MultilineBracketedExpressionIndent'; + return '/DWS/Sniffs/Formatting/MultilineBracketedExpressionIndentSniff.php'; } } diff --git a/tests/DWS/Sniffs/Scope/VariableScopeSniffTest.php b/tests/DWS/Sniffs/Scope/VariableScopeSniffTest.php index 68d54e7..6caf558 100644 --- a/tests/DWS/Sniffs/Scope/VariableScopeSniffTest.php +++ b/tests/DWS/Sniffs/Scope/VariableScopeSniffTest.php @@ -14,6 +14,6 @@ public function getWarningList() protected function _getSniffName() { - return 'DWS.Scope.VariableScope'; + return '/DWS/Sniffs/Scope/VariableScopeSniff.php'; } } diff --git a/tests/DWS/Sniffs/Strings/DoubleQuoteUsageSniffTest.php b/tests/DWS/Sniffs/Strings/DoubleQuoteUsageSniffTest.php index c50c60b..b22f841 100644 --- a/tests/DWS/Sniffs/Strings/DoubleQuoteUsageSniffTest.php +++ b/tests/DWS/Sniffs/Strings/DoubleQuoteUsageSniffTest.php @@ -14,6 +14,6 @@ public function getWarningList() protected function _getSniffName() { - return 'DWS.Strings.DoubleQuoteUsage'; + return '/DWS/Sniffs/Strings/DoubleQuoteUsageSniff.php'; } } diff --git a/tests/DWS/Sniffs/Strings/EmbeddedVariablesSniffTest.php b/tests/DWS/Sniffs/Strings/EmbeddedVariablesSniffTest.php index 7fc7ab5..8dd92c2 100644 --- a/tests/DWS/Sniffs/Strings/EmbeddedVariablesSniffTest.php +++ b/tests/DWS/Sniffs/Strings/EmbeddedVariablesSniffTest.php @@ -14,6 +14,6 @@ public function getWarningList() protected function _getSniffName() { - return 'DWS.Strings.EmbeddedVariables'; + return '/DWS/Sniffs/Strings/EmbeddedVariablesSniff.php'; } } diff --git a/tests/DWS/Sniffs/Strings/UnnecessaryStringConcatSniffTest.php b/tests/DWS/Sniffs/Strings/UnnecessaryStringConcatSniffTest.php index 6fa8f74..901af64 100644 --- a/tests/DWS/Sniffs/Strings/UnnecessaryStringConcatSniffTest.php +++ b/tests/DWS/Sniffs/Strings/UnnecessaryStringConcatSniffTest.php @@ -14,6 +14,6 @@ public function getWarningList() protected function _getSniffName() { - return 'DWS.Strings.UnnecessaryStringConcat'; + return '/DWS/Sniffs/Strings/UnnecessaryStringConcatSniff.php'; } } diff --git a/tests/DWS/Sniffs/WhiteSpace/ControlStructureInteriorSpacingSniffTest.php b/tests/DWS/Sniffs/WhiteSpace/ControlStructureInteriorSpacingSniffTest.php index 48ea268..3621db3 100644 --- a/tests/DWS/Sniffs/WhiteSpace/ControlStructureInteriorSpacingSniffTest.php +++ b/tests/DWS/Sniffs/WhiteSpace/ControlStructureInteriorSpacingSniffTest.php @@ -35,6 +35,6 @@ public function getWarningList() protected function _getSniffName() { - return 'DWS.WhiteSpace.ControlStructureInteriorSpacing'; + return '/DWS/Sniffs/WhiteSpace/ControlStructureInteriorSpacingSniff.php'; } } diff --git a/tests/DWS/Sniffs/WhiteSpace/ControlStructureTrailingSpacingSniffTest.php b/tests/DWS/Sniffs/WhiteSpace/ControlStructureTrailingSpacingSniffTest.php index 8d44275..ac4dda9 100644 --- a/tests/DWS/Sniffs/WhiteSpace/ControlStructureTrailingSpacingSniffTest.php +++ b/tests/DWS/Sniffs/WhiteSpace/ControlStructureTrailingSpacingSniffTest.php @@ -14,6 +14,6 @@ public function getWarningList() protected function _getSniffName() { - return 'DWS.WhiteSpace.ControlStructureTrailingSpacing'; + return '/DWS/Sniffs/WhiteSpace/ControlStructureTrailingSpacingSniff.php'; } } diff --git a/tests/DWS/Sniffs/WhiteSpace/OperatorSpacingSniffTest.php b/tests/DWS/Sniffs/WhiteSpace/OperatorSpacingSniffTest.php index e86ac13..293cd54 100644 --- a/tests/DWS/Sniffs/WhiteSpace/OperatorSpacingSniffTest.php +++ b/tests/DWS/Sniffs/WhiteSpace/OperatorSpacingSniffTest.php @@ -31,6 +31,6 @@ public function getWarningList() protected function _getSniffName() { - return 'DWS.WhiteSpace.OperatorSpacing'; + return '/DWS/Sniffs/WhiteSpace/OperatorSpacingSniff.php'; } } diff --git a/tests/DWS/Sniffs/WhiteSpace/SuperfluousWhitespaceSniffGoodBeginningTest.php b/tests/DWS/Sniffs/WhiteSpace/SuperfluousWhitespaceSniffGoodBeginningTest.php index ecdade0..ccac3ee 100644 --- a/tests/DWS/Sniffs/WhiteSpace/SuperfluousWhitespaceSniffGoodBeginningTest.php +++ b/tests/DWS/Sniffs/WhiteSpace/SuperfluousWhitespaceSniffGoodBeginningTest.php @@ -14,6 +14,6 @@ public function getWarningList() protected function _getSniffName() { - return 'DWS.WhiteSpace.SuperfluousWhitespace'; + return '/DWS/Sniffs/WhiteSpace/SuperfluousWhitespaceSniff.php'; } } diff --git a/tests/DWS/Sniffs/WhiteSpace/SuperfluousWhitespaceSniffTest.php b/tests/DWS/Sniffs/WhiteSpace/SuperfluousWhitespaceSniffTest.php index 91a17e6..d672036 100644 --- a/tests/DWS/Sniffs/WhiteSpace/SuperfluousWhitespaceSniffTest.php +++ b/tests/DWS/Sniffs/WhiteSpace/SuperfluousWhitespaceSniffTest.php @@ -14,6 +14,6 @@ public function getWarningList() protected function _getSniffName() { - return 'DWS.WhiteSpace.SuperfluousWhitespace'; + return '/DWS/Sniffs/WhiteSpace/SuperfluousWhitespaceSniff.php'; } } diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 3fe016c..82c229a 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -2,3 +2,5 @@ $loader = require dirname(__DIR__) . '/vendor/autoload.php'; $loader->add('', __DIR__); + +require dirname(__DIR__) . '/vendor/squizlabs/php_codesniffer/tests/bootstrap.php';