From d236414d16e0d35f415245dfe944e8280b23afed Mon Sep 17 00:00:00 2001 From: Dan Wallis Date: Tue, 12 Jul 2022 14:55:03 +0100 Subject: [PATCH 1/2] Upgrade PSR2 -> PSR12 for ControlStructureSpacing --- Magento2/ruleset.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Magento2/ruleset.xml b/Magento2/ruleset.xml index ee171871..9d472172 100644 --- a/Magento2/ruleset.xml +++ b/Magento2/ruleset.xml @@ -350,7 +350,7 @@ 8 warning - + 7 @@ -579,7 +579,7 @@ warning - + 6 warning From e1621afc0ac1818d03c9e412391166b880acb5cf Mon Sep 17 00:00:00 2001 From: Dan Wallis Date: Tue, 17 Jan 2023 10:28:26 +1300 Subject: [PATCH 2/2] Update codebase for new ruleset with phpcbf --- .../Commenting/PHPDocFormattingValidator.php | 10 +++--- .../TestUtils/UtilityMethodTestCase.php | 3 +- .../Helpers/PHPCSUtils/Utils/Conditions.php | 3 +- .../PHPCSUtils/Utils/FunctionDeclarations.php | 36 ++++++++++++------- .../PHPCSUtils/Utils/ObjectDeclarations.php | 15 +++++--- .../Helpers/PHPCSUtils/Utils/Parentheses.php | 6 ++-- .../Helpers/PHPCSUtils/Utils/TextStrings.php | 3 +- .../PHPCSUtils/Utils/UseStatements.php | 9 +++-- .../Annotation/AnnotationFormatValidator.php | 27 +++++++++----- .../Annotation/MethodArgumentsSniff.php | 21 +++++++---- .../Sniffs/CodeAnalysis/EmptyBlockSniff.php | 12 ++++--- .../ClassPropertyPHPDocFormattingSniff.php | 12 ++++--- .../ConstantsPHPDocFormattingSniff.php | 3 +- .../Sniffs/Exceptions/DirectThrowSniff.php | 6 ++-- Magento2/Sniffs/Html/HtmlBindingSniff.php | 3 +- Magento2/Sniffs/Less/ClassNamingSniff.php | 3 +- Magento2/Sniffs/Less/CommentLevelsSniff.php | 15 +++++--- .../Sniffs/Less/ImportantPropertySniff.php | 3 +- Magento2/Sniffs/Less/IndentationSniff.php | 3 +- .../Sniffs/Less/PropertiesSortingSniff.php | 6 ++-- .../Sniffs/Less/SelectorDelimiterSniff.php | 3 +- .../Sniffs/Less/SemicolonSpacingSniff.php | 3 +- .../Less/TypeSelectorConcatenationSniff.php | 3 +- Magento2/Sniffs/Less/TypeSelectorsSniff.php | 3 +- Magento2/Sniffs/Less/ZeroUnitsSniff.php | 6 ++-- .../ImportsFromTestNamespaceSniff.php | 3 +- ...utogeneratedClassNotInConstructorSniff.php | 6 ++-- .../Sniffs/PHP/LiteralNamespacesSniff.php | 3 +- Magento2/Sniffs/PHP/ReturnValueCheckSniff.php | 3 +- ...llingDestructAfterConstructorExitSniff.php | 12 ++++--- Magento2/Sniffs/SQL/RawQuerySniff.php | 3 +- Magento2/Sniffs/Security/IncludeFileSniff.php | 6 ++-- Magento2/Sniffs/Security/XssTemplateSniff.php | 3 +- .../Sniffs/Strings/ExecutableRegExSniff.php | 3 +- Magento2/Sniffs/Strings/StringConcatSniff.php | 3 +- .../Whitespace/MultipleEmptyLinesSniff.php | 6 ++-- .../CopyrightAnotherExtensionsFilesSniff.php | 3 +- .../Tests/Header/CopyrightGraphQLUnitTest.php | 12 ++++--- 38 files changed, 187 insertions(+), 96 deletions(-) diff --git a/Magento2/Helpers/Commenting/PHPDocFormattingValidator.php b/Magento2/Helpers/Commenting/PHPDocFormattingValidator.php index a87312d5..80ba188a 100644 --- a/Magento2/Helpers/Commenting/PHPDocFormattingValidator.php +++ b/Magento2/Helpers/Commenting/PHPDocFormattingValidator.php @@ -123,10 +123,12 @@ public function hasDeprecatedWellFormatted($commentStartPtr, $tokens) } $seePtr = $this->getTagPosition('@see', $commentStartPtr, $tokens); if ($seePtr === -1) { - if (preg_match( - "/This [a-zA-Z]* will be removed in version \d.\d.\d without replacement/", - $tokens[$deprecatedPtr + 2]['content'] - )) { + if ( + preg_match( + "/This [a-zA-Z]* will be removed in version \d.\d.\d without replacement/", + $tokens[$deprecatedPtr + 2]['content'] + ) + ) { return true; } return false; diff --git a/Magento2/Helpers/PHPCSUtils/TestUtils/UtilityMethodTestCase.php b/Magento2/Helpers/PHPCSUtils/TestUtils/UtilityMethodTestCase.php index 7ffcc1e3..73e306ef 100644 --- a/Magento2/Helpers/PHPCSUtils/TestUtils/UtilityMethodTestCase.php +++ b/Magento2/Helpers/PHPCSUtils/TestUtils/UtilityMethodTestCase.php @@ -331,7 +331,8 @@ public static function resetTestFile() public static function usesPhp8NameTokens() { $version = Helper::getVersion(); - if ((\version_compare(\PHP_VERSION_ID, '80000', '>=') === true + if ( + (\version_compare(\PHP_VERSION_ID, '80000', '>=') === true && \version_compare($version, '3.5.7', '<') === true) || \version_compare($version, '4.0.0', '>=') === true ) { diff --git a/Magento2/Helpers/PHPCSUtils/Utils/Conditions.php b/Magento2/Helpers/PHPCSUtils/Utils/Conditions.php index 4d34ed92..89e262a4 100644 --- a/Magento2/Helpers/PHPCSUtils/Utils/Conditions.php +++ b/Magento2/Helpers/PHPCSUtils/Utils/Conditions.php @@ -86,7 +86,8 @@ public static function getCondition(File $phpcsFile, $stackPtr, $types = [], $fi } foreach ($conditions as $ptr => $type) { - if (isset($tokens[$ptr]) === true + if ( + isset($tokens[$ptr]) === true && \in_array($type, $types, true) === true ) { // We found a token with the required type. diff --git a/Magento2/Helpers/PHPCSUtils/Utils/FunctionDeclarations.php b/Magento2/Helpers/PHPCSUtils/Utils/FunctionDeclarations.php index 94641d48..6a4725f5 100644 --- a/Magento2/Helpers/PHPCSUtils/Utils/FunctionDeclarations.php +++ b/Magento2/Helpers/PHPCSUtils/Utils/FunctionDeclarations.php @@ -81,7 +81,8 @@ public static function getProperties(File $phpcsFile, $stackPtr) $tokens = $phpcsFile->getTokens(); $arrowOpenClose = self::getArrowFunctionOpenClose($phpcsFile, $stackPtr); - if (isset($tokens[$stackPtr]) === false + if ( + isset($tokens[$stackPtr]) === false || ($tokens[$stackPtr]['code'] !== \T_FUNCTION && $tokens[$stackPtr]['code'] !== \T_CLOSURE && $arrowOpenClose === false) @@ -169,7 +170,8 @@ public static function getProperties(File $phpcsFile, $stackPtr) break; } - if ($tokens[$i]['type'] === 'T_NULLABLE' + if ( + $tokens[$i]['type'] === 'T_NULLABLE' // Handle nullable tokens in PHPCS < 2.8.0. || (\defined('T_NULLABLE') === false && $tokens[$i]['code'] === \T_INLINE_THEN) // Handle nullable tokens with arrow functions in PHPCS 2.8.0 - 2.9.0. @@ -242,14 +244,16 @@ public static function getArrowFunctionOpenClose(File $phpcsFile, $stackPtr) { $tokens = $phpcsFile->getTokens(); - if (isset($tokens[$stackPtr]) === false + if ( + isset($tokens[$stackPtr]) === false || isset(Collections::arrowFunctionTokensBC()[$tokens[$stackPtr]['code']]) === false || \strtolower($tokens[$stackPtr]['content']) !== 'fn' ) { return false; } - if ($tokens[$stackPtr]['type'] === 'T_FN' + if ( + $tokens[$stackPtr]['type'] === 'T_FN' && isset($tokens[$stackPtr]['scope_closer']) === true && \version_compare(Helper::getVersion(), '3.5.4', '>') === true ) { @@ -304,7 +308,8 @@ public static function getArrowFunctionOpenClose(File $phpcsFile, $stackPtr) true ); - if ($arrow === false + if ( + $arrow === false || ($tokens[$arrow]['code'] !== \T_DOUBLE_ARROW && $tokens[$arrow]['type'] !== 'T_FN_ARROW') ) { return false; @@ -315,11 +320,13 @@ public static function getArrowFunctionOpenClose(File $phpcsFile, $stackPtr) $lastEndToken = null; for ($scopeCloser = ($arrow + 1); $scopeCloser < $phpcsFile->numTokens; $scopeCloser++) { - if (isset(self::$arrowFunctionEndTokens[$tokens[$scopeCloser]['code']]) === true + if ( + isset(self::$arrowFunctionEndTokens[$tokens[$scopeCloser]['code']]) === true // BC for misidentified ternary else in some PHPCS versions. && ($tokens[$scopeCloser]['code'] !== \T_COLON || $inTernary === false) ) { - if ($lastEndToken !== null + if ( + $lastEndToken !== null && $tokens[$scopeCloser]['code'] === \T_CLOSE_PARENTHESIS && $tokens[$scopeCloser]['parenthesis_opener'] < $arrow ) { @@ -338,7 +345,8 @@ public static function getArrowFunctionOpenClose(File $phpcsFile, $stackPtr) } } - if (isset($tokens[$scopeCloser]['scope_closer']) === true + if ( + isset($tokens[$scopeCloser]['scope_closer']) === true && $tokens[$scopeCloser]['code'] !== \T_INLINE_ELSE && $tokens[$scopeCloser]['code'] !== \T_END_HEREDOC && $tokens[$scopeCloser]['code'] !== \T_END_NOWDOC @@ -488,7 +496,8 @@ public static function getParameters(File $phpcsFile, $stackPtr) $tokens = $phpcsFile->getTokens(); $arrowOpenClose = self::getArrowFunctionOpenClose($phpcsFile, $stackPtr); - if (isset($tokens[$stackPtr]) === false + if ( + isset($tokens[$stackPtr]) === false || ($tokens[$stackPtr]['code'] !== \T_FUNCTION && $tokens[$stackPtr]['code'] !== \T_CLOSURE && $tokens[$stackPtr]['code'] !== \T_USE @@ -500,7 +509,8 @@ public static function getParameters(File $phpcsFile, $stackPtr) if ($tokens[$stackPtr]['code'] === \T_USE) { // This will work PHPCS 3.x/4.x cross-version without much overhead. $opener = $phpcsFile->findNext(Tokens::$emptyTokens, ($stackPtr + 1), null, true); - if ($opener === false + if ( + $opener === false || $tokens[$opener]['code'] !== \T_OPEN_PARENTHESIS || UseStatements::isClosureUse($phpcsFile, $stackPtr) === false ) { @@ -732,13 +742,15 @@ public static function isArrowFunction(File $phpcsFile, $stackPtr) return false; } - if ($tokens[$stackPtr]['type'] === 'T_FN' + if ( + $tokens[$stackPtr]['type'] === 'T_FN' && isset($tokens[$stackPtr]['scope_closer']) === true ) { return true; } - if (isset(Collections::arrowFunctionTokensBC()[$tokens[$stackPtr]['code']]) === false + if ( + isset(Collections::arrowFunctionTokensBC()[$tokens[$stackPtr]['code']]) === false || \strtolower($tokens[$stackPtr]['content']) !== 'fn' ) { return false; diff --git a/Magento2/Helpers/PHPCSUtils/Utils/ObjectDeclarations.php b/Magento2/Helpers/PHPCSUtils/Utils/ObjectDeclarations.php index fdb46adb..f39515ac 100644 --- a/Magento2/Helpers/PHPCSUtils/Utils/ObjectDeclarations.php +++ b/Magento2/Helpers/PHPCSUtils/Utils/ObjectDeclarations.php @@ -68,7 +68,8 @@ public static function getName(File $phpcsFile, $stackPtr) { $tokens = $phpcsFile->getTokens(); - if (isset($tokens[$stackPtr]) === false + if ( + isset($tokens[$stackPtr]) === false || ($tokens[$stackPtr]['code'] === \T_ANON_CLASS || $tokens[$stackPtr]['code'] === \T_CLOSURE) ) { return null; @@ -79,7 +80,8 @@ public static function getName(File $phpcsFile, $stackPtr) /* * BC: Work-around JS ES6 classes not being tokenized as T_CLASS in PHPCS < 3.0.0. */ - if (isset($phpcsFile->tokenizerType) + if ( + isset($phpcsFile->tokenizerType) && $phpcsFile->tokenizerType === 'JS' && $tokenCode === \T_STRING && $tokens[$stackPtr]['content'] === 'class' @@ -87,7 +89,8 @@ public static function getName(File $phpcsFile, $stackPtr) $tokenCode = \T_CLASS; } - if ($tokenCode !== \T_FUNCTION + if ( + $tokenCode !== \T_FUNCTION && $tokenCode !== \T_CLASS && $tokenCode !== \T_INTERFACE && $tokenCode !== \T_TRAIT @@ -97,7 +100,8 @@ public static function getName(File $phpcsFile, $stackPtr) ); } - if ($tokenCode === \T_FUNCTION + if ( + $tokenCode === \T_FUNCTION && \strtolower($tokens[$stackPtr]['content']) !== 'function' ) { // This is a function declared without the "function" keyword. @@ -323,7 +327,8 @@ private static function findNames(File $phpcsFile, $stackPtr, $keyword, $allowed { $tokens = $phpcsFile->getTokens(); - if (isset($tokens[$stackPtr]) === false + if ( + isset($tokens[$stackPtr]) === false || isset($allowedFor[$tokens[$stackPtr]['code']]) === false || isset($tokens[$stackPtr]['scope_opener']) === false ) { diff --git a/Magento2/Helpers/PHPCSUtils/Utils/Parentheses.php b/Magento2/Helpers/PHPCSUtils/Utils/Parentheses.php index 26ba1fd2..5b3d8729 100644 --- a/Magento2/Helpers/PHPCSUtils/Utils/Parentheses.php +++ b/Magento2/Helpers/PHPCSUtils/Utils/Parentheses.php @@ -82,7 +82,8 @@ public static function getOwner(File $phpcsFile, $stackPtr) * {@internal As the 'parenthesis_owner' index is only set on parentheses, we didn't need to do any * input validation before, but now we do.} */ - if (isset($tokens[$stackPtr]) === false + if ( + isset($tokens[$stackPtr]) === false || ($tokens[$stackPtr]['code'] !== \T_OPEN_PARENTHESIS && $tokens[$stackPtr]['code'] !== \T_CLOSE_PARENTHESIS) ) { @@ -97,7 +98,8 @@ public static function getOwner(File $phpcsFile, $stackPtr) $skip[\T_BITWISE_AND] = \T_BITWISE_AND; $prevNonEmpty = $phpcsFile->findPrevious($skip, ($stackPtr - 1), null, true); - if ($prevNonEmpty !== false + if ( + $prevNonEmpty !== false && (isset(self::$extraParenthesesOwners[$tokens[$prevNonEmpty]['code']]) // Possibly an arrow function. || FunctionDeclarations::isArrowFunction($phpcsFile, $prevNonEmpty) === true) diff --git a/Magento2/Helpers/PHPCSUtils/Utils/TextStrings.php b/Magento2/Helpers/PHPCSUtils/Utils/TextStrings.php index aca9ce09..72ab8804 100644 --- a/Magento2/Helpers/PHPCSUtils/Utils/TextStrings.php +++ b/Magento2/Helpers/PHPCSUtils/Utils/TextStrings.php @@ -62,7 +62,8 @@ public static function getCompleteTextString(File $phpcsFile, $stackPtr, $stripQ ); } - if ($tokens[$stackPtr]['code'] === \T_CONSTANT_ENCAPSED_STRING + if ( + $tokens[$stackPtr]['code'] === \T_CONSTANT_ENCAPSED_STRING || $tokens[$stackPtr]['code'] === \T_DOUBLE_QUOTED_STRING ) { $prev = $phpcsFile->findPrevious(\T_WHITESPACE, ($stackPtr - 1), null, true); diff --git a/Magento2/Helpers/PHPCSUtils/Utils/UseStatements.php b/Magento2/Helpers/PHPCSUtils/Utils/UseStatements.php index 5e965d33..37e5c111 100644 --- a/Magento2/Helpers/PHPCSUtils/Utils/UseStatements.php +++ b/Magento2/Helpers/PHPCSUtils/Utils/UseStatements.php @@ -46,7 +46,8 @@ public static function getType(File $phpcsFile, $stackPtr) { $tokens = $phpcsFile->getTokens(); - if (isset($tokens[$stackPtr]) === false + if ( + isset($tokens[$stackPtr]) === false || $tokens[$stackPtr]['code'] !== \T_USE ) { throw new RuntimeException('$stackPtr must be of type T_USE'); @@ -59,7 +60,8 @@ public static function getType(File $phpcsFile, $stackPtr) } $prev = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($stackPtr - 1), null, true); - if ($prev !== false && $tokens[$prev]['code'] === \T_CLOSE_PARENTHESIS + if ( + $prev !== false && $tokens[$prev]['code'] === \T_CLOSE_PARENTHESIS && Parentheses::isOwnerIn($phpcsFile, $prev, \T_CLOSURE) === true ) { return 'closure'; @@ -245,7 +247,8 @@ public static function splitImportUseStatement(File $phpcsFile, $stackPtr) // Only when either at the start of the statement or at the start of a new sub within a group. if ($start === true && $fixedType === false) { $content = \strtolower($tokens[$i]['content']); - if ($content === 'function' + if ( + $content === 'function' || $content === 'const' ) { $type = $content; diff --git a/Magento2/Sniffs/Annotation/AnnotationFormatValidator.php b/Magento2/Sniffs/Annotation/AnnotationFormatValidator.php index b69d2ad6..2666d5d9 100644 --- a/Magento2/Sniffs/Annotation/AnnotationFormatValidator.php +++ b/Magento2/Sniffs/Annotation/AnnotationFormatValidator.php @@ -57,7 +57,8 @@ private function validateMultiLinesInShortDescription( $commentEndPtr ); $shortPtrEndContent = $tokens[$shortPtrEnd]['content']; - if (preg_match('/^[a-z]/', $shortPtrEndContent) + if ( + preg_match('/^[a-z]/', $shortPtrEndContent) && $shortPtrEnd != $shortPtr && !preg_match('/\bSee\b/', $shortPtrEndContent) && $tokens[$shortPtr]['line'] + 1 === $tokens[$shortPtrEnd]['line'] @@ -89,7 +90,8 @@ private function validateSpacingBetweenShortAndLongDescriptions( $commentEndPtr ); $shortPtrEndContent = $tokens[$shortPtrEnd]['content']; - if (preg_match('/^[A-Z]/', $shortPtrEndContent) + if ( + preg_match('/^[A-Z]/', $shortPtrEndContent) && !preg_match('/\bSee\b/', $shortPtrEndContent) && $tokens[$shortPtr]['line'] + 1 === $tokens[$shortPtrEnd]['line'] && $tokens[$shortPtrEnd]['code'] !== T_DOC_COMMENT_TAG @@ -199,7 +201,8 @@ public function validateTagsSpacingFormat(File $phpcsFile, int $commentStartPtr, $firstTagPtr = $tokens[$commentStartPtr]['comment_tags'][0]; $commentTagPtrContent = $tokens[$firstTagPtr]['content']; $prevPtr = $phpcsFile->findPrevious($emptyTypeTokens, $firstTagPtr - 1, $commentStartPtr, true); - if ($tokens[$firstTagPtr]['line'] !== $tokens[$prevPtr]['line'] + 2 + if ( + $tokens[$firstTagPtr]['line'] !== $tokens[$prevPtr]['line'] + 2 && strtolower($commentTagPtrContent) !== '@inheritdoc' ) { $error = 'There must be exactly one blank line before tags'; @@ -237,8 +240,10 @@ public function validateTagGroupingFormat(File $phpcsFile, int $commentStartPtr) } if (strtolower($tokens[$tag]['content']) === '@param') { - if ($paramGroupId !== null - && $paramGroupId !== $groupId) { + if ( + $paramGroupId !== null + && $paramGroupId !== $groupId + ) { $error = 'Parameter tags must be grouped together'; $phpcsFile->addError($error, $tag, 'MethodAnnotation'); } @@ -271,8 +276,10 @@ public function validateTagAligningFormat(File $phpcsFile, int $commentStartPtr) } } - if (!$this->allTagsAligned($actualPositions) - && !$this->noneTagsAligned($actualPositions, $noAlignmentPositions)) { + if ( + !$this->allTagsAligned($actualPositions) + && !$this->noneTagsAligned($actualPositions, $noAlignmentPositions) + ) { $phpcsFile->addError( 'Tags visual alignment must be consistent', $stackPtr, @@ -343,11 +350,13 @@ public function validateDescriptionFormatStructure( array $emptyTypeTokens ): void { $tokens = $phpcsFile->getTokens(); - if (isset($tokens[$commentStartPtr]['comment_tags'][0]) + if ( + isset($tokens[$commentStartPtr]['comment_tags'][0]) ) { $commentTagPtr = $tokens[$commentStartPtr]['comment_tags'][0]; $commentTagPtrContent = $tokens[$commentTagPtr]['content']; - if ($tokens[$shortPtr]['code'] !== T_DOC_COMMENT_STRING + if ( + $tokens[$shortPtr]['code'] !== T_DOC_COMMENT_STRING && strtolower($commentTagPtrContent) !== '@inheritdoc' ) { $error = 'Missing short description'; diff --git a/Magento2/Sniffs/Annotation/MethodArgumentsSniff.php b/Magento2/Sniffs/Annotation/MethodArgumentsSniff.php index 27ac0dfd..f219c64a 100644 --- a/Magento2/Sniffs/Annotation/MethodArgumentsSniff.php +++ b/Magento2/Sniffs/Annotation/MethodArgumentsSniff.php @@ -246,7 +246,8 @@ private function validateParameterAnnotationForArgumentExists( $stackPtr, 'InheritDoc' ); - } elseif ($this->validateCommentBlockExists($phpcsFile, $previousCommentClosePtr, $stackPtr) + } elseif ( + $this->validateCommentBlockExists($phpcsFile, $previousCommentClosePtr, $stackPtr) && !$inheritdocAnnotationWithoutBracesExists ) { $phpcsFile->addError( @@ -352,7 +353,8 @@ private function validateParameterOrderIsCorrect( $parameterNames = $this->getMethodParameters($paramDefinitions); $paramDefinitionsCount = count($paramDefinitions); for ($ptr = 0; $ptr < $paramDefinitionsCount; $ptr++) { - if (isset($methodArguments[$ptr]) && isset($parameterNames[$ptr]) + if ( + isset($methodArguments[$ptr]) && isset($parameterNames[$ptr]) && in_array($methodArguments[$ptr], $parameterNames) ) { if ($methodArguments[$ptr] != $parameterNames[$ptr]) { @@ -390,7 +392,8 @@ private function validateDuplicateAnnotationDoesnotExists( if (isset($paramDefinition['paramName'])) { $parameterContent = $paramDefinition['paramName']; foreach (array_slice($paramDefinitions, $i + 1) as $nextParamDefinition) { - if (isset($nextParamDefinition['paramName']) + if ( + isset($nextParamDefinition['paramName']) && $parameterContent === $nextParamDefinition['paramName'] ) { $duplicateParameters[] = $parameterContent; @@ -647,8 +650,10 @@ private function validateFormattingConsistency( ? strrpos($paramContent, $paramDefinition['comment']) : null; } } - if (!$this->allParamsAligned($argumentPositions, $commentPositions) - && !$this->noneParamsAligned($argumentPositions, $commentPositions, $paramDefinitions)) { + if ( + !$this->allParamsAligned($argumentPositions, $commentPositions) + && !$this->noneParamsAligned($argumentPositions, $commentPositions, $paramDefinitions) + ) { $phpcsFile->addError( 'Method arguments visual alignment must be consistent', $paramPointers[0], @@ -688,8 +693,10 @@ private function noneParamsAligned(array $argumentPositions, array $commentPosit continue; } $paramName = $paramDefinitions[$index]['paramName']; - if (($argumentPosition !== strlen($type) + 1) || - (isset($commentPosition) && ($commentPosition !== $argumentPosition + strlen($paramName) + 1))) { + if ( + ($argumentPosition !== strlen($type) + 1) || + (isset($commentPosition) && ($commentPosition !== $argumentPosition + strlen($paramName) + 1)) + ) { $flag = false; break; } diff --git a/Magento2/Sniffs/CodeAnalysis/EmptyBlockSniff.php b/Magento2/Sniffs/CodeAnalysis/EmptyBlockSniff.php index 87c60a62..233da43f 100644 --- a/Magento2/Sniffs/CodeAnalysis/EmptyBlockSniff.php +++ b/Magento2/Sniffs/CodeAnalysis/EmptyBlockSniff.php @@ -32,18 +32,22 @@ public function register() public function process(File $phpcsFile, $stackPtr) { $tokens = $phpcsFile->getTokens(); - if ($tokens[$stackPtr]['code'] === T_FUNCTION && - strpos($phpcsFile->getDeclarationName($stackPtr), 'around') === 0) { + if ( + $tokens[$stackPtr]['code'] === T_FUNCTION && + strpos($phpcsFile->getDeclarationName($stackPtr), 'around') === 0 + ) { return; } // Ignore empty constructor function blocks when using property promotion - if ($tokens[$stackPtr]['code'] === T_FUNCTION && + if ( + $tokens[$stackPtr]['code'] === T_FUNCTION && strpos($phpcsFile->getDeclarationName($stackPtr), '__construct') === 0 && count($phpcsFile->getMethodParameters($stackPtr)) > 0 && array_reduce($phpcsFile->getMethodParameters($stackPtr), static function ($result, $methodParam) { return $result && isset($methodParam['property_visibility']); - }, true)) { + }, true) + ) { return; } diff --git a/Magento2/Sniffs/Commenting/ClassPropertyPHPDocFormattingSniff.php b/Magento2/Sniffs/Commenting/ClassPropertyPHPDocFormattingSniff.php index 3732e2ac..61aa29d2 100644 --- a/Magento2/Sniffs/Commenting/ClassPropertyPHPDocFormattingSniff.php +++ b/Magento2/Sniffs/Commenting/ClassPropertyPHPDocFormattingSniff.php @@ -122,11 +122,13 @@ public function processMemberVar(File $phpcsFile, $stackPtr) false ); - if ($this->PHPDocFormattingValidator->providesMeaning( - $shortDescriptionAfterVarPosition, - $commentStart, - $tokens - ) !== true) { + if ( + $this->PHPDocFormattingValidator->providesMeaning( + $shortDescriptionAfterVarPosition, + $commentStart, + $tokens + ) !== true + ) { preg_match( '`^((?:\|?(?:array\([^\)]*\)|[\\\\\[\]]+))*)( .*)?`i', $tokens[($varAnnotationPosition + 2)]['content'], diff --git a/Magento2/Sniffs/Commenting/ConstantsPHPDocFormattingSniff.php b/Magento2/Sniffs/Commenting/ConstantsPHPDocFormattingSniff.php index 5d715af5..5425e4b8 100644 --- a/Magento2/Sniffs/Commenting/ConstantsPHPDocFormattingSniff.php +++ b/Magento2/Sniffs/Commenting/ConstantsPHPDocFormattingSniff.php @@ -45,7 +45,8 @@ public function process(File $phpcsFile, $stackPtr) { $tokens = $phpcsFile->getTokens(); - if ($tokens[$stackPtr]['code'] !== T_CONST + if ( + $tokens[$stackPtr]['code'] !== T_CONST && !($tokens[$stackPtr]['content'] === 'define' && $tokens[$stackPtr + 1]['code'] === T_OPEN_PARENTHESIS) ) { return; diff --git a/Magento2/Sniffs/Exceptions/DirectThrowSniff.php b/Magento2/Sniffs/Exceptions/DirectThrowSniff.php index 576d2066..1e284e51 100644 --- a/Magento2/Sniffs/Exceptions/DirectThrowSniff.php +++ b/Magento2/Sniffs/Exceptions/DirectThrowSniff.php @@ -56,7 +56,8 @@ public function process(File $phpcsFile, $stackPtr) $useStatementValue = $this->getFullClassNameAndAlias($tokens, $key, $endOfUse); //we safely consider use statement has alias will not be a direct exception class if (empty($useStatementValue['alias'])) { - if (substr($useStatementValue['name'], 0, strlen($exceptionString)) !== $exceptionString + if ( + substr($useStatementValue['name'], 0, strlen($exceptionString)) !== $exceptionString && substr($useStatementValue['name'], -strlen($exceptionString)) === $exceptionString && $useStatementValue['name'] !== $exceptionString ) { @@ -65,7 +66,8 @@ public function process(File $phpcsFile, $stackPtr) } } } - if (($tokens[$posOfException]['content'] === 'Exception' && !$customExceptionFound) + if ( + ($tokens[$posOfException]['content'] === 'Exception' && !$customExceptionFound) || $fullExceptionString['name'] === '\Exception' ) { $phpcsFile->addWarning( diff --git a/Magento2/Sniffs/Html/HtmlBindingSniff.php b/Magento2/Sniffs/Html/HtmlBindingSniff.php index cf498da1..ce3701cb 100644 --- a/Magento2/Sniffs/Html/HtmlBindingSniff.php +++ b/Magento2/Sniffs/Html/HtmlBindingSniff.php @@ -75,7 +75,8 @@ public function process(File $phpcsFile, $stackPtr) $htmlBindings[] = trim($magentoBinding); } foreach ($htmlBindings as $htmlBinding) { - if (!preg_match('/^[0-9\\\'\"]/ims', $htmlBinding) + if ( + !preg_match('/^[0-9\\\'\"]/ims', $htmlBinding) && !preg_match('/UnsanitizedHtml(\(.*?\))*?$/', $htmlBinding) ) { $phpcsFile->addError( diff --git a/Magento2/Sniffs/Less/ClassNamingSniff.php b/Magento2/Sniffs/Less/ClassNamingSniff.php index e684172b..115fdc3f 100644 --- a/Magento2/Sniffs/Less/ClassNamingSniff.php +++ b/Magento2/Sniffs/Less/ClassNamingSniff.php @@ -45,7 +45,8 @@ public function process(File $phpcsFile, $stackPtr) { $tokens = $phpcsFile->getTokens(); - if (T_WHITESPACE !== $tokens[$stackPtr - 1]['code'] + if ( + T_WHITESPACE !== $tokens[$stackPtr - 1]['code'] && !in_array( $tokens[$stackPtr - 1]['content'], [ diff --git a/Magento2/Sniffs/Less/CommentLevelsSniff.php b/Magento2/Sniffs/Less/CommentLevelsSniff.php index be7c93c9..82cd6afc 100644 --- a/Magento2/Sniffs/Less/CommentLevelsSniff.php +++ b/Magento2/Sniffs/Less/CommentLevelsSniff.php @@ -55,7 +55,8 @@ public function process(File $phpcsFile, $stackPtr) { $tokens = $phpcsFile->getTokens(); - if ((T_STRING !== $tokens[$stackPtr]['code']) + if ( + (T_STRING !== $tokens[$stackPtr]['code']) || (self::COMMENT_STRING !== $tokens[$stackPtr]['content']) || (1 === $tokens[$stackPtr]['line']) ) { @@ -65,7 +66,8 @@ public function process(File $phpcsFile, $stackPtr) $textInSameLine = $phpcsFile->findPrevious([T_STRING, T_STYLE], $stackPtr - 1); // is inline comment - if ((false !== $textInSameLine) + if ( + (false !== $textInSameLine) && ($tokens[$textInSameLine]['line'] === $tokens[$stackPtr]['line']) ) { $this->validateInlineComment($phpcsFile, $stackPtr, $tokens); @@ -164,7 +166,8 @@ private function checkNthLevelComment(File $phpcsFile, $stackPtr, array $tokens) return $correct; } - if (($tokens[$nextLine]['content'] !== TokenizerSymbolsInterface::NEW_LINE) + if ( + ($tokens[$nextLine]['content'] !== TokenizerSymbolsInterface::NEW_LINE) || ($tokens[$nextLine + 1]['content'] !== TokenizerSymbolsInterface::NEW_LINE) ) { return $correct; @@ -178,7 +181,8 @@ private function checkNthLevelComment(File $phpcsFile, $stackPtr, array $tokens) continue; } - if (($tokens[$commentLinePtr - 1]['content'] === TokenizerSymbolsInterface::NEW_LINE) + if ( + ($tokens[$commentLinePtr - 1]['content'] === TokenizerSymbolsInterface::NEW_LINE) && ($tokens[$commentLinePtr - 2]['content'] === TokenizerSymbolsInterface::NEW_LINE) ) { $correct = true; @@ -198,7 +202,8 @@ private function checkNthLevelComment(File $phpcsFile, $stackPtr, array $tokens) */ private function validateCommentLevel(File $phpcsFile, int $stackPtr, array $tokens): void { - if ($tokens[$stackPtr + 2]['content'] !== 'magento_import' && + if ( + $tokens[$stackPtr + 2]['content'] !== 'magento_import' && !in_array( $tokens[$stackPtr + 1]['content'], [ diff --git a/Magento2/Sniffs/Less/ImportantPropertySniff.php b/Magento2/Sniffs/Less/ImportantPropertySniff.php index ad1fd10c..f39b7918 100644 --- a/Magento2/Sniffs/Less/ImportantPropertySniff.php +++ b/Magento2/Sniffs/Less/ImportantPropertySniff.php @@ -42,7 +42,8 @@ public function process(File $phpcsFile, $stackPtr) // Will be implemented in MAGETWO-49778 //$phpcsFile->addWarning('!important is used', $stackPtr, '!ImportantIsUsed'); - if (($tokens[$stackPtr + 1]['content'] === 'important') + if ( + ($tokens[$stackPtr + 1]['content'] === 'important') && ($tokens[$stackPtr - 1]['content'] !== TokenizerSymbolsInterface::WHITESPACE) ) { $phpcsFile->addError('Space before !important is missing', $stackPtr, 'NoSpace'); diff --git a/Magento2/Sniffs/Less/IndentationSniff.php b/Magento2/Sniffs/Less/IndentationSniff.php index 57947a07..0f5c755d 100644 --- a/Magento2/Sniffs/Less/IndentationSniff.php +++ b/Magento2/Sniffs/Less/IndentationSniff.php @@ -88,7 +88,8 @@ public function process(File $phpcsFile, $stackPtr) } $expectedIndent = ($indentLevel * $this->indent); - if (!($expectedIndent > 0 && strpos($tokens[$i]['content'], $phpcsFile->eolChar) !== false) + if ( + !($expectedIndent > 0 && strpos($tokens[$i]['content'], $phpcsFile->eolChar) !== false) && ($foundIndent !== $expectedIndent) && (!in_array($tokens[$i + 1]['code'], $this->styleCodesToSkip)) ) { diff --git a/Magento2/Sniffs/Less/PropertiesSortingSniff.php b/Magento2/Sniffs/Less/PropertiesSortingSniff.php index 2c5fe9e5..838fa63b 100644 --- a/Magento2/Sniffs/Less/PropertiesSortingSniff.php +++ b/Magento2/Sniffs/Less/PropertiesSortingSniff.php @@ -60,14 +60,16 @@ public function process(File $phpcsFile, $stackPtr) $currentToken = $tokens[$stackPtr]; // if variables, mixins, extends area used - skip - if ((T_ASPERAND === $tokens[$stackPtr - 1]['code']) + if ( + (T_ASPERAND === $tokens[$stackPtr - 1]['code']) || in_array($tokens[$stackPtr]['content'], $this->styleSymbolsToSkip) ) { return; } $nextCurlyBracket = $phpcsFile->findNext(T_OPEN_CURLY_BRACKET, $stackPtr + 1); - if (in_array($currentToken['code'], [T_OPEN_CURLY_BRACKET, T_CLOSE_CURLY_BRACKET]) + if ( + in_array($currentToken['code'], [T_OPEN_CURLY_BRACKET, T_CLOSE_CURLY_BRACKET]) || ((false !== $nextCurlyBracket) && ($tokens[$nextCurlyBracket]['line'] === $tokens[$stackPtr]['line'])) ) { if ($this->properties) { diff --git a/Magento2/Sniffs/Less/SelectorDelimiterSniff.php b/Magento2/Sniffs/Less/SelectorDelimiterSniff.php index cdbd5117..8ef7982a 100644 --- a/Magento2/Sniffs/Less/SelectorDelimiterSniff.php +++ b/Magento2/Sniffs/Less/SelectorDelimiterSniff.php @@ -76,7 +76,8 @@ private function validateParenthesis(File $phpcsFile, $stackPtr, array $tokens) $prevParenthesis = $phpcsFile->findPrevious(T_OPEN_PARENTHESIS, $stackPtr); $nextParenthesis = $phpcsFile->findNext(T_OPEN_PARENTHESIS, $stackPtr); - if ((false !== $prevParenthesis) && (false !== $nextParenthesis) + if ( + (false !== $prevParenthesis) && (false !== $nextParenthesis) && ($tokens[$prevParenthesis]['line'] === $tokens[$stackPtr]['line']) && ($tokens[$nextParenthesis]['line'] === $tokens[$stackPtr]['line']) ) { diff --git a/Magento2/Sniffs/Less/SemicolonSpacingSniff.php b/Magento2/Sniffs/Less/SemicolonSpacingSniff.php index 16783481..b588f5a5 100644 --- a/Magento2/Sniffs/Less/SemicolonSpacingSniff.php +++ b/Magento2/Sniffs/Less/SemicolonSpacingSniff.php @@ -78,7 +78,8 @@ public function process(File $phpcsFile, $stackPtr) */ private function validateSemicolon(File $phpcsFile, $stackPtr, array $tokens, $semicolonPtr) { - if ((false === $semicolonPtr || $tokens[$semicolonPtr]['line'] !== $tokens[$stackPtr]['line']) + if ( + (false === $semicolonPtr || $tokens[$semicolonPtr]['line'] !== $tokens[$stackPtr]['line']) && (isset($tokens[$stackPtr - 1]) && !in_array($tokens[$stackPtr - 1]['code'], $this->styleCodesToSkip)) && (T_COLON !== $tokens[$stackPtr]['code']) ) { diff --git a/Magento2/Sniffs/Less/TypeSelectorConcatenationSniff.php b/Magento2/Sniffs/Less/TypeSelectorConcatenationSniff.php index 5b42c9b2..d7b133c8 100644 --- a/Magento2/Sniffs/Less/TypeSelectorConcatenationSniff.php +++ b/Magento2/Sniffs/Less/TypeSelectorConcatenationSniff.php @@ -47,7 +47,8 @@ public function process(File $phpcsFile, $stackPtr) { $tokens = $phpcsFile->getTokens(); - if (0 === strpos($tokens[$stackPtr + 1]['content'], '-') + if ( + 0 === strpos($tokens[$stackPtr + 1]['content'], '-') && in_array($tokens[$stackPtr - 1]['content'], $this->symbolsBeforeConcat) ) { $phpcsFile->addError('Concatenation is used', $stackPtr, 'ConcatenationUsage'); diff --git a/Magento2/Sniffs/Less/TypeSelectorsSniff.php b/Magento2/Sniffs/Less/TypeSelectorsSniff.php index 4735c761..a3d913cf 100644 --- a/Magento2/Sniffs/Less/TypeSelectorsSniff.php +++ b/Magento2/Sniffs/Less/TypeSelectorsSniff.php @@ -80,7 +80,8 @@ public function process(File $phpcsFile, $stackPtr) } // phpcs:ignore Magento2.CodeAnalysis.EmptyBlock - if ((T_STRING === $tokens[$stackPtr - 1]['code']) + if ( + (T_STRING === $tokens[$stackPtr - 1]['code']) && in_array($tokens[$stackPtr - 1]['content'], $this->tags) ) { // Will be implemented in MAGETWO-49778 diff --git a/Magento2/Sniffs/Less/ZeroUnitsSniff.php b/Magento2/Sniffs/Less/ZeroUnitsSniff.php index 7117bdb8..c3e25612 100644 --- a/Magento2/Sniffs/Less/ZeroUnitsSniff.php +++ b/Magento2/Sniffs/Less/ZeroUnitsSniff.php @@ -58,7 +58,8 @@ public function process(File $phpcsFile, $stackPtr) $nextToken = $tokens[$stackPtr + 1]; - if (T_LNUMBER === $tokenCode + if ( + T_LNUMBER === $tokenCode && "0" === $tokenContent && T_STRING === $nextToken['code'] && in_array($nextToken['content'], $this->units) @@ -66,7 +67,8 @@ public function process(File $phpcsFile, $stackPtr) $phpcsFile->addError('Units specified for "0" value', $stackPtr, 'ZeroUnitFound'); } - if ((T_DNUMBER === $tokenCode) + if ( + (T_DNUMBER === $tokenCode) && 0 === strpos($tokenContent, "0") && ((float)$tokenContent < 1) ) { diff --git a/Magento2/Sniffs/Namespaces/ImportsFromTestNamespaceSniff.php b/Magento2/Sniffs/Namespaces/ImportsFromTestNamespaceSniff.php index 765631d4..dffed3ba 100644 --- a/Magento2/Sniffs/Namespaces/ImportsFromTestNamespaceSniff.php +++ b/Magento2/Sniffs/Namespaces/ImportsFromTestNamespaceSniff.php @@ -48,7 +48,8 @@ public function process(File $phpcsFile, $stackPtr) if (strpos($getTokenAsContent, $this->prohibitNamespace) !== false) { $phpcsFile->addWarning($this->warningMessage, $stackPtr, $this->warningCode); } - if ($next !== false + if ( + $next !== false && $tokens[$next]['code'] !== T_SEMICOLON && $tokens[$next]['code'] !== T_CLOSE_TAG ) { diff --git a/Magento2/Sniffs/PHP/AutogeneratedClassNotInConstructorSniff.php b/Magento2/Sniffs/PHP/AutogeneratedClassNotInConstructorSniff.php index 6b074a2e..66a0e62f 100644 --- a/Magento2/Sniffs/PHP/AutogeneratedClassNotInConstructorSniff.php +++ b/Magento2/Sniffs/PHP/AutogeneratedClassNotInConstructorSniff.php @@ -40,7 +40,8 @@ public function process(File $phpcsFile, $stackPtr) $tokens = $phpcsFile->getTokens(); - if ($tokens[$stackPtr - 1]['content'] !== 'ObjectManager' + if ( + $tokens[$stackPtr - 1]['content'] !== 'ObjectManager' && $tokens[$stackPtr + 1]['content'] !== 'getInstance' ) { return; @@ -79,7 +80,8 @@ private function validateRequestedClass(File $phpcsFile, int $arrowPosition): vo { $requestedClass = $this->getRequestedClass($phpcsFile, $arrowPosition); - if (!$requestedClass + if ( + !$requestedClass || !$this->isClassAutogenerated($requestedClass) || $this->isConstructorParameter($phpcsFile, $requestedClass) ) { diff --git a/Magento2/Sniffs/PHP/LiteralNamespacesSniff.php b/Magento2/Sniffs/PHP/LiteralNamespacesSniff.php index d76dae3e..40547941 100644 --- a/Magento2/Sniffs/PHP/LiteralNamespacesSniff.php +++ b/Magento2/Sniffs/PHP/LiteralNamespacesSniff.php @@ -40,7 +40,8 @@ public function register() public function process(File $phpcsFile, $stackPtr) { $tokens = $phpcsFile->getTokens(); - if ($phpcsFile->findPrevious(T_STRING_CONCAT, $stackPtr, $stackPtr - 3) || + if ( + $phpcsFile->findPrevious(T_STRING_CONCAT, $stackPtr, $stackPtr - 3) || $phpcsFile->findNext(T_STRING_CONCAT, $stackPtr, $stackPtr + 3) ) { return; diff --git a/Magento2/Sniffs/PHP/ReturnValueCheckSniff.php b/Magento2/Sniffs/PHP/ReturnValueCheckSniff.php index 9929d46b..04447ede 100644 --- a/Magento2/Sniffs/PHP/ReturnValueCheckSniff.php +++ b/Magento2/Sniffs/PHP/ReturnValueCheckSniff.php @@ -120,7 +120,8 @@ public function process(File $phpcsFile, $stackPtr) $this->leftLimit = $open = $this->tokens[$stackPtr]['parenthesis_opener']; $this->rightLimit = $close = $this->tokens[$stackPtr]['parenthesis_closer']; for ($i = ($open + 1); $i < $close; $i++) { - if (($this->tokens[$i]['code'] === T_STRING && in_array($this->tokens[$i]['content'], $this->functions)) + if ( + ($this->tokens[$i]['code'] === T_STRING && in_array($this->tokens[$i]['content'], $this->functions)) && (!$this->findIdentical($i - 1, $this->findFunctionParenthesisCloser($i) + 1)) ) { $foundFunctionName = $this->tokens[$i]['content']; diff --git a/Magento2/Sniffs/PHPCompatibility/RemovedCallingDestructAfterConstructorExitSniff.php b/Magento2/Sniffs/PHPCompatibility/RemovedCallingDestructAfterConstructorExitSniff.php index 8782039d..3f868496 100644 --- a/Magento2/Sniffs/PHPCompatibility/RemovedCallingDestructAfterConstructorExitSniff.php +++ b/Magento2/Sniffs/PHPCompatibility/RemovedCallingDestructAfterConstructorExitSniff.php @@ -100,7 +100,8 @@ public function process(File $phpcsFile, $stackPtr) // Skip over nested closed scopes as possible for efficiency. // Ignore arrow functions as they aren't closed scopes. - if (isset(Collections::$closedScopes[$tokens[$current]['code']]) === true + if ( + isset(Collections::$closedScopes[$tokens[$current]['code']]) === true && isset($tokens[$current]['scope_closer']) === true ) { $current = $tokens[$current]['scope_closer']; @@ -108,7 +109,8 @@ public function process(File $phpcsFile, $stackPtr) } // Skip over array access and short arrays/lists, but not control structures. - if (isset($tokens[$current]['bracket_closer']) === true + if ( + isset($tokens[$current]['bracket_closer']) === true && isset($tokens[$current]['scope_closer']) === false ) { $current = $tokens[$current]['bracket_closer']; @@ -116,7 +118,8 @@ public function process(File $phpcsFile, $stackPtr) } // Skip over long array/lists as they can't contain an exit statement, except within a closed scope. - if (($tokens[$current]['code'] === \T_ARRAY || $tokens[$current]['code'] === \T_LIST) + if ( + ($tokens[$current]['code'] === \T_ARRAY || $tokens[$current]['code'] === \T_LIST) && isset($tokens[$current]['parenthesis_closer']) === true ) { $current = $tokens[$current]['parenthesis_closer']; @@ -148,7 +151,8 @@ public function process(File $phpcsFile, $stackPtr) continue; } - if ($tokens[$nextFunc]['code'] === \T_USE + if ( + $tokens[$nextFunc]['code'] === \T_USE && UseStatements::isTraitUse($phpcsFile, $nextFunc) === true ) { $usesTraits = true; diff --git a/Magento2/Sniffs/SQL/RawQuerySniff.php b/Magento2/Sniffs/SQL/RawQuerySniff.php index a32d4eb0..cf4d1c70 100644 --- a/Magento2/Sniffs/SQL/RawQuerySniff.php +++ b/Magento2/Sniffs/SQL/RawQuerySniff.php @@ -64,7 +64,8 @@ public function process(File $phpcsFile, $stackPtr) $tokens = $phpcsFile->getTokens(); $ignoredTokens = array_merge([T_WHITESPACE, T_OPEN_PARENTHESIS], Tokens::$stringTokens); $prev = $tokens[$phpcsFile->findPrevious($ignoredTokens, $stackPtr - 1, null, true)]; - if ($prev['code'] === T_EQUAL + if ( + $prev['code'] === T_EQUAL || ($prev['code'] === T_STRING && in_array($prev['content'], $this->queryFunctions)) || in_array($tokens[$stackPtr]['code'], [T_HEREDOC, T_NOWDOC]) ) { diff --git a/Magento2/Sniffs/Security/IncludeFileSniff.php b/Magento2/Sniffs/Security/IncludeFileSniff.php index 567f3224..7106c7ab 100644 --- a/Magento2/Sniffs/Security/IncludeFileSniff.php +++ b/Magento2/Sniffs/Security/IncludeFileSniff.php @@ -56,8 +56,10 @@ public function process(File $phpcsFile, $stackPtr) $isUrl = false; $hasVariable = false; $includePath = ''; - while ($tokens[$nextToken]['code'] !== T_SEMICOLON && - $tokens[$nextToken]['code'] !== T_CLOSE_TAG) { + while ( + $tokens[$nextToken]['code'] !== T_SEMICOLON && + $tokens[$nextToken]['code'] !== T_CLOSE_TAG + ) { switch ($tokens[$nextToken]['code']) { case T_CONSTANT_ENCAPSED_STRING: $includePath = trim($tokens[$nextToken]['content'], '"\''); diff --git a/Magento2/Sniffs/Security/XssTemplateSniff.php b/Magento2/Sniffs/Security/XssTemplateSniff.php index 3b4385e8..d9ee9553 100644 --- a/Magento2/Sniffs/Security/XssTemplateSniff.php +++ b/Magento2/Sniffs/Security/XssTemplateSniff.php @@ -216,7 +216,8 @@ private function detectUnescapedString($statement) break; } $posOfMethod = $this->file->findNext([T_STRING, T_VARIABLE], $posOfObjOperator + 1, $statement['end']); - if ($this->tokens[$posOfMethod]['code'] === T_STRING && + if ( + $this->tokens[$posOfMethod]['code'] === T_STRING && (in_array($this->tokens[$posOfMethod]['content'], $this->allowedMethods) || stripos($this->tokens[$posOfMethod]['content'], $this->methodNameContains) !== false) ) { diff --git a/Magento2/Sniffs/Strings/ExecutableRegExSniff.php b/Magento2/Sniffs/Strings/ExecutableRegExSniff.php index 09706ed6..179356eb 100644 --- a/Magento2/Sniffs/Strings/ExecutableRegExSniff.php +++ b/Magento2/Sniffs/Strings/ExecutableRegExSniff.php @@ -73,7 +73,8 @@ public function process(File $phpcsFile, $stackPtr) return; } $nextToken = $phpcsFile->findNext([T_WHITESPACE, T_OPEN_PARENTHESIS], $stackPtr + 1, null, true); - if (in_array($tokens[$nextToken]['code'], Tokens::$stringTokens) + if ( + in_array($tokens[$nextToken]['code'], Tokens::$stringTokens) && preg_match('/[#\/|~\}\)][imsxADSUXJu]*e[imsxADSUXJu]*.$/', $tokens[$nextToken]['content']) ) { $phpcsFile->addError( diff --git a/Magento2/Sniffs/Strings/StringConcatSniff.php b/Magento2/Sniffs/Strings/StringConcatSniff.php index 89c8dc9b..00c7dc35 100644 --- a/Magento2/Sniffs/Strings/StringConcatSniff.php +++ b/Magento2/Sniffs/Strings/StringConcatSniff.php @@ -49,7 +49,8 @@ public function process(File $phpcsFile, $stackPtr) } $beforePrev = $phpcsFile->findPrevious(T_WHITESPACE, $prev - 1, null, true); $stringTokens = Tokens::$stringTokens; - if ($tokens[$beforePrev]['code'] === T_STRING_CONCAT + if ( + $tokens[$beforePrev]['code'] === T_STRING_CONCAT || in_array($tokens[$prev]['code'], $stringTokens) || in_array($tokens[$next]['code'], $stringTokens) ) { diff --git a/Magento2/Sniffs/Whitespace/MultipleEmptyLinesSniff.php b/Magento2/Sniffs/Whitespace/MultipleEmptyLinesSniff.php index 4d74a29e..d564992e 100644 --- a/Magento2/Sniffs/Whitespace/MultipleEmptyLinesSniff.php +++ b/Magento2/Sniffs/Whitespace/MultipleEmptyLinesSniff.php @@ -41,11 +41,13 @@ public function register() public function process(File $phpcsFile, $stackPtr) { $tokens = $phpcsFile->getTokens(); - if ($phpcsFile->hasCondition($stackPtr, T_FUNCTION) + if ( + $phpcsFile->hasCondition($stackPtr, T_FUNCTION) || $phpcsFile->hasCondition($stackPtr, T_CLASS) || $phpcsFile->hasCondition($stackPtr, T_INTERFACE) ) { - if ($tokens[$stackPtr - 1]['line'] < $tokens[$stackPtr]['line'] + if ( + $tokens[$stackPtr - 1]['line'] < $tokens[$stackPtr]['line'] && $tokens[$stackPtr - 2]['line'] === $tokens[$stackPtr - 1]['line'] ) { // This is an empty line and the line before this one is not diff --git a/Magento2Framework/Sniffs/Header/CopyrightAnotherExtensionsFilesSniff.php b/Magento2Framework/Sniffs/Header/CopyrightAnotherExtensionsFilesSniff.php index 3bafbb1f..54331910 100644 --- a/Magento2Framework/Sniffs/Header/CopyrightAnotherExtensionsFilesSniff.php +++ b/Magento2Framework/Sniffs/Header/CopyrightAnotherExtensionsFilesSniff.php @@ -46,7 +46,8 @@ public function process(File $phpcsFile, $stackPtr) $fileText = $phpcsFile->getTokensAsString($stackPtr, count($phpcsFile->getTokens())); - if (strpos($fileText, self::COPYRIGHT_MAGENTO_TEXT) !== false + if ( + strpos($fileText, self::COPYRIGHT_MAGENTO_TEXT) !== false || preg_match(self::COPYRIGHT_ADOBE, $fileText) ) { return; diff --git a/Magento2Framework/Tests/Header/CopyrightGraphQLUnitTest.php b/Magento2Framework/Tests/Header/CopyrightGraphQLUnitTest.php index 7323bd96..20b860d6 100644 --- a/Magento2Framework/Tests/Header/CopyrightGraphQLUnitTest.php +++ b/Magento2Framework/Tests/Header/CopyrightGraphQLUnitTest.php @@ -22,13 +22,17 @@ public function getErrorList(): array */ public function getWarningList($testFile = ''): array { - if ($testFile === 'CopyrightGraphQLUnitTest.1.graphqls' || - $testFile === 'CopyrightGraphQLUnitTest.2.graphqls') { + if ( + $testFile === 'CopyrightGraphQLUnitTest.1.graphqls' || + $testFile === 'CopyrightGraphQLUnitTest.2.graphqls' + ) { return []; } - if ($testFile === 'CopyrightGraphQLUnitTest.3.graphqls' || - $testFile === 'CopyrightGraphQLUnitTest.4.graphqls') { + if ( + $testFile === 'CopyrightGraphQLUnitTest.3.graphqls' || + $testFile === 'CopyrightGraphQLUnitTest.4.graphqls' + ) { return [ null => 1 ];