diff --git a/Magento2/Sniffs/Legacy/PhtmlTemplateSniff.php b/Magento2/Sniffs/Legacy/PhtmlTemplateSniff.php index 4217ecda..fa5eb70e 100644 --- a/Magento2/Sniffs/Legacy/PhtmlTemplateSniff.php +++ b/Magento2/Sniffs/Legacy/PhtmlTemplateSniff.php @@ -13,23 +13,7 @@ class PhtmlTemplateSniff implements Sniff { private const WARNING_CODE_TEXT_JAVASCRIPT = 'TextJavascriptTypeFound'; - private const WARNING_CODE_THIS_USAGE = 'ThisUsageObsolete'; private const WARNING_CODE_PROTECTED_PRIVATE_BLOCK_ACCESS = 'ProtectedPrivateBlockAccess'; - - private const OBSOLETE_REGEX = [ - 'FoundJQueryUI' => [ - 'pattern' => '/(["\'])jquery\/ui\1/', - 'message' => 'Please do not use "jquery/ui" library in templates. Use needed jquery ui widget instead' - ], - 'FoundDataMageInit' => [ - 'pattern' => '/data-mage-init=(?:\'|")(?!\s*{\s*"[^"]+")/', - 'message' => 'Please do not initialize JS component in php. Do it in template' - ], - 'FoundXMagentoInit' => [ - 'pattern' => '@x-magento-init.>(?!\s*+{\s*"[^"]+"\s*:\s*{\s*"[\w/-]+")@i', - 'message' => 'Please do not initialize JS component in php. Do it in template' - ], - ]; /** * @inheritdoc @@ -51,18 +35,9 @@ public function process(File $phpcsFile, $stackPtr) $tokens = $phpcsFile->getTokens(); if ($tokens[$stackPtr]['code'] === T_OBJECT_OPERATOR) { $this->checkBlockVariable($phpcsFile, $stackPtr, $tokens); - $this->checkThisVariable($phpcsFile, $stackPtr, $tokens); } if ($tokens[$stackPtr]['code'] === T_INLINE_HTML || $tokens[$stackPtr]['code'] === T_HEREDOC) { $this->checkHtml($phpcsFile, $stackPtr); - - $file = $phpcsFile->getFilename(); - - if (strpos($file, '/view/frontend/templates/') !== false - || strpos($file, '/view/base/templates/') !== false - ) { - $this->checkHtmlSpecificFiles($phpcsFile, $stackPtr); - } } } @@ -90,30 +65,6 @@ private function checkBlockVariable(File $phpcsFile, int $stackPtr, array $token } } - /** - * Check access to members and methods of Block class through $this - * - * @param File $phpcsFile - * @param int $stackPtr - * @param array $tokens - */ - private function checkThisVariable(File $phpcsFile, int $stackPtr, array $tokens): void - { - $varPos = $phpcsFile->findPrevious(T_VARIABLE, $stackPtr - 1); - if ($tokens[$varPos]['content'] !== '$this') { - return; - } - $stringPos = $phpcsFile->findNext(T_STRING, $stackPtr + 1); - if (strpos($tokens[$stringPos]['content'], 'helper') === false) { - $phpcsFile->addWarning( - 'Access to members and methods of Block class through $this is ' . - 'obsolete in phtml templates. Use only $block instead of $this.', - $stringPos, - self::WARNING_CODE_THIS_USAGE - ); - } - } - /** * Check use of "text/javascript" type * @@ -132,25 +83,4 @@ private function checkHtml(File $phpcsFile, int $stackPtr): void ); } } - - /** - * Check of some obsoletes uses in specific files - * - * @param File $phpcsFile - * @param int $stackPtr - */ - private function checkHtmlSpecificFiles(File $phpcsFile, int $stackPtr): void - { - $content = $phpcsFile->getTokensAsString($stackPtr, 1); - - foreach (self::OBSOLETE_REGEX as $code => $data) { - if (preg_match($data['pattern'], $content)) { - $phpcsFile->addWarning( - $data['message'], - $stackPtr, - $code - ); - } - } - } } diff --git a/Magento2/Sniffs/PHPCompatibility/AbstractPrivateMethodsSniff.php b/Magento2/Sniffs/PHPCompatibility/AbstractPrivateMethodsSniff.php deleted file mode 100644 index 4972a87e..00000000 --- a/Magento2/Sniffs/PHPCompatibility/AbstractPrivateMethodsSniff.php +++ /dev/null @@ -1,104 +0,0 @@ -supportsAbove('5.1') === false) { - return; - } - - $tokens = $phpcsFile->getTokens(); - $scopePtr = Scopes::validDirectScope($phpcsFile, $stackPtr, BCTokens::ooScopeTokens()); - if ($scopePtr === false) { - // Function, not method. - return; - } - - $properties = FunctionDeclarations::getProperties($phpcsFile, $stackPtr); - if ($properties['scope'] !== 'private' || $properties['is_abstract'] !== true) { - // Not an abstract private method. - return; - } - - if ($tokens[$scopePtr]['code'] === \T_TRAIT) { - if ($this->supportsBelow('7.4') === true) { - $phpcsFile->addError( - 'Traits cannot declare "abstract private" methods in PHP 7.4 or below', - $stackPtr, - 'InTrait' - ); - } - - return; - } - - // Not a trait. - $phpcsFile->addError( - 'Abstract methods cannot be declared as private since PHP 5.1', - $stackPtr, - 'Found' - ); - } -} diff --git a/Magento2/Sniffs/PHPCompatibility/NewAttributesSniff.php b/Magento2/Sniffs/PHPCompatibility/NewAttributesSniff.php deleted file mode 100644 index f1904a0e..00000000 --- a/Magento2/Sniffs/PHPCompatibility/NewAttributesSniff.php +++ /dev/null @@ -1,234 +0,0 @@ -= 3.6.0. - $targets[] = \T_ATTRIBUTE; - - } - - return $targets; - } - - /** - * Processes this test, when one of its tokens is encountered. - * - * @since 10.0.0 - * - * @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(File $phpcsFile, $stackPtr) - { - if ($this->supportsBelow('7.4') === false) { - return; - } - - $tokens = $phpcsFile->getTokens(); - - if ($tokens[$stackPtr]['type'] === 'T_ATTRIBUTE') { - /* - * Either PHP 8.0 or PHPCS 3.6.0+. - * PHP 8.0 tokenizes the start marker of the attribute as `T_ATTRIBUTE` and the - * end marker as `T_CLOSE_SQUARE_BRACKET. - * In PHPCS 3.6.0+ the end marker will be tokenized as `T_ATTRIBUTE_END` and - * the start marker will have an 'attribute_closer' token array index. - */ - if (isset($tokens[$stackPtr]['attribute_closer']) === true) { - // This is PHPCS >= 3.6.0. - $this->throwError( - $phpcsFile, - $stackPtr, - GetTokensAsString::compact($phpcsFile, $stackPtr, $tokens[$stackPtr]['attribute_closer'], true) - ); - return; - } - - // This must be PHP 8.0 in combination with PHPCS < 3.6.0. - $nestedBrackets = 1; - for ($i = ($stackPtr + 1); $i < $phpcsFile->numTokens; $i++) { - if ($tokens[$i]['code'] === \T_OPEN_SQUARE_BRACKET) { - ++$nestedBrackets; - continue; - } - - if ($tokens[$i]['code'] === \T_CLOSE_SQUARE_BRACKET) { - --$nestedBrackets; - - if ($nestedBrackets === 0) { - // Found the end of the attribute. - break; - } - } - - if ($tokens[$i]['code'] === \T_CLOSE_TAG) { - /* - * Prevent looping to the end of the file for a particular edge case which - * breaks the tokenizer 8.0. - */ - break; - } - } - - $this->throwError($phpcsFile, $stackPtr, GetTokensAsString::compact($phpcsFile, $stackPtr, $i, true)); - return; - } - - /* - * PHP < 8.0 in combination with PHPCS < 3.6.0 will tokenize attributes as comments. - * This comment can contain multiple attributes on the same line or can be followed - * by actual code. - * The attribute closer can also be on a later line. - */ - $contents = $tokens[$stackPtr]['content']; - - if (\substr($contents, 0, 2) !== '#[') { - // Bow out early if we already know this is not an attribute. - return; - } - - $expectedErrors = \substr_count($contents, '#['); - $actualErrors = 0; - - while (empty($contents) === false && \substr($contents, 0, 2) === '#[') { - $length = \strlen($contents); - $nestedBrackets = 1; - - for ($i = 2; $i < $length; $i++) { - if ($contents[$i] === '[') { - ++$nestedBrackets; - continue; - } - - if ($contents[$i] === ']') { - --$nestedBrackets; - - if ($nestedBrackets === 0) { - // Found the end of the attribute. - $this->throwError($phpcsFile, $stackPtr, \substr($contents, 0, ($i + 1))); - ++$actualErrors; - - if (($i + 1) === $length) { - $contents = ''; - } else { - $contents = \trim(\substr($contents, ($i + 1))); - } - break; - } - } - } - - if ($i === $length) { - // Reached the end of the content without finding a closing bracket. - break; - } - } - - if ($expectedErrors === $actualErrors) { - // This was a single-line attribute, closer found. - return; - } - - // This must be a multi-line attribute. - $nestedBrackets = 1; - for ($i = ($stackPtr + 1); $i < $phpcsFile->numTokens; $i++) { - if ($tokens[$i]['code'] === \T_OPEN_SQUARE_BRACKET) { - ++$nestedBrackets; - continue; - } - - if ($tokens[$i]['code'] === \T_CLOSE_SQUARE_BRACKET) { - --$nestedBrackets; - - if ($nestedBrackets === 0) { - // Found the end of the attribute. - break; - } - } - - if ($tokens[$i]['code'] === \T_CLOSE_TAG) { - /* - * Prevent looping to the end of the file for a particular edge case which - * breaks the tokenizer on PHP < 8.0. - */ - break; - } - } - - $this->throwError( - $phpcsFile, - $stackPtr, - \rtrim($contents, "\r\n") . GetTokensAsString::compact($phpcsFile, $stackPtr, $i, true) - ); - } - - /** - * Throw an error when an attribute is encountered. - * - * @since 10.0.0 - * - * @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. - * @param string $content Attribute content for use in the error message. - * - * @return void - */ - protected function throwError($phpcsFile, $stackPtr, $content) - { - $phpcsFile->addError( - 'Attributes are not supported in PHP 7.4 or earlier. Found: %s', - $stackPtr, - 'Found', - [$content] - ); - } -} diff --git a/Magento2/Sniffs/PHPCompatibility/NewInterpolatedStringDereferencingSniff.php b/Magento2/Sniffs/PHPCompatibility/NewInterpolatedStringDereferencingSniff.php deleted file mode 100644 index ded7b819..00000000 --- a/Magento2/Sniffs/PHPCompatibility/NewInterpolatedStringDereferencingSniff.php +++ /dev/null @@ -1,93 +0,0 @@ -supportsBelow('7.4') === false) { - return; - } - - $tokens = $phpcsFile->getTokens(); - - // Check whether the text string uses interpolation. - $string = TextStrings::getCompleteTextString($phpcsFile, $stackPtr, true); - $endOfQuote = $phpcsFile->findNext([\T_DOUBLE_QUOTED_STRING], $stackPtr + 1, null, true); - if ($this->stripVariables($string) === $string) { - return $endOfQuote; - } - - // Check whether the string is being dereferenced. - $nextNonEmpty = $phpcsFile->findNext(Tokens::$emptyTokens, $endOfQuote, null, true); - $nextNonEmptyCode = $tokens[$nextNonEmpty]['code']; - if ($nextNonEmptyCode !== \T_OPEN_SQUARE_BRACKET - && $nextNonEmptyCode !== \T_OBJECT_OPERATOR - // Work-around for a bug in PHPCS < 3.6.0. - // @link https://github.com/squizlabs/PHP_CodeSniffer/pull/3172 - && $nextNonEmptyCode !== \T_OPEN_SHORT_ARRAY - ) { - return $endOfQuote; - } - - $phpcsFile->addError( - 'Dereferencing of interpolated strings is not supported in PHP 7.4 or earlier', - $stackPtr, - 'Found' - ); - - return $endOfQuote; - } -} diff --git a/Magento2/Sniffs/PHPCompatibility/NewMagicClassConstantSniff.php b/Magento2/Sniffs/PHPCompatibility/NewMagicClassConstantSniff.php deleted file mode 100644 index b3bcc3be..00000000 --- a/Magento2/Sniffs/PHPCompatibility/NewMagicClassConstantSniff.php +++ /dev/null @@ -1,124 +0,0 @@ -supportsBelow('7.4') === false) { - return; - } - - $tokens = $phpcsFile->getTokens(); - - if (\strtolower($tokens[$stackPtr]['content']) !== 'class') { - return; - } - - $prevToken = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($stackPtr - 1), null, true, null, true); - if ($prevToken === false || $tokens[$prevToken]['code'] !== \T_DOUBLE_COLON) { - return; - } - - $subjectPtr = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($prevToken - 1), null, true, null, true); - if ($subjectPtr === false) { - // Shouldn't be possible. - return; - } - - $preSubjectPtr = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($subjectPtr - 1), null, true, null, true); - if (isset(Collections::$OOHierarchyKeywords[$tokens[$subjectPtr]['code']]) === true - || ($tokens[$subjectPtr]['code'] === \T_STRING - && isset(Collections::$objectOperators[$tokens[$preSubjectPtr]['code']]) === false) - ) { - // This is a syntax which is supported on PHP 5.5 and higher. - if ($this->supportsBelow('5.4') === true) { - $phpcsFile->addError( - 'The magic class constant ClassName::class was not available in PHP 5.4 or earlier', - $stackPtr, - 'Found' - ); - } - - return; - } - - /* - * This syntax was not supported until PHP 8.0. - * - * Includes throwing an error for syntaxes which are still not supported, as differentiating - * between them would be hard, if not impossible, and cause more overhead than it's worth. - */ - $phpcsFile->addError( - 'Using the magic class constant ::class with dynamic class names is not supported in PHP 7.4 or earlier', - $stackPtr, - 'UsedOnObject' - ); - } -} diff --git a/Magento2/Sniffs/PHPCompatibility/NewMagicConstantDereferencingSniff.php b/Magento2/Sniffs/PHPCompatibility/NewMagicConstantDereferencingSniff.php deleted file mode 100644 index ef767157..00000000 --- a/Magento2/Sniffs/PHPCompatibility/NewMagicConstantDereferencingSniff.php +++ /dev/null @@ -1,126 +0,0 @@ -supportsBelow('7.4') === false) { - return; - } - - $tokens = $phpcsFile->getTokens(); - $nextNonEmpty = $phpcsFile->findNext(Tokens::$emptyTokens, ($stackPtr + 1), null, true); - if ($nextNonEmpty === false) { - return; - } - - if ($tokens[$nextNonEmpty]['code'] !== \T_OPEN_SQUARE_BRACKET - // Work around bug #3013 in PHPCS 3.5.5 and lower. - && $tokens[$nextNonEmpty]['code'] !== \T_OPEN_SHORT_ARRAY - ) { - return; - } - - if (isset($tokens[$nextNonEmpty]['bracket_closer']) === false) { - // Live coding or parse error. - return; - } - - $hasContent = $phpcsFile->findNext( - Tokens::$emptyTokens, - ($nextNonEmpty + 1), - $tokens[$nextNonEmpty]['bracket_closer'], - true - ); - - if ($hasContent === false) { - /* - * Attempt to assign to the magic constant as if it were an array. - * Not allowed now, nor prior to PHP 8, so not our concern. - */ - return; - } - - // Make sure this isn't an array assignment. That would be illegal, i.e. a parse error. - $nextNext = $tokens[$nextNonEmpty]['bracket_closer']; - do { - $nextNext = $phpcsFile->findNext(Tokens::$emptyTokens, ($nextNext + 1), null, true); - if ($nextNext === false) { - break; - } - - // If the next token is an assignment, that's all we need to know. - if (isset(BCTokens::assignmentTokens()[$tokens[$nextNext]['code']]) === true) { - return; - } - - // Check if this is an multi-access array assignment, e.g., `__FILE__[1][2] = 'val';` . - if (($tokens[$nextNext]['code'] === \T_OPEN_SQUARE_BRACKET - // Work around for nested array access being incorrectly tokenized in PHPCS 2.8.x. - || $tokens[$nextNext]['code'] === \T_OPEN_SHORT_ARRAY) - && isset($tokens[$nextNext]['bracket_closer']) === true - ) { - $nextNext = $tokens[$nextNext]['bracket_closer']; - continue; - } - - break; - } while (true); - - $phpcsFile->addError( - 'Dereferencing of magic constants is not present in PHP version 7.4 or earlier. Found dereferencing of: %s', - $nextNonEmpty, - 'Found', - [$tokens[$stackPtr]['content']] - ); - } -} diff --git a/Magento2/Sniffs/PHPCompatibility/NewNestedStaticAccessSniff.php b/Magento2/Sniffs/PHPCompatibility/NewNestedStaticAccessSniff.php deleted file mode 100644 index 1e4c6b12..00000000 --- a/Magento2/Sniffs/PHPCompatibility/NewNestedStaticAccessSniff.php +++ /dev/null @@ -1,153 +0,0 @@ - true, - \T_DOUBLE_COLON => true, - ]; - - /** - * Returns an array of tokens this test wants to listen for. - * - * @since 10.0.0 - * - * @return array - */ - public function register() - { - return [\T_DOUBLE_COLON]; - } - - /** - * Processes this test, when one of its tokens is encountered. - * - * @since 10.0.0 - * - * @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(File $phpcsFile, $stackPtr) - { - // PHP 8.0 supports both nested static access and class constant dereferencing - if ($this->supportsBelow('7.4') === false) { - return; - } - - $tokens = $phpcsFile->getTokens(); - $prev = $stackPtr; - $seenBrackets = false; - $prevOperator = false; - - do { - $prev = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($prev - 1), null, true); - - if ($prev === false) { - return; - } - - if ($tokens[$prev]['code'] === \T_CLOSE_SQUARE_BRACKET - || $tokens[$prev]['code'] === \T_CLOSE_CURLY_BRACKET - ) { - if (isset($tokens[$prev]['bracket_opener']) === false) { - // Parse error. - return; - } - - $prev = $tokens[$prev]['bracket_opener']; - $seenBrackets = true; - continue; - } - - if ($tokens[$prev]['code'] === \T_CLOSE_PARENTHESIS) { - if (isset($tokens[$prev]['parenthesis_opener']) === false) { - // Parse error. - return; - } - - $prev = $tokens[$prev]['parenthesis_opener']; - $seenBrackets = true; - continue; - } - - // Now this should either be a T_STRING or a T_VARIABLE. - if ($tokens[$prev]['code'] !== \T_STRING && $tokens[$prev]['code'] !== \T_VARIABLE) { - // Not sure what's happening, but this is outside the scope of this sniff. - return; - } - - // OK, we have the start of the access, let see if it's nested. - $prevOperator = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($prev - 1), null, true); - break; - - } while (true); - - if ($prevOperator === false - || isset($this->accessOperators[$tokens[$prevOperator]['code']]) === false - ) { - return; - } - - // Class constants cannot be dereferenced before PHP 8.0. - if ($seenBrackets === false - && $tokens[$prev]['code'] === \T_STRING - && $tokens[$prevOperator]['code'] === \T_DOUBLE_COLON - && $this->supportsBelow('7.4') === true - ) { - $phpcsFile->addError( - 'Dereferencing class constants was not supported in PHP 7.4 or earlier.', - $stackPtr, - 'ClassConstantDereferenced' - ); - return; - } - - // This is nested static access. - if ($this->supportsBelow('5.6') === true) { - $phpcsFile->addError( - 'Nested access to static properties, constants and methods was not supported in PHP 5.6 or earlier.', - $stackPtr, - 'NestedStaticAccess' - ); - } - } -} diff --git a/Magento2/Sniffs/PHPCompatibility/NewNonCapturingCatchSniff.php b/Magento2/Sniffs/PHPCompatibility/NewNonCapturingCatchSniff.php deleted file mode 100644 index b9fc74e6..00000000 --- a/Magento2/Sniffs/PHPCompatibility/NewNonCapturingCatchSniff.php +++ /dev/null @@ -1,84 +0,0 @@ -supportsBelow('7.4') === false) { - return; - } - - $tokens = $phpcsFile->getTokens(); - $token = $tokens[$stackPtr]; - - // Bow out during live coding. - if (isset($token['parenthesis_opener'], $token['parenthesis_closer']) === false) { - return; - } - - $lastNonEmptyToken = $phpcsFile->findPrevious( - Tokens::$emptyTokens, - ($token['parenthesis_closer'] - 1), - $token['parenthesis_opener'], - true - ); - - if ($tokens[$lastNonEmptyToken]['code'] === \T_VARIABLE) { - return; - } - - $phpcsFile->addError( - 'Catching exceptions without capturing them to a variable is not supported in PHP 7.4 or earlier.', - $stackPtr, - 'Found' - ); - } -} diff --git a/Magento2/Sniffs/PHPCompatibility/NewTrailingCommaSniff.php b/Magento2/Sniffs/PHPCompatibility/NewTrailingCommaSniff.php deleted file mode 100644 index 1239c10b..00000000 --- a/Magento2/Sniffs/PHPCompatibility/NewTrailingCommaSniff.php +++ /dev/null @@ -1,128 +0,0 @@ -supportsBelow('7.4') === false) { - return; - } - - $tokens = $phpcsFile->getTokens(); - - if (isset(Collections::arrowFunctionTokensBC()[$tokens[$stackPtr]['code']]) === true) { - $arrowInfo = FunctionDeclarations::getArrowFunctionOpenClose($phpcsFile, $stackPtr); - if ($arrowInfo === false) { - // Not an arrow function. - return; - } - - $closer = $arrowInfo['parenthesis_closer']; - } else { - if (isset($tokens[$stackPtr]['parenthesis_closer']) === false) { - // Live coding or parse error. - return; - } - - $closer = $tokens[$stackPtr]['parenthesis_closer']; - } - - /* - * Check for trailing comma's in a function declaration parameter list. - */ - $lastInParenthesis = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($closer - 1), null, true); - - if ($tokens[$lastInParenthesis]['code'] === \T_COMMA) { - $phpcsFile->addError( - 'Trailing comma\'s are not allowed in function declaration parameter lists in PHP 7.4 or earlier', - $lastInParenthesis, - 'InParameterList' - ); - } - - /* - * From this point forward, we're only interested in closures to check for - * trailing comma's in closure use lists. - * Bow out for any of the other tokens. - */ - if ($tokens[$stackPtr]['code'] !== \T_CLOSURE) { - return; - } - - $usePtr = $phpcsFile->findNext(Tokens::$emptyTokens, ($closer + 1), null, true); - if ($usePtr === false || $tokens[$usePtr]['code'] !== \T_USE) { - // Closure without use list or live coding/parse error. - return; - } - - $openParens = $phpcsFile->findNext(Tokens::$emptyTokens, ($usePtr + 1), null, true); - if ($openParens === false - || $tokens[$openParens]['code'] !== \T_OPEN_PARENTHESIS - || isset($tokens[$openParens]['parenthesis_closer']) === false - ) { - // Live coding/parse error. - return; - } - - $closer = $tokens[$openParens]['parenthesis_closer']; - $lastInParenthesis = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($closer - 1), null, true); - - if ($tokens[$lastInParenthesis]['code'] === \T_COMMA) { - $phpcsFile->addError( - 'Trailing comma\'s are not allowed in closure use lists in PHP 7.4 or earlier', - $lastInParenthesis, - 'InClosureUseList' - ); - } - } -} diff --git a/Magento2/Tests/Legacy/PhtmlTemplateUnitTest.php b/Magento2/Tests/Legacy/PhtmlTemplateUnitTest.php index 6624ad3c..129229a3 100644 --- a/Magento2/Tests/Legacy/PhtmlTemplateUnitTest.php +++ b/Magento2/Tests/Legacy/PhtmlTemplateUnitTest.php @@ -56,22 +56,16 @@ public function getWarningList($testFile = '') { if ($testFile === 'PhtmlTemplateUnitTest.1.phtml' || $testFile === 'PhtmlTemplateUnitTest.2.phtml') { return [ - 7 => 1, 9 => 1, - 13 => 1, 20 => 1, - 22 => 1, 23 => 1, - 27 => 1, - 33 => 1, - 39 => 1 + 27 => 1 ]; } if ($testFile === 'PhtmlTemplateUnitTest.3.phtml') { return [ 9 => 1, 20 => 1, - 22 => 1, 23 => 1, 27 => 1, ]; diff --git a/Magento2/Tests/PHPCompatibility/AbstractPrivateMethodsUnitTest.inc b/Magento2/Tests/PHPCompatibility/AbstractPrivateMethodsUnitTest.inc deleted file mode 100644 index 216e8c62..00000000 --- a/Magento2/Tests/PHPCompatibility/AbstractPrivateMethodsUnitTest.inc +++ /dev/null @@ -1,44 +0,0 @@ -sniffFile(__FILE__, '5.1'); - $this->assertError($file, $line, 'Abstract methods cannot be declared as private since PHP 5.1'); - } - - /** - * Data provider. - * - * @see testForbiddenAbstractPrivateMethods() - * - * @return array - */ - public function dataForbiddenAbstractPrivateMethods() - { - return [ - [28], - [29], - [33], - [34], - ]; - } - - /** - * Verify that the sniff throws an error for abstract private methods in traits for PHP 7.4 - * and doesn't for PHP 8.0. - * - * @dataProvider dataNewTraitAbstractPrivateMethods - * - * @param int $line The line number where a warning is expected. - * - * @return void - */ - public function testNewTraitAbstractPrivateMethods($line) - { - $file = $this->sniffFile(__FILE__, '7.4'); - $this->assertError($file, $line, 'Traits cannot declare "abstract private" methods in PHP 7.4 or below'); - - $file = $this->sniffFile(__FILE__, '8.0'); - $this->assertNoViolation($file, $line); - } - - /** - * Data provider. - * - * @see testNewTraitAbstractPrivateMethods() - * - * @return array - */ - public function dataNewTraitAbstractPrivateMethods() - { - return [ - [42], - [43], - ]; - } - - /** - * Verify the sniff does not throw false positives for valid code. - * - * @dataProvider dataNoFalsePositives - * - * @param int $line The line number. - * - * @return void - */ - public function testNoFalsePositives($line) - { - $file = $this->sniffFile(__FILE__, '5.1'); - $this->assertNoViolation($file, $line); - - $file = $this->sniffFile(__FILE__, '7.4'); - $this->assertNoViolation($file, $line); - } - - /** - * Data provider. - * - * @see testNoFalsePositives() - * - * @return array - */ - public function dataNoFalsePositives() - { - $cases = []; - // No errors expected on the first 24 lines. - for ($line = 1; $line <= 24; $line++) { - $cases[] = [$line]; - } - - return $cases; - } - - /** - * Verify no notices are thrown at all. - * - * @return void - */ - public function testNoViolationsInFileOnValidVersion() - { - $file = $this->sniffFile(__FILE__, '5.0'); - $this->assertNoViolation($file); - } -} diff --git a/Magento2/Tests/PHPCompatibility/NewAttributesUnitTest.inc b/Magento2/Tests/PHPCompatibility/NewAttributesUnitTest.inc deleted file mode 100644 index 1817c84c..00000000 --- a/Magento2/Tests/PHPCompatibility/NewAttributesUnitTest.inc +++ /dev/null @@ -1,112 +0,0 @@ - "value"))] -#[MyAttribute(100 + 200)] -class Thing {} - -#[MyAttribute(1234), MyAttribute(5678)] -class MultipleAttributesGrouped {} - -$object = new #[ExampleAttribute] class () { }; - -#[WithoutArgument] -#[Another\SingleArgument(0)] -#[FewArguments('Hello', 'World')] -#[\My\Attributes\FewArguments("foo", "bar")] -function multipleAttributesMultipleLines() {} - -$f2 = #[ExampleAttribute] function () { }; - -$f3 = #[ExampleAttribute] fn () => 1; - -#[WithoutArgument]#[SingleArgument(0)]#[FewArguments('Hello', 'World')] -function multipleAttributesSingleLines() {} - -#[ORM\Entity] -class User -{ - #[ORM\Id]#[ORM\Column("integer")] #[ORM\GeneratedValue] - private $id; - - #[Assert\Range(["min" => 120, "max" => 180, "minMessage" => "You must be at least {{ limit }}cm tall to enter"])] - #[ORM\Column(ORM\Column::T_INTEGER)] - protected $height; -} - -#[Attr1, Attr2] -class MultilineAttributeExamples -{ - #[Attr2("foo"), - Attr2("bar")] - public function testMultiLine() - { - } - - #[ - Attr1("foo"), - Attr2("bar"), - ] - public function testMultiLineDifferentFormatAndTrailingComma() - { - } -} - -function attributeUsedForTypedParameter( - #[MyAttr([1, 2])] Type $myParam, -) {} - -#[ - ORM\Entity, - ORM\Table("user") -] -class AnotherMultilineAttributeTest -{ - #[ORM\Id, ORM\Column("integer"), ORM\GeneratedValue] - private $id; - - #[ORM\Column("string", ORM\Column::UNIQUE)] - #[Assert\Email(["message" => "text"])] #[Assert\Text(["message" => "text"]), - Assert\Domain(["message" => "text"]), - Assert\Id(Assert\Id::REGEX[10]), - ] - private $email; -} - -// This code will cause a tokenizer error in PHP < 8.0. This must be the last test in the file! -#[DeprecationReason('reason: ')] -function attribute_containing_text_looking_like_close_tag() {} -const APP_SECRET = 'app-secret'; -echo "Test\n"; - -#[DeprecationReason( - 'reason: ' -)] -function attribute_containing_mulitline_text_looking_like_close_tag() {} diff --git a/Magento2/Tests/PHPCompatibility/NewAttributesUnitTest.php b/Magento2/Tests/PHPCompatibility/NewAttributesUnitTest.php deleted file mode 100644 index 2b288c29..00000000 --- a/Magento2/Tests/PHPCompatibility/NewAttributesUnitTest.php +++ /dev/null @@ -1,154 +0,0 @@ -sniffFile(__FILE__, '7.4'); - $error = 'Attributes are not supported in PHP 7.4 or earlier.'; - if ($found !== '') { - $error .= ' Found: ' . $found; - } - - $this->assertError($file, $line, $error); - } - - /** - * Data provider. - * - * @see testNewAttributes() - * - * @return array - */ - public function dataNewAttributes() - { - $data = [ - [17], - [20], - [23], - [24], - [25], - [26], - [30], - [31], - [32], - [35], - [38], - [40], - [41], - [42], - [43], - [46], - [48], - [50, '#[WithoutArgument]'], - [50, '#[SingleArgument(0)]'], - [50, "#[FewArguments('Hello', 'World')]"], - [53], - [56, '#[ORM\Id]'], - [56, '#[ORM\Column("integer")]'], - [56, '#[ORM\GeneratedValue]'], - [59], - [60], - [64], - [67, '#[Attr2("foo"), Attr2("bar")]'], - [73, '#[ Attr1("foo"), Attr2("bar"), ]'], - [83, '#[MyAttr([1, 2])]'], - [86, '#[ ORM\Entity, ORM\Table("user") ]'], - [92], - [95], - [96, '#[Assert\Email(["message" => "text"])]'], - [96, '#[Assert\Text(["message" => "text"]), Assert\Domain(["message" => "text"]), Assert\Id(Assert\Id::REGEX[10]), ]'], - [104], - ]; - - /* - * In PHP < 8.0 in combination with PHPCS < 3.6.1, anything after the test case on - * line 104 will be tokenized as `T_INLINE_HTML` and undetectable. - */ - if (version_compare(Helper::getVersion(), '3.6.1', '>=') === true - || version_compare(PHP_VERSION_ID, '80000', '>=') === true - ) { - $data[] = [109]; - } - - return $data; - } - - /** - * Verify the sniff does not throw false positives for valid code. - * - * @dataProvider dataNoFalsePositives - * - * @param int $line The line number. - * - * @return void - */ - public function testNoFalsePositives($line) - { - $file = $this->sniffFile(__FILE__, '7.4'); - $this->assertNoViolation($file, $line); - } - - /** - * Data provider. - * - * @see testNoFalsePositives() - * - * @return array - */ - public function dataNoFalsePositives() - { - $data = []; - - // No errors expected on the first 12 lines. - for ($line = 1; $line <= 12; $line++) { - $data[] = [$line]; - } - - return $data; - } - - /** - * Verify no notices are thrown at all. - * - * @return void - */ - public function testNoViolationsInFileOnValidVersion() - { - $file = $this->sniffFile(__FILE__, '8.0'); - $this->assertNoViolation($file); - } -} diff --git a/Magento2/Tests/PHPCompatibility/NewInterpolatedStringDereferencingUnitTest.inc b/Magento2/Tests/PHPCompatibility/NewInterpolatedStringDereferencingUnitTest.inc deleted file mode 100644 index 17d50363..00000000 --- a/Magento2/Tests/PHPCompatibility/NewInterpolatedStringDereferencingUnitTest.inc +++ /dev/null @@ -1,30 +0,0 @@ -baz(); -$a = "foo"->baz(); -$a = "foo -bar"->baz(); - -// PHP 8.0: strings that use interpolation and dereferencing. -$a = "foo$bar"[0]; -$a = "foo$bar"->baz(); -$a = "foo -$bar"->baz(); -$a = "foo $lines -$bar -more foo"[10]; diff --git a/Magento2/Tests/PHPCompatibility/NewInterpolatedStringDereferencingUnitTest.php b/Magento2/Tests/PHPCompatibility/NewInterpolatedStringDereferencingUnitTest.php deleted file mode 100644 index d2ab258d..00000000 --- a/Magento2/Tests/PHPCompatibility/NewInterpolatedStringDereferencingUnitTest.php +++ /dev/null @@ -1,112 +0,0 @@ -sniffFile(__FILE__, '7.4'); - $this->assertError($file, $line, 'Dereferencing of interpolated strings is not supported in PHP 7.4 or earlier'); - } - - /** - * Data provider. - * - * @see testInterpolatedStringDereferencing - * - * @return array - */ - public function dataInterpolatedStringDereferencing() - { - return [ - [24], - [25], - [26], - [28], - ]; - } - - /** - * Verify the sniff does not throw false positives for valid code. - * - * @dataProvider dataNoFalsePositives - * - * @param int $line The line number. - * - * @return void - */ - public function testNoFalsePositives($line) - { - $file = $this->sniffFile(__FILE__, '7.4'); - $this->assertNoViolation($file, $line); - } - - /** - * Data provider. - * - * @see testNoFalsePositives() - * - * @return array - */ - public function dataNoFalsePositives() - { - return [ - // No interpolation, no dereferencing. - [4], - [5], - [6], - - // Interpolation, no dereferencing. - [10], - [11], - [12], - - // Dereferencing, no interpolation. - [16], - [17], - [18], - [19], - [20], - ]; - } - - /** - * Verify no notices are thrown at all. - * - * @return void - */ - public function testNoViolationsInFileOnValidVersion() - { - $file = $this->sniffFile(__FILE__, '8.0'); - $this->assertNoViolation($file); - } -} diff --git a/Magento2/Tests/PHPCompatibility/NewMagicClassConstantUnitTest.inc b/Magento2/Tests/PHPCompatibility/NewMagicClassConstantUnitTest.inc deleted file mode 100644 index 5708f7af..00000000 --- a/Magento2/Tests/PHPCompatibility/NewMagicClassConstantUnitTest.inc +++ /dev/null @@ -1,52 +0,0 @@ -otherObjectSavedAsProperty::class)) {} - } -} - -/* - * Syntaxes which are not supported in any version. - * PHPCompatibility shouldn't throw an error for these, but it's darn hard to figure out if it's - * a supported or non-supported syntax. - * As it would be a fatal error anyway, don't bother differentiating for now. - */ -$name = ($string = 'text')::class; // Using ::class on a string literal. -$name = (1+1)::class; // Using ::class on a literal. -const A = [0]::class; // Using ::class on a literal. -$name = ClassName::CONSTANT_NAME::class; // Objects can not be set as the value for a constant. diff --git a/Magento2/Tests/PHPCompatibility/NewMagicClassConstantUnitTest.php b/Magento2/Tests/PHPCompatibility/NewMagicClassConstantUnitTest.php deleted file mode 100644 index d4aa8e21..00000000 --- a/Magento2/Tests/PHPCompatibility/NewMagicClassConstantUnitTest.php +++ /dev/null @@ -1,146 +0,0 @@ -sniffFile(__FILE__, '5.4'); - $this->assertError($file, $line, 'The magic class constant ClassName::class was not available in PHP 5.4 or earlier'); - - $file = $this->sniffFile(__FILE__, '5.5'); - $this->assertNoViolation($file, $line); - } - - /** - * Data provider. - * - * @see testNewMagicClassConstant() - * - * @return array - */ - public function dataNewMagicClassConstant() - { - return [ - [6], - [12], - [27], - [28], - [29], - [30], - [31], - [32], - ]; - } - - /** - * Verify that no false positives are thrown for valid code. - * - * @dataProvider dataNoFalsePositives - * - * @param int $line The line number. - * - * @return void - */ - public function testNoFalsePositives($line) - { - $file = $this->sniffFile(__FILE__, '5.4'); - $this->assertNoViolation($file, $line); - } - - /** - * Data provider. - * - * @see testNoFalsePositives() - * - * @return array - */ - public function dataNoFalsePositives() - { - return [ - [4], - [10], - [18], - [19], - ]; - } - - /** - * Test correctly identifying the magic class constant when used on instantiated objects. - * - * @dataProvider dataNewMagicClassConstantOnObject - * - * @param int $line The line number. - * - * @return void - */ - public function testNewMagicClassConstantOnObject($line) - { - $file = $this->sniffFile(__FILE__, '7.4'); - $this->assertError($file, $line, 'Using the magic class constant ::class with dynamic class names is not supported in PHP 7.4 or earlier'); - } - - /** - * Data provider. - * - * @see testNewMagicClassConstantOnObject() - * - * @return array - */ - public function dataNewMagicClassConstantOnObject() - { - return [ - [35], - [36], - [37], - [38], - [39], - - // Still not supported, but throwing an error anyhow. - [49], - [50], - [51], - [52], - ]; - } - - /** - * Verify no notices are thrown at all. - * - * @return void - */ - public function testNoViolationsInFileOnValidVersion() - { - $file = $this->sniffFile(__FILE__, '8.0'); - $this->assertNoViolation($file); - } -} diff --git a/Magento2/Tests/PHPCompatibility/NewMagicConstantDereferencingUnitTest.inc b/Magento2/Tests/PHPCompatibility/NewMagicConstantDereferencingUnitTest.inc deleted file mode 100644 index 5c5ef295..00000000 --- a/Magento2/Tests/PHPCompatibility/NewMagicConstantDereferencingUnitTest.inc +++ /dev/null @@ -1,40 +0,0 @@ -sniffFile(__FILE__, '7.4'); - $this->assertError($file, $line, 'Dereferencing of magic constants is not present in PHP version 7.4 or earlier'); - } - - /** - * Data provider. - * - * @see testNewMagicConstantDereferencing() - * - * @return array - */ - public function dataNewMagicConstantDereferencing() - { - return [ - [15], - [16], - [17], - [18], - [19], - [20], - [21], - [22], - ]; - } - - /** - * Verify the sniff does not throw false positives for valid code, nor for code which is still invalid. - * - * @dataProvider dataNoFalsePositives - * - * @param int $line The line number. - * - * @return void - */ - public function testNoFalsePositives($line) - { - $file = $this->sniffFile(__FILE__, '7.4'); - $this->assertNoViolation($file, $line); - } - - /** - * Data provider. - * - * @see testNoFalsePositives() - * - * @return array - */ - public function dataNoFalsePositives() - { - return [ - [6], - [7], - [10], - [29], - [30], - [31], - [32], - [33], - [36], - [40], - ]; - } - - /** - * Verify no notices are thrown at all. - * - * @return void - */ - public function testNoViolationsInFileOnValidVersion() - { - $file = $this->sniffFile(__FILE__, '8.0'); - $this->assertNoViolation($file); - } -} diff --git a/Magento2/Tests/PHPCompatibility/NewNestedStaticAccessUnitTest.inc b/Magento2/Tests/PHPCompatibility/NewNestedStaticAccessUnitTest.inc deleted file mode 100644 index da51bbe5..00000000 --- a/Magento2/Tests/PHPCompatibility/NewNestedStaticAccessUnitTest.inc +++ /dev/null @@ -1,38 +0,0 @@ -bar()::baz(); -echo $instance->prop::MY_CONSTANT; -echo $bar::$foo['bar']::$baz; -echo $bar::$foo{'bar'}::$baz; -echo $bar::foo()['bar']::$baz; -echo $bar::foo(){'bar'}::$baz; -echo Foo::$boo::$baz; -echo self::$boo::$baz; -echo self::MY_CONSTANT[0]::$baz; -echo Foo::MY_CONSTANT[0]::$baz; -echo Bar::$bar::BAZ; - -// Test code style independent sniffing. -echo $obj -> /* comment */ $var() - :: $bar; // Bad. - -// PHP 7.0 change, but outside the scope of this sniff -// (dereferencing operations can now be applied to arbitrary parenthesis-expressions). -echo ($foo::$bar)::$baz; -echo ($foo->bar())::baz(); - -// Parse error in any PHP version. Outside the scope of this sniff. -echo $bar::($foo['bar'])::$baz; - -// PHP 8.0: class constant dereferencing. -self::MY_CONSTANT::$baz; -Foo::MY_CONSTANT::$baz; - -// Issue #1016. -echo Foo::bar()::baz(); diff --git a/Magento2/Tests/PHPCompatibility/NewNestedStaticAccessUnitTest.php b/Magento2/Tests/PHPCompatibility/NewNestedStaticAccessUnitTest.php deleted file mode 100644 index 22650e6b..00000000 --- a/Magento2/Tests/PHPCompatibility/NewNestedStaticAccessUnitTest.php +++ /dev/null @@ -1,144 +0,0 @@ -sniffFile(__FILE__, '5.6'); - $this->assertError($file, $line, 'Nested access to static properties, constants and methods was not supported in PHP 5.6 or earlier.'); - - $file = $this->sniffFile(__FILE__, '7.0'); - $this->assertNoViolation($file, $line); - } - - /** - * Data provider. - * - * @see testNestedStaticAccess() - * - * @return array - */ - public function dataNestedStaticAccess() - { - return [ - [7], - [8], - [9], - [10], - [11], - [12], - [13], - [14], - [15], - [16], - [17], - [18], - [19], - [23], - [38], - ]; - } - - /** - * Verify that class constant dereferencing emits an error in PHP 7.4. - * - * @dataProvider dataClassConstantDereferencing - * - * @param int $line The line number. - * - * @return void - */ - public function testClassConstantDereferencing($line) - { - $file = $this->sniffFile(__FILE__, '7.4'); - $this->assertError($file, $line, 'Dereferencing class constants was not supported in PHP 7.4 or earlier.'); - } - - /** - * Data provider. - * - * @see testClassConstantDereferencing() - * - * @return array - */ - public function dataClassConstantDereferencing() - { - return [ - [34], - [35], - ]; - } - - /** - * Verify the sniff doesn't throw false positives. - * - * @dataProvider dataNoFalsePositives - * - * @param int $line The line number. - * - * @return void - */ - public function testNoFalsePositives($line) - { - $file = $this->sniffFile(__FILE__, '5.6'); - $this->assertNoViolation($file, $line); - } - - /** - * Data provider. - * - * @see testNoFalsePositives() - * - * @return array - */ - public function dataNoFalsePositives() - { - return [ - [4], - [27], - [28], - [31], - ]; - } - - /** - * Verify no notices are thrown at all. - * - * @return void - */ - public function testNoViolationsInFileOnValidVersion() - { - $file = $this->sniffFile(__FILE__, '8.0'); - $this->assertNoViolation($file); - } -} diff --git a/Magento2/Tests/PHPCompatibility/NewNonCapturingCatchUnitTest.inc b/Magento2/Tests/PHPCompatibility/NewNonCapturingCatchUnitTest.inc deleted file mode 100644 index a8a9881f..00000000 --- a/Magento2/Tests/PHPCompatibility/NewNonCapturingCatchUnitTest.inc +++ /dev/null @@ -1,34 +0,0 @@ -getMessage()); -} catch (ExceptionType1 | ExceptionType2 $e) { - die($e->getMessage()); -} catch (CustomException::class $e) { - // ... -} - -/** - * Non-capturing catch - only valid in PHP 8.0+. - */ -try { - // Some code... -} catch (ExceptionType1 | ExceptionType2) { - // Code to handle the exception. -} catch (CustomException::class) { - // ... -} catch ($exceptionObject::class) { // PHP 8 syntax - using ::class on objects. - // ... -} catch (\Exception) { - // ... -} - -// Don't throw errors during live code review. -try { - // Some code... -} catch ( diff --git a/Magento2/Tests/PHPCompatibility/NewNonCapturingCatchUnitTest.php b/Magento2/Tests/PHPCompatibility/NewNonCapturingCatchUnitTest.php deleted file mode 100644 index 97ee69e0..00000000 --- a/Magento2/Tests/PHPCompatibility/NewNonCapturingCatchUnitTest.php +++ /dev/null @@ -1,101 +0,0 @@ -sniffFile(__FILE__, '7.4'); - $this->assertError($file, $line, 'Catching exceptions without capturing them to a variable is not supported in PHP 7.4 or earlier.'); - } - - /** - * Data provider. - * - * @see testNewNonCapturingCatch() - * - * @return array - */ - public function dataNewNonCapturingCatch() - { - return [ - [21], - [23], - [25], - [27], - ]; - } - - /** - * Verify no false positives are thrown for valid code. - * - * @dataProvider dataNoFalsePositives - * - * @param int $line The line number. - * - * @return void - */ - public function testNoFalsePositives($line) - { - $file = $this->sniffFile(__FILE__, '7.4'); - $this->assertNoViolation($file, $line); - } - - /** - * Data provider. - * - * @see testNoFalsePositives() - * - * @return array - */ - public function dataNoFalsePositives() - { - return [ - [8], - [10], - [12], - [34], // Live coding. - ]; - } - - /** - * Verify no notices are thrown at all. - * - * @return void - */ - public function testNoViolationsInFileOnValidVersion() - { - $file = $this->sniffFile(__FILE__, '8.0'); - $this->assertNoViolation($file); - } -} diff --git a/Magento2/Tests/PHPCompatibility/NewTrailingCommaUnitTest.inc b/Magento2/Tests/PHPCompatibility/NewTrailingCommaUnitTest.inc deleted file mode 100644 index 4ee5f21f..00000000 --- a/Magento2/Tests/PHPCompatibility/NewTrailingCommaUnitTest.inc +++ /dev/null @@ -1,101 +0,0 @@ - $foo + $bar; - -class LotsOfParams7 { - private function __construct( - ?string $scheme, - ?string $user, - ?string $pass, - ?string $host, - ?int $port, - string $path, - ?string $query, - ?string $fragment // <-- ARGH! - ) { - // Do something. - } -} - -/* - * PHP 8.0 trailing comma's in function declarations. - */ -function Foo8( - $foo, - $bar, -) { - return $foo + $bar; -} - -$closure = function ($foo, $bar,) { - return $foo + $bar; -}; - -$arrow = fn($foo, $bar,) => $foo + $bar; - -class LotsOfParams8 { - private function __construct( - ?string $scheme, - ?string $user, - ?string $pass, - ?string $host, - ?int $port, - string $path, - ?string $query, - ?string $fragment, // Trailing comment. - ) { - // Do something. - } -} - -/* - * PHP 8.0 trailing comma's in closure use lists. - */ -$closure = function ($foo, $bar) use ($baz, $booboo,) { - return ($foo + $bar) * $baz / $booboo; -}; - -$longArgs_longVars = function ( - $longArgument, - $longerArgument, - $muchLongerArgument, -) use ( - $longVar1, - $longerVar2, - $muchLongerVar3, -) { - // body -}; - -/* - * Still not allowed. - */ - -// Free-standing comma. -$c = function(,) {}; // Parse error, but throw an error anyway. - -$c = function($foo) use(,) {}; // Parse error, but throw an error anyway. - -// Multiple trailing comma's. -$a = fn($foo, $bar,,) => $bar; // Parse error, but throw an error anyway. - -// Leading comma. -function Leading(, $foo, $bar) {} // Parse error, but not our concern. - -// Live coding. -// Intentional parse error. This has to be the last test in the file. -function Unfinished( $foo, $bar, diff --git a/Magento2/Tests/PHPCompatibility/NewTrailingCommaUnitTest.php b/Magento2/Tests/PHPCompatibility/NewTrailingCommaUnitTest.php deleted file mode 100644 index 0d3e93fd..00000000 --- a/Magento2/Tests/PHPCompatibility/NewTrailingCommaUnitTest.php +++ /dev/null @@ -1,138 +0,0 @@ -sniffFile(__FILE__, '7.4'); - $this->assertError($file, $line, "Trailing comma's are not allowed in function declaration parameter lists in PHP 7.4 or earlier"); - } - - /** - * Data provider. - * - * @see testTrailingComma() - * - * @return array - */ - public function dataTrailingComma() - { - return [ - [39], - [44], - [48], - [59], - [75], - [89], - [94], - ]; - } - - /** - * Test correctly identifying trailing comma's in closure use lists. - * - * @dataProvider dataTrailingCommaClosureUse - * - * @param int $line The line number. - * - * @return void - */ - public function testTrailingCommaClosureUse($line) - { - $file = $this->sniffFile(__FILE__, '7.4'); - $this->assertError($file, $line, "Trailing comma's are not allowed in closure use lists in PHP 7.4 or earlier"); - } - - /** - * Data provider. - * - * @see testTrailingCommaClosureUse() - * - * @return array - */ - public function dataTrailingCommaClosureUse() - { - return [ - [68], - [79], - [91], - ]; - } - - /** - * Verify the sniff does not throw false positives for valid code. - * - * @dataProvider dataNoFalsePositives - * - * @param int $line The line number. - * - * @return void - */ - public function testNoFalsePositives($line) - { - $file = $this->sniffFile(__FILE__, '7.4'); - $this->assertNoViolation($file, $line); - } - - /** - * Data provider. - * - * @see testNoFalsePositives() - * - * @return array - */ - public function dataNoFalsePositives() - { - // No errors expected on the first 33 lines. - $data = []; - for ($line = 1; $line <= 33; $line++) { - $data[] = [$line]; - } - - $data[] = [97]; - $data[] = [101]; - - return $data; - } - - /** - * Verify no notices are thrown at all. - * - * @return void - */ - public function testNoViolationsInFileOnValidVersion() - { - $file = $this->sniffFile(__FILE__, '8.0'); - $this->assertNoViolation($file); - } -} diff --git a/Magento2/ruleset.xml b/Magento2/ruleset.xml index 2edd2c9c..3e5bb36e 100644 --- a/Magento2/ruleset.xml +++ b/Magento2/ruleset.xml @@ -6,10 +6,6 @@ - - 10 - error - 10 error @@ -779,19 +775,11 @@ All these rules belong to the unreleased PhpCompatibility 10. Remove them once PHPCompatibility is updated to version 10 --> - - - - - - - -