diff --git a/src/Standards/Generic/Sniffs/PHP/DisallowAlternativePHPTagsSniff.php b/src/Standards/Generic/Sniffs/PHP/DisallowAlternativePHPTagsSniff.php index a2cf1b931c..511b31cc08 100644 --- a/src/Standards/Generic/Sniffs/PHP/DisallowAlternativePHPTagsSniff.php +++ b/src/Standards/Generic/Sniffs/PHP/DisallowAlternativePHPTagsSniff.php @@ -11,27 +11,12 @@ namespace PHP_CodeSniffer\Standards\Generic\Sniffs\PHP; -use PHP_CodeSniffer\Config; use PHP_CodeSniffer\Files\File; use PHP_CodeSniffer\Sniffs\Sniff; class DisallowAlternativePHPTagsSniff implements Sniff { - /** - * Whether ASP tags are enabled or not. - * - * @var boolean - */ - private $aspTags = false; - - /** - * The current PHP version. - * - * @var integer|string|null - */ - private $phpVersion = null; - /** * Returns an array of tokens this test wants to listen for. @@ -40,22 +25,7 @@ class DisallowAlternativePHPTagsSniff implements Sniff */ public function register() { - if ($this->phpVersion === null) { - $this->phpVersion = Config::getConfigData('php_version'); - if ($this->phpVersion === null) { - $this->phpVersion = PHP_VERSION_ID; - } - } - - if ($this->phpVersion < 70000) { - $this->aspTags = (bool) ini_get('asp_tags'); - } - - return [ - T_OPEN_TAG, - T_OPEN_TAG_WITH_ECHO, - T_INLINE_HTML, - ]; + return [T_INLINE_HTML]; }//end register() @@ -79,61 +49,8 @@ public function process(File $phpcsFile, $stackPtr) return; } - if ($openTag['code'] === T_OPEN_TAG) { - if ($content === '<%') { - $error = 'ASP style opening tag used; expected "findClosingTag($phpcsFile, $tokens, $stackPtr, '%>'); - $errorCode = 'ASPOpenTagFound'; - } else if (strpos($content, ''); - $errorCode = 'ScriptOpenTagFound'; - } - - if (isset($error, $closer, $errorCode) === true) { - $data = [$content]; - - if ($closer === false) { - $phpcsFile->addError($error, $stackPtr, $errorCode, $data); - } else { - $fix = $phpcsFile->addFixableError($error, $stackPtr, $errorCode, $data); - if ($fix === true) { - $this->addChangeset($phpcsFile, $tokens, $stackPtr, $closer); - } - } - } - - return; - }//end if - - if ($openTag['code'] === T_OPEN_TAG_WITH_ECHO && $content === '<%=') { - $error = 'ASP style opening tag used with echo; expected "findNext(T_WHITESPACE, ($stackPtr + 1), null, true); - $snippet = $this->getSnippet($tokens[$nextVar]['content']); - $data = [ - $snippet, - $content, - $snippet, - ]; - - $closer = $this->findClosingTag($phpcsFile, $tokens, $stackPtr, '%>'); - - if ($closer === false) { - $phpcsFile->addError($error, $stackPtr, 'ASPShortOpenTagFound', $data); - } else { - $fix = $phpcsFile->addFixableError($error, $stackPtr, 'ASPShortOpenTagFound', $data); - if ($fix === true) { - $this->addChangeset($phpcsFile, $tokens, $stackPtr, $closer, true); - } - } - - return; - }//end if - - // Account for incorrect script open tags. - if ($openTag['code'] === T_INLINE_HTML - && preg_match('`( - - diff --git a/src/Standards/Generic/Tests/PHP/DisallowAlternativePHPTagsUnitTest.2.inc.fixed b/src/Standards/Generic/Tests/PHP/DisallowAlternativePHPTagsUnitTest.2.inc.fixed deleted file mode 100644 index 6eafb422ec..0000000000 --- a/src/Standards/Generic/Tests/PHP/DisallowAlternativePHPTagsUnitTest.2.inc.fixed +++ /dev/null @@ -1,6 +0,0 @@ -
- -

Some text and some more text

- -

Some text and some more text

-
diff --git a/src/Standards/Generic/Tests/PHP/DisallowAlternativePHPTagsUnitTest.3.inc b/src/Standards/Generic/Tests/PHP/DisallowAlternativePHPTagsUnitTest.3.inc deleted file mode 100644 index ba86345a77..0000000000 --- a/src/Standards/Generic/Tests/PHP/DisallowAlternativePHPTagsUnitTest.3.inc +++ /dev/null @@ -1,7 +0,0 @@ - -
-<% echo $var; %> -

Some text <% echo $var; %> and some more text

-<%= $var . ' and some more text to make sure the snippet works'; %> -

Some text <%= $var %> and some more text

-
diff --git a/src/Standards/Generic/Tests/PHP/DisallowAlternativePHPTagsUnitTest.php b/src/Standards/Generic/Tests/PHP/DisallowAlternativePHPTagsUnitTest.php index 8dd6deb97b..ddac521619 100644 --- a/src/Standards/Generic/Tests/PHP/DisallowAlternativePHPTagsUnitTest.php +++ b/src/Standards/Generic/Tests/PHP/DisallowAlternativePHPTagsUnitTest.php @@ -20,33 +20,6 @@ final class DisallowAlternativePHPTagsUnitTest extends AbstractSniffUnitTest { - /** - * Get a list of all test files to check. - * - * @param string $testFileBase The base path that the unit tests files will have. - * - * @return string[] - */ - protected function getTestFiles($testFileBase) - { - $testFiles = [$testFileBase.'1.inc']; - - $aspTags = false; - if (PHP_VERSION_ID < 70000) { - $aspTags = (bool) ini_get('asp_tags'); - } - - if ($aspTags === true) { - $testFiles[] = $testFileBase.'2.inc'; - } else { - $testFiles[] = $testFileBase.'3.inc'; - } - - return $testFiles; - - }//end getTestFiles() - - /** * Returns the lines where errors should occur. * @@ -67,13 +40,7 @@ public function getErrorList($testFile='') 8 => 1, 11 => 1, ]; - case 'DisallowAlternativePHPTagsUnitTest.2.inc': - return [ - 2 => 1, - 3 => 1, - 4 => 1, - 5 => 1, - ]; + default: return []; }//end switch @@ -93,12 +60,12 @@ public function getErrorList($testFile='') */ public function getWarningList($testFile='') { - if ($testFile === 'DisallowAlternativePHPTagsUnitTest.3.inc') { + if ($testFile === 'DisallowAlternativePHPTagsUnitTest.2.inc') { return [ + 2 => 1, 3 => 1, 4 => 1, 5 => 1, - 6 => 1, ]; } diff --git a/src/Standards/Squiz/Tests/Commenting/FunctionCommentUnitTest.php b/src/Standards/Squiz/Tests/Commenting/FunctionCommentUnitTest.php index 036bdc622b..977220822c 100644 --- a/src/Standards/Squiz/Tests/Commenting/FunctionCommentUnitTest.php +++ b/src/Standards/Squiz/Tests/Commenting/FunctionCommentUnitTest.php @@ -37,6 +37,7 @@ public function getErrorList() 13 => 2, 14 => 1, 15 => 1, + 17 => 3, 28 => 1, 43 => 1, 76 => 1, @@ -49,12 +50,14 @@ public function getErrorList() 124 => 2, 125 => 1, 126 => 1, + 128 => 1, 137 => 4, 138 => 4, 139 => 4, - 143 => 2, + 143 => 3, 155 => 1, 159 => 1, + 161 => 2, 166 => 1, 173 => 1, 183 => 1, @@ -62,6 +65,7 @@ public function getErrorList() 193 => 2, 196 => 1, 199 => 2, + 201 => 1, 210 => 1, 211 => 1, 222 => 1, @@ -71,7 +75,7 @@ public function getErrorList() 226 => 1, 227 => 1, 230 => 2, - 232 => 2, + 232 => 7, 246 => 1, 248 => 4, 261 => 1, @@ -89,14 +93,18 @@ public function getErrorList() 312 => 1, 358 => 1, 359 => 2, + 363 => 3, 372 => 1, 373 => 1, + 377 => 1, 387 => 1, 407 => 1, 441 => 1, 500 => 1, 526 => 1, 548 => 1, + 575 => 2, + 627 => 2, 641 => 1, 669 => 1, 688 => 1, @@ -116,6 +124,7 @@ public function getErrorList() 890 => 1, 978 => 1, 997 => 1, + 1002 => 1, 1004 => 2, 1006 => 1, 1029 => 1, @@ -124,58 +133,31 @@ public function getErrorList() 1069 => 1, 1070 => 1, 1071 => 1, + 1075 => 6, 1080 => 2, 1083 => 1, 1084 => 1, 1085 => 1, + 1089 => 3, 1093 => 4, 1100 => 1, 1101 => 1, 1102 => 1, 1103 => 1, + 1107 => 8, 1123 => 1, 1124 => 1, 1125 => 1, + 1129 => 3, 1138 => 1, 1139 => 1, 1144 => 1, 1145 => 1, 1151 => 1, + 1154 => 1, + 1160 => 1, ]; - // Scalar type hints only work from PHP 7 onwards. - if (PHP_VERSION_ID >= 70000) { - $errors[17] = 3; - $errors[128] = 1; - $errors[143] = 3; - $errors[161] = 2; - $errors[201] = 1; - $errors[232] = 7; - $errors[363] = 3; - $errors[377] = 1; - $errors[575] = 2; - $errors[627] = 1; - $errors[1002] = 1; - $errors[1075] = 6; - $errors[1089] = 3; - $errors[1107] = 8; - $errors[1129] = 3; - $errors[1154] = 1; - $errors[1160] = 1; - } else { - $errors[729] = 4; - $errors[740] = 2; - $errors[752] = 2; - $errors[982] = 1; - }//end if - - // Object type hints only work from PHP 7.2 onwards. - if (PHP_VERSION_ID >= 70200) { - $errors[627] = 2; - } else { - $errors[992] = 2; - } - // Mixed type hints only work from PHP 8.0 onwards. if (PHP_VERSION_ID >= 80000) { $errors[265] = 1; diff --git a/src/Tokenizers/PHP.php b/src/Tokenizers/PHP.php index 73a0c4b4a8..dde3beab92 100644 --- a/src/Tokenizers/PHP.php +++ b/src/Tokenizers/PHP.php @@ -607,27 +607,6 @@ protected function tokenize($string) echo PHP_EOL; } - /* - Before PHP 5.5, the yield keyword was tokenized as - T_STRING. So look for and change this token in - earlier versions. - */ - - if (PHP_VERSION_ID < 50500 - && $tokenIsArray === true - && $token[0] === T_STRING - && strtolower($token[1]) === 'yield' - && isset($this->tstringContexts[$finalTokens[$lastNotEmptyToken]['code']]) === false - ) { - // Could still be a context sensitive keyword or "yield from" and potentially multi-line, - // so adjust the token stack in place. - $token[0] = T_YIELD; - - if (PHP_CODESNIFFER_VERBOSITY > 1) { - echo "\t\t* token $stackPtr changed from T_STRING to T_YIELD".PHP_EOL; - } - } - /* Tokenize context sensitive keyword as string when it should be string. */ @@ -1562,41 +1541,10 @@ protected function tokenize($string) }//end if /* - Before PHP 7.0, "yield from" was tokenized as - T_YIELD, T_WHITESPACE and T_STRING. So look for - and change this token in earlier versions. + Deal with "yield from" in various PHP versions. */ - if (PHP_VERSION_ID < 70000 - && $tokenIsArray === true - && $token[0] === T_YIELD - && isset($tokens[($stackPtr + 1)]) === true - && isset($tokens[($stackPtr + 2)]) === true - && $tokens[($stackPtr + 1)][0] === T_WHITESPACE - && strpos($tokens[($stackPtr + 1)][1], $this->eolChar) === false - && $tokens[($stackPtr + 2)][0] === T_STRING - && strtolower($tokens[($stackPtr + 2)][1]) === 'from' - ) { - // Single-line "yield from" with only whitespace between. - $finalTokens[$newStackPtr] = [ - 'code' => T_YIELD_FROM, - 'type' => 'T_YIELD_FROM', - 'content' => $token[1].$tokens[($stackPtr + 1)][1].$tokens[($stackPtr + 2)][1], - ]; - - if (PHP_CODESNIFFER_VERBOSITY > 1) { - for ($i = ($stackPtr + 1); $i <= ($stackPtr + 2); $i++) { - $type = Tokens::tokenName($tokens[$i][0]); - $content = Common::prepareForOutput($tokens[$i][1]); - echo "\t\t* token $i merged into T_YIELD_FROM; was: $type => $content".PHP_EOL; - } - } - - $newStackPtr++; - $stackPtr += 2; - - continue; - } else if (PHP_VERSION_ID < 80300 + if (PHP_VERSION_ID < 80300 && $tokenIsArray === true && $token[0] === T_STRING && strtolower($token[1]) === 'from' @@ -1625,8 +1573,7 @@ protected function tokenize($string) } continue; - } else if (PHP_VERSION_ID >= 70000 - && $tokenIsArray === true + } else if ($tokenIsArray === true && $token[0] === T_YIELD_FROM && strpos($token[1], $this->eolChar) !== false && preg_match('`^yield\s+from$`i', $token[1]) === 1 @@ -1719,92 +1666,15 @@ protected function tokenize($string) }//end if /* - Before PHP 5.6, the ... operator was tokenized as three - T_STRING_CONCAT tokens in a row. So look for and combine - these tokens in earlier versions. - */ - - if ($tokenIsArray === false - && $token[0] === '.' - && isset($tokens[($stackPtr + 1)]) === true - && isset($tokens[($stackPtr + 2)]) === true - && $tokens[($stackPtr + 1)] === '.' - && $tokens[($stackPtr + 2)] === '.' - ) { - $newToken = []; - $newToken['code'] = T_ELLIPSIS; - $newToken['type'] = 'T_ELLIPSIS'; - $newToken['content'] = '...'; - $finalTokens[$newStackPtr] = $newToken; - - $newStackPtr++; - $stackPtr += 2; - continue; - } - - /* - Before PHP 5.6, the ** operator was tokenized as two - T_MULTIPLY tokens in a row. So look for and combine - these tokens in earlier versions. - */ - - if ($tokenIsArray === false - && $token[0] === '*' - && isset($tokens[($stackPtr + 1)]) === true - && $tokens[($stackPtr + 1)] === '*' - ) { - $newToken = []; - $newToken['code'] = T_POW; - $newToken['type'] = 'T_POW'; - $newToken['content'] = '**'; - $finalTokens[$newStackPtr] = $newToken; - - $newStackPtr++; - $stackPtr++; - continue; - } - - /* - Before PHP 5.6, the **= operator was tokenized as - T_MULTIPLY followed by T_MUL_EQUAL. So look for and combine - these tokens in earlier versions. - */ - - if ($tokenIsArray === false - && $token[0] === '*' - && isset($tokens[($stackPtr + 1)]) === true - && is_array($tokens[($stackPtr + 1)]) === true - && $tokens[($stackPtr + 1)][1] === '*=' - ) { - $newToken = []; - $newToken['code'] = T_POW_EQUAL; - $newToken['type'] = 'T_POW_EQUAL'; - $newToken['content'] = '**='; - $finalTokens[$newStackPtr] = $newToken; - - $newStackPtr++; - $stackPtr++; - continue; - } - - /* - Before PHP 7, the ??= operator was tokenized as - T_INLINE_THEN, T_INLINE_THEN, T_EQUAL. Between PHP 7.0 and 7.3, the ??= operator was tokenized as T_COALESCE, T_EQUAL. So look for and combine these tokens in earlier versions. */ - if (($tokenIsArray === false - && $token[0] === '?' - && isset($tokens[($stackPtr + 1)]) === true - && $tokens[($stackPtr + 1)][0] === '?' - && isset($tokens[($stackPtr + 2)]) === true - && $tokens[($stackPtr + 2)][0] === '=') - || ($tokenIsArray === true + if ($tokenIsArray === true && $token[0] === T_COALESCE && isset($tokens[($stackPtr + 1)]) === true - && $tokens[($stackPtr + 1)][0] === '=') + && $tokens[($stackPtr + 1)][0] === '=' ) { $newToken = []; $newToken['code'] = T_COALESCE_EQUAL; @@ -1815,33 +1685,6 @@ protected function tokenize($string) $newStackPtr++; $stackPtr++; - if ($tokenIsArray === false) { - // Pre PHP 7. - $stackPtr++; - } - - continue; - } - - /* - Before PHP 7, the ?? operator was tokenized as - T_INLINE_THEN followed by T_INLINE_THEN. - So look for and combine these tokens in earlier versions. - */ - - if ($tokenIsArray === false - && $token[0] === '?' - && isset($tokens[($stackPtr + 1)]) === true - && $tokens[($stackPtr + 1)][0] === '?' - ) { - $newToken = []; - $newToken['code'] = T_COALESCE; - $newToken['type'] = 'T_COALESCE'; - $newToken['content'] = '??'; - $finalTokens[$newStackPtr] = $newToken; - - $newStackPtr++; - $stackPtr++; continue; } @@ -2345,28 +2188,6 @@ function return types. We want to keep the parenthesis map clean, }//end if }//end if - /* - Before PHP 7, the <=> operator was tokenized as - T_IS_SMALLER_OR_EQUAL followed by T_GREATER_THAN. - So look for and combine these tokens in earlier versions. - */ - - if ($tokenIsArray === true - && $token[0] === T_IS_SMALLER_OR_EQUAL - && isset($tokens[($stackPtr + 1)]) === true - && $tokens[($stackPtr + 1)][0] === '>' - ) { - $newToken = []; - $newToken['code'] = T_SPACESHIP; - $newToken['type'] = 'T_SPACESHIP'; - $newToken['content'] = '<=>'; - $finalTokens[$newStackPtr] = $newToken; - - $newStackPtr++; - $stackPtr++; - continue; - } - /* PHP doesn't assign a token to goto labels, so we have to. These are just string tokens with a single colon after them. Double @@ -2680,16 +2501,6 @@ function return types. We want to keep the parenthesis map clean, } } - // This is a special case when checking PHP 5.5+ code in PHP < 5.5 - // where "finally" should be T_FINALLY instead of T_STRING. - if ($newToken['code'] === T_STRING - && strtolower($newToken['content']) === 'finally' - && $finalTokens[$lastNotEmptyToken]['code'] === T_CLOSE_CURLY_BRACKET - ) { - $newToken['code'] = T_FINALLY; - $newToken['type'] = 'T_FINALLY'; - } - // This is a special case for PHP 5.6 use function and use const // where "function" and "const" should be T_STRING instead of T_FUNCTION // and T_CONST. diff --git a/src/Util/MessageCollector.php b/src/Util/MessageCollector.php index 6db9414c18..92884ceecd 100644 --- a/src/Util/MessageCollector.php +++ b/src/Util/MessageCollector.php @@ -124,7 +124,7 @@ public function add($message, $type=self::NOTICE) */ public function containsBlockingErrors() { - $seenTypes = $this->arrayColumn($this->cache, 'type'); + $seenTypes = array_column($this->cache, 'type'); $typeFrequency = array_count_values($seenTypes); return isset($typeFrequency[self::ERROR]); @@ -156,7 +156,7 @@ public function display($order=self::ORDERBY_SEVERITY) $this->clearCache(); if ($order === self::ORDERBY_RECEIVED) { - $messages = $this->arrayColumn($messageInfo, 'message'); + $messages = array_column($messageInfo, 'message'); } else { $messages = $this->sortBySeverity($messageInfo); } @@ -278,33 +278,4 @@ private function clearCache() }//end clearCache() - /** - * Return the values from a single column in the input array. - * - * Polyfill for the PHP 5.5+ native array_column() function (for the functionality needed here). - * - * @param array> $input A multi-dimensional array from which to pull a column of values. - * @param string $columnKey The name of the column of values to return. - * - * @link https://www.php.net/function.array-column - * - * @return array - */ - private function arrayColumn(array $input, $columnKey) - { - if (function_exists('array_column') === true) { - // PHP 5.5+. - return array_column($input, $columnKey); - } - - // PHP 5.4. - $callback = function ($row) use ($columnKey) { - return $row[$columnKey]; - }; - - return array_map($callback, $input); - - }//end arrayColumn() - - }//end class diff --git a/src/Util/Tokens.php b/src/Util/Tokens.php index 73cf02ddd7..1ec4c51595 100644 --- a/src/Util/Tokens.php +++ b/src/Util/Tokens.php @@ -90,46 +90,11 @@ * `PHP_CodeSniffer\Tests\Core\Util\Tokens\TokenNameTest::dataPolyfilledPHPNativeTokens()` test method!} */ -// Some PHP 5.5 tokens, replicated for lower versions. -if (defined('T_FINALLY') === false) { - define('T_FINALLY', 'PHPCS_T_FINALLY'); -} - -if (defined('T_YIELD') === false) { - define('T_YIELD', 'PHPCS_T_YIELD'); -} - -// Some PHP 5.6 tokens, replicated for lower versions. -if (defined('T_ELLIPSIS') === false) { - define('T_ELLIPSIS', 'PHPCS_T_ELLIPSIS'); -} - -if (defined('T_POW') === false) { - define('T_POW', 'PHPCS_T_POW'); -} - -if (defined('T_POW_EQUAL') === false) { - define('T_POW_EQUAL', 'PHPCS_T_POW_EQUAL'); -} - -// Some PHP 7 tokens, replicated for lower versions. -if (defined('T_SPACESHIP') === false) { - define('T_SPACESHIP', 'PHPCS_T_SPACESHIP'); -} - -if (defined('T_COALESCE') === false) { - define('T_COALESCE', 'PHPCS_T_COALESCE'); -} - +// Some PHP 7.4 tokens, replicated for lower versions. if (defined('T_COALESCE_EQUAL') === false) { define('T_COALESCE_EQUAL', 'PHPCS_T_COALESCE_EQUAL'); } -if (defined('T_YIELD_FROM') === false) { - define('T_YIELD_FROM', 'PHPCS_T_YIELD_FROM'); -} - -// Some PHP 7.4 tokens, replicated for lower versions. if (defined('T_BAD_CHARACTER') === false) { define('T_BAD_CHARACTER', 'PHPCS_T_BAD_CHARACTER'); } diff --git a/tests/Core/Tokenizers/PHP/FinallyTest.inc b/tests/Core/Tokenizers/PHP/FinallyTest.inc index e65600b6b4..2a475d93fb 100644 --- a/tests/Core/Tokenizers/PHP/FinallyTest.inc +++ b/tests/Core/Tokenizers/PHP/FinallyTest.inc @@ -1,31 +1,5 @@ phpcsFile->getTokens(); - $target = $this->getTargetToken($testMarker, [T_FINALLY, T_STRING]); - $tokenArray = $tokens[$target]; - - $this->assertSame(T_FINALLY, $tokenArray['code'], 'Token tokenized as '.$tokenArray['type'].', not T_FINALLY (code)'); - $this->assertSame('T_FINALLY', $tokenArray['type'], 'Token tokenized as '.$tokenArray['type'].', not T_FINALLY (type)'); - - }//end testFinallyKeyword() - - - /** - * Data provider. - * - * @see testFinallyKeyword() - * - * @return array> - */ - public static function dataFinallyKeyword() - { - return [ - 'finally after try and catch' => ['/* testTryCatchFinally */'], - 'finally between try and catch' => ['/* testTryFinallyCatch */'], - 'finally after try, no catch' => ['/* testTryFinally */'], - ]; - - }//end dataFinallyKeyword() - - /** * Test that 'finally' when not used as the reserved keyword is tokenized as `T_STRING`. * diff --git a/tests/Core/Tokenizers/PHP/YieldTest.inc b/tests/Core/Tokenizers/PHP/YieldTest.inc index 3130b84600..90ab7ce2e3 100644 --- a/tests/Core/Tokenizers/PHP/YieldTest.inc +++ b/tests/Core/Tokenizers/PHP/YieldTest.inc @@ -2,12 +2,6 @@ function generator() { - /* testYield */ - yield 1; - - /* testYieldFollowedByComment */ - YIELD/*comment*/ 2; - /* testYieldFrom */ yield from gen2(); diff --git a/tests/Core/Tokenizers/PHP/YieldTest.php b/tests/Core/Tokenizers/PHP/YieldTest.php index efb12096cf..3f9abe9a3b 100644 --- a/tests/Core/Tokenizers/PHP/YieldTest.php +++ b/tests/Core/Tokenizers/PHP/YieldTest.php @@ -38,15 +38,7 @@ public function testYieldKeyword($testMarker, $expectedContent) $tokenArray = $tokens[$target]; $this->assertSame(T_YIELD, $tokenArray['code'], 'Token tokenized as '.$tokenArray['type'].', not T_YIELD (code)'); - - // This assertion would fail on PHP 5.4 with PHPUnit 4 as PHPUnit polyfills the `T_YIELD` token too, but - // with a different value, which causes the token 'type' to be set to `UNKNOWN`. - // This issue _only_ occurs when running the tests, not when running PHPCS outside of a test situation. - // The PHPUnit polyfilled token is declared in the PHP_CodeCoverage_Report_HTML_Renderer_File class - // in vendor/phpunit/php-code-coverage/src/CodeCoverage/Report/HTML/Renderer/File.php. - if (PHP_VERSION_ID >= 50500) { - $this->assertSame('T_YIELD', $tokenArray['type'], 'Token tokenized as '.$tokenArray['type'].', not T_YIELD (type)'); - } + $this->assertSame('T_YIELD', $tokenArray['type'], 'Token tokenized as '.$tokenArray['type'].', not T_YIELD (type)'); $this->assertSame($expectedContent, $tokenArray['content'], 'Token content does not match expectation'); @@ -63,14 +55,6 @@ public function testYieldKeyword($testMarker, $expectedContent) public static function dataYieldKeyword() { return [ - 'yield' => [ - 'testMarker' => '/* testYield */', - 'expectedContent' => 'yield', - ], - 'yield followed by comment' => [ - 'testMarker' => '/* testYieldFollowedByComment */', - 'expectedContent' => 'YIELD', - ], 'yield at end of file, live coding' => [ 'testMarker' => '/* testYieldLiveCoding */', 'expectedContent' => 'yield', diff --git a/tests/Core/Util/Tokens/TokenNameTest.php b/tests/Core/Util/Tokens/TokenNameTest.php index 28c6c613c2..6c0b180fe8 100644 --- a/tests/Core/Util/Tokens/TokenNameTest.php +++ b/tests/Core/Util/Tokens/TokenNameTest.php @@ -87,41 +87,6 @@ public static function dataTokenName() public static function dataPolyfilledPHPNativeTokens() { return [ - 'PHP 5.5 native token, polyfilled: T_FINALLY' => [ - 'tokenCode' => T_FINALLY, - 'expected' => 'T_FINALLY', - ], - 'PHP 5.5 native token, polyfilled: T_YIELD' => [ - 'tokenCode' => T_YIELD, - 'expected' => 'T_YIELD', - ], - - 'PHP 5.6 native token, polyfilled: T_ELLIPSIS' => [ - 'tokenCode' => T_ELLIPSIS, - 'expected' => 'T_ELLIPSIS', - ], - 'PHP 5.6 native token, polyfilled: T_POW' => [ - 'tokenCode' => T_POW, - 'expected' => 'T_POW', - ], - 'PHP 5.6 native token, polyfilled: T_POW_EQUAL' => [ - 'tokenCode' => T_POW_EQUAL, - 'expected' => 'T_POW_EQUAL', - ], - - 'PHP 7.0 native token, polyfilled: T_SPACESHIP' => [ - 'tokenCode' => T_SPACESHIP, - 'expected' => 'T_SPACESHIP', - ], - 'PHP 7.0 native token, polyfilled: T_COALESCE' => [ - 'tokenCode' => T_COALESCE, - 'expected' => 'T_COALESCE', - ], - 'PHP 7.0 native token, polyfilled: T_YIELD_FROM' => [ - 'tokenCode' => T_YIELD_FROM, - 'expected' => 'T_YIELD_FROM', - ], - 'PHP 7.4 native token, polyfilled: T_COALESCE_EQUAL' => [ 'tokenCode' => T_COALESCE_EQUAL, 'expected' => 'T_COALESCE_EQUAL',