diff --git a/Magento2/Helpers/Assert.php b/Magento2/Helpers/Assert.php index 54bb3995..a900c1cd 100644 --- a/Magento2/Helpers/Assert.php +++ b/Magento2/Helpers/Assert.php @@ -1,8 +1,10 @@ getTokens(); $nextPtr = $phpcsFile->findNext(Tokens::$emptyTokens, ($stackPtr + 1), null, true); - if ($nextPtr === false + if ( + $nextPtr === false || $tokens[$nextPtr]['code'] !== \T_OPEN_PARENTHESIS || isset($tokens[$nextPtr]['parenthesis_owner']) ) { @@ -36,7 +40,8 @@ public static function isBuiltinFunctionCall(File $phpcsFile, int $stackPtr): bo $prevPtr = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($stackPtr - 1), null, true); if ($prevPtr !== false) { - if (isset(Collections::objectOperators()[$tokens[$prevPtr]['code']]) + if ( + isset(Collections::objectOperators()[$tokens[$prevPtr]['code']]) || $tokens[$prevPtr]['code'] === \T_NEW ) { return false; diff --git a/Magento2/Helpers/Commenting/PHPDocFormattingValidator.php b/Magento2/Helpers/Commenting/PHPDocFormattingValidator.php index 1a9b77c1..2b098c59 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/Sniffs/Annotation/AnnotationFormatValidator.php b/Magento2/Sniffs/Annotation/AnnotationFormatValidator.php index fb0d4e2e..51f204a5 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/MethodAnnotationStructureSniff.php b/Magento2/Sniffs/Annotation/MethodAnnotationStructureSniff.php index e9139fdf..06e01cdc 100644 --- a/Magento2/Sniffs/Annotation/MethodAnnotationStructureSniff.php +++ b/Magento2/Sniffs/Annotation/MethodAnnotationStructureSniff.php @@ -62,7 +62,8 @@ public function process(File $phpcsFile, $stackPtr) do { $commentEndPtr = $phpcsFile->findPrevious($tokensToFind, $commentEndPtr - 1); - if ($commentEndPtr !== false + if ( + $commentEndPtr !== false && $tokens[$commentEndPtr]['code'] === \T_ATTRIBUTE_END && isset($tokens[$commentEndPtr]['attribute_opener']) ) { diff --git a/Magento2/Sniffs/Annotation/MethodArgumentsSniff.php b/Magento2/Sniffs/Annotation/MethodArgumentsSniff.php index 830984cd..3ad01f94 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 852e0f7d..89517a5e 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/ClassAndInterfacePHPDocFormattingSniff.php b/Magento2/Sniffs/Commenting/ClassAndInterfacePHPDocFormattingSniff.php index 0144fae4..decbe380 100644 --- a/Magento2/Sniffs/Commenting/ClassAndInterfacePHPDocFormattingSniff.php +++ b/Magento2/Sniffs/Commenting/ClassAndInterfacePHPDocFormattingSniff.php @@ -80,7 +80,8 @@ public function process(File $phpcsFile, $stackPtr) $phpcsFile->fixer->replaceToken($i, ''); } - if ($tokens[$commentStartPtr - 1]['code'] === T_WHITESPACE + if ( + $tokens[$commentStartPtr - 1]['code'] === T_WHITESPACE && $tokens[$commentCloserPtr + 1]['code'] === T_WHITESPACE ) { $phpcsFile->fixer->replaceToken($commentCloserPtr + 1, ''); diff --git a/Magento2/Sniffs/Commenting/ClassPropertyPHPDocFormattingSniff.php b/Magento2/Sniffs/Commenting/ClassPropertyPHPDocFormattingSniff.php index e6823c16..27015a37 100644 --- a/Magento2/Sniffs/Commenting/ClassPropertyPHPDocFormattingSniff.php +++ b/Magento2/Sniffs/Commenting/ClassPropertyPHPDocFormattingSniff.php @@ -123,11 +123,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 4d76e615..03a84b12 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 0687ecf7..88c20fd6 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 0032fa07..f7bddb52 100644 --- a/Magento2/Sniffs/Html/HtmlBindingSniff.php +++ b/Magento2/Sniffs/Html/HtmlBindingSniff.php @@ -74,7 +74,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/Legacy/EscapeMethodsOnBlockClassSniff.php b/Magento2/Sniffs/Legacy/EscapeMethodsOnBlockClassSniff.php index fd5f3f7f..c8459afd 100644 --- a/Magento2/Sniffs/Legacy/EscapeMethodsOnBlockClassSniff.php +++ b/Magento2/Sniffs/Legacy/EscapeMethodsOnBlockClassSniff.php @@ -55,7 +55,8 @@ public function process(File $phpcsFile, $stackPtr) } } - if ($tokens[$objectPtr]['code'] !== T_VARIABLE + if ( + $tokens[$objectPtr]['code'] !== T_VARIABLE || $tokens[$objectPtr]['content'] !== '$block' ) { return; @@ -70,7 +71,8 @@ public function process(File $phpcsFile, $stackPtr) } } - if ($tokens[$methodPtr]['code'] !== T_STRING + if ( + $tokens[$methodPtr]['code'] !== T_STRING || !isset(self::ESCAPER_METHODS[$tokens[$methodPtr]['content']]) ) { return; diff --git a/Magento2/Sniffs/Less/ClassNamingSniff.php b/Magento2/Sniffs/Less/ClassNamingSniff.php index 20aa6823..a8112712 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'], [ @@ -67,7 +68,9 @@ public function process(File $phpcsFile, $stackPtr) ); } - if (strlen($className) > 1 && strpos($className, self::STRING_HELPER_CLASSES_PREFIX, 2) !== false + if ( + strlen($className) > 1 + && strpos($className, self::STRING_HELPER_CLASSES_PREFIX, 2) !== false && !str_starts_with($className, 'admin__') ) { $phpcsFile->addError( diff --git a/Magento2/Sniffs/Less/CommentLevelsSniff.php b/Magento2/Sniffs/Less/CommentLevelsSniff.php index d86f3be8..678f7711 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 509852e6..14143767 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 c4e52ed2..9dbf752b 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 03c62e29..02dbad54 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 4b8aff11..8781068b 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 97f3800e..e77d63a6 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 b4e52041..b5dd57cf 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 62b33dfb..0dd43c77 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 61183b34..2fea1f81 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 653fb40b..714d227e 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 abbe3d1d..df9abd83 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 dc142fe8..eaacc06f 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 66337b5b..49e05b37 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/SQL/RawQuerySniff.php b/Magento2/Sniffs/SQL/RawQuerySniff.php index 4309457a..be9aa3c3 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 dec0b61b..937b0853 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 bd536624..9f94f188 100644 --- a/Magento2/Sniffs/Security/XssTemplateSniff.php +++ b/Magento2/Sniffs/Security/XssTemplateSniff.php @@ -217,7 +217,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 36616521..7a7bd992 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 198a2229..ff40c7ec 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 79c64d67..851b9e91 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/Magento2/ruleset.xml b/Magento2/ruleset.xml index 4ac058c0..119a757c 100644 --- a/Magento2/ruleset.xml +++ b/Magento2/ruleset.xml @@ -582,7 +582,7 @@ warning - + 6 warning diff --git a/Magento2Framework/Sniffs/Header/CopyrightAnotherExtensionsFilesSniff.php b/Magento2Framework/Sniffs/Header/CopyrightAnotherExtensionsFilesSniff.php index 9af6a64d..7d66fab1 100644 --- a/Magento2Framework/Sniffs/Header/CopyrightAnotherExtensionsFilesSniff.php +++ b/Magento2Framework/Sniffs/Header/CopyrightAnotherExtensionsFilesSniff.php @@ -42,7 +42,7 @@ public function process(File $phpcsFile, $stackPtr) return; } - // @phpcs:ignore Magento2.Functions.DiscouragedFunction.Discouraged + // @phpcs:ignore Magento2.Functions.DiscouragedFunction.Discouraged $content = file_get_contents($phpcsFile->getFilename()); if ($this->isCopyrightYearValid($content) === false) { diff --git a/Magento2Framework/Tests/Header/CopyrightGraphQLUnitTest.php b/Magento2Framework/Tests/Header/CopyrightGraphQLUnitTest.php index 58fc7346..6a5fcdb8 100644 --- a/Magento2Framework/Tests/Header/CopyrightGraphQLUnitTest.php +++ b/Magento2Framework/Tests/Header/CopyrightGraphQLUnitTest.php @@ -9,17 +9,17 @@ class CopyrightGraphQLUnitTest extends AbstractGraphQLSniffUnitTestCase { - /** - * @inheritdoc - */ + /** + * @inheritdoc + */ public function getErrorList(): array { return []; } - /** - * @inheritdoc - */ + /** + * @inheritdoc + */ public function getWarningList($testFile = ''): array { if ($testFile === 'CopyrightGraphQLUnitTest.1.graphqls' ||