From ac5f9fde6e9be22a1f4c8cdb0107c562f60af38d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Cuerdo=20=C3=81lvarez?= Date: Tue, 7 Sep 2021 10:16:55 +0200 Subject: [PATCH 01/37] AC-667: Create phpcs static check for EmailTemplateTest --- Magento2/Sniffs/Legacy/EmailTemplateSniff.php | 50 +++++++++++++++++++ .../Tests/Legacy/EmailTemplateUnitTest.1.html | 3 ++ .../Tests/Legacy/EmailTemplateUnitTest.2.html | 4 ++ .../Tests/Legacy/EmailTemplateUnitTest.php | 38 ++++++++++++++ Magento2/ruleset.xml | 7 +++ 5 files changed, 102 insertions(+) create mode 100644 Magento2/Sniffs/Legacy/EmailTemplateSniff.php create mode 100644 Magento2/Tests/Legacy/EmailTemplateUnitTest.1.html create mode 100644 Magento2/Tests/Legacy/EmailTemplateUnitTest.2.html create mode 100644 Magento2/Tests/Legacy/EmailTemplateUnitTest.php diff --git a/Magento2/Sniffs/Legacy/EmailTemplateSniff.php b/Magento2/Sniffs/Legacy/EmailTemplateSniff.php new file mode 100644 index 00000000..7fbcb7d9 --- /dev/null +++ b/Magento2/Sniffs/Legacy/EmailTemplateSniff.php @@ -0,0 +1,50 @@ + 'Directive {{htmlescape}} is obsolete. Use {{var}} instead.', + '/\{\{escapehtml.*?\}\}/i' => 'Directive {{escapehtml}} is obsolete. Use {{var}} instead.', + ]; + + private const WARNING_CODE = 'FoundObsoleteEmailDirective'; + + /** + * @inheritdoc + */ + public function register(): array + { + return [ + T_INLINE_HTML + ]; + } + + /** + * @inheritDoc + */ + public function process(File $phpcsFile, $stackPtr) + { + $content = $phpcsFile->getTokens()[$stackPtr]['content']; + foreach (self::OBSOLETE_EMAIL_DIRECTIVES as $directiveRegex => $errorMessage) { + if(preg_match($directiveRegex, $content)) { + $phpcsFile->addWarning( + $errorMessage, + $stackPtr, + self::WARNING_CODE + ); + } + } + } +} diff --git a/Magento2/Tests/Legacy/EmailTemplateUnitTest.1.html b/Magento2/Tests/Legacy/EmailTemplateUnitTest.1.html new file mode 100644 index 00000000..435302e1 --- /dev/null +++ b/Magento2/Tests/Legacy/EmailTemplateUnitTest.1.html @@ -0,0 +1,3 @@ +

{{var "H1"}}

+

{{var "H2"}}

+

{{var "p"}} {{var "p"}}

diff --git a/Magento2/Tests/Legacy/EmailTemplateUnitTest.2.html b/Magento2/Tests/Legacy/EmailTemplateUnitTest.2.html new file mode 100644 index 00000000..6b24ea76 --- /dev/null +++ b/Magento2/Tests/Legacy/EmailTemplateUnitTest.2.html @@ -0,0 +1,4 @@ +

{{htmlescape "H1"}}

+

{{escapehtml "H2"}}

+

{{escapehtml "p"}} {{htmlescape "p"}}

+

{{trans "Translateme"}}

\ No newline at end of file diff --git a/Magento2/Tests/Legacy/EmailTemplateUnitTest.php b/Magento2/Tests/Legacy/EmailTemplateUnitTest.php new file mode 100644 index 00000000..b6df0c8e --- /dev/null +++ b/Magento2/Tests/Legacy/EmailTemplateUnitTest.php @@ -0,0 +1,38 @@ + 1, + 2 => 1, + 3 => 2, + ]; + } + + return []; + } +} diff --git a/Magento2/ruleset.xml b/Magento2/ruleset.xml index f31b105d..9e6202cb 100644 --- a/Magento2/ruleset.xml +++ b/Magento2/ruleset.xml @@ -242,6 +242,13 @@ warning + + view/email/*.html + view/*/email/*.html + 8 + warning + + 7 From 0cb8f6763c2319e0a2ea9a219e4ee7e09af9f6e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Cuerdo=20=C3=81lvarez?= Date: Tue, 7 Sep 2021 11:32:47 +0200 Subject: [PATCH 02/37] AC-667: Create phpcs static check for EmailTemplateTest --- Magento2/Sniffs/Legacy/EmailTemplateSniff.php | 2 +- Magento2/Tests/Legacy/EmailTemplateUnitTest.php | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Magento2/Sniffs/Legacy/EmailTemplateSniff.php b/Magento2/Sniffs/Legacy/EmailTemplateSniff.php index 7fbcb7d9..4e240213 100644 --- a/Magento2/Sniffs/Legacy/EmailTemplateSniff.php +++ b/Magento2/Sniffs/Legacy/EmailTemplateSniff.php @@ -38,7 +38,7 @@ public function process(File $phpcsFile, $stackPtr) { $content = $phpcsFile->getTokens()[$stackPtr]['content']; foreach (self::OBSOLETE_EMAIL_DIRECTIVES as $directiveRegex => $errorMessage) { - if(preg_match($directiveRegex, $content)) { + if (preg_match($directiveRegex, $content)) { $phpcsFile->addWarning( $errorMessage, $stackPtr, diff --git a/Magento2/Tests/Legacy/EmailTemplateUnitTest.php b/Magento2/Tests/Legacy/EmailTemplateUnitTest.php index b6df0c8e..2dbb5676 100644 --- a/Magento2/Tests/Legacy/EmailTemplateUnitTest.php +++ b/Magento2/Tests/Legacy/EmailTemplateUnitTest.php @@ -3,6 +3,7 @@ * Copyright © Magento. All rights reserved. * See COPYING.txt for license details. */ + namespace Magento2\Tests\Legacy; use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; From 4a78a9439af2e5a7e6c47bbc9dac6ae38f1c1b4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Cuerdo=20=C3=81lvarez?= Date: Tue, 7 Sep 2021 12:19:26 +0200 Subject: [PATCH 03/37] AC-667: Create phpcs static check for EmailTemplateTest --- Magento2/Tests/Legacy/EmailTemplateUnitTest.1.html | 1 + Magento2/Tests/Legacy/EmailTemplateUnitTest.2.html | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Magento2/Tests/Legacy/EmailTemplateUnitTest.1.html b/Magento2/Tests/Legacy/EmailTemplateUnitTest.1.html index 435302e1..9516974b 100644 --- a/Magento2/Tests/Legacy/EmailTemplateUnitTest.1.html +++ b/Magento2/Tests/Legacy/EmailTemplateUnitTest.1.html @@ -1,3 +1,4 @@

{{var "H1"}}

{{var "H2"}}

{{var "p"}} {{var "p"}}

+ diff --git a/Magento2/Tests/Legacy/EmailTemplateUnitTest.2.html b/Magento2/Tests/Legacy/EmailTemplateUnitTest.2.html index 6b24ea76..422cea21 100644 --- a/Magento2/Tests/Legacy/EmailTemplateUnitTest.2.html +++ b/Magento2/Tests/Legacy/EmailTemplateUnitTest.2.html @@ -1,4 +1,4 @@

{{htmlescape "H1"}}

{{escapehtml "H2"}}

{{escapehtml "p"}} {{htmlescape "p"}}

-

{{trans "Translateme"}}

\ No newline at end of file +

{{trans "Translateme"}}

From e4698fbf56ffa3011e114d331f480ea4b4ed9d43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Cuerdo=20=C3=81lvarez?= Date: Tue, 7 Sep 2021 15:47:16 +0200 Subject: [PATCH 04/37] AC-667: Create phpcs static check for EmailTemplateTest --- Magento2/Sniffs/Legacy/EmailTemplateSniff.php | 6 +++--- .../Tests/Legacy/EmailTemplateUnitTest.php | 18 +++++++++--------- Magento2/ruleset.xml | 3 +-- 3 files changed, 13 insertions(+), 14 deletions(-) diff --git a/Magento2/Sniffs/Legacy/EmailTemplateSniff.php b/Magento2/Sniffs/Legacy/EmailTemplateSniff.php index 4e240213..17ebbf08 100644 --- a/Magento2/Sniffs/Legacy/EmailTemplateSniff.php +++ b/Magento2/Sniffs/Legacy/EmailTemplateSniff.php @@ -19,7 +19,7 @@ class EmailTemplateSniff implements Sniff '/\{\{escapehtml.*?\}\}/i' => 'Directive {{escapehtml}} is obsolete. Use {{var}} instead.', ]; - private const WARNING_CODE = 'FoundObsoleteEmailDirective'; + private const ERROR_CODE = 'FoundObsoleteEmailDirective'; /** * @inheritdoc @@ -39,10 +39,10 @@ public function process(File $phpcsFile, $stackPtr) $content = $phpcsFile->getTokens()[$stackPtr]['content']; foreach (self::OBSOLETE_EMAIL_DIRECTIVES as $directiveRegex => $errorMessage) { if (preg_match($directiveRegex, $content)) { - $phpcsFile->addWarning( + $phpcsFile->addError( $errorMessage, $stackPtr, - self::WARNING_CODE + self::ERROR_CODE ); } } diff --git a/Magento2/Tests/Legacy/EmailTemplateUnitTest.php b/Magento2/Tests/Legacy/EmailTemplateUnitTest.php index 2dbb5676..c0b42189 100644 --- a/Magento2/Tests/Legacy/EmailTemplateUnitTest.php +++ b/Magento2/Tests/Legacy/EmailTemplateUnitTest.php @@ -13,15 +13,7 @@ class EmailTemplateUnitTest extends AbstractSniffUnitTest /** * @inheritdoc */ - public function getErrorList() - { - return []; - } - - /** - * @inheritdoc - */ - public function getWarningList($testFile = '') + public function getErrorList($testFile = '') { if ($testFile === 'EmailTemplateUnitTest.1.html') { return []; @@ -36,4 +28,12 @@ public function getWarningList($testFile = '') return []; } + + /** + * @inheritdoc + */ + public function getWarningList($testFile = '') + { + return []; + } } diff --git a/Magento2/ruleset.xml b/Magento2/ruleset.xml index 9e6202cb..4736026d 100644 --- a/Magento2/ruleset.xml +++ b/Magento2/ruleset.xml @@ -241,12 +241,11 @@ 8 warning
- view/email/*.html view/*/email/*.html 8 - warning + error From e4f55405f684d530cd5c987c1a662a1bbd28c196 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Cuerdo=20=C3=81lvarez?= Date: Wed, 8 Sep 2021 10:44:45 +0200 Subject: [PATCH 05/37] Update Magento2/ruleset.xml Co-authored-by: Sergii Ivashchenko --- Magento2/ruleset.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Magento2/ruleset.xml b/Magento2/ruleset.xml index 4736026d..2a499391 100644 --- a/Magento2/ruleset.xml +++ b/Magento2/ruleset.xml @@ -244,7 +244,7 @@ view/email/*.html view/*/email/*.html - 8 + 10 error From 2751031cef73853f8ba652135223c0083c1ea964 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Cuerdo=20=C3=81lvarez?= Date: Wed, 8 Sep 2021 11:40:31 +0200 Subject: [PATCH 06/37] AC-667: Create phpcs static check for EmailTemplateTest --- Magento2/ruleset.xml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Magento2/ruleset.xml b/Magento2/ruleset.xml index 2a499391..e1b0f521 100644 --- a/Magento2/ruleset.xml +++ b/Magento2/ruleset.xml @@ -109,6 +109,12 @@ 10 error + + view/email/*.html + view/*/email/*.html + 10 + error + @@ -241,12 +247,6 @@ 8 warning - - view/email/*.html - view/*/email/*.html - 10 - error - From 8b2cd9041f1337aec04c28519984fc6eb5f7afc7 Mon Sep 17 00:00:00 2001 From: Elisea Cornejo Date: Thu, 9 Sep 2021 11:35:52 +0200 Subject: [PATCH 07/37] AC-666: Create phpcs static check for CopyrightTest --- Magento2/Sniffs/Legacy/CopyrightSniff.php | 46 +++++++++++++++++++ Magento2/Tests/Legacy/CopyrightUnitTest.1.inc | 2 + Magento2/Tests/Legacy/CopyrightUnitTest.2.inc | 10 ++++ Magento2/Tests/Legacy/CopyrightUnitTest.3.inc | 6 +++ Magento2/Tests/Legacy/CopyrightUnitTest.4.inc | 7 +++ Magento2/Tests/Legacy/CopyrightUnitTest.php | 33 +++++++++++++ 6 files changed, 104 insertions(+) create mode 100644 Magento2/Sniffs/Legacy/CopyrightSniff.php create mode 100644 Magento2/Tests/Legacy/CopyrightUnitTest.1.inc create mode 100644 Magento2/Tests/Legacy/CopyrightUnitTest.2.inc create mode 100644 Magento2/Tests/Legacy/CopyrightUnitTest.3.inc create mode 100644 Magento2/Tests/Legacy/CopyrightUnitTest.4.inc create mode 100644 Magento2/Tests/Legacy/CopyrightUnitTest.php diff --git a/Magento2/Sniffs/Legacy/CopyrightSniff.php b/Magento2/Sniffs/Legacy/CopyrightSniff.php new file mode 100644 index 00000000..7e524b43 --- /dev/null +++ b/Magento2/Sniffs/Legacy/CopyrightSniff.php @@ -0,0 +1,46 @@ +findPrevious(T_OPEN_TAG, $stackPtr - 1); + + if ($positionOpenTag === false){ + $positionComment = $phpcsFile->findNext(T_DOC_COMMENT_STRING, $stackPtr); + $contentFile = $phpcsFile->getTokens()[$positionComment]['content']; + $adobeCopyrightFound = preg_match(self::COPYRIGHT_ADOBE, $contentFile); + + if (strpos($contentFile, self::COPYRIGHT_MAGENTO_TEXT) === false || $adobeCopyrightFound === false) { + $phpcsFile->addWarningOnLine( + 'Copyright is missing or has wrong format', + null, + self::WARNING_CODE + ); + } + } + } +} diff --git a/Magento2/Tests/Legacy/CopyrightUnitTest.1.inc b/Magento2/Tests/Legacy/CopyrightUnitTest.1.inc new file mode 100644 index 00000000..a4abe2da --- /dev/null +++ b/Magento2/Tests/Legacy/CopyrightUnitTest.1.inc @@ -0,0 +1,2 @@ + + + diff --git a/Magento2/Tests/Legacy/CopyrightUnitTest.4.inc b/Magento2/Tests/Legacy/CopyrightUnitTest.4.inc new file mode 100644 index 00000000..1cadcad0 --- /dev/null +++ b/Magento2/Tests/Legacy/CopyrightUnitTest.4.inc @@ -0,0 +1,7 @@ + 1, + ]; + } +} From 702cd60d087c65061e5ebc6a017a4a20ee4360d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Cuerdo=20=C3=81lvarez?= Date: Thu, 9 Sep 2021 11:38:04 +0200 Subject: [PATCH 08/37] AC-661: Create phpcs static check for XmlTest --- Magento2/Sniffs/Legacy/WidgetXMLSniff.php | 114 ++++++++++++++++++ Magento2/Tests/Legacy/WidgetXMLUnitTest.1.xml | 19 +++ Magento2/Tests/Legacy/WidgetXMLUnitTest.php | 31 +++++ 3 files changed, 164 insertions(+) create mode 100644 Magento2/Sniffs/Legacy/WidgetXMLSniff.php create mode 100644 Magento2/Tests/Legacy/WidgetXMLUnitTest.1.xml create mode 100644 Magento2/Tests/Legacy/WidgetXMLUnitTest.php diff --git a/Magento2/Sniffs/Legacy/WidgetXMLSniff.php b/Magento2/Sniffs/Legacy/WidgetXMLSniff.php new file mode 100644 index 00000000..f15b8a94 --- /dev/null +++ b/Magento2/Sniffs/Legacy/WidgetXMLSniff.php @@ -0,0 +1,114 @@ + 0) { + return; + } + + $xml = simplexml_load_string($this->getFormattedXML($phpcsFile)); + if ($xml === false) { + $phpcsFile->addError( + sprintf( + "Couldn't parse contents of '%s', check that they are in valid XML format", + $phpcsFile->getFilename(), + ), + 1, + self::ERROR_CODE_XML + ); + } + + $foundElements = $xml->xpath('/widgets/*[@type]'); + + foreach ($foundElements as $element) { + if (property_exists($element->attributes(), 'type')) { + $type = $element['type']; + if (preg_match('/\//', $type)) { + $phpcsFile->addError( + "Factory name detected: {$type}.", + dom_import_simplexml($element)->getLineNo() - 1, + self::ERROR_CODE_FACTORY + ); + } + } + } + + $foundElements = $xml->xpath('/widgets/*/supported_blocks'); + foreach ($foundElements as $element) { + $phpcsFile->addError( + "Obsolete node: . To be replaced with ", + dom_import_simplexml($element)->getLineNo() - 1, + self::ERROR_CODE_OBSOLETE + ); + } + + $foundElements = $xml->xpath('/widgets/*/*/*/block_name'); + foreach ($foundElements as $element) { + $phpcsFile->addError( + "Obsolete node: . To be replaced with ", + dom_import_simplexml($element)->getLineNo() - 1, + self::ERROR_CODE_OBSOLETE + ); + } + } + + /** + * Check if the element passed is in the currently sniffed line + * + * @param SimpleXMLElement $element + * @param int $stackPtr + * @return bool + */ + private function elementIsCurrentlySniffedLine(SimpleXMLElement $element, int $stackPtr): bool + { + $node = dom_import_simplexml($element); + + return $node->getLineNo() === $stackPtr + 1; + } + + /** + * Format the incoming XML to avoid tags split into several lines. + * + * @param File $phpcsFile + * @return false|string + */ + private function getFormattedXML(File $phpcsFile) + { + $doc = new DomDocument('1.0'); + $doc->formatOutput = true; + $doc->loadXML($phpcsFile->getTokensAsString(0, 999999)); + return $doc->saveXML(); + } +} diff --git a/Magento2/Tests/Legacy/WidgetXMLUnitTest.1.xml b/Magento2/Tests/Legacy/WidgetXMLUnitTest.1.xml new file mode 100644 index 00000000..9c70a9cf --- /dev/null +++ b/Magento2/Tests/Legacy/WidgetXMLUnitTest.1.xml @@ -0,0 +1,19 @@ + + + + + + List of Products that are set as New + Deprecated + + Deprecated + + + + + diff --git a/Magento2/Tests/Legacy/WidgetXMLUnitTest.php b/Magento2/Tests/Legacy/WidgetXMLUnitTest.php new file mode 100644 index 00000000..36026b93 --- /dev/null +++ b/Magento2/Tests/Legacy/WidgetXMLUnitTest.php @@ -0,0 +1,31 @@ + 1, + 12 => 1, + 14 => 1, + ]; + } + + /** + * @inheritdoc + */ + public function getWarningList($testFile = '') + { + return []; + } +} From 76359c2f8daf43e9478d3cc6dd60615ee8fb9a5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Cuerdo=20=C3=81lvarez?= Date: Thu, 9 Sep 2021 11:40:55 +0200 Subject: [PATCH 09/37] AC-661: Create phpcs static check for XmlTest --- Magento2/Sniffs/Legacy/WidgetXMLSniff.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Magento2/Sniffs/Legacy/WidgetXMLSniff.php b/Magento2/Sniffs/Legacy/WidgetXMLSniff.php index f15b8a94..6bc673b8 100644 --- a/Magento2/Sniffs/Legacy/WidgetXMLSniff.php +++ b/Magento2/Sniffs/Legacy/WidgetXMLSniff.php @@ -34,7 +34,7 @@ public function register(): array */ public function process(File $phpcsFile, $stackPtr) { - if($stackPtr > 0) { + if ($stackPtr > 0) { return; } From e2c2d07c09f8bc6d9538cc92fa6732d35da88601 Mon Sep 17 00:00:00 2001 From: Elisea Cornejo Date: Thu, 9 Sep 2021 12:08:35 +0200 Subject: [PATCH 10/37] AC-666: Create phpcs static check for CopyrightTest --- Magento2/Helpers/Commenting/PHPDocFormattingValidator.php | 2 +- Magento2/Sniffs/Classes/AbstractApiSniff.php | 2 +- Magento2/Sniffs/Classes/DiscouragedDependenciesSniff.php | 2 +- Magento2/Sniffs/CodeAnalysis/EmptyBlockSniff.php | 2 +- .../Commenting/ClassAndInterfacePHPDocFormattingSniff.php | 2 +- .../Sniffs/Commenting/ClassPropertyPHPDocFormattingSniff.php | 4 ++++ .../Sniffs/Commenting/ConstantsPHPDocFormattingSniff.php | 2 +- Magento2/Sniffs/Exceptions/DirectThrowSniff.php | 2 +- Magento2/Sniffs/Exceptions/ThrowCatchSniff.php | 2 +- .../Sniffs/Exceptions/TryProcessSystemResourcesSniff.php | 2 +- Magento2/Sniffs/Functions/DiscouragedFunctionSniff.php | 2 +- Magento2/Sniffs/Functions/StaticFunctionSniff.php | 2 +- Magento2/Sniffs/GraphQL/AbstractGraphQLSniff.php | 2 +- Magento2/Sniffs/GraphQL/ValidArgumentNameSniff.php | 2 +- Magento2/Sniffs/GraphQL/ValidEnumValueSniff.php | 2 +- Magento2/Sniffs/GraphQL/ValidFieldNameSniff.php | 2 +- Magento2/Sniffs/GraphQL/ValidTopLevelFieldNameSniff.php | 2 +- Magento2/Sniffs/GraphQL/ValidTypeNameSniff.php | 2 +- Magento2/Sniffs/Legacy/AbstractBlockSniff.php | 2 +- Magento2/Sniffs/Legacy/CopyrightSniff.php | 5 ++++- Magento2/Sniffs/Legacy/MageEntitySniff.php | 2 +- Magento2/Sniffs/Methods/DeprecatedModelMethodSniff.php | 2 +- Magento2/Sniffs/Namespaces/ImportsFromTestNamespaceSniff.php | 2 +- Magento2/Sniffs/NamingConvention/InterfaceNameSniff.php | 2 +- Magento2/Sniffs/PHP/FinalImplementationSniff.php | 2 +- Magento2/Sniffs/PHP/GotoSniff.php | 2 +- Magento2/Sniffs/PHP/ReturnValueCheckSniff.php | 2 +- Magento2/Sniffs/PHP/VarSniff.php | 2 +- Magento2/Sniffs/Performance/ForeachArrayMergeSniff.php | 2 +- Magento2/Sniffs/SQL/RawQuerySniff.php | 2 +- Magento2/Sniffs/Security/IncludeFileSniff.php | 2 +- Magento2/Sniffs/Security/InsecureFunctionSniff.php | 2 +- Magento2/Sniffs/Security/LanguageConstructSniff.php | 2 +- Magento2/Sniffs/Security/SuperglobalSniff.php | 2 +- Magento2/Sniffs/Security/XssTemplateSniff.php | 2 +- Magento2/Sniffs/Strings/ExecutableRegExSniff.php | 2 +- Magento2/Sniffs/Strings/StringConcatSniff.php | 2 +- Magento2/Sniffs/Templates/ThisInTemplateSniff.php | 2 +- Magento2/Sniffs/Whitespace/MultipleEmptyLinesSniff.php | 2 +- Magento2/Tests/Classes/AbstractApiUnitTest.php | 2 +- Magento2/Tests/Classes/DiscouragedDependenciesUnitTest.php | 2 +- Magento2/Tests/CodeAnalysis/EmptyBlockUnitTest.php | 2 +- .../Commenting/ClassAndInterfacePHPDocFormattingUnitTest.php | 2 +- .../Commenting/ClassPropertyPHPDocFormattingUnitTest.php | 2 +- .../Tests/Commenting/ConstantsPHPDocFormattingUnitTest.php | 2 +- Magento2/Tests/Exceptions/DirectThrowUnitTest.php | 2 +- Magento2/Tests/Exceptions/ThrowCatchUnitTest.php | 2 +- .../Tests/Exceptions/TryProcessSystemResourcesUnitTest.php | 2 +- Magento2/Tests/Functions/DiscouragedFunctionUnitTest.php | 2 +- Magento2/Tests/Functions/StaticFunctionUnitTest.php | 2 +- Magento2/Tests/GraphQL/AbstractGraphQLSniffUnitTestCase.php | 2 +- Magento2/Tests/GraphQL/ValidArgumentNameUnitTest.php | 2 +- Magento2/Tests/GraphQL/ValidEnumValueUnitTest.php | 2 +- Magento2/Tests/GraphQL/ValidFieldNameUnitTest.php | 2 +- Magento2/Tests/GraphQL/ValidTopLevelFieldNameUnitTest.php | 2 +- Magento2/Tests/GraphQL/ValidTypeNameUnitTest.php | 2 +- Magento2/Tests/Html/HtmlBindingUnitTest.php | 2 +- Magento2/Tests/Html/HtmlDirectiveUnitTest.php | 2 +- Magento2/Tests/Legacy/AbstractBlockUnitTest.php | 2 +- Magento2/Tests/Legacy/CopyrightUnitTest.php | 2 +- Magento2/Tests/Legacy/DiConfigUnitTest.php | 2 +- Magento2/Tests/Legacy/EmailTemplateUnitTest.php | 2 +- Magento2/Tests/Legacy/MageEntityUnitTest.php | 2 +- Magento2/Tests/Legacy/ModuleXMLUnitTest.php | 2 +- Magento2/Tests/Less/AbstractLessSniffUnitTestCase.php | 2 +- Magento2/Tests/Less/AvoidIdUnitTest.php | 2 +- Magento2/Tests/Less/BracesFormattingUnitTest.php | 2 +- Magento2/Tests/Less/ClassNamingUnitTest.php | 2 +- Magento2/Tests/Less/ColonSpacingUnitTest.php | 2 +- Magento2/Tests/Less/ColourDefinitionUnitTest.php | 2 +- Magento2/Tests/Less/CombinatorIndentationUnitTest.php | 2 +- Magento2/Tests/Less/CommentLevelsUnitTest.php | 2 +- Magento2/Tests/Less/ImportantPropertyUnitTest.php | 2 +- Magento2/Tests/Less/IndentationUnitTest.php | 2 +- Magento2/Tests/Less/PropertiesLineBreakUnitTest.php | 2 +- Magento2/Tests/Less/PropertiesSortingUnitTest.php | 2 +- Magento2/Tests/Less/QuotesUnitTest.php | 2 +- Magento2/Tests/Less/SelectorDelimiterUnitTest.php | 2 +- Magento2/Tests/Less/SemicolonSpacingUnitTest.php | 2 +- Magento2/Tests/Less/TypeSelectorConcatenationUnitTest.php | 2 +- Magento2/Tests/Less/TypeSelectorsUnitTest.php | 2 +- Magento2/Tests/Less/VariablesUnitTest.php | 2 +- Magento2/Tests/Less/ZeroUnitsUnitTest.php | 2 +- Magento2/Tests/Methods/DeprecatedModelMethodUnitTest.php | 2 +- .../Tests/Namespaces/ImportsFromTestNamespaceUnitTest.php | 2 +- Magento2/Tests/NamingConvention/InterfaceNameUnitTest.php | 2 +- Magento2/Tests/NamingConvention/ReservedWordsUnitTest.php | 2 +- Magento2/Tests/PHP/FinalImplementationUnitTest.php | 2 +- Magento2/Tests/PHP/GotoUnitTest.php | 2 +- Magento2/Tests/PHP/LiteralNamespacesUnitTest.php | 2 +- Magento2/Tests/PHP/ReturnValueCheckUnitTest.php | 2 +- Magento2/Tests/PHP/ShortEchoSyntaxUnitTest.php | 2 +- Magento2/Tests/PHP/VarUnitTest.php | 2 +- Magento2/Tests/Performance/ForeachArrayMergeUnitTest.php | 2 +- Magento2/Tests/SQL/RawQueryUnitTest.php | 2 +- Magento2/Tests/Security/IncludeFileUnitTest.php | 2 +- Magento2/Tests/Security/InsecureFunctionUnitTest.php | 2 +- Magento2/Tests/Security/LanguageConstructUnitTest.php | 2 +- Magento2/Tests/Security/SuperglobalUnitTest.php | 2 +- Magento2/Tests/Security/XssTemplateUnitTest.php | 2 +- Magento2/Tests/Strings/ExecutableRegExUnitTest.php | 2 +- Magento2/Tests/Strings/StringConcatUnitTest.php | 2 +- Magento2/Tests/Templates/ThisInTemplateUnitTest.php | 2 +- Magento2/Tests/Translation/ConstantUsageUnitTest.php | 2 +- Magento2/Tests/Whitespace/MultipleEmptyLinesUnitTest.php | 2 +- Magento2/ruleset.xml | 4 ++++ PHP_CodeSniffer/Tokenizers/GRAPHQL.php | 2 +- 107 files changed, 116 insertions(+), 105 deletions(-) diff --git a/Magento2/Helpers/Commenting/PHPDocFormattingValidator.php b/Magento2/Helpers/Commenting/PHPDocFormattingValidator.php index fb98db7c..745ec587 100644 --- a/Magento2/Helpers/Commenting/PHPDocFormattingValidator.php +++ b/Magento2/Helpers/Commenting/PHPDocFormattingValidator.php @@ -1,7 +1,7 @@ findPrevious(T_OPEN_TAG, $stackPtr - 1); - if ($positionOpenTag === false){ + if ($positionOpenTag === false) { $positionComment = $phpcsFile->findNext(T_DOC_COMMENT_STRING, $stackPtr); $contentFile = $phpcsFile->getTokens()[$positionComment]['content']; $adobeCopyrightFound = preg_match(self::COPYRIGHT_ADOBE, $contentFile); diff --git a/Magento2/Sniffs/Legacy/MageEntitySniff.php b/Magento2/Sniffs/Legacy/MageEntitySniff.php index 637c3b1c..de8b7dbf 100644 --- a/Magento2/Sniffs/Legacy/MageEntitySniff.php +++ b/Magento2/Sniffs/Legacy/MageEntitySniff.php @@ -1,6 +1,6 @@ */Test/* *Test.php + + 5 + warning + 0 diff --git a/PHP_CodeSniffer/Tokenizers/GRAPHQL.php b/PHP_CodeSniffer/Tokenizers/GRAPHQL.php index 8dd5fcae..05c38d50 100644 --- a/PHP_CodeSniffer/Tokenizers/GRAPHQL.php +++ b/PHP_CodeSniffer/Tokenizers/GRAPHQL.php @@ -1,6 +1,6 @@ Date: Thu, 9 Sep 2021 13:17:19 +0200 Subject: [PATCH 11/37] AC-661: Create phpcs static check for XmlTest --- Magento2/Sniffs/Legacy/WidgetXMLSniff.php | 32 ++++++++--------------- 1 file changed, 11 insertions(+), 21 deletions(-) diff --git a/Magento2/Sniffs/Legacy/WidgetXMLSniff.php b/Magento2/Sniffs/Legacy/WidgetXMLSniff.php index 6bc673b8..b97311b7 100644 --- a/Magento2/Sniffs/Legacy/WidgetXMLSniff.php +++ b/Magento2/Sniffs/Legacy/WidgetXMLSniff.php @@ -11,7 +11,7 @@ use PHP_CodeSniffer\Sniffs\Sniff; /** - * Test for obsolete nodes/attributes in the module.xml + * Test for obsolete nodes/attributes in the widget.xml */ class WidgetXMLSniff implements Sniff { @@ -39,29 +39,19 @@ public function process(File $phpcsFile, $stackPtr) } $xml = simplexml_load_string($this->getFormattedXML($phpcsFile)); - if ($xml === false) { - $phpcsFile->addError( - sprintf( - "Couldn't parse contents of '%s', check that they are in valid XML format", - $phpcsFile->getFilename(), - ), - 1, - self::ERROR_CODE_XML - ); - } $foundElements = $xml->xpath('/widgets/*[@type]'); - foreach ($foundElements as $element) { - if (property_exists($element->attributes(), 'type')) { - $type = $element['type']; - if (preg_match('/\//', $type)) { - $phpcsFile->addError( - "Factory name detected: {$type}.", - dom_import_simplexml($element)->getLineNo() - 1, - self::ERROR_CODE_FACTORY - ); - } + if (!property_exists($element->attributes(), 'type')) { + continue; + } + $type = $element['type']; + if (preg_match('/\//', $type)) { + $phpcsFile->addError( + "Factory name detected: {$type}.", + dom_import_simplexml($element)->getLineNo() - 1, + self::ERROR_CODE_FACTORY + ); } } From dc49aaa1a2218afc466ad95b2eac4d68d19e2dbb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Cuerdo=20=C3=81lvarez?= Date: Thu, 9 Sep 2021 13:37:36 +0200 Subject: [PATCH 12/37] AC-661: Create phpcs static check for XmlTest --- Magento2/Sniffs/Legacy/WidgetXMLSniff.php | 15 ++++++++++++++- Magento2/Tests/Legacy/WidgetXMLUnitTest.2.xml | 11 +++++++++++ Magento2/Tests/Legacy/WidgetXMLUnitTest.php | 18 +++++++++++++----- 3 files changed, 38 insertions(+), 6 deletions(-) create mode 100644 Magento2/Tests/Legacy/WidgetXMLUnitTest.2.xml diff --git a/Magento2/Sniffs/Legacy/WidgetXMLSniff.php b/Magento2/Sniffs/Legacy/WidgetXMLSniff.php index b97311b7..f1d85161 100644 --- a/Magento2/Sniffs/Legacy/WidgetXMLSniff.php +++ b/Magento2/Sniffs/Legacy/WidgetXMLSniff.php @@ -38,9 +38,22 @@ public function process(File $phpcsFile, $stackPtr) return; } - $xml = simplexml_load_string($this->getFormattedXML($phpcsFile)); + try{ + $xml = simplexml_load_string($this->getFormattedXML($phpcsFile)); + } catch (\Exception $e) { + $phpcsFile->addError( + sprintf( + "Couldn't parse contents of '%s', check that they are in valid XML format", + $phpcsFile->getFilename(), + ), + $stackPtr, + self::ERROR_CODE_XML + ); + return; + } $foundElements = $xml->xpath('/widgets/*[@type]'); + foreach ($foundElements as $element) { if (!property_exists($element->attributes(), 'type')) { continue; diff --git a/Magento2/Tests/Legacy/WidgetXMLUnitTest.2.xml b/Magento2/Tests/Legacy/WidgetXMLUnitTest.2.xml new file mode 100644 index 00000000..03066d9f --- /dev/null +++ b/Magento2/Tests/Legacy/WidgetXMLUnitTest.2.xml @@ -0,0 +1,11 @@ + + + + + diff --git a/Magento2/Tests/Legacy/WidgetXMLUnitTest.php b/Magento2/Tests/Legacy/WidgetXMLUnitTest.php index 36026b93..0af6f292 100644 --- a/Magento2/Tests/Legacy/WidgetXMLUnitTest.php +++ b/Magento2/Tests/Legacy/WidgetXMLUnitTest.php @@ -14,11 +14,19 @@ class WidgetXMLUnitTest extends AbstractSniffUnitTest */ public function getErrorList($testFile = '') { - return [ - 9 => 1, - 12 => 1, - 14 => 1, - ]; + if ($testFile === 'WidgetXMLUnitTest.1.xml') { + return [ + 9 => 1, + 12 => 1, + 14 => 1, + ]; + } + if ($testFile === 'WidgetXMLUnitTest.2.xml') { + return [ + 1 => 1 + ]; + } + return []; } /** From f4b01177d18193b6c5c986567320d6d82c6d5889 Mon Sep 17 00:00:00 2001 From: Elisea Cornejo Date: Thu, 9 Sep 2021 15:29:37 +0200 Subject: [PATCH 13/37] AC-666: Create phpcs static check for CopyrightTest --- Magento2/Sniffs/Legacy/CopyrightSniff.php | 2 +- Magento2/Tests/Legacy/CopyrightUnitTest.php | 15 ++++++++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/Magento2/Sniffs/Legacy/CopyrightSniff.php b/Magento2/Sniffs/Legacy/CopyrightSniff.php index e2facc85..76cb43ea 100644 --- a/Magento2/Sniffs/Legacy/CopyrightSniff.php +++ b/Magento2/Sniffs/Legacy/CopyrightSniff.php @@ -40,7 +40,7 @@ public function process(File $phpcsFile, $stackPtr) if (strpos($contentFile, self::COPYRIGHT_MAGENTO_TEXT) === false || $adobeCopyrightFound === false) { $phpcsFile->addWarningOnLine( 'Copyright is missing or has wrong format', - null, + $phpcsFile->getTokens()[$positionComment]['line'], self::WARNING_CODE ); } diff --git a/Magento2/Tests/Legacy/CopyrightUnitTest.php b/Magento2/Tests/Legacy/CopyrightUnitTest.php index 2d6e8c3f..37133e0e 100644 --- a/Magento2/Tests/Legacy/CopyrightUnitTest.php +++ b/Magento2/Tests/Legacy/CopyrightUnitTest.php @@ -26,8 +26,17 @@ public function getWarningList($testFile = ''): array return []; } - return [ - null => 1, - ]; + if ($testFile === 'CopyrightUnitTest.1.inc') { + return [ + 1 => 1, + ]; + } + if ($testFile === 'CopyrightUnitTest.2.inc' || 'CopyrightUnitTest.3.inc') { + return [ + 3 => 1, + ]; + } + + return []; } } From 64512dd75251493940fe2773ed30fc1f84e81bd7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Cuerdo=20=C3=81lvarez?= Date: Thu, 9 Sep 2021 16:12:14 +0200 Subject: [PATCH 14/37] AC-661: Create phpcs static check for XmlTest --- Magento2/Sniffs/Legacy/WidgetXMLSniff.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Magento2/Sniffs/Legacy/WidgetXMLSniff.php b/Magento2/Sniffs/Legacy/WidgetXMLSniff.php index f1d85161..f139e37d 100644 --- a/Magento2/Sniffs/Legacy/WidgetXMLSniff.php +++ b/Magento2/Sniffs/Legacy/WidgetXMLSniff.php @@ -38,7 +38,7 @@ public function process(File $phpcsFile, $stackPtr) return; } - try{ + try { $xml = simplexml_load_string($this->getFormattedXML($phpcsFile)); } catch (\Exception $e) { $phpcsFile->addError( From df14044f89bf21a33de2b27a72f67153311af15b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Cuerdo=20=C3=81lvarez?= Date: Thu, 9 Sep 2021 17:10:38 +0200 Subject: [PATCH 15/37] AC-661: Create phpcs static check for XmlTest --- Magento2/Sniffs/Legacy/WidgetXMLSniff.php | 29 ++++++++++++++++------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/Magento2/Sniffs/Legacy/WidgetXMLSniff.php b/Magento2/Sniffs/Legacy/WidgetXMLSniff.php index f139e37d..e80f221b 100644 --- a/Magento2/Sniffs/Legacy/WidgetXMLSniff.php +++ b/Magento2/Sniffs/Legacy/WidgetXMLSniff.php @@ -41,14 +41,11 @@ public function process(File $phpcsFile, $stackPtr) try { $xml = simplexml_load_string($this->getFormattedXML($phpcsFile)); } catch (\Exception $e) { - $phpcsFile->addError( - sprintf( - "Couldn't parse contents of '%s', check that they are in valid XML format", - $phpcsFile->getFilename(), - ), - $stackPtr, - self::ERROR_CODE_XML - ); + $this->invalidXML($phpcsFile, $stackPtr); + return; + } + if ($xml === false) { + $this->invalidXML($phpcsFile, $stackPtr); return; } @@ -87,6 +84,22 @@ public function process(File $phpcsFile, $stackPtr) } } + /** + * @param File $phpcsFile + * @param int $stackPtr + */ + protected function invalidXML(File $phpcsFile, int $stackPtr): void + { + $phpcsFile->addError( + sprintf( + "Couldn't parse contents of '%s', check that they are in valid XML format", + $phpcsFile->getFilename(), + ), + $stackPtr, + self::ERROR_CODE_XML + ); + } + /** * Check if the element passed is in the currently sniffed line * From 2f4c72ead7ef5b6994faeb96ebad161f9fdb6afd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Cuerdo=20=C3=81lvarez?= Date: Thu, 9 Sep 2021 17:11:52 +0200 Subject: [PATCH 16/37] AC-661: Create phpcs static check for XmlTest --- Magento2/Sniffs/Legacy/WidgetXMLSniff.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Magento2/Sniffs/Legacy/WidgetXMLSniff.php b/Magento2/Sniffs/Legacy/WidgetXMLSniff.php index e80f221b..064c88c2 100644 --- a/Magento2/Sniffs/Legacy/WidgetXMLSniff.php +++ b/Magento2/Sniffs/Legacy/WidgetXMLSniff.php @@ -85,6 +85,8 @@ public function process(File $phpcsFile, $stackPtr) } /** + * Adds an invalid XML error + * * @param File $phpcsFile * @param int $stackPtr */ From 7a6f29fe56df07f19af7b16a49529eaa79e3c9cf Mon Sep 17 00:00:00 2001 From: Elisea Cornejo Date: Thu, 9 Sep 2021 17:12:41 +0200 Subject: [PATCH 17/37] AC-666: Create phpcs static check for CopyrightTest --- Magento2/Sniffs/Legacy/CopyrightSniff.php | 4 +++- Magento2/Tests/Legacy/CopyrightUnitTest.5.inc | 7 +++++++ Magento2/Tests/Legacy/CopyrightUnitTest.php | 4 ++-- 3 files changed, 12 insertions(+), 3 deletions(-) create mode 100644 Magento2/Tests/Legacy/CopyrightUnitTest.5.inc diff --git a/Magento2/Sniffs/Legacy/CopyrightSniff.php b/Magento2/Sniffs/Legacy/CopyrightSniff.php index 76cb43ea..960819e8 100644 --- a/Magento2/Sniffs/Legacy/CopyrightSniff.php +++ b/Magento2/Sniffs/Legacy/CopyrightSniff.php @@ -37,7 +37,9 @@ public function process(File $phpcsFile, $stackPtr) $contentFile = $phpcsFile->getTokens()[$positionComment]['content']; $adobeCopyrightFound = preg_match(self::COPYRIGHT_ADOBE, $contentFile); - if (strpos($contentFile, self::COPYRIGHT_MAGENTO_TEXT) === false || $adobeCopyrightFound === false) { + if (strpos($contentFile, self::COPYRIGHT_MAGENTO_TEXT) !== false || $adobeCopyrightFound) { + return; + } else { $phpcsFile->addWarningOnLine( 'Copyright is missing or has wrong format', $phpcsFile->getTokens()[$positionComment]['line'], diff --git a/Magento2/Tests/Legacy/CopyrightUnitTest.5.inc b/Magento2/Tests/Legacy/CopyrightUnitTest.5.inc new file mode 100644 index 00000000..e874c2ca --- /dev/null +++ b/Magento2/Tests/Legacy/CopyrightUnitTest.5.inc @@ -0,0 +1,7 @@ + 1, ]; } - if ($testFile === 'CopyrightUnitTest.2.inc' || 'CopyrightUnitTest.3.inc') { + if ($testFile === 'CopyrightUnitTest.2.inc' || $testFile === 'CopyrightUnitTest.3.inc') { return [ 3 => 1, ]; From a2864d222ff6c1afb86ae37b8672a1e5f0d07b4e Mon Sep 17 00:00:00 2001 From: Elisea Cornejo Date: Mon, 13 Sep 2021 09:29:07 +0200 Subject: [PATCH 18/37] AC-666: Create phpcs static check for CopyrightTest --- Magento2/Sniffs/Legacy/CopyrightSniff.php | 42 ++++++++++++++--------- 1 file changed, 26 insertions(+), 16 deletions(-) diff --git a/Magento2/Sniffs/Legacy/CopyrightSniff.php b/Magento2/Sniffs/Legacy/CopyrightSniff.php index 960819e8..f4ccd647 100644 --- a/Magento2/Sniffs/Legacy/CopyrightSniff.php +++ b/Magento2/Sniffs/Legacy/CopyrightSniff.php @@ -30,22 +30,32 @@ public function register() */ public function process(File $phpcsFile, $stackPtr) { - $positionOpenTag = $phpcsFile->findPrevious(T_OPEN_TAG, $stackPtr - 1); - - if ($positionOpenTag === false) { - $positionComment = $phpcsFile->findNext(T_DOC_COMMENT_STRING, $stackPtr); - $contentFile = $phpcsFile->getTokens()[$positionComment]['content']; - $adobeCopyrightFound = preg_match(self::COPYRIGHT_ADOBE, $contentFile); - - if (strpos($contentFile, self::COPYRIGHT_MAGENTO_TEXT) !== false || $adobeCopyrightFound) { - return; - } else { - $phpcsFile->addWarningOnLine( - 'Copyright is missing or has wrong format', - $phpcsFile->getTokens()[$positionComment]['line'], - self::WARNING_CODE - ); - } + if ($phpcsFile->findPrevious(T_OPEN_TAG, $stackPtr - 1) !== false) { + return; } + + $positionComment = $phpcsFile->findNext(T_DOC_COMMENT_STRING, $stackPtr); + + if ($positionComment === false) { + $phpcsFile->addWarning( + 'Copyright is missing', + $stackPtr, + self::WARNING_CODE + ); + return; + } + + $content = $phpcsFile->getTokens()[$positionComment]['content']; + $adobeCopyrightFound = preg_match(self::COPYRIGHT_ADOBE, $content); + + if (strpos($content, self::COPYRIGHT_MAGENTO_TEXT) !== false || $adobeCopyrightFound) { + return; + } + + $phpcsFile->addWarningOnLine( + 'Copyright is missing or has wrong format', + $phpcsFile->getTokens()[$positionComment]['line'], + self::WARNING_CODE + ); } } From 74c47b2928e260d0071dbc75c55b2a76c5db087d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Cuerdo=20=C3=81lvarez?= Date: Mon, 13 Sep 2021 11:55:33 +0200 Subject: [PATCH 19/37] AC-661: Create phpcs static check for XmlTest --- Magento2/Sniffs/Legacy/WidgetXMLSniff.php | 22 ++----------------- Magento2/Tests/Legacy/WidgetXMLUnitTest.2.xml | 22 +++++++++++++++++++ Magento2/Tests/Legacy/WidgetXMLUnitTest.3.xml | 22 +++++++++++++++++++ Magento2/Tests/Legacy/WidgetXMLUnitTest.php | 4 +++- 4 files changed, 49 insertions(+), 21 deletions(-) create mode 100644 Magento2/Tests/Legacy/WidgetXMLUnitTest.3.xml diff --git a/Magento2/Sniffs/Legacy/WidgetXMLSniff.php b/Magento2/Sniffs/Legacy/WidgetXMLSniff.php index 064c88c2..efd62aee 100644 --- a/Magento2/Sniffs/Legacy/WidgetXMLSniff.php +++ b/Magento2/Sniffs/Legacy/WidgetXMLSniff.php @@ -38,12 +38,8 @@ public function process(File $phpcsFile, $stackPtr) return; } - try { - $xml = simplexml_load_string($this->getFormattedXML($phpcsFile)); - } catch (\Exception $e) { - $this->invalidXML($phpcsFile, $stackPtr); - return; - } + $xml = simplexml_load_string($this->getFormattedXML($phpcsFile)); + if ($xml === false) { $this->invalidXML($phpcsFile, $stackPtr); return; @@ -102,20 +98,6 @@ protected function invalidXML(File $phpcsFile, int $stackPtr): void ); } - /** - * Check if the element passed is in the currently sniffed line - * - * @param SimpleXMLElement $element - * @param int $stackPtr - * @return bool - */ - private function elementIsCurrentlySniffedLine(SimpleXMLElement $element, int $stackPtr): bool - { - $node = dom_import_simplexml($element); - - return $node->getLineNo() === $stackPtr + 1; - } - /** * Format the incoming XML to avoid tags split into several lines. * diff --git a/Magento2/Tests/Legacy/WidgetXMLUnitTest.2.xml b/Magento2/Tests/Legacy/WidgetXMLUnitTest.2.xml index 03066d9f..f99ae1ca 100644 --- a/Magento2/Tests/Legacy/WidgetXMLUnitTest.2.xml +++ b/Magento2/Tests/Legacy/WidgetXMLUnitTest.2.xml @@ -7,5 +7,27 @@ --> + + + + List of Products that are set as New + + + + + Deprecated + + + + Deprecated + + + diff --git a/Magento2/Tests/Legacy/WidgetXMLUnitTest.3.xml b/Magento2/Tests/Legacy/WidgetXMLUnitTest.3.xml new file mode 100644 index 00000000..ef90e28b --- /dev/null +++ b/Magento2/Tests/Legacy/WidgetXMLUnitTest.3.xml @@ -0,0 +1,22 @@ + + + + + + + diff --git a/Magento2/Tests/Legacy/WidgetXMLUnitTest.php b/Magento2/Tests/Legacy/WidgetXMLUnitTest.php index 0af6f292..c52b920b 100644 --- a/Magento2/Tests/Legacy/WidgetXMLUnitTest.php +++ b/Magento2/Tests/Legacy/WidgetXMLUnitTest.php @@ -23,7 +23,9 @@ public function getErrorList($testFile = '') } if ($testFile === 'WidgetXMLUnitTest.2.xml') { return [ - 1 => 1 + 9 => 1, + 17 => 1, + 24 => 1, ]; } return []; From dae1ab386078bb872a143216285b891d27d6c967 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Cuerdo=20=C3=81lvarez?= Date: Mon, 13 Sep 2021 12:07:11 +0200 Subject: [PATCH 20/37] AC-661: Create phpcs static check for XmlTest --- Magento2/ruleset.xml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Magento2/ruleset.xml b/Magento2/ruleset.xml index 1e247a2f..158173f3 100644 --- a/Magento2/ruleset.xml +++ b/Magento2/ruleset.xml @@ -247,6 +247,11 @@ 8 warning + + *\/widget.xml$ + 8 + warning + From d528da6f9861f73ccaff8a9eff578a1fee3337c1 Mon Sep 17 00:00:00 2001 From: Elisea Cornejo Date: Mon, 13 Sep 2021 12:29:54 +0200 Subject: [PATCH 21/37] AC-666: Static check for CopyrightTest for another extensions files --- .../CopyrightAnotherExtensionsFilesSniff.php | 52 +++++++++++++++++++ .../Legacy/AbstractJsSniffUnitTestCase.php | 33 ++++++++++++ ...yrightAnotherExtensionsFilesUnitTest.1.xml | 10 ++++ ...pyrightAnotherExtensionsFilesUnitTest.2.js | 10 ++++ ...pyrightAnotherExtensionsFilesUnitTest.4.js | 10 ++++ ...opyrightAnotherExtensionsFilesUnitTest.php | 41 +++++++++++++++ ...opyrightAnotherExtensionsFilesUnitTest.xml | 10 ++++ 7 files changed, 166 insertions(+) create mode 100644 Magento2/Sniffs/Legacy/CopyrightAnotherExtensionsFilesSniff.php create mode 100644 Magento2/Tests/Legacy/AbstractJsSniffUnitTestCase.php create mode 100644 Magento2/Tests/Legacy/CopyrightAnotherExtensionsFilesUnitTest.1.xml create mode 100644 Magento2/Tests/Legacy/CopyrightAnotherExtensionsFilesUnitTest.2.js create mode 100644 Magento2/Tests/Legacy/CopyrightAnotherExtensionsFilesUnitTest.4.js create mode 100644 Magento2/Tests/Legacy/CopyrightAnotherExtensionsFilesUnitTest.php create mode 100644 Magento2/Tests/Legacy/CopyrightAnotherExtensionsFilesUnitTest.xml diff --git a/Magento2/Sniffs/Legacy/CopyrightAnotherExtensionsFilesSniff.php b/Magento2/Sniffs/Legacy/CopyrightAnotherExtensionsFilesSniff.php new file mode 100644 index 00000000..1455ee58 --- /dev/null +++ b/Magento2/Sniffs/Legacy/CopyrightAnotherExtensionsFilesSniff.php @@ -0,0 +1,52 @@ + 0) { + return; + } + + $fileText = $phpcsFile->getTokensAsString($stackPtr, count($phpcsFile->getTokens())); + $adobeCopyrightFound = preg_match(self::COPYRIGHT_ADOBE, $fileText); + + if (strpos($fileText, self::COPYRIGHT_MAGENTO_TEXT) !== false || $adobeCopyrightFound) { + return; + } + + $phpcsFile->addWarningOnLine( + 'Copyright is missing or has wrong format', + null, + self::WARNING_CODE + ); + } +} diff --git a/Magento2/Tests/Legacy/AbstractJsSniffUnitTestCase.php b/Magento2/Tests/Legacy/AbstractJsSniffUnitTestCase.php new file mode 100644 index 00000000..4b891a3c --- /dev/null +++ b/Magento2/Tests/Legacy/AbstractJsSniffUnitTestCase.php @@ -0,0 +1,33 @@ +extensions = array_merge( + $config->extensions, + [ + 'js' => 'PHP' + ] + ); + + $GLOBALS['PHP_CODESNIFFER_CONFIG'] = $config; + } +} diff --git a/Magento2/Tests/Legacy/CopyrightAnotherExtensionsFilesUnitTest.1.xml b/Magento2/Tests/Legacy/CopyrightAnotherExtensionsFilesUnitTest.1.xml new file mode 100644 index 00000000..5bbf8807 --- /dev/null +++ b/Magento2/Tests/Legacy/CopyrightAnotherExtensionsFilesUnitTest.1.xml @@ -0,0 +1,10 @@ + + + + + \ No newline at end of file diff --git a/Magento2/Tests/Legacy/CopyrightAnotherExtensionsFilesUnitTest.2.js b/Magento2/Tests/Legacy/CopyrightAnotherExtensionsFilesUnitTest.2.js new file mode 100644 index 00000000..511f7b94 --- /dev/null +++ b/Magento2/Tests/Legacy/CopyrightAnotherExtensionsFilesUnitTest.2.js @@ -0,0 +1,10 @@ +/** + * Copyright Adobe. + * See COPYING.txt for license details. + */ + +define([ + 'jquery' +], function (){ + +}); \ No newline at end of file diff --git a/Magento2/Tests/Legacy/CopyrightAnotherExtensionsFilesUnitTest.4.js b/Magento2/Tests/Legacy/CopyrightAnotherExtensionsFilesUnitTest.4.js new file mode 100644 index 00000000..2eb60f49 --- /dev/null +++ b/Magento2/Tests/Legacy/CopyrightAnotherExtensionsFilesUnitTest.4.js @@ -0,0 +1,10 @@ +/** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +define([ + 'jquery' +], function (){ + +}); \ No newline at end of file diff --git a/Magento2/Tests/Legacy/CopyrightAnotherExtensionsFilesUnitTest.php b/Magento2/Tests/Legacy/CopyrightAnotherExtensionsFilesUnitTest.php new file mode 100644 index 00000000..8796abb9 --- /dev/null +++ b/Magento2/Tests/Legacy/CopyrightAnotherExtensionsFilesUnitTest.php @@ -0,0 +1,41 @@ + 1, + ]; + } + if ($testFile === 'CopyrightAnotherExtensionsFilesUnitTest.2.js') { + return [ + null => 1, + ]; + } + if ($testFile === 'CopyrightAnotherExtensionsFilesUnitTest.3.xml') { + return []; + } + if ($testFile === 'CopyrightAnotherExtensionsFilesUnitTest.4.js') { + return []; + } + return []; + } +} diff --git a/Magento2/Tests/Legacy/CopyrightAnotherExtensionsFilesUnitTest.xml b/Magento2/Tests/Legacy/CopyrightAnotherExtensionsFilesUnitTest.xml new file mode 100644 index 00000000..d1dcf359 --- /dev/null +++ b/Magento2/Tests/Legacy/CopyrightAnotherExtensionsFilesUnitTest.xml @@ -0,0 +1,10 @@ + + + + + \ No newline at end of file From 6a735c15d4ace82b9ee224fd36174cd05d0da42e Mon Sep 17 00:00:00 2001 From: Elisea Cornejo Date: Mon, 13 Sep 2021 12:30:05 +0200 Subject: [PATCH 22/37] AC-666: Static check for CopyrightTest for another extensions files --- Magento2/ruleset.xml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Magento2/ruleset.xml b/Magento2/ruleset.xml index 1e247a2f..ac130d68 100644 --- a/Magento2/ruleset.xml +++ b/Magento2/ruleset.xml @@ -3,7 +3,7 @@ Magento Coding Standard - + @@ -629,6 +629,10 @@ */Test/* *Test.php + + 5 + warning + 0 From ef00afd073dbed5a43e36674ec9c3de847844687 Mon Sep 17 00:00:00 2001 From: Sergio Vera Date: Mon, 13 Sep 2021 17:07:55 +0200 Subject: [PATCH 23/37] Fixed wrongly returning error for valid descriptions --- .../ClassPropertyPHPDocFormattingSniff.php | 38 +++++++++++-------- .../ClassPropertyPHPDocFormattingUnitTest.inc | 23 ++++++++++- .../ClassPropertyPHPDocFormattingUnitTest.php | 4 +- 3 files changed, 47 insertions(+), 18 deletions(-) diff --git a/Magento2/Sniffs/Commenting/ClassPropertyPHPDocFormattingSniff.php b/Magento2/Sniffs/Commenting/ClassPropertyPHPDocFormattingSniff.php index 8ec509b4..18deeeff 100644 --- a/Magento2/Sniffs/Commenting/ClassPropertyPHPDocFormattingSniff.php +++ b/Magento2/Sniffs/Commenting/ClassPropertyPHPDocFormattingSniff.php @@ -112,10 +112,11 @@ public function processMemberVar(File $phpcsFile, $stackPtr) if ($varParts[1]) { return; } - $error = 'Short description duplicates class property name.'; - $phpcsFile->addWarning($error, $isShortDescriptionAfterVar, 'AlreadyHaveMeaningFulNameVar'); + $error = 'Short description must be before @var tag.'; + $phpcsFile->addWarning($error, $isShortDescriptionAfterVar, 'ShortDescriptionAfterVar'); return; } + // Check if class has already have meaningful description before @var tag $isShortDescriptionPreviousVar = $phpcsFile->findPrevious( T_DOC_COMMENT_STRING, @@ -125,23 +126,28 @@ public function processMemberVar(File $phpcsFile, $stackPtr) null, false ); - if ($this->PHPDocFormattingValidator->providesMeaning( - $isShortDescriptionPreviousVar, - $commentStart, - $tokens - ) !== true) { - preg_match( - '`^((?:\|?(?:array\([^\)]*\)|[\\\\\[\]]+))*)( .*)?`i', - $tokens[($foundVar + 2)]['content'], - $varParts - ); - if ($varParts[1]) { - return; - } + + if (stripos($tokens[$isShortDescriptionPreviousVar]['content'], $tokens[$string]['content']) !== false) { $error = 'Short description duplicates class property name.'; - $phpcsFile->addWarning($error, $isShortDescriptionPreviousVar, 'AlreadyHaveMeaningFulNameVar'); + $phpcsFile->addWarning($error, $isShortDescriptionPreviousVar, 'AlreadyHaveMeaningfulNameVar'); return; } + $re = '/ + # Split camelCase "words". Two global alternatives. Either g1of2: + (?<=[a-z]) # Position is after a lowercase, + (?=[A-Z]) # and before an uppercase letter. + | (?<=[A-Z]) # Or g2of2; Position is after uppercase, + (?=[A-Z][a-z]) # and before upper-then-lower case. + /x'; + $varTagParts = preg_split($re, $tokens[$string]['content']); + + foreach ($varTagParts as $part) { + if (stripos($tokens[$isShortDescriptionPreviousVar]['content'], $part) === false) { + return; + } + } + $error = 'Short description duplicates class property name.'; + $phpcsFile->addWarning($error, $isShortDescriptionPreviousVar, 'AlreadyHaveMeaningfulNameVar'); } /** diff --git a/Magento2/Tests/Commenting/ClassPropertyPHPDocFormattingUnitTest.inc b/Magento2/Tests/Commenting/ClassPropertyPHPDocFormattingUnitTest.inc index 6dcccf65..93339460 100644 --- a/Magento2/Tests/Commenting/ClassPropertyPHPDocFormattingUnitTest.inc +++ b/Magento2/Tests/Commenting/ClassPropertyPHPDocFormattingUnitTest.inc @@ -65,11 +65,25 @@ class Bar { private $variableName; /** - * Some more invalid description + * Some more invalid description with test which is the same name as the variable and is not allowed * * @var test */ protected $test; + + /** + * Formatted Correctly Protected Class Member + * + * @var correctlyFormattedProtectedClassMember + */ + protected $correctlyFormattedProtectedClassMember; + + /** + * anotherCorrectlyFormattedProtectedClassMember + * + * @var anotherCorrectlyFormattedProtectedClassMember + */ + protected $anotherCorrectlyFormattedProtectedClassMember; } class correctlyFormattedClassMemberDocBlock @@ -99,4 +113,11 @@ class correctlyFormattedClassMemberDocBlock * \FooObject_TEST_C */ private $testObject; + + /** + * Fallback factory + * + * @var RulePool + */ + protected $rulePool; } diff --git a/Magento2/Tests/Commenting/ClassPropertyPHPDocFormattingUnitTest.php b/Magento2/Tests/Commenting/ClassPropertyPHPDocFormattingUnitTest.php index 5ce3f0d2..6686607b 100644 --- a/Magento2/Tests/Commenting/ClassPropertyPHPDocFormattingUnitTest.php +++ b/Magento2/Tests/Commenting/ClassPropertyPHPDocFormattingUnitTest.php @@ -32,7 +32,9 @@ public function getWarningList() 49 => 1, 56 => 1, 63 => 1, - 68 => 1 + 68 => 1, + 75 => 1, + 82 => 1, ]; } } From 95c56c9de1e426be89a042706f35876d9706e573 Mon Sep 17 00:00:00 2001 From: Sergio Vera Date: Tue, 14 Sep 2021 09:00:25 +0200 Subject: [PATCH 24/37] Update Magento2/Sniffs/Commenting/ClassPropertyPHPDocFormattingSniff.php Co-authored-by: Sergii Ivashchenko --- .../Sniffs/Commenting/ClassPropertyPHPDocFormattingSniff.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Magento2/Sniffs/Commenting/ClassPropertyPHPDocFormattingSniff.php b/Magento2/Sniffs/Commenting/ClassPropertyPHPDocFormattingSniff.php index 18deeeff..08dc5c0a 100644 --- a/Magento2/Sniffs/Commenting/ClassPropertyPHPDocFormattingSniff.php +++ b/Magento2/Sniffs/Commenting/ClassPropertyPHPDocFormattingSniff.php @@ -132,7 +132,7 @@ public function processMemberVar(File $phpcsFile, $stackPtr) $phpcsFile->addWarning($error, $isShortDescriptionPreviousVar, 'AlreadyHaveMeaningfulNameVar'); return; } - $re = '/ + $regularExpression = '/ # Split camelCase "words". Two global alternatives. Either g1of2: (?<=[a-z]) # Position is after a lowercase, (?=[A-Z]) # and before an uppercase letter. From 2a57af8e3db57f02518f90880358efe0b42d4dda Mon Sep 17 00:00:00 2001 From: Sergio Vera Date: Tue, 14 Sep 2021 09:00:30 +0200 Subject: [PATCH 25/37] Update Magento2/Sniffs/Commenting/ClassPropertyPHPDocFormattingSniff.php Co-authored-by: Sergii Ivashchenko --- .../Sniffs/Commenting/ClassPropertyPHPDocFormattingSniff.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Magento2/Sniffs/Commenting/ClassPropertyPHPDocFormattingSniff.php b/Magento2/Sniffs/Commenting/ClassPropertyPHPDocFormattingSniff.php index 08dc5c0a..492a1012 100644 --- a/Magento2/Sniffs/Commenting/ClassPropertyPHPDocFormattingSniff.php +++ b/Magento2/Sniffs/Commenting/ClassPropertyPHPDocFormattingSniff.php @@ -141,11 +141,9 @@ public function processMemberVar(File $phpcsFile, $stackPtr) /x'; $varTagParts = preg_split($re, $tokens[$string]['content']); - foreach ($varTagParts as $part) { - if (stripos($tokens[$isShortDescriptionPreviousVar]['content'], $part) === false) { + if (stripos($tokens[$isShortDescriptionPreviousVar]['content'], implode(' ', $varTagParts)) === false) { return; } - } $error = 'Short description duplicates class property name.'; $phpcsFile->addWarning($error, $isShortDescriptionPreviousVar, 'AlreadyHaveMeaningfulNameVar'); } From f209db6b754b9aaa6f665f67e6a8ba4e940f06a2 Mon Sep 17 00:00:00 2001 From: Sergio Vera Date: Tue, 14 Sep 2021 09:02:05 +0200 Subject: [PATCH 26/37] Fixed wrongly returning error for valid descriptions --- .../Commenting/ClassPropertyPHPDocFormattingSniff.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Magento2/Sniffs/Commenting/ClassPropertyPHPDocFormattingSniff.php b/Magento2/Sniffs/Commenting/ClassPropertyPHPDocFormattingSniff.php index 492a1012..113da3e6 100644 --- a/Magento2/Sniffs/Commenting/ClassPropertyPHPDocFormattingSniff.php +++ b/Magento2/Sniffs/Commenting/ClassPropertyPHPDocFormattingSniff.php @@ -127,6 +127,10 @@ public function processMemberVar(File $phpcsFile, $stackPtr) false ); + if ($isShortDescriptionPreviousVar === false) { + return; + } + if (stripos($tokens[$isShortDescriptionPreviousVar]['content'], $tokens[$string]['content']) !== false) { $error = 'Short description duplicates class property name.'; $phpcsFile->addWarning($error, $isShortDescriptionPreviousVar, 'AlreadyHaveMeaningfulNameVar'); @@ -139,7 +143,7 @@ public function processMemberVar(File $phpcsFile, $stackPtr) | (?<=[A-Z]) # Or g2of2; Position is after uppercase, (?=[A-Z][a-z]) # and before upper-then-lower case. /x'; - $varTagParts = preg_split($re, $tokens[$string]['content']); + $varTagParts = preg_split($regularExpression, $tokens[$string]['content']); if (stripos($tokens[$isShortDescriptionPreviousVar]['content'], implode(' ', $varTagParts)) === false) { return; From 1ed415620f31f914e590a113b3bfe7464e71d38e Mon Sep 17 00:00:00 2001 From: Sergio Vera Date: Tue, 14 Sep 2021 09:06:46 +0200 Subject: [PATCH 27/37] Fixed wrongly returning error for valid descriptions --- .../Tests/Commenting/ClassPropertyPHPDocFormattingUnitTest.php | 1 - 1 file changed, 1 deletion(-) diff --git a/Magento2/Tests/Commenting/ClassPropertyPHPDocFormattingUnitTest.php b/Magento2/Tests/Commenting/ClassPropertyPHPDocFormattingUnitTest.php index 6686607b..7e8ecc91 100644 --- a/Magento2/Tests/Commenting/ClassPropertyPHPDocFormattingUnitTest.php +++ b/Magento2/Tests/Commenting/ClassPropertyPHPDocFormattingUnitTest.php @@ -33,7 +33,6 @@ public function getWarningList() 56 => 1, 63 => 1, 68 => 1, - 75 => 1, 82 => 1, ]; } From efaffacb5ff94f21c12ca529926ee2b81ba06906 Mon Sep 17 00:00:00 2001 From: Sergio Vera Date: Tue, 14 Sep 2021 09:12:01 +0200 Subject: [PATCH 28/37] Fixed wrongly returning error for valid descriptions --- .../Commenting/ClassPropertyPHPDocFormattingSniff.php | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/Magento2/Sniffs/Commenting/ClassPropertyPHPDocFormattingSniff.php b/Magento2/Sniffs/Commenting/ClassPropertyPHPDocFormattingSniff.php index 113da3e6..09d7afa9 100644 --- a/Magento2/Sniffs/Commenting/ClassPropertyPHPDocFormattingSniff.php +++ b/Magento2/Sniffs/Commenting/ClassPropertyPHPDocFormattingSniff.php @@ -131,11 +131,6 @@ public function processMemberVar(File $phpcsFile, $stackPtr) return; } - if (stripos($tokens[$isShortDescriptionPreviousVar]['content'], $tokens[$string]['content']) !== false) { - $error = 'Short description duplicates class property name.'; - $phpcsFile->addWarning($error, $isShortDescriptionPreviousVar, 'AlreadyHaveMeaningfulNameVar'); - return; - } $regularExpression = '/ # Split camelCase "words". Two global alternatives. Either g1of2: (?<=[a-z]) # Position is after a lowercase, @@ -145,9 +140,9 @@ public function processMemberVar(File $phpcsFile, $stackPtr) /x'; $varTagParts = preg_split($regularExpression, $tokens[$string]['content']); - if (stripos($tokens[$isShortDescriptionPreviousVar]['content'], implode(' ', $varTagParts)) === false) { - return; - } + if (stripos($tokens[$isShortDescriptionPreviousVar]['content'], implode('', $varTagParts)) === false) { + return; + } $error = 'Short description duplicates class property name.'; $phpcsFile->addWarning($error, $isShortDescriptionPreviousVar, 'AlreadyHaveMeaningfulNameVar'); } From 62e0fc11dc03994fb290e6986b7724d536f3a4bf Mon Sep 17 00:00:00 2001 From: Sergio Vera Date: Tue, 14 Sep 2021 09:25:05 +0200 Subject: [PATCH 29/37] Fixed wrongly returning error for valid descriptions --- Magento2/Sniffs/Classes/AbstractApiSniff.php | 2 +- Magento2/Sniffs/Classes/DiscouragedDependenciesSniff.php | 2 +- Magento2/Sniffs/Exceptions/DirectThrowSniff.php | 2 +- Magento2/Sniffs/Exceptions/ThrowCatchSniff.php | 2 +- Magento2/Sniffs/Exceptions/TryProcessSystemResourcesSniff.php | 2 +- Magento2/Sniffs/Functions/StaticFunctionSniff.php | 2 +- Magento2/Sniffs/Legacy/MageEntitySniff.php | 2 +- Magento2/Sniffs/Methods/DeprecatedModelMethodSniff.php | 2 +- Magento2/Sniffs/NamingConvention/InterfaceNameSniff.php | 2 +- Magento2/Sniffs/PHP/GotoSniff.php | 2 +- Magento2/Sniffs/PHP/ReturnValueCheckSniff.php | 4 +--- Magento2/Sniffs/PHP/VarSniff.php | 2 +- Magento2/Sniffs/Performance/ForeachArrayMergeSniff.php | 2 +- Magento2/Sniffs/SQL/RawQuerySniff.php | 2 +- Magento2/Sniffs/Security/LanguageConstructSniff.php | 4 ++-- Magento2/Sniffs/Security/SuperglobalSniff.php | 4 ++-- Magento2/Sniffs/Security/XssTemplateSniff.php | 2 +- Magento2/Sniffs/Strings/ExecutableRegExSniff.php | 2 +- Magento2/Sniffs/Strings/StringConcatSniff.php | 2 +- Magento2/Sniffs/Templates/ThisInTemplateSniff.php | 4 ++-- Magento2/Sniffs/Whitespace/MultipleEmptyLinesSniff.php | 2 +- 21 files changed, 24 insertions(+), 26 deletions(-) diff --git a/Magento2/Sniffs/Classes/AbstractApiSniff.php b/Magento2/Sniffs/Classes/AbstractApiSniff.php index bb8a6571..3f709b70 100644 --- a/Magento2/Sniffs/Classes/AbstractApiSniff.php +++ b/Magento2/Sniffs/Classes/AbstractApiSniff.php @@ -15,7 +15,7 @@ class AbstractApiSniff implements Sniff { /** - * String representation of warning. + * Representation of warning. * * @var string */ diff --git a/Magento2/Sniffs/Classes/DiscouragedDependenciesSniff.php b/Magento2/Sniffs/Classes/DiscouragedDependenciesSniff.php index f5e45c63..8f82ff74 100644 --- a/Magento2/Sniffs/Classes/DiscouragedDependenciesSniff.php +++ b/Magento2/Sniffs/Classes/DiscouragedDependenciesSniff.php @@ -18,7 +18,7 @@ class DiscouragedDependenciesSniff implements Sniff const CONSTRUCT_METHOD_NAME = '__construct'; /** - * String representation of warning. + * Representation of warning. * * @var string */ diff --git a/Magento2/Sniffs/Exceptions/DirectThrowSniff.php b/Magento2/Sniffs/Exceptions/DirectThrowSniff.php index 622644bf..60140afb 100644 --- a/Magento2/Sniffs/Exceptions/DirectThrowSniff.php +++ b/Magento2/Sniffs/Exceptions/DirectThrowSniff.php @@ -14,7 +14,7 @@ class DirectThrowSniff implements Sniff { /** - * String representation of warning. + * Representation of warning. * phpcs:disable Generic.Files.LineLength.TooLong * @var string */ diff --git a/Magento2/Sniffs/Exceptions/ThrowCatchSniff.php b/Magento2/Sniffs/Exceptions/ThrowCatchSniff.php index c2510168..6497d47c 100644 --- a/Magento2/Sniffs/Exceptions/ThrowCatchSniff.php +++ b/Magento2/Sniffs/Exceptions/ThrowCatchSniff.php @@ -16,7 +16,7 @@ class ThrowCatchSniff implements Sniff { /** - * String representation of warning. + * Representation of warning. * * @var string */ diff --git a/Magento2/Sniffs/Exceptions/TryProcessSystemResourcesSniff.php b/Magento2/Sniffs/Exceptions/TryProcessSystemResourcesSniff.php index 0fa28149..49ddcf33 100644 --- a/Magento2/Sniffs/Exceptions/TryProcessSystemResourcesSniff.php +++ b/Magento2/Sniffs/Exceptions/TryProcessSystemResourcesSniff.php @@ -15,7 +15,7 @@ class TryProcessSystemResourcesSniff implements Sniff { /** - * String representation of warning. + * Representation of warning. * * @var string */ diff --git a/Magento2/Sniffs/Functions/StaticFunctionSniff.php b/Magento2/Sniffs/Functions/StaticFunctionSniff.php index 2ae706d0..b74683a9 100644 --- a/Magento2/Sniffs/Functions/StaticFunctionSniff.php +++ b/Magento2/Sniffs/Functions/StaticFunctionSniff.php @@ -14,7 +14,7 @@ class StaticFunctionSniff implements Sniff { /** - * String representation of warning. + * Representation of warning. * * @var string */ diff --git a/Magento2/Sniffs/Legacy/MageEntitySniff.php b/Magento2/Sniffs/Legacy/MageEntitySniff.php index de8b7dbf..ad334cec 100644 --- a/Magento2/Sniffs/Legacy/MageEntitySniff.php +++ b/Magento2/Sniffs/Legacy/MageEntitySniff.php @@ -14,7 +14,7 @@ class MageEntitySniff implements Sniff { /** - * String representation of error. + * Representation of error. * * @var string */ diff --git a/Magento2/Sniffs/Methods/DeprecatedModelMethodSniff.php b/Magento2/Sniffs/Methods/DeprecatedModelMethodSniff.php index f094c353..8e68b35a 100644 --- a/Magento2/Sniffs/Methods/DeprecatedModelMethodSniff.php +++ b/Magento2/Sniffs/Methods/DeprecatedModelMethodSniff.php @@ -16,7 +16,7 @@ class DeprecatedModelMethodSniff implements Sniff const RESOURCE_METHOD = "getResource"; /** - * String representation of warning. + * Representation of warning. * * @var string */ diff --git a/Magento2/Sniffs/NamingConvention/InterfaceNameSniff.php b/Magento2/Sniffs/NamingConvention/InterfaceNameSniff.php index 2ad688ec..b04da011 100644 --- a/Magento2/Sniffs/NamingConvention/InterfaceNameSniff.php +++ b/Magento2/Sniffs/NamingConvention/InterfaceNameSniff.php @@ -14,7 +14,7 @@ class InterfaceNameSniff implements Sniff { /** - * String representation of warning. + * Representation of warning. * * @var string */ diff --git a/Magento2/Sniffs/PHP/GotoSniff.php b/Magento2/Sniffs/PHP/GotoSniff.php index 4a5f06ca..0b74e855 100644 --- a/Magento2/Sniffs/PHP/GotoSniff.php +++ b/Magento2/Sniffs/PHP/GotoSniff.php @@ -14,7 +14,7 @@ class GotoSniff implements Sniff { /** - * String representation of warning. + * Representation of warning. * * @var string */ diff --git a/Magento2/Sniffs/PHP/ReturnValueCheckSniff.php b/Magento2/Sniffs/PHP/ReturnValueCheckSniff.php index 9929d46b..5a6d507f 100644 --- a/Magento2/Sniffs/PHP/ReturnValueCheckSniff.php +++ b/Magento2/Sniffs/PHP/ReturnValueCheckSniff.php @@ -14,7 +14,7 @@ class ReturnValueCheckSniff implements Sniff { /** - * String representation of error. + * Representation of error. * * @var string */ @@ -46,8 +46,6 @@ class ReturnValueCheckSniff implements Sniff protected $tokens = []; /** - * PHP_CodeSniffer file. - * * @var File */ protected $file; diff --git a/Magento2/Sniffs/PHP/VarSniff.php b/Magento2/Sniffs/PHP/VarSniff.php index fa7b28b7..dfa9bdee 100644 --- a/Magento2/Sniffs/PHP/VarSniff.php +++ b/Magento2/Sniffs/PHP/VarSniff.php @@ -14,7 +14,7 @@ class VarSniff implements Sniff { /** - * String representation of warning. + * Representation of warning. * * @var string */ diff --git a/Magento2/Sniffs/Performance/ForeachArrayMergeSniff.php b/Magento2/Sniffs/Performance/ForeachArrayMergeSniff.php index 9ab6c8cc..5e701bd7 100644 --- a/Magento2/Sniffs/Performance/ForeachArrayMergeSniff.php +++ b/Magento2/Sniffs/Performance/ForeachArrayMergeSniff.php @@ -14,7 +14,7 @@ class ForeachArrayMergeSniff implements Sniff { /** - * String representation of warning. + * Representation of warning. * * @var string */ diff --git a/Magento2/Sniffs/SQL/RawQuerySniff.php b/Magento2/Sniffs/SQL/RawQuerySniff.php index a32d4eb0..966e90ea 100644 --- a/Magento2/Sniffs/SQL/RawQuerySniff.php +++ b/Magento2/Sniffs/SQL/RawQuerySniff.php @@ -15,7 +15,7 @@ class RawQuerySniff implements Sniff { /** - * String representation of warning. + * Representation of warning. * * @var string */ diff --git a/Magento2/Sniffs/Security/LanguageConstructSniff.php b/Magento2/Sniffs/Security/LanguageConstructSniff.php index 9b10ae4a..f6ea2be2 100644 --- a/Magento2/Sniffs/Security/LanguageConstructSniff.php +++ b/Magento2/Sniffs/Security/LanguageConstructSniff.php @@ -14,14 +14,14 @@ class LanguageConstructSniff implements Sniff { /** - * String representation of error. + * Representation of error. * * @var string */ protected $errorMessage = 'Use of %s language construct is discouraged.'; /** - * String representation of backtick error. + * Representation of backtick error. * * phpcs:disable Generic.Files.LineLength * diff --git a/Magento2/Sniffs/Security/SuperglobalSniff.php b/Magento2/Sniffs/Security/SuperglobalSniff.php index 136f991f..7a30a3aa 100644 --- a/Magento2/Sniffs/Security/SuperglobalSniff.php +++ b/Magento2/Sniffs/Security/SuperglobalSniff.php @@ -14,14 +14,14 @@ class SuperglobalSniff implements Sniff { /** - * String representation of warning. + * Representation of warning. * * @var string */ protected $warningMessage = 'Direct use of %s Superglobal detected.'; /** - * String representation of error. + * Representation of error. * * @var string */ diff --git a/Magento2/Sniffs/Security/XssTemplateSniff.php b/Magento2/Sniffs/Security/XssTemplateSniff.php index f35943e5..eabff249 100644 --- a/Magento2/Sniffs/Security/XssTemplateSniff.php +++ b/Magento2/Sniffs/Security/XssTemplateSniff.php @@ -14,7 +14,7 @@ class XssTemplateSniff implements Sniff { /** - * String representation of warning. + * Representation of warning. * * @var string */ diff --git a/Magento2/Sniffs/Strings/ExecutableRegExSniff.php b/Magento2/Sniffs/Strings/ExecutableRegExSniff.php index 09706ed6..769a176c 100644 --- a/Magento2/Sniffs/Strings/ExecutableRegExSniff.php +++ b/Magento2/Sniffs/Strings/ExecutableRegExSniff.php @@ -15,7 +15,7 @@ class ExecutableRegExSniff implements Sniff { /** - * String representation of error. + * Representation of error. * * phpcs:disable Generic.Files.LineLength * diff --git a/Magento2/Sniffs/Strings/StringConcatSniff.php b/Magento2/Sniffs/Strings/StringConcatSniff.php index 89c8dc9b..f409f421 100644 --- a/Magento2/Sniffs/Strings/StringConcatSniff.php +++ b/Magento2/Sniffs/Strings/StringConcatSniff.php @@ -15,7 +15,7 @@ class StringConcatSniff implements Sniff { /** - * String representation of warning. + * Representation of warning. * * @var string */ diff --git a/Magento2/Sniffs/Templates/ThisInTemplateSniff.php b/Magento2/Sniffs/Templates/ThisInTemplateSniff.php index 9b5e5358..45b4ebad 100644 --- a/Magento2/Sniffs/Templates/ThisInTemplateSniff.php +++ b/Magento2/Sniffs/Templates/ThisInTemplateSniff.php @@ -21,7 +21,7 @@ class ThisInTemplateSniff implements Sniff protected $warningCodeFoundHelper = 'FoundHelper'; /** - * String representation of warning. + * Representation of warning. * * @var string */ @@ -35,7 +35,7 @@ class ThisInTemplateSniff implements Sniff protected $warningCodeFoundThis = 'FoundThis'; /** - * String representation of warning. + * Representation of warning. * * @var string */ diff --git a/Magento2/Sniffs/Whitespace/MultipleEmptyLinesSniff.php b/Magento2/Sniffs/Whitespace/MultipleEmptyLinesSniff.php index 4d74a29e..12bdc263 100644 --- a/Magento2/Sniffs/Whitespace/MultipleEmptyLinesSniff.php +++ b/Magento2/Sniffs/Whitespace/MultipleEmptyLinesSniff.php @@ -14,7 +14,7 @@ class MultipleEmptyLinesSniff implements Sniff { /** - * String representation of warning. + * Representation of warning. * * @var string */ From 5b4b543da950ec3c29ac41890c48ee302430cf87 Mon Sep 17 00:00:00 2001 From: Sergio Vera Date: Tue, 14 Sep 2021 09:28:54 +0200 Subject: [PATCH 30/37] Fixed wrongly returning error for valid descriptions --- Magento2/Sniffs/Classes/AbstractApiSniff.php | 2 +- Magento2/Sniffs/Classes/DiscouragedDependenciesSniff.php | 2 +- Magento2/Sniffs/Exceptions/DirectThrowSniff.php | 2 +- Magento2/Sniffs/Exceptions/ThrowCatchSniff.php | 2 +- Magento2/Sniffs/Exceptions/TryProcessSystemResourcesSniff.php | 2 +- Magento2/Sniffs/Functions/StaticFunctionSniff.php | 2 +- Magento2/Sniffs/Legacy/MageEntitySniff.php | 2 +- Magento2/Sniffs/Methods/DeprecatedModelMethodSniff.php | 2 +- Magento2/Sniffs/Performance/ForeachArrayMergeSniff.php | 2 +- Magento2/Sniffs/SQL/RawQuerySniff.php | 2 +- Magento2/Sniffs/Security/LanguageConstructSniff.php | 4 ++-- Magento2/Sniffs/Security/SuperglobalSniff.php | 4 ++-- Magento2/Sniffs/Security/XssTemplateSniff.php | 4 +--- Magento2/Sniffs/Strings/ExecutableRegExSniff.php | 2 +- Magento2/Sniffs/Strings/StringConcatSniff.php | 2 +- Magento2/Sniffs/Templates/ThisInTemplateSniff.php | 4 ++-- Magento2/Sniffs/Whitespace/MultipleEmptyLinesSniff.php | 2 +- 17 files changed, 20 insertions(+), 22 deletions(-) diff --git a/Magento2/Sniffs/Classes/AbstractApiSniff.php b/Magento2/Sniffs/Classes/AbstractApiSniff.php index 3f709b70..a32dc0f5 100644 --- a/Magento2/Sniffs/Classes/AbstractApiSniff.php +++ b/Magento2/Sniffs/Classes/AbstractApiSniff.php @@ -15,7 +15,7 @@ class AbstractApiSniff implements Sniff { /** - * Representation of warning. + * Representation of warning. * * @var string */ diff --git a/Magento2/Sniffs/Classes/DiscouragedDependenciesSniff.php b/Magento2/Sniffs/Classes/DiscouragedDependenciesSniff.php index 8f82ff74..8996131f 100644 --- a/Magento2/Sniffs/Classes/DiscouragedDependenciesSniff.php +++ b/Magento2/Sniffs/Classes/DiscouragedDependenciesSniff.php @@ -18,7 +18,7 @@ class DiscouragedDependenciesSniff implements Sniff const CONSTRUCT_METHOD_NAME = '__construct'; /** - * Representation of warning. + * Representation of warning. * * @var string */ diff --git a/Magento2/Sniffs/Exceptions/DirectThrowSniff.php b/Magento2/Sniffs/Exceptions/DirectThrowSniff.php index 60140afb..1c74f63a 100644 --- a/Magento2/Sniffs/Exceptions/DirectThrowSniff.php +++ b/Magento2/Sniffs/Exceptions/DirectThrowSniff.php @@ -14,7 +14,7 @@ class DirectThrowSniff implements Sniff { /** - * Representation of warning. + * Representation of warning. * phpcs:disable Generic.Files.LineLength.TooLong * @var string */ diff --git a/Magento2/Sniffs/Exceptions/ThrowCatchSniff.php b/Magento2/Sniffs/Exceptions/ThrowCatchSniff.php index 6497d47c..5c2efbcc 100644 --- a/Magento2/Sniffs/Exceptions/ThrowCatchSniff.php +++ b/Magento2/Sniffs/Exceptions/ThrowCatchSniff.php @@ -16,7 +16,7 @@ class ThrowCatchSniff implements Sniff { /** - * Representation of warning. + * Representation of warning. * * @var string */ diff --git a/Magento2/Sniffs/Exceptions/TryProcessSystemResourcesSniff.php b/Magento2/Sniffs/Exceptions/TryProcessSystemResourcesSniff.php index 49ddcf33..6d714dcc 100644 --- a/Magento2/Sniffs/Exceptions/TryProcessSystemResourcesSniff.php +++ b/Magento2/Sniffs/Exceptions/TryProcessSystemResourcesSniff.php @@ -15,7 +15,7 @@ class TryProcessSystemResourcesSniff implements Sniff { /** - * Representation of warning. + * Representation of warning. * * @var string */ diff --git a/Magento2/Sniffs/Functions/StaticFunctionSniff.php b/Magento2/Sniffs/Functions/StaticFunctionSniff.php index b74683a9..0805e3ce 100644 --- a/Magento2/Sniffs/Functions/StaticFunctionSniff.php +++ b/Magento2/Sniffs/Functions/StaticFunctionSniff.php @@ -14,7 +14,7 @@ class StaticFunctionSniff implements Sniff { /** - * Representation of warning. + * Representation of warning. * * @var string */ diff --git a/Magento2/Sniffs/Legacy/MageEntitySniff.php b/Magento2/Sniffs/Legacy/MageEntitySniff.php index ad334cec..8e305345 100644 --- a/Magento2/Sniffs/Legacy/MageEntitySniff.php +++ b/Magento2/Sniffs/Legacy/MageEntitySniff.php @@ -14,7 +14,7 @@ class MageEntitySniff implements Sniff { /** - * Representation of error. + * Representation of error. * * @var string */ diff --git a/Magento2/Sniffs/Methods/DeprecatedModelMethodSniff.php b/Magento2/Sniffs/Methods/DeprecatedModelMethodSniff.php index 8e68b35a..cf58267f 100644 --- a/Magento2/Sniffs/Methods/DeprecatedModelMethodSniff.php +++ b/Magento2/Sniffs/Methods/DeprecatedModelMethodSniff.php @@ -16,7 +16,7 @@ class DeprecatedModelMethodSniff implements Sniff const RESOURCE_METHOD = "getResource"; /** - * Representation of warning. + * Representation of warning. * * @var string */ diff --git a/Magento2/Sniffs/Performance/ForeachArrayMergeSniff.php b/Magento2/Sniffs/Performance/ForeachArrayMergeSniff.php index 5e701bd7..09bc0bdd 100644 --- a/Magento2/Sniffs/Performance/ForeachArrayMergeSniff.php +++ b/Magento2/Sniffs/Performance/ForeachArrayMergeSniff.php @@ -14,7 +14,7 @@ class ForeachArrayMergeSniff implements Sniff { /** - * Representation of warning. + * Representation of warning. * * @var string */ diff --git a/Magento2/Sniffs/SQL/RawQuerySniff.php b/Magento2/Sniffs/SQL/RawQuerySniff.php index 966e90ea..cb27c570 100644 --- a/Magento2/Sniffs/SQL/RawQuerySniff.php +++ b/Magento2/Sniffs/SQL/RawQuerySniff.php @@ -15,7 +15,7 @@ class RawQuerySniff implements Sniff { /** - * Representation of warning. + * Representation of warning. * * @var string */ diff --git a/Magento2/Sniffs/Security/LanguageConstructSniff.php b/Magento2/Sniffs/Security/LanguageConstructSniff.php index f6ea2be2..a8e1c979 100644 --- a/Magento2/Sniffs/Security/LanguageConstructSniff.php +++ b/Magento2/Sniffs/Security/LanguageConstructSniff.php @@ -14,14 +14,14 @@ class LanguageConstructSniff implements Sniff { /** - * Representation of error. + * Representation of error. * * @var string */ protected $errorMessage = 'Use of %s language construct is discouraged.'; /** - * Representation of backtick error. + * Representation of backtick error. * * phpcs:disable Generic.Files.LineLength * diff --git a/Magento2/Sniffs/Security/SuperglobalSniff.php b/Magento2/Sniffs/Security/SuperglobalSniff.php index 7a30a3aa..4d029dfc 100644 --- a/Magento2/Sniffs/Security/SuperglobalSniff.php +++ b/Magento2/Sniffs/Security/SuperglobalSniff.php @@ -14,14 +14,14 @@ class SuperglobalSniff implements Sniff { /** - * Representation of warning. + * Representation of warning. * * @var string */ protected $warningMessage = 'Direct use of %s Superglobal detected.'; /** - * Representation of error. + * Representation of error. * * @var string */ diff --git a/Magento2/Sniffs/Security/XssTemplateSniff.php b/Magento2/Sniffs/Security/XssTemplateSniff.php index eabff249..490d5cbd 100644 --- a/Magento2/Sniffs/Security/XssTemplateSniff.php +++ b/Magento2/Sniffs/Security/XssTemplateSniff.php @@ -14,7 +14,7 @@ class XssTemplateSniff implements Sniff { /** - * Representation of warning. + * Representation of warning. * * @var string */ @@ -85,8 +85,6 @@ class XssTemplateSniff implements Sniff private $statements = []; /** - * PHP_CodeSniffer file. - * * @var File */ private $file; diff --git a/Magento2/Sniffs/Strings/ExecutableRegExSniff.php b/Magento2/Sniffs/Strings/ExecutableRegExSniff.php index 769a176c..5e435322 100644 --- a/Magento2/Sniffs/Strings/ExecutableRegExSniff.php +++ b/Magento2/Sniffs/Strings/ExecutableRegExSniff.php @@ -15,7 +15,7 @@ class ExecutableRegExSniff implements Sniff { /** - * Representation of error. + * Representation of error. * * phpcs:disable Generic.Files.LineLength * diff --git a/Magento2/Sniffs/Strings/StringConcatSniff.php b/Magento2/Sniffs/Strings/StringConcatSniff.php index f409f421..06eb6a27 100644 --- a/Magento2/Sniffs/Strings/StringConcatSniff.php +++ b/Magento2/Sniffs/Strings/StringConcatSniff.php @@ -15,7 +15,7 @@ class StringConcatSniff implements Sniff { /** - * Representation of warning. + * Representation of warning. * * @var string */ diff --git a/Magento2/Sniffs/Templates/ThisInTemplateSniff.php b/Magento2/Sniffs/Templates/ThisInTemplateSniff.php index 45b4ebad..afedc43f 100644 --- a/Magento2/Sniffs/Templates/ThisInTemplateSniff.php +++ b/Magento2/Sniffs/Templates/ThisInTemplateSniff.php @@ -21,7 +21,7 @@ class ThisInTemplateSniff implements Sniff protected $warningCodeFoundHelper = 'FoundHelper'; /** - * Representation of warning. + * Representation of warning. * * @var string */ @@ -35,7 +35,7 @@ class ThisInTemplateSniff implements Sniff protected $warningCodeFoundThis = 'FoundThis'; /** - * Representation of warning. + * Representation of warning. * * @var string */ diff --git a/Magento2/Sniffs/Whitespace/MultipleEmptyLinesSniff.php b/Magento2/Sniffs/Whitespace/MultipleEmptyLinesSniff.php index 12bdc263..d5152da3 100644 --- a/Magento2/Sniffs/Whitespace/MultipleEmptyLinesSniff.php +++ b/Magento2/Sniffs/Whitespace/MultipleEmptyLinesSniff.php @@ -14,7 +14,7 @@ class MultipleEmptyLinesSniff implements Sniff { /** - * Representation of warning. + * Representation of warning. * * @var string */ From 0c29f5b65a149dff8c991b1e9afebd9826ff1c8b Mon Sep 17 00:00:00 2001 From: Sergio Vera Date: Tue, 14 Sep 2021 09:32:23 +0200 Subject: [PATCH 31/37] Fixed wrongly returning error for valid descriptions --- .../Commenting/ClassPropertyPHPDocFormattingSniff.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/Magento2/Sniffs/Commenting/ClassPropertyPHPDocFormattingSniff.php b/Magento2/Sniffs/Commenting/ClassPropertyPHPDocFormattingSniff.php index 09d7afa9..0c08e5ef 100644 --- a/Magento2/Sniffs/Commenting/ClassPropertyPHPDocFormattingSniff.php +++ b/Magento2/Sniffs/Commenting/ClassPropertyPHPDocFormattingSniff.php @@ -140,11 +140,10 @@ public function processMemberVar(File $phpcsFile, $stackPtr) /x'; $varTagParts = preg_split($regularExpression, $tokens[$string]['content']); - if (stripos($tokens[$isShortDescriptionPreviousVar]['content'], implode('', $varTagParts)) === false) { - return; + if (stripos($tokens[$isShortDescriptionPreviousVar]['content'], implode('', $varTagParts)) !== false) { + $error = 'Short description duplicates class property name.'; + $phpcsFile->addWarning($error, $isShortDescriptionPreviousVar, 'AlreadyHaveMeaningfulNameVar'); } - $error = 'Short description duplicates class property name.'; - $phpcsFile->addWarning($error, $isShortDescriptionPreviousVar, 'AlreadyHaveMeaningfulNameVar'); } /** From 3fb9cbae028a770b467fc6d8e2833ccdea81c0ac Mon Sep 17 00:00:00 2001 From: Sergio Vera Date: Tue, 14 Sep 2021 10:09:36 +0200 Subject: [PATCH 32/37] Fixed wrongly returning error for valid descriptions --- .../ClassPropertyPHPDocFormattingSniff.php | 25 +++++++++++-------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/Magento2/Sniffs/Commenting/ClassPropertyPHPDocFormattingSniff.php b/Magento2/Sniffs/Commenting/ClassPropertyPHPDocFormattingSniff.php index 0c08e5ef..7b418435 100644 --- a/Magento2/Sniffs/Commenting/ClassPropertyPHPDocFormattingSniff.php +++ b/Magento2/Sniffs/Commenting/ClassPropertyPHPDocFormattingSniff.php @@ -131,16 +131,21 @@ public function processMemberVar(File $phpcsFile, $stackPtr) return; } - $regularExpression = '/ - # Split camelCase "words". Two global alternatives. Either g1of2: - (?<=[a-z]) # Position is after a lowercase, - (?=[A-Z]) # and before an uppercase letter. - | (?<=[A-Z]) # Or g2of2; Position is after uppercase, - (?=[A-Z][a-z]) # and before upper-then-lower case. - /x'; - $varTagParts = preg_split($regularExpression, $tokens[$string]['content']); - - if (stripos($tokens[$isShortDescriptionPreviousVar]['content'], implode('', $varTagParts)) !== false) { + $propertyNamePosition = $phpcsFile->findNext( + T_VARIABLE, + $foundVar, + null, + false, + null, + false + ); + if ($propertyNamePosition === false) { + return; + }; + $propertyName = trim($tokens[$propertyNamePosition]['content'], '$'); + $propertyNameParts = array_filter(preg_split('/(?=[A-Z])/', $propertyName)); + + if (stripos($tokens[$isShortDescriptionPreviousVar]['content'], implode('', $propertyNameParts)) !== false) { $error = 'Short description duplicates class property name.'; $phpcsFile->addWarning($error, $isShortDescriptionPreviousVar, 'AlreadyHaveMeaningfulNameVar'); } From d238849c5c59bc07c7f37df89018ebe14612b74a Mon Sep 17 00:00:00 2001 From: Sergio Vera Date: Tue, 14 Sep 2021 10:33:48 +0200 Subject: [PATCH 33/37] Fixed wrongly returning error for valid descriptions --- .../ClassPropertyPHPDocFormattingSniff.php | 9 ++++++++- .../ClassPropertyPHPDocFormattingUnitTest.inc | 16 ++++++++-------- .../ClassPropertyPHPDocFormattingUnitTest.php | 2 +- 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/Magento2/Sniffs/Commenting/ClassPropertyPHPDocFormattingSniff.php b/Magento2/Sniffs/Commenting/ClassPropertyPHPDocFormattingSniff.php index 7b418435..45f3276c 100644 --- a/Magento2/Sniffs/Commenting/ClassPropertyPHPDocFormattingSniff.php +++ b/Magento2/Sniffs/Commenting/ClassPropertyPHPDocFormattingSniff.php @@ -143,9 +143,16 @@ public function processMemberVar(File $phpcsFile, $stackPtr) return; }; $propertyName = trim($tokens[$propertyNamePosition]['content'], '$'); + + if (strtolower($tokens[$isShortDescriptionPreviousVar]['content']) === strtolower($propertyName)) { + $error = 'Short description duplicates class property name.'; + $phpcsFile->addWarning($error, $isShortDescriptionPreviousVar, 'AlreadyHaveMeaningfulNameVar'); + return; + } + $propertyNameParts = array_filter(preg_split('/(?=[A-Z])/', $propertyName)); - if (stripos($tokens[$isShortDescriptionPreviousVar]['content'], implode('', $propertyNameParts)) !== false) { + if (strtolower($tokens[$isShortDescriptionPreviousVar]['content']) === strtolower(implode(' ', $propertyNameParts))) { $error = 'Short description duplicates class property name.'; $phpcsFile->addWarning($error, $isShortDescriptionPreviousVar, 'AlreadyHaveMeaningfulNameVar'); } diff --git a/Magento2/Tests/Commenting/ClassPropertyPHPDocFormattingUnitTest.inc b/Magento2/Tests/Commenting/ClassPropertyPHPDocFormattingUnitTest.inc index 93339460..05f9cd13 100644 --- a/Magento2/Tests/Commenting/ClassPropertyPHPDocFormattingUnitTest.inc +++ b/Magento2/Tests/Commenting/ClassPropertyPHPDocFormattingUnitTest.inc @@ -65,14 +65,7 @@ class Bar { private $variableName; /** - * Some more invalid description with test which is the same name as the variable and is not allowed - * - * @var test - */ - protected $test; - - /** - * Formatted Correctly Protected Class Member + * Correctly Formatted Protected Class Member * * @var correctlyFormattedProtectedClassMember */ @@ -120,4 +113,11 @@ class correctlyFormattedClassMemberDocBlock * @var RulePool */ protected $rulePool; + + /** + * A description that includes test which is the same name as the variable is allowed + * + * @var test + */ + protected $test; } diff --git a/Magento2/Tests/Commenting/ClassPropertyPHPDocFormattingUnitTest.php b/Magento2/Tests/Commenting/ClassPropertyPHPDocFormattingUnitTest.php index 7e8ecc91..6a49be76 100644 --- a/Magento2/Tests/Commenting/ClassPropertyPHPDocFormattingUnitTest.php +++ b/Magento2/Tests/Commenting/ClassPropertyPHPDocFormattingUnitTest.php @@ -33,7 +33,7 @@ public function getWarningList() 56 => 1, 63 => 1, 68 => 1, - 82 => 1, + 75 => 1, ]; } } From e92e17db5e3eae31dc258cbe2ed0ac8f6a36df19 Mon Sep 17 00:00:00 2001 From: Sergio Vera Date: Tue, 14 Sep 2021 10:39:15 +0200 Subject: [PATCH 34/37] Fixed wrongly returning error for valid descriptions --- .../Sniffs/Commenting/ClassPropertyPHPDocFormattingSniff.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Magento2/Sniffs/Commenting/ClassPropertyPHPDocFormattingSniff.php b/Magento2/Sniffs/Commenting/ClassPropertyPHPDocFormattingSniff.php index 45f3276c..34cb7dd3 100644 --- a/Magento2/Sniffs/Commenting/ClassPropertyPHPDocFormattingSniff.php +++ b/Magento2/Sniffs/Commenting/ClassPropertyPHPDocFormattingSniff.php @@ -143,8 +143,9 @@ public function processMemberVar(File $phpcsFile, $stackPtr) return; }; $propertyName = trim($tokens[$propertyNamePosition]['content'], '$'); + $shortDescription = strtolower($tokens[$isShortDescriptionPreviousVar]['content']); - if (strtolower($tokens[$isShortDescriptionPreviousVar]['content']) === strtolower($propertyName)) { + if ($shortDescription === strtolower($propertyName)) { $error = 'Short description duplicates class property name.'; $phpcsFile->addWarning($error, $isShortDescriptionPreviousVar, 'AlreadyHaveMeaningfulNameVar'); return; @@ -152,7 +153,7 @@ public function processMemberVar(File $phpcsFile, $stackPtr) $propertyNameParts = array_filter(preg_split('/(?=[A-Z])/', $propertyName)); - if (strtolower($tokens[$isShortDescriptionPreviousVar]['content']) === strtolower(implode(' ', $propertyNameParts))) { + if ($shortDescription === strtolower(implode(' ', $propertyNameParts))) { $error = 'Short description duplicates class property name.'; $phpcsFile->addWarning($error, $isShortDescriptionPreviousVar, 'AlreadyHaveMeaningfulNameVar'); } From 0fb55fcc54a77bc207ed0aaebf7b77b514e870b5 Mon Sep 17 00:00:00 2001 From: Sergio Vera Date: Tue, 14 Sep 2021 10:45:50 +0200 Subject: [PATCH 35/37] Fixed wrongly returning error for valid descriptions --- Magento2/Sniffs/Classes/AbstractApiSniff.php | 2 +- Magento2/Sniffs/Classes/DiscouragedDependenciesSniff.php | 2 +- Magento2/Sniffs/Exceptions/DirectThrowSniff.php | 2 +- Magento2/Sniffs/Exceptions/ThrowCatchSniff.php | 2 +- Magento2/Sniffs/Exceptions/TryProcessSystemResourcesSniff.php | 2 +- Magento2/Sniffs/Functions/StaticFunctionSniff.php | 2 +- Magento2/Sniffs/Legacy/MageEntitySniff.php | 2 +- Magento2/Sniffs/Methods/DeprecatedModelMethodSniff.php | 2 +- Magento2/Sniffs/NamingConvention/InterfaceNameSniff.php | 2 +- Magento2/Sniffs/PHP/GotoSniff.php | 2 +- Magento2/Sniffs/PHP/ReturnValueCheckSniff.php | 4 +++- Magento2/Sniffs/PHP/VarSniff.php | 2 +- Magento2/Sniffs/Performance/ForeachArrayMergeSniff.php | 2 +- Magento2/Sniffs/SQL/RawQuerySniff.php | 2 +- Magento2/Sniffs/Security/LanguageConstructSniff.php | 4 ++-- Magento2/Sniffs/Security/SuperglobalSniff.php | 4 ++-- Magento2/Sniffs/Security/XssTemplateSniff.php | 4 +++- Magento2/Sniffs/Strings/ExecutableRegExSniff.php | 2 +- Magento2/Sniffs/Strings/StringConcatSniff.php | 2 +- Magento2/Sniffs/Templates/ThisInTemplateSniff.php | 4 ++-- Magento2/Sniffs/Whitespace/MultipleEmptyLinesSniff.php | 2 +- 21 files changed, 28 insertions(+), 24 deletions(-) diff --git a/Magento2/Sniffs/Classes/AbstractApiSniff.php b/Magento2/Sniffs/Classes/AbstractApiSniff.php index a32dc0f5..bb8a6571 100644 --- a/Magento2/Sniffs/Classes/AbstractApiSniff.php +++ b/Magento2/Sniffs/Classes/AbstractApiSniff.php @@ -15,7 +15,7 @@ class AbstractApiSniff implements Sniff { /** - * Representation of warning. + * String representation of warning. * * @var string */ diff --git a/Magento2/Sniffs/Classes/DiscouragedDependenciesSniff.php b/Magento2/Sniffs/Classes/DiscouragedDependenciesSniff.php index 8996131f..f5e45c63 100644 --- a/Magento2/Sniffs/Classes/DiscouragedDependenciesSniff.php +++ b/Magento2/Sniffs/Classes/DiscouragedDependenciesSniff.php @@ -18,7 +18,7 @@ class DiscouragedDependenciesSniff implements Sniff const CONSTRUCT_METHOD_NAME = '__construct'; /** - * Representation of warning. + * String representation of warning. * * @var string */ diff --git a/Magento2/Sniffs/Exceptions/DirectThrowSniff.php b/Magento2/Sniffs/Exceptions/DirectThrowSniff.php index 1c74f63a..622644bf 100644 --- a/Magento2/Sniffs/Exceptions/DirectThrowSniff.php +++ b/Magento2/Sniffs/Exceptions/DirectThrowSniff.php @@ -14,7 +14,7 @@ class DirectThrowSniff implements Sniff { /** - * Representation of warning. + * String representation of warning. * phpcs:disable Generic.Files.LineLength.TooLong * @var string */ diff --git a/Magento2/Sniffs/Exceptions/ThrowCatchSniff.php b/Magento2/Sniffs/Exceptions/ThrowCatchSniff.php index 5c2efbcc..c2510168 100644 --- a/Magento2/Sniffs/Exceptions/ThrowCatchSniff.php +++ b/Magento2/Sniffs/Exceptions/ThrowCatchSniff.php @@ -16,7 +16,7 @@ class ThrowCatchSniff implements Sniff { /** - * Representation of warning. + * String representation of warning. * * @var string */ diff --git a/Magento2/Sniffs/Exceptions/TryProcessSystemResourcesSniff.php b/Magento2/Sniffs/Exceptions/TryProcessSystemResourcesSniff.php index 6d714dcc..0fa28149 100644 --- a/Magento2/Sniffs/Exceptions/TryProcessSystemResourcesSniff.php +++ b/Magento2/Sniffs/Exceptions/TryProcessSystemResourcesSniff.php @@ -15,7 +15,7 @@ class TryProcessSystemResourcesSniff implements Sniff { /** - * Representation of warning. + * String representation of warning. * * @var string */ diff --git a/Magento2/Sniffs/Functions/StaticFunctionSniff.php b/Magento2/Sniffs/Functions/StaticFunctionSniff.php index 0805e3ce..2ae706d0 100644 --- a/Magento2/Sniffs/Functions/StaticFunctionSniff.php +++ b/Magento2/Sniffs/Functions/StaticFunctionSniff.php @@ -14,7 +14,7 @@ class StaticFunctionSniff implements Sniff { /** - * Representation of warning. + * String representation of warning. * * @var string */ diff --git a/Magento2/Sniffs/Legacy/MageEntitySniff.php b/Magento2/Sniffs/Legacy/MageEntitySniff.php index 8e305345..de8b7dbf 100644 --- a/Magento2/Sniffs/Legacy/MageEntitySniff.php +++ b/Magento2/Sniffs/Legacy/MageEntitySniff.php @@ -14,7 +14,7 @@ class MageEntitySniff implements Sniff { /** - * Representation of error. + * String representation of error. * * @var string */ diff --git a/Magento2/Sniffs/Methods/DeprecatedModelMethodSniff.php b/Magento2/Sniffs/Methods/DeprecatedModelMethodSniff.php index cf58267f..f094c353 100644 --- a/Magento2/Sniffs/Methods/DeprecatedModelMethodSniff.php +++ b/Magento2/Sniffs/Methods/DeprecatedModelMethodSniff.php @@ -16,7 +16,7 @@ class DeprecatedModelMethodSniff implements Sniff const RESOURCE_METHOD = "getResource"; /** - * Representation of warning. + * String representation of warning. * * @var string */ diff --git a/Magento2/Sniffs/NamingConvention/InterfaceNameSniff.php b/Magento2/Sniffs/NamingConvention/InterfaceNameSniff.php index b04da011..2ad688ec 100644 --- a/Magento2/Sniffs/NamingConvention/InterfaceNameSniff.php +++ b/Magento2/Sniffs/NamingConvention/InterfaceNameSniff.php @@ -14,7 +14,7 @@ class InterfaceNameSniff implements Sniff { /** - * Representation of warning. + * String representation of warning. * * @var string */ diff --git a/Magento2/Sniffs/PHP/GotoSniff.php b/Magento2/Sniffs/PHP/GotoSniff.php index 0b74e855..4a5f06ca 100644 --- a/Magento2/Sniffs/PHP/GotoSniff.php +++ b/Magento2/Sniffs/PHP/GotoSniff.php @@ -14,7 +14,7 @@ class GotoSniff implements Sniff { /** - * Representation of warning. + * String representation of warning. * * @var string */ diff --git a/Magento2/Sniffs/PHP/ReturnValueCheckSniff.php b/Magento2/Sniffs/PHP/ReturnValueCheckSniff.php index 5a6d507f..9929d46b 100644 --- a/Magento2/Sniffs/PHP/ReturnValueCheckSniff.php +++ b/Magento2/Sniffs/PHP/ReturnValueCheckSniff.php @@ -14,7 +14,7 @@ class ReturnValueCheckSniff implements Sniff { /** - * Representation of error. + * String representation of error. * * @var string */ @@ -46,6 +46,8 @@ class ReturnValueCheckSniff implements Sniff protected $tokens = []; /** + * PHP_CodeSniffer file. + * * @var File */ protected $file; diff --git a/Magento2/Sniffs/PHP/VarSniff.php b/Magento2/Sniffs/PHP/VarSniff.php index dfa9bdee..fa7b28b7 100644 --- a/Magento2/Sniffs/PHP/VarSniff.php +++ b/Magento2/Sniffs/PHP/VarSniff.php @@ -14,7 +14,7 @@ class VarSniff implements Sniff { /** - * Representation of warning. + * String representation of warning. * * @var string */ diff --git a/Magento2/Sniffs/Performance/ForeachArrayMergeSniff.php b/Magento2/Sniffs/Performance/ForeachArrayMergeSniff.php index 09bc0bdd..9ab6c8cc 100644 --- a/Magento2/Sniffs/Performance/ForeachArrayMergeSniff.php +++ b/Magento2/Sniffs/Performance/ForeachArrayMergeSniff.php @@ -14,7 +14,7 @@ class ForeachArrayMergeSniff implements Sniff { /** - * Representation of warning. + * String representation of warning. * * @var string */ diff --git a/Magento2/Sniffs/SQL/RawQuerySniff.php b/Magento2/Sniffs/SQL/RawQuerySniff.php index cb27c570..a32d4eb0 100644 --- a/Magento2/Sniffs/SQL/RawQuerySniff.php +++ b/Magento2/Sniffs/SQL/RawQuerySniff.php @@ -15,7 +15,7 @@ class RawQuerySniff implements Sniff { /** - * Representation of warning. + * String representation of warning. * * @var string */ diff --git a/Magento2/Sniffs/Security/LanguageConstructSniff.php b/Magento2/Sniffs/Security/LanguageConstructSniff.php index a8e1c979..9b10ae4a 100644 --- a/Magento2/Sniffs/Security/LanguageConstructSniff.php +++ b/Magento2/Sniffs/Security/LanguageConstructSniff.php @@ -14,14 +14,14 @@ class LanguageConstructSniff implements Sniff { /** - * Representation of error. + * String representation of error. * * @var string */ protected $errorMessage = 'Use of %s language construct is discouraged.'; /** - * Representation of backtick error. + * String representation of backtick error. * * phpcs:disable Generic.Files.LineLength * diff --git a/Magento2/Sniffs/Security/SuperglobalSniff.php b/Magento2/Sniffs/Security/SuperglobalSniff.php index 4d029dfc..136f991f 100644 --- a/Magento2/Sniffs/Security/SuperglobalSniff.php +++ b/Magento2/Sniffs/Security/SuperglobalSniff.php @@ -14,14 +14,14 @@ class SuperglobalSniff implements Sniff { /** - * Representation of warning. + * String representation of warning. * * @var string */ protected $warningMessage = 'Direct use of %s Superglobal detected.'; /** - * Representation of error. + * String representation of error. * * @var string */ diff --git a/Magento2/Sniffs/Security/XssTemplateSniff.php b/Magento2/Sniffs/Security/XssTemplateSniff.php index 490d5cbd..f35943e5 100644 --- a/Magento2/Sniffs/Security/XssTemplateSniff.php +++ b/Magento2/Sniffs/Security/XssTemplateSniff.php @@ -14,7 +14,7 @@ class XssTemplateSniff implements Sniff { /** - * Representation of warning. + * String representation of warning. * * @var string */ @@ -85,6 +85,8 @@ class XssTemplateSniff implements Sniff private $statements = []; /** + * PHP_CodeSniffer file. + * * @var File */ private $file; diff --git a/Magento2/Sniffs/Strings/ExecutableRegExSniff.php b/Magento2/Sniffs/Strings/ExecutableRegExSniff.php index 5e435322..09706ed6 100644 --- a/Magento2/Sniffs/Strings/ExecutableRegExSniff.php +++ b/Magento2/Sniffs/Strings/ExecutableRegExSniff.php @@ -15,7 +15,7 @@ class ExecutableRegExSniff implements Sniff { /** - * Representation of error. + * String representation of error. * * phpcs:disable Generic.Files.LineLength * diff --git a/Magento2/Sniffs/Strings/StringConcatSniff.php b/Magento2/Sniffs/Strings/StringConcatSniff.php index 06eb6a27..89c8dc9b 100644 --- a/Magento2/Sniffs/Strings/StringConcatSniff.php +++ b/Magento2/Sniffs/Strings/StringConcatSniff.php @@ -15,7 +15,7 @@ class StringConcatSniff implements Sniff { /** - * Representation of warning. + * String representation of warning. * * @var string */ diff --git a/Magento2/Sniffs/Templates/ThisInTemplateSniff.php b/Magento2/Sniffs/Templates/ThisInTemplateSniff.php index afedc43f..9b5e5358 100644 --- a/Magento2/Sniffs/Templates/ThisInTemplateSniff.php +++ b/Magento2/Sniffs/Templates/ThisInTemplateSniff.php @@ -21,7 +21,7 @@ class ThisInTemplateSniff implements Sniff protected $warningCodeFoundHelper = 'FoundHelper'; /** - * Representation of warning. + * String representation of warning. * * @var string */ @@ -35,7 +35,7 @@ class ThisInTemplateSniff implements Sniff protected $warningCodeFoundThis = 'FoundThis'; /** - * Representation of warning. + * String representation of warning. * * @var string */ diff --git a/Magento2/Sniffs/Whitespace/MultipleEmptyLinesSniff.php b/Magento2/Sniffs/Whitespace/MultipleEmptyLinesSniff.php index d5152da3..4d74a29e 100644 --- a/Magento2/Sniffs/Whitespace/MultipleEmptyLinesSniff.php +++ b/Magento2/Sniffs/Whitespace/MultipleEmptyLinesSniff.php @@ -14,7 +14,7 @@ class MultipleEmptyLinesSniff implements Sniff { /** - * Representation of warning. + * String representation of warning. * * @var string */ From 813a761a84e16792dac5d9af5af416e9cbf02d19 Mon Sep 17 00:00:00 2001 From: Sergio Vera Date: Tue, 14 Sep 2021 11:36:59 +0200 Subject: [PATCH 36/37] Increased version to 10 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index c06ab6c7..3fd9762b 100644 --- a/composer.json +++ b/composer.json @@ -6,7 +6,7 @@ "AFL-3.0" ], "type": "phpcodesniffer-standard", - "version": "9", + "version": "10", "require": { "php": ">=7.3", "squizlabs/php_codesniffer": "^3.6", From f7df4550adbbdded4f4af2ad42f894fab02773bf Mon Sep 17 00:00:00 2001 From: Sergio Vera Date: Tue, 14 Sep 2021 11:39:26 +0200 Subject: [PATCH 37/37] Increased version to 10 --- composer.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.lock b/composer.lock index 025e27ee..f9b3efca 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "9f04a53a3b02845918c714a149ab00b2", + "content-hash": "2c33aea65b2ef629308fd92cad58dfad", "packages": [ { "name": "squizlabs/php_codesniffer",