From f7c47a0ce9a8923e0f950a66ecc2eb7f45c128d5 Mon Sep 17 00:00:00 2001 From: Pieter Hoste Date: Sun, 18 Aug 2019 12:03:42 +0200 Subject: [PATCH 001/630] No longer require a space before a colon for control structures using the alternative syntax --- Magento2/ruleset.xml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Magento2/ruleset.xml b/Magento2/ruleset.xml index df66ac69..30fde861 100644 --- a/Magento2/ruleset.xml +++ b/Magento2/ruleset.xml @@ -431,6 +431,9 @@ 6 warning + + + *.phtml From 13ceb9af4bdccb9caeef5136cdd406e99623f75e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stjepan=20Udovi=C4=8Di=C4=87?= Date: Thu, 22 Aug 2019 20:04:14 +0200 Subject: [PATCH 002/630] implement rule from #131 --- ...ClassAndInterfacePHPDocFormattingSniff.php | 9 +++ .../ConstantsPHPDocFormattingSniff.php | 9 +++ .../Commenting/PHPDocFormattingValidator.php | 50 ++++++++++++++++ ...AndInterfacePHPDocFormattingUnitTest.1.inc | 57 +++++++++++++++++- ...AndInterfacePHPDocFormattingUnitTest.2.inc | 58 ++++++++++++++++++- ...ssAndInterfacePHPDocFormattingUnitTest.php | 6 +- .../ConstantsPHPDocFormattingUnitTest.1.inc | 12 ++++ .../ConstantsPHPDocFormattingUnitTest.2.inc | 45 ++++++++++++++ .../ConstantsPHPDocFormattingUnitTest.php | 16 +++-- 9 files changed, 254 insertions(+), 8 deletions(-) diff --git a/Magento2/Sniffs/Commenting/ClassAndInterfacePHPDocFormattingSniff.php b/Magento2/Sniffs/Commenting/ClassAndInterfacePHPDocFormattingSniff.php index e3ed49b8..6eecabed 100644 --- a/Magento2/Sniffs/Commenting/ClassAndInterfacePHPDocFormattingSniff.php +++ b/Magento2/Sniffs/Commenting/ClassAndInterfacePHPDocFormattingSniff.php @@ -87,6 +87,15 @@ public function process(File $phpcsFile, $stackPtr) ); } + if ($this->PHPDocFormattingValidator->hasDeprecatedWellFormatted($commentStartPtr, $tokens) !== true) { + $phpcsFile->addWarning( + 'Motivation behind the added @deprecated tag MUST be explained. ' + . '@see tag MUST be used with reference to new implementation.', + $stackPtr, + 'InvalidDeprecatedTagUsage' + ); + } + $this->validateTags($phpcsFile, $commentStartPtr, $tokens); } diff --git a/Magento2/Sniffs/Commenting/ConstantsPHPDocFormattingSniff.php b/Magento2/Sniffs/Commenting/ConstantsPHPDocFormattingSniff.php index 205dcdf9..d922d050 100644 --- a/Magento2/Sniffs/Commenting/ConstantsPHPDocFormattingSniff.php +++ b/Magento2/Sniffs/Commenting/ConstantsPHPDocFormattingSniff.php @@ -71,5 +71,14 @@ public function process(File $phpcsFile, $stackPtr) 'MissingConstantPHPDoc' ); } + + if ($this->PHPDocFormattingValidator->hasDeprecatedWellFormatted($commentStartPtr, $tokens) !== true) { + $phpcsFile->addWarning( + 'Motivation behind the added @deprecated tag MUST be explained. ' + . '@see tag MUST be used with reference to new implementation.', + $stackPtr, + 'InvalidDeprecatedTagUsage' + ); + } } } diff --git a/Magento2/Sniffs/Commenting/PHPDocFormattingValidator.php b/Magento2/Sniffs/Commenting/PHPDocFormattingValidator.php index 4112f675..241a2dc9 100644 --- a/Magento2/Sniffs/Commenting/PHPDocFormattingValidator.php +++ b/Magento2/Sniffs/Commenting/PHPDocFormattingValidator.php @@ -71,4 +71,54 @@ public function providesMeaning($namePtr, $commentStartPtr, $tokens) return false; } + + /** + * In case comment has deprecated tag, it must be explained and followed by see tag with details + * + * @param int $commentStartPtr + * @param array $tokens + * @return bool + */ + public function hasDeprecatedWellFormatted($commentStartPtr, $tokens) + { + $commentCloserPtr = $tokens[$commentStartPtr]['comment_closer']; + + $hasDeprecated = false; + $hasSee = false; + + for ($i = $commentStartPtr; $i <= $commentCloserPtr; $i++) { + $token = $tokens[$i]; + + // Not interesting + if ($token['code'] !== T_DOC_COMMENT_TAG) { + continue; + } + + $tag = $token['content']; + + // Not an interesting tag + if ($tag !== '@deprecated' && $tag !== '@see') { + continue; + } + + if ($tag === '@deprecated') { + $hasDeprecated = true; + } + + if ($tag === '@see') { + $hasSee = true; + } + + // Tag not followed by description + if ($tokens[$i + 2]['code'] !== T_DOC_COMMENT_STRING) { + return false; + } + } + + if ($hasDeprecated === true && $hasSee !== true) { + return false; + } + + return true; + } } diff --git a/Magento2/Tests/Commenting/ClassAndInterfacePHPDocFormattingUnitTest.1.inc b/Magento2/Tests/Commenting/ClassAndInterfacePHPDocFormattingUnitTest.1.inc index 81cfa9bc..bf47ae48 100644 --- a/Magento2/Tests/Commenting/ClassAndInterfacePHPDocFormattingUnitTest.1.inc +++ b/Magento2/Tests/Commenting/ClassAndInterfacePHPDocFormattingUnitTest.1.inc @@ -59,6 +59,7 @@ class EmptyHandler * * @api is ok here * @deprecated can be used in this context + * @see is ok here * @author is actually ok * @category is irrelevant * @package is not ment to be used @@ -90,4 +91,58 @@ class AsyncApiHandler * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ class GroupRepositoryHandler -{} +{ + +} + +/** + * @deprecated + */ +class DeprecatedHandler +{ + +} + +/** + * @deprecated Should not be used + */ +class AncientHandler +{ + +} + +/** + * @deprecated + * @see + */ +class AgedHandler +{ + +} + +/** + * @deprecated Should not be used + * @see + */ +class ArhaicHandler +{ + +} + +/** + * @deprecated Should not be used + * @see Magento\Framework\NewHandler + */ +class OldHandler +{ + +} + +/** + * @see Magento\Framework\NewHandler + */ +interface SomethingHandler +{ + +} + diff --git a/Magento2/Tests/Commenting/ClassAndInterfacePHPDocFormattingUnitTest.2.inc b/Magento2/Tests/Commenting/ClassAndInterfacePHPDocFormattingUnitTest.2.inc index 7a9c9b6a..75e7bbc3 100644 --- a/Magento2/Tests/Commenting/ClassAndInterfacePHPDocFormattingUnitTest.2.inc +++ b/Magento2/Tests/Commenting/ClassAndInterfacePHPDocFormattingUnitTest.2.inc @@ -59,6 +59,7 @@ interface EmptyHandler * * @api is ok here * @deprecated can be used in this context + * @see is ok here * @author is actually ok * @category is irrelevant * @package is not ment to be used @@ -89,5 +90,58 @@ interface AsyncApiHandler /** * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ -class GroupRepositoryHandler -{} +interface GroupRepositoryHandler +{ + +} + +/** + * @deprecated + */ +interface DeprecatedHandler +{ + +} + +/** + * @deprecated Should not be used + */ +interface AncientHandler +{ + +} + +/** + * @deprecated + * @see + */ +interface AgedHandler +{ + +} + +/** + * @deprecated Should not be used + * @see + */ +interface ArhaicHandler +{ + +} + +/** + * @deprecated Should not be used + * @see Magento\Framework\NewHandler + */ +interface OldHandler +{ + +} + +/** + * @see Magento\Framework\NewHandler + */ +interface SomethingHandler +{ + +} diff --git a/Magento2/Tests/Commenting/ClassAndInterfacePHPDocFormattingUnitTest.php b/Magento2/Tests/Commenting/ClassAndInterfacePHPDocFormattingUnitTest.php index 477c1adf..9e7bfde2 100644 --- a/Magento2/Tests/Commenting/ClassAndInterfacePHPDocFormattingUnitTest.php +++ b/Magento2/Tests/Commenting/ClassAndInterfacePHPDocFormattingUnitTest.php @@ -29,9 +29,13 @@ public function getWarningList($testFile = '') 35 => 1, 44 => 1, 52 => 1, - 63 => 1, 64 => 1, 65 => 1, + 66 => 1, + 101 => 1, + 109 => 1, + 118 => 1, + 127 => 1, ]; } } diff --git a/Magento2/Tests/Commenting/ConstantsPHPDocFormattingUnitTest.1.inc b/Magento2/Tests/Commenting/ConstantsPHPDocFormattingUnitTest.1.inc index e3d2000a..f0e8b474 100644 --- a/Magento2/Tests/Commenting/ConstantsPHPDocFormattingUnitTest.1.inc +++ b/Magento2/Tests/Commenting/ConstantsPHPDocFormattingUnitTest.1.inc @@ -7,6 +7,12 @@ define('DS', DIRECTORY_SEPARATOR); define('BP', dirname(__FILE__)); +/** + * @deprecated New implementation available + * @see \Ascii\Asterisk + */ +define('ANSWER', '42'); + class Profiler { const NESTING_SEPARATOR = '->'; @@ -15,4 +21,10 @@ class Profiler * Unlike first const, this one is not self explanatory. */ const NUMBER_TWO = 2; + + /** + * @deprecated Unable to identify the question, replaced + * @see \ComputationalMatrix\Earth + */ + const COMPUTER = 'Deep Thought'; } diff --git a/Magento2/Tests/Commenting/ConstantsPHPDocFormattingUnitTest.2.inc b/Magento2/Tests/Commenting/ConstantsPHPDocFormattingUnitTest.2.inc index c4189ff1..924fe1e6 100644 --- a/Magento2/Tests/Commenting/ConstantsPHPDocFormattingUnitTest.2.inc +++ b/Magento2/Tests/Commenting/ConstantsPHPDocFormattingUnitTest.2.inc @@ -1,4 +1,5 @@ 0'); /** */ define('NUMBER_ONE', 1); +/** + * @deprecated + */ +define('A', 65); + +/** + * @deprecated Slightly better, but no see tag + */ +define('B', 66); + +/** + * @deprecated + * @see + */ +define('C', 67); + +/** + * @deprecated No reference specified + * @see + */ +define('D', 68); + class Profiler { /** @@ -18,4 +41,26 @@ class Profiler * */ const NUMBER_TWO = 2; + + /** + * @deprecated + */ + const a = 97; + + /** + * @deprecated Slightly better, but no see tag + */ + const b = 98; + + /** + * @deprecated + * @see + */ + const c = 99; + + /** + * @deprecated No reference specified + * @see + */ + const d = 100; } diff --git a/Magento2/Tests/Commenting/ConstantsPHPDocFormattingUnitTest.php b/Magento2/Tests/Commenting/ConstantsPHPDocFormattingUnitTest.php index aa475c3d..ef6cc85d 100644 --- a/Magento2/Tests/Commenting/ConstantsPHPDocFormattingUnitTest.php +++ b/Magento2/Tests/Commenting/ConstantsPHPDocFormattingUnitTest.php @@ -27,10 +27,18 @@ public function getWarningList($testFile = '') } return [ - 5 => 1, - 8 => 1, - 15 => 1, - 20 => 1 + 6 => 1, + 9 => 1, + 14 => 1, + 19 => 1, + 25 => 1, + 31 => 1, + 38 => 1, + 43 => 1, + 48 => 1, + 53 => 1, + 59 => 1, + 65 => 1 ]; } } From 5465546122ced493b449bf57160d5c8be03329fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stjepan=20Udovi=C4=8Di=C4=87?= Date: Sat, 24 Aug 2019 10:47:54 +0200 Subject: [PATCH 003/630] Refactor PHPDoc search --- ...ClassAndInterfacePHPDocFormattingSniff.php | 19 ++-------- .../ConstantsPHPDocFormattingSniff.php | 4 +-- .../Commenting/PHPDocFormattingValidator.php | 36 +++++++++++++++++++ .../ConstantsPHPDocFormattingUnitTest.3.inc | 9 +++++ .../ConstantsPHPDocFormattingUnitTest.php | 2 +- 5 files changed, 50 insertions(+), 20 deletions(-) create mode 100644 Magento2/Tests/Commenting/ConstantsPHPDocFormattingUnitTest.3.inc diff --git a/Magento2/Sniffs/Commenting/ClassAndInterfacePHPDocFormattingSniff.php b/Magento2/Sniffs/Commenting/ClassAndInterfacePHPDocFormattingSniff.php index e3ed49b8..d890147d 100644 --- a/Magento2/Sniffs/Commenting/ClassAndInterfacePHPDocFormattingSniff.php +++ b/Magento2/Sniffs/Commenting/ClassAndInterfacePHPDocFormattingSniff.php @@ -56,23 +56,8 @@ public function process(File $phpcsFile, $stackPtr) $namePtr = $phpcsFile->findNext(T_STRING, $stackPtr + 1, null, false, null, true); - $commentStartPtr = $phpcsFile->findPrevious( - [ - T_WHITESPACE, - T_DOC_COMMENT_STAR, - T_DOC_COMMENT_WHITESPACE, - T_DOC_COMMENT_TAG, - T_DOC_COMMENT_STRING, - T_DOC_COMMENT_CLOSE_TAG - ], - $stackPtr - 1, - null, - true, - null, - true - ); - - if ($tokens[$commentStartPtr]['code'] !== T_DOC_COMMENT_OPEN_TAG) { + $commentStartPtr = $this->PHPDocFormattingValidator->findPHPDoc($stackPtr, $phpcsFile); + if ($commentStartPtr === -1) { return; } diff --git a/Magento2/Sniffs/Commenting/ConstantsPHPDocFormattingSniff.php b/Magento2/Sniffs/Commenting/ConstantsPHPDocFormattingSniff.php index 205dcdf9..a4b9e71b 100644 --- a/Magento2/Sniffs/Commenting/ConstantsPHPDocFormattingSniff.php +++ b/Magento2/Sniffs/Commenting/ConstantsPHPDocFormattingSniff.php @@ -59,8 +59,8 @@ public function process(File $phpcsFile, $stackPtr) true ); - $commentStartPtr = $phpcsFile->findPrevious(T_DOC_COMMENT_OPEN_TAG, $stackPtr - 1, null, false, null, true); - if ($commentStartPtr === false) { + $commentStartPtr = $this->PHPDocFormattingValidator->findPHPDoc($stackPtr, $phpcsFile); + if ($commentStartPtr === -1) { return; } diff --git a/Magento2/Sniffs/Commenting/PHPDocFormattingValidator.php b/Magento2/Sniffs/Commenting/PHPDocFormattingValidator.php index 4112f675..5be093ae 100644 --- a/Magento2/Sniffs/Commenting/PHPDocFormattingValidator.php +++ b/Magento2/Sniffs/Commenting/PHPDocFormattingValidator.php @@ -6,11 +6,47 @@ */ namespace Magento2\Sniffs\Commenting; +use PHP_CodeSniffer\Files\File; + /** * Helper class for common DocBlock validations */ class PHPDocFormattingValidator { + /** + * Finds matching PHPDoc for current pointer + * + * @param int $startPtr + * @param File $phpcsFile + * @return int + */ + public function findPHPDoc($startPtr, $phpcsFile) + { + $tokens = $phpcsFile->getTokens(); + + $commentStartPtr = $phpcsFile->findPrevious( + [ + T_WHITESPACE, + T_DOC_COMMENT_STAR, + T_DOC_COMMENT_WHITESPACE, + T_DOC_COMMENT_TAG, + T_DOC_COMMENT_STRING, + T_DOC_COMMENT_CLOSE_TAG + ], + $startPtr - 1, + null, + true, + null, + true + ); + + if ($tokens[$commentStartPtr]['code'] !== T_DOC_COMMENT_OPEN_TAG) { + return -1; + } + + return $commentStartPtr; + } + /** * Determines if the comment identified by $commentStartPtr provides additional meaning to origin at $namePtr * diff --git a/Magento2/Tests/Commenting/ConstantsPHPDocFormattingUnitTest.3.inc b/Magento2/Tests/Commenting/ConstantsPHPDocFormattingUnitTest.3.inc new file mode 100644 index 00000000..ba6686ef --- /dev/null +++ b/Magento2/Tests/Commenting/ConstantsPHPDocFormattingUnitTest.3.inc @@ -0,0 +1,9 @@ + Date: Sat, 31 Aug 2019 14:47:25 +0530 Subject: [PATCH 004/630] test folder is excluded from the coding standard rules --- Magento2/ruleset.xml | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/Magento2/ruleset.xml b/Magento2/ruleset.xml index 30fde861..246b6fe1 100644 --- a/Magento2/ruleset.xml +++ b/Magento2/ruleset.xml @@ -35,6 +35,7 @@ */Fixtures/* */Test/* *Test.php + */tests/* 10 @@ -64,6 +65,7 @@ */lib/* */Test/* *Test.php + */tests/* 10 @@ -84,6 +86,7 @@ */lib/* */Test/* *Test.php + */tests/* 10 @@ -116,6 +119,7 @@ */lib/* */Test/* *Test.php + */tests/* *.phtml @@ -130,6 +134,7 @@ */lib/* */Test/* *Test.php + */tests/* 9 @@ -148,6 +153,7 @@ */Fixtures/* */Test/* *Test.php + */tests/* 8 @@ -160,6 +166,7 @@ */Fixtures/* */Test/* *Test.php + */tests/* 8 @@ -169,6 +176,7 @@ */lib/* */Test/* *Test.php + */tests/* 8 @@ -179,6 +187,7 @@ */Setup/* */Test/* *Test.php + */tests/* 8 @@ -245,6 +254,7 @@ */Fixtures/* */Test/* *Test.php + */tests/* 7 @@ -253,6 +263,7 @@ */Fixtures/* */Test/* *Test.php + */tests/* 7 @@ -277,6 +288,7 @@ */Fixtures/* */Test/* *Test.php + */tests/* 7 @@ -294,6 +306,7 @@ */Fixtures/* */Test/* *Test.php + */tests/* 7 @@ -367,6 +380,7 @@ */Fixtures/* */Test/* *Test.php + */tests/* 6 From ba0bbce3e893c1c1854edb3736a571218ed73cd9 Mon Sep 17 00:00:00 2001 From: Jean-Bernard Valentaten Date: Fri, 6 Sep 2019 16:52:27 +0200 Subject: [PATCH 005/630] MC-19366: Adds a tokenizer for GraphQL schema files --- Magento2/ruleset.xml | 6 ++- PHP_CodeSniffer/Tokenizers/GraphQL.php | 52 ++++++++++++++++++++++++++ composer.json | 5 +++ 3 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 PHP_CodeSniffer/Tokenizers/GraphQL.php diff --git a/Magento2/ruleset.xml b/Magento2/ruleset.xml index 246b6fe1..adda516c 100644 --- a/Magento2/ruleset.xml +++ b/Magento2/ruleset.xml @@ -3,7 +3,7 @@ Magento Coding Standard - + @@ -522,6 +522,10 @@ 0 + + 6 + warning + diff --git a/PHP_CodeSniffer/Tokenizers/GraphQL.php b/PHP_CodeSniffer/Tokenizers/GraphQL.php new file mode 100644 index 00000000..2b66e3a0 --- /dev/null +++ b/PHP_CodeSniffer/Tokenizers/GraphQL.php @@ -0,0 +1,52 @@ + 'T_CLASS', + 'interface' => 'T_CLASS', + 'enum' => 'T_CLASS', + '#' => 'T_COMMENT', + ]; + + /** + * Constructor. + * + * @param string $content + * @param Config $config + * @param string $eolChar + * @throws \PHP_CodeSniffer\Exceptions\TokenizerException + */ + public function __construct($content, Config $config, $eolChar = '\n') + { + //add our token values + $this->tokenValues = array_merge( + $this->tokenValues, + $this->additionalTokenValues + ); + + //let parent do its job (which will start tokenizing) + parent::__construct($content, $config, $eolChar); + } + + /** + * @inheritDoc + */ + public function processAdditional() + { + //NOP Does nothing intentionally + } + +} diff --git a/composer.json b/composer.json index d67474e9..a3684c36 100644 --- a/composer.json +++ b/composer.json @@ -14,6 +14,11 @@ "require-dev": { "phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0" }, + "autoload": { + "classmap": [ + "PHP_CodeSniffer/Tokenizers/" + ] + }, "scripts": { "post-install-cmd": "vendor/bin/phpcs --config-set installed_paths ../../..", "post-update-cmd": "vendor/bin/phpcs --config-set installed_paths ../../.." From 6003dcd0a79f0a49cb3bb152ab4939f80aa2f3bc Mon Sep 17 00:00:00 2001 From: Jean-Bernard Valentaten Date: Fri, 6 Sep 2019 16:59:17 +0200 Subject: [PATCH 006/630] MC-19366: Adds sniff for type names --- .../Sniffs/GraphQL/ValidTypeNameSniff.php | 32 ++++++++ .../GraphQL/ValidTypeNameUnitTest.graphqls | 44 +++++++++++ .../Tests/GraphQL/ValidTypeNameUnitTest.php | 77 +++++++++++++++++++ 3 files changed, 153 insertions(+) create mode 100644 Magento2/Sniffs/GraphQL/ValidTypeNameSniff.php create mode 100644 Magento2/Tests/GraphQL/ValidTypeNameUnitTest.graphqls create mode 100644 Magento2/Tests/GraphQL/ValidTypeNameUnitTest.php diff --git a/Magento2/Sniffs/GraphQL/ValidTypeNameSniff.php b/Magento2/Sniffs/GraphQL/ValidTypeNameSniff.php new file mode 100644 index 00000000..76af7b7d --- /dev/null +++ b/Magento2/Sniffs/GraphQL/ValidTypeNameSniff.php @@ -0,0 +1,32 @@ +type, interface and enum) that are not specified in + * UpperCamelCase. + */ +class ValidTypeNameSniff extends ValidClassNameSniff +{ + + /** + * Defines the tokenizers that this sniff is using. + * + * @var array + */ + public $supportedTokenizers = ['GraphQL']; + + /** + * @inheritDoc + */ + public function register() + { + return [T_CLASS]; + } + +} diff --git a/Magento2/Tests/GraphQL/ValidTypeNameUnitTest.graphqls b/Magento2/Tests/GraphQL/ValidTypeNameUnitTest.graphqls new file mode 100644 index 00000000..1fba0386 --- /dev/null +++ b/Magento2/Tests/GraphQL/ValidTypeNameUnitTest.graphqls @@ -0,0 +1,44 @@ +# Valid type names. +type ValidCamelCaseType {} +interface ValidCamelCaseInterface {} +enum ValidCamelCaseEnum {} + +# Incorrect usage of camel case. +type invalidCamelCaseType {} +type Invalid_Camel_Case_Type_With_Underscores {} +interface invalidCamelCaseInterface {} +interface Invalid_Camel_Case_Interface_With_Underscores {} +enum invalidCamelCaseEnum {} +enum Invalid_Camel_Case_Enum_With_Underscores {} + +# All lowercase +type invalidlowercasetype {} +interface invalidlowercaseinterface {} +enum invalidlowercaseenum {} + +# All uppercase +type VALIDUPPERCASETYPE {} +type INVALID_UPPERCASE_TYPE_WITH_UNDERSCORES {} +interface VALIDUPPERCASEINTERFACE {} +interface INVALID_UPPERCASE_INTERFACE_WITH_UNDERSCORES {} +enum VALIDUPPERCASECENUM {} +enum INVALID_UPPERCASE_ENUM_WITH_UNDERSCORES {} + +# Mix camel case with uppercase +type ValidCamelCaseTypeWITHUPPERCASE {} +interface ValidCamelCaseInterfaceWITHUPPERCASE {} +enum ValidCamelCaseEnumWITHUPPERCASE {} + +# Usage of numeric characters +type ValidCamelCaseTypeWith1Number {} +type ValidCamelCaseTypeWith12345Numbers {} +type 5InvalidCamelCaseTypeStartingWithNumber {} +type ValidCamelCaseTypeEndingWithNumber4 {} +interface ValidCamelCaseInterfaceWith1Number {} +interface ValidCamelCaseInterfaceWith12345Numbers {} +interface 5InvalidCamelCaseInterfaceStartingWithNumber {} +interface ValidCamelCaseInterfaceEndingWithNumber4 {} +enum ValidCamelCaseEnumWith1Number {} +enum ValidCamelCaseEnumWith12345Numbers {} +enum 5InvalidCamelCaseEnumStartingWithNumber {} +enum ValidCamelCaseEnumEndingWithNumber4 {} \ No newline at end of file diff --git a/Magento2/Tests/GraphQL/ValidTypeNameUnitTest.php b/Magento2/Tests/GraphQL/ValidTypeNameUnitTest.php new file mode 100644 index 00000000..0e07c91d --- /dev/null +++ b/Magento2/Tests/GraphQL/ValidTypeNameUnitTest.php @@ -0,0 +1,77 @@ +extensions = array_merge( + $config->extensions, + [ + 'graphqls' => 'GraphQL' + ] + ); + + //and write back to a global that is used in base class + $GLOBALS['PHP_CODESNIFFER_CONFIG'] = $config; + } + + /** + * Returns the lines where errors should occur. + * + * The key of the array should represent the line number and the value + * should represent the number of errors that should occur on that line. + * + * @return array + */ + protected function getErrorList() + { + return [ + 7 => 1, + 8 => 1, + 9 => 1, + 10 => 1, + 11 => 1, + 12 => 1, + 15 => 1, + 16 => 1, + 17 => 1, + 21 => 1, + 23 => 1, + 25 => 1, + 35 => 1, + 39 => 1, + 43 => 1, + ]; + } + + /** + * Returns the lines where warnings should occur. + * + * The key of the array should represent the line number and the value + * should represent the number of warnings that should occur on that line. + * + * @return array + */ + protected function getWarningList() + { + return []; + } +} + From 8cb90c89e32224b641beed3c42493be61174f836 Mon Sep 17 00:00:00 2001 From: Jean-Bernard Valentaten Date: Mon, 9 Sep 2019 17:06:02 +0200 Subject: [PATCH 007/630] MC-19366: Improves GraphQL tokenizer by making use of webonyx/graphql-php library --- .../Sniffs/GraphQL/ValidArgumentNameSniff.php | 28 +++ .../Sniffs/GraphQL/ValidTypeNameSniff.php | 36 +++- PHP_CodeSniffer/Tokenizers/GraphQL.php | 171 ++++++++++++++++-- composer.json | 3 +- composer.lock | 54 +++++- 5 files changed, 273 insertions(+), 19 deletions(-) create mode 100644 Magento2/Sniffs/GraphQL/ValidArgumentNameSniff.php diff --git a/Magento2/Sniffs/GraphQL/ValidArgumentNameSniff.php b/Magento2/Sniffs/GraphQL/ValidArgumentNameSniff.php new file mode 100644 index 00000000..e7acd46a --- /dev/null +++ b/Magento2/Sniffs/GraphQL/ValidArgumentNameSniff.php @@ -0,0 +1,28 @@ + - TechDivision GmbH + * All rights reserved + * + * This product includes proprietary software developed at TechDivision GmbH, Germany + * For more information see https://www.techdivision.com/ + * + * To obtain a valid license for using this software please contact us at license@techdivision.com + */ + +namespace Magento2\Sniffs\GraphQL; + +/** + * Kurze Beschreibung der Klasse + * + * Lange Beschreibung der Klasse (wenn vorhanden)... + * + * @copyright Copyright (c) 2019 TechDivision GmbH - TechDivision GmbH + * @link https://www.techdivision.com/ + * @author Jean-Bernard Valentaten + */ +class ValidArgumentNymeSniff +{ + +} diff --git a/Magento2/Sniffs/GraphQL/ValidTypeNameSniff.php b/Magento2/Sniffs/GraphQL/ValidTypeNameSniff.php index 76af7b7d..c6aba7f8 100644 --- a/Magento2/Sniffs/GraphQL/ValidTypeNameSniff.php +++ b/Magento2/Sniffs/GraphQL/ValidTypeNameSniff.php @@ -5,13 +5,15 @@ */ namespace Magento2\Sniffs\GraphQL; -use PHP_CodeSniffer\Standards\Squiz\Sniffs\Classes\ValidClassNameSniff; +use PHP_CodeSniffer\Files\File; +use PHP_CodeSniffer\Sniffs\Sniff; +use PHP_CodeSniffer\Util\Common; /** * Detects types (type, interface and enum) that are not specified in * UpperCamelCase. */ -class ValidTypeNameSniff extends ValidClassNameSniff +class ValidTypeNameSniff implements Sniff { /** @@ -26,7 +28,35 @@ class ValidTypeNameSniff extends ValidClassNameSniff */ public function register() { - return [T_CLASS]; + return [T_CLASS, T_INTERFACE]; } + /** + * @inheritDoc + */ + public function process(File $phpcsFile, $stackPtr) + { + $tokens = $phpcsFile->getTokens(); + + //compose entity name by making use of the next strings the we find until we hit a non-string token + $name = ''; + for ($i=$stackPtr+1; $tokens[$i]['code'] === T_STRING; ++$i) { + $name .= $tokens[$i]['content']; + } + + $valid = Common::isCamelCaps($name, true, true, false); + + if ($valid === false) { + $type = ucfirst($tokens[$stackPtr]['content']); + $error = '%s name "%s" is not in PascalCase format'; + $data = [ + $type, + $name, + ]; + $phpcsFile->addError($error, $stackPtr, 'NotCamelCaps', $data); + $phpcsFile->recordMetric($stackPtr, 'PascalCase class name', 'no'); + } else { + $phpcsFile->recordMetric($stackPtr, 'PascalCase class name', 'yes'); + } + } } diff --git a/PHP_CodeSniffer/Tokenizers/GraphQL.php b/PHP_CodeSniffer/Tokenizers/GraphQL.php index 2b66e3a0..2fbe2634 100644 --- a/PHP_CodeSniffer/Tokenizers/GraphQL.php +++ b/PHP_CodeSniffer/Tokenizers/GraphQL.php @@ -6,19 +6,63 @@ namespace PHP_CodeSniffer\Tokenizers; +use GraphQL\Language\Lexer; +use GraphQL\Language\Source; +use GraphQL\Language\Token; use PHP_CodeSniffer\Config; +use PHP_CodeSniffer\Exceptions\TokenizerException; /** * Implements a tokenizer for GraphQL files. + * + * @todo Reimplement using the official GraphQL implementation */ -class GraphQL extends JS +class GraphQL extends Tokenizer { - protected $additionalTokenValues = [ - 'type' => 'T_CLASS', - 'interface' => 'T_CLASS', - 'enum' => 'T_CLASS', - '#' => 'T_COMMENT', + /** + * Defines how GraphQL token types are mapped to PHP token types. + * + * @var array + */ + private $tokenTypeMap = [ + Token::AMP => null, //TODO + Token::AT => 'T_DOC_COMMENT_TAG', + Token::BANG => null, //TODO + Token::BLOCK_STRING => 'T_COMMENT', + Token::BRACE_L => 'T_OPEN_CURLY_BRACKET', + Token::BRACE_R => 'T_CLOSE_CURLY_BRACKET', + Token::BRACKET_L => 'T_OPEN_SQUARE_BRACKET', + Token::BRACKET_R => 'T_CLOSE_CURLY_BRACKET', + Token::COLON => 'T_COLON', + Token::COMMENT => 'T_COMMENT', + Token::DOLLAR => 'T_DOLLAR', + Token::EOF => 'T_CLOSE_TAG', + Token::EQUALS => 'T_EQUAL', + Token::FLOAT => null, //TODO + Token::INT => null, //TODO + Token::NAME => 'T_STRING', + Token::PAREN_L => 'T_OPEN_PARENTHESIS', + Token::PAREN_R => 'T_CLOSE_PARENTHESIS', + Token::PIPE => null, //TODO + Token::SPREAD => 'T_ELLIPSIS', + Token::SOF => 'T_OPEN_TAG', + Token::STRING => 'T_STRING', + ]; + + /** + * Defines how special keywords are mapped to PHP token types + * + * @var array + */ + private $keywordTokenTypeMap = [ + 'enum' => 'T_CLASS', + 'extend' => 'T_EXTENDS', //TODO This might not be the appropriate equivalent + 'interface' => 'T_INTERFACE', + 'implements' => 'T_IMPLEMENTS', + 'type' => 'T_CLASS', + 'union' => 'T_CLASS', + //TODO Add further types ]; /** @@ -27,17 +71,13 @@ class GraphQL extends JS * @param string $content * @param Config $config * @param string $eolChar - * @throws \PHP_CodeSniffer\Exceptions\TokenizerException + * @throws TokenizerException */ public function __construct($content, Config $config, $eolChar = '\n') { - //add our token values - $this->tokenValues = array_merge( - $this->tokenValues, - $this->additionalTokenValues - ); + //TODO We might want to delete this unless we need the constructor to work totally different - //let parent do its job (which will start tokenizing) + //let parent do its job parent::__construct($content, $config, $eolChar); } @@ -46,7 +86,110 @@ public function __construct($content, Config $config, $eolChar = '\n') */ public function processAdditional() { - //NOP Does nothing intentionally + //NOP: Does nothing intentionally } + /** + * {@inheritDoc} + * + * @throws TokenizerException + */ + protected function tokenize($string) + { + $this->logVerbose('*** START GRAPHQL TOKENIZING ***'); + + $string = str_replace($this->eolChar, "\n", $string); + $tokens = []; + $lexer = new Lexer( + new Source($string) + ); + + do { + $kind = $lexer->token->kind; + $value = $lexer->token->value ?: ''; + + //if we have encountered a keyword, we convert it + //otherwise we translate the token or default it to T_STRING + if ($kind === Token::NAME && isset($this->keywordTokenTypeMap[$value])) { + $tokenType = $this->keywordTokenTypeMap[$value]; + } elseif (isset($this->tokenTypeMap[$kind])) { + $tokenType = $this->tokenTypeMap[$kind]; + } else { + $tokenType = 'T_STRING'; + } + + //some GraphQL tokens need special handling + switch ($kind) { + case Token::AT: + case Token::BRACE_L: + case Token::BRACE_R: + case Token::PAREN_L: + case Token::PAREN_R: + $value = $kind; + break; + default: + //NOP + } + + //finally we create the PHP token + $token = [ + 'code' => constant($tokenType), + 'type' => $tokenType, + 'content' => $value, + ]; + $line = $lexer->token->line; + + $lexer->advance(); + + //if line has changed (and we're not on start of file) we have to append at least one line break to current + //tokens content otherwise PHP_CodeSniffer will screw up line numbers + if ($lexer->token->line !== $line && $kind !== Token::SOF) { + $token['content'] .= $this->eolChar; + } + $tokens[] = $token; + $tokens = array_merge( + $tokens, + $this->getNewLineTokens($line, $lexer->token->line) + ); + } while ($lexer->token->kind !== Token::EOF); + + $this->logVerbose('*** END GRAPHQL TOKENIZING ***'); + return $tokens; + } + + /** + * Returns tokens of empty new lines for the range $lineStart to $lineEnd + * + * @param int $lineStart + * @param int $lineEnd + * @return array + */ + private function getNewLineTokens($lineStart, $lineEnd) + { + $amount = ($lineEnd - $lineStart) - 1; + $tokens = []; + + for ($i = 0; $i < $amount; ++$i) { + $tokens[] = [ + 'code' => T_WHITESPACE, + 'type' => 'T_WHITESPACE', + 'content' => $this->eolChar, + ]; + } + + return $tokens; + } + + /** + * Logs $message if {@link PHP_CODESNIFFER_VERBOSITY} is greater than $level. + * + * @param string $message + * @param int $level + */ + private function logVerbose($message, $level = 1) + { + if (PHP_CODESNIFFER_VERBOSITY > $level) { + printf("\t%s" . PHP_EOL, $message); + } + } } diff --git a/composer.json b/composer.json index a3684c36..889a9f4e 100644 --- a/composer.json +++ b/composer.json @@ -9,7 +9,8 @@ "version": "4", "require": { "php": ">=5.6.0", - "squizlabs/php_codesniffer": "^3.4" + "squizlabs/php_codesniffer": "^3.4", + "webonyx/graphql-php": "^0.13.8" }, "require-dev": { "phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0" diff --git a/composer.lock b/composer.lock index 416f08c7..377b98d9 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": "dd5642c8fa31b4c4fdcf19135002185f", + "content-hash": "c407f30fd32fc53345205fe5c6d3aa4d", "packages": [ { "name": "squizlabs/php_codesniffer", @@ -56,6 +56,58 @@ "standards" ], "time": "2019-04-10T23:49:02+00:00" + }, + { + "name": "webonyx/graphql-php", + "version": "v0.13.8", + "source": { + "type": "git", + "url": "https://github.com/webonyx/graphql-php.git", + "reference": "6829ae58f4c59121df1f86915fb9917a2ec595e8" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/webonyx/graphql-php/zipball/6829ae58f4c59121df1f86915fb9917a2ec595e8", + "reference": "6829ae58f4c59121df1f86915fb9917a2ec595e8", + "shasum": "" + }, + "require": { + "ext-json": "*", + "ext-mbstring": "*", + "php": "^7.1||^8.0" + }, + "require-dev": { + "doctrine/coding-standard": "^6.0", + "phpbench/phpbench": "^0.14.0", + "phpstan/phpstan": "^0.11.4", + "phpstan/phpstan-phpunit": "^0.11.0", + "phpstan/phpstan-strict-rules": "^0.11.0", + "phpunit/phpcov": "^5.0", + "phpunit/phpunit": "^7.2", + "psr/http-message": "^1.0", + "react/promise": "2.*" + }, + "suggest": { + "psr/http-message": "To use standard GraphQL server", + "react/promise": "To leverage async resolving on React PHP platform" + }, + "type": "library", + "autoload": { + "psr-4": { + "GraphQL\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "A PHP port of GraphQL reference implementation", + "homepage": "https://github.com/webonyx/graphql-php", + "keywords": [ + "api", + "graphql" + ], + "time": "2019-08-25T10:32:47+00:00" } ], "packages-dev": [ From 5fd88b518cd9d40121ac14e75dd55ae063376ed5 Mon Sep 17 00:00:00 2001 From: konarshankar07 Date: Mon, 9 Sep 2019 22:21:44 +0530 Subject: [PATCH 008/630] New rule added for class property PHP Doc block --- .../ClassPropertyPHPDocFormattingSniff.php | 72 +++++++++++++++++++ .../ClassPropertyPHPDocFormattingUnitTest.inc | 35 +++++++++ .../ClassPropertyPHPDocFormattingUnitTest.php | 32 +++++++++ Magento2/ruleset.xml | 4 ++ 4 files changed, 143 insertions(+) create mode 100644 Magento2/Sniffs/Commenting/ClassPropertyPHPDocFormattingSniff.php create mode 100644 Magento2/Tests/Commenting/ClassPropertyPHPDocFormattingUnitTest.inc create mode 100644 Magento2/Tests/Commenting/ClassPropertyPHPDocFormattingUnitTest.php diff --git a/Magento2/Sniffs/Commenting/ClassPropertyPHPDocFormattingSniff.php b/Magento2/Sniffs/Commenting/ClassPropertyPHPDocFormattingSniff.php new file mode 100644 index 00000000..3a08852d --- /dev/null +++ b/Magento2/Sniffs/Commenting/ClassPropertyPHPDocFormattingSniff.php @@ -0,0 +1,72 @@ +getTokens(); + + $commentEnd = $phpcsFile->findPrevious($this->ignoreTokens, ($stackPtr - 1), null, true); + if ($commentEnd === false + || ($tokens[$commentEnd]['code'] !== T_DOC_COMMENT_CLOSE_TAG + && $tokens[$commentEnd]['code'] !== T_COMMENT) + ) { + $phpcsFile->addWarning('Missing class property doc comment', $stackPtr, 'Missing'); + return; + } + + $commentStart = $tokens[$commentEnd]['comment_opener']; + + $foundVar = null; + foreach ($tokens[$commentStart]['comment_tags'] as $tag) { + if ($tokens[$tag]['content'] === '@var') { + if ($foundVar !== null) { + $error = 'Only one @var tag is allowed in a class property comment'; + $phpcsFile->addWarning($error, $tag, 'DuplicateVar'); + } else { + $foundVar = $tag; + } + } + } + + if ($foundVar === null) { + $error = 'Missing @var tag in class property comment'; + $phpcsFile->addWarning($error, $commentEnd, 'MissingVar'); + return; + } + + $string = $phpcsFile->findNext(T_DOC_COMMENT_STRING, $foundVar, $commentEnd); + if ($string === false || $tokens[$string]['line'] !== $tokens[$foundVar]['line']) { + $error = 'Content missing for @var tag in class property comment'; + $phpcsFile->addWarning($error, $foundVar, 'EmptyVar'); + return; + } + } +} diff --git a/Magento2/Tests/Commenting/ClassPropertyPHPDocFormattingUnitTest.inc b/Magento2/Tests/Commenting/ClassPropertyPHPDocFormattingUnitTest.inc new file mode 100644 index 00000000..2abc3e8f --- /dev/null +++ b/Magento2/Tests/Commenting/ClassPropertyPHPDocFormattingUnitTest.inc @@ -0,0 +1,35 @@ + 1, + 23 => 1, + 30 => 1, + 34 => 1 + ]; + } +} diff --git a/Magento2/ruleset.xml b/Magento2/ruleset.xml index 246b6fe1..e8e34d12 100644 --- a/Magento2/ruleset.xml +++ b/Magento2/ruleset.xml @@ -528,6 +528,10 @@ 5 warning + + 5 + warning + 5 warning From 586244ad0718b730d03eaf532a2b2a12218e3f67 Mon Sep 17 00:00:00 2001 From: Jean-Bernard Valentaten Date: Tue, 10 Sep 2019 14:38:08 +0200 Subject: [PATCH 009/630] MC-19366: Adds sniff for field names --- .../Sniffs/GraphQL/ValidArgumentNameSniff.php | 28 ----- .../Sniffs/GraphQL/ValidFieldNameSniff.php | 65 +++++++++++ .../Sniffs/GraphQL/ValidTypeNameSniff.php | 2 +- .../AbstractGraphQLSniffUnitTestCase.php | 35 ++++++ .../GraphQL/ValidFieldNameUnitTest.graphqls | 31 ++++++ .../Tests/GraphQL/ValidFieldNameUnitTest.php | 45 ++++++++ .../Tests/GraphQL/ValidTypeNameUnitTest.php | 24 +--- PHP_CodeSniffer/Tokenizers/GraphQL.php | 103 ++++++++++++------ 8 files changed, 249 insertions(+), 84 deletions(-) delete mode 100644 Magento2/Sniffs/GraphQL/ValidArgumentNameSniff.php create mode 100644 Magento2/Sniffs/GraphQL/ValidFieldNameSniff.php create mode 100644 Magento2/Tests/GraphQL/AbstractGraphQLSniffUnitTestCase.php create mode 100644 Magento2/Tests/GraphQL/ValidFieldNameUnitTest.graphqls create mode 100644 Magento2/Tests/GraphQL/ValidFieldNameUnitTest.php diff --git a/Magento2/Sniffs/GraphQL/ValidArgumentNameSniff.php b/Magento2/Sniffs/GraphQL/ValidArgumentNameSniff.php deleted file mode 100644 index e7acd46a..00000000 --- a/Magento2/Sniffs/GraphQL/ValidArgumentNameSniff.php +++ /dev/null @@ -1,28 +0,0 @@ - - TechDivision GmbH - * All rights reserved - * - * This product includes proprietary software developed at TechDivision GmbH, Germany - * For more information see https://www.techdivision.com/ - * - * To obtain a valid license for using this software please contact us at license@techdivision.com - */ - -namespace Magento2\Sniffs\GraphQL; - -/** - * Kurze Beschreibung der Klasse - * - * Lange Beschreibung der Klasse (wenn vorhanden)... - * - * @copyright Copyright (c) 2019 TechDivision GmbH - TechDivision GmbH - * @link https://www.techdivision.com/ - * @author Jean-Bernard Valentaten - */ -class ValidArgumentNymeSniff -{ - -} diff --git a/Magento2/Sniffs/GraphQL/ValidFieldNameSniff.php b/Magento2/Sniffs/GraphQL/ValidFieldNameSniff.php new file mode 100644 index 00000000..c8aef8c0 --- /dev/null +++ b/Magento2/Sniffs/GraphQL/ValidFieldNameSniff.php @@ -0,0 +1,65 @@ +snake_case. + */ +class ValidFieldNameSniff implements Sniff +{ + + /** + * Defines the tokenizers that this sniff is using. + * + * @var array + */ + public $supportedTokenizers = ['GraphQL']; + + /** + * @inheritDoc + */ + public function register() + { + return [T_VARIABLE]; + } + + /** + * @inheritDoc + */ + public function process(File $phpcsFile, $stackPtr) + { + $tokens = $phpcsFile->getTokens(); + $name = $tokens[$stackPtr]['content']; + + if (!$this->isSnakeCase($name)) { + $type = 'Field'; + $error = '%s name "%s" is not in snake_case format'; + $data = [ + $type, + $name, + ]; + $phpcsFile->addError($error, $stackPtr, 'NotSnakeCase', $data); + $phpcsFile->recordMetric($stackPtr, 'SnakeCase field name', 'no'); + } else { + $phpcsFile->recordMetric($stackPtr, 'SnakeCase field name', 'yes'); + } + } + + /** + * Returns whether $name is strictly lower case, potentially separated by underscores. + * + * @param string $name + * @return bool + */ + private function isSnakeCase($name) + { + return preg_match('/^[a-z][a-z0-9_]*$/', $name); + } +} diff --git a/Magento2/Sniffs/GraphQL/ValidTypeNameSniff.php b/Magento2/Sniffs/GraphQL/ValidTypeNameSniff.php index c6aba7f8..6b639294 100644 --- a/Magento2/Sniffs/GraphQL/ValidTypeNameSniff.php +++ b/Magento2/Sniffs/GraphQL/ValidTypeNameSniff.php @@ -38,7 +38,7 @@ public function process(File $phpcsFile, $stackPtr) { $tokens = $phpcsFile->getTokens(); - //compose entity name by making use of the next strings the we find until we hit a non-string token + //compose entity name by making use of the next strings that we find until we hit a non-string token $name = ''; for ($i=$stackPtr+1; $tokens[$i]['code'] === T_STRING; ++$i) { $name .= $tokens[$i]['content']; diff --git a/Magento2/Tests/GraphQL/AbstractGraphQLSniffUnitTestCase.php b/Magento2/Tests/GraphQL/AbstractGraphQLSniffUnitTestCase.php new file mode 100644 index 00000000..83f858b0 --- /dev/null +++ b/Magento2/Tests/GraphQL/AbstractGraphQLSniffUnitTestCase.php @@ -0,0 +1,35 @@ +extensions = array_merge( + $config->extensions, + [ + 'graphqls' => 'GraphQL' + ] + ); + + //and write back to a global that is used in base class + $GLOBALS['PHP_CODESNIFFER_CONFIG'] = $config; + } + +} diff --git a/Magento2/Tests/GraphQL/ValidFieldNameUnitTest.graphqls b/Magento2/Tests/GraphQL/ValidFieldNameUnitTest.graphqls new file mode 100644 index 00000000..54b496ac --- /dev/null +++ b/Magento2/Tests/GraphQL/ValidFieldNameUnitTest.graphqls @@ -0,0 +1,31 @@ +type FooType { + # Valid snake case field names + valid_snake_case_field: String + validlowercasefield: String + valid_snake_case_field_ending_with_number_5: String + valid_snake_case_field_with_ending_numbers_12345: String + valid_snake_case_field_5_with_number5_inline: String + + # Incorrect use of snake case + INVALIDUPPERCASEFIELD: String + INVALID_SCREAMING_SNAKE_CASE_FIELD: String + Invalid_Upper_Snake_Case_Field: String + invalid_mixed_case_FIELD: String + InvalidCameCaseFieldName: String +} + +interface FooInterface { + # Valid snake case field names + valid_snake_case_field: String + validlowercasefield: String + valid_snake_case_field_ending_with_number_5: String + valid_snake_case_field_with_ending_numbers_12345: String + valid_snake_case_field_5_with_number5_inline: String + + # Incorrect use of snake case + INVALIDUPPERCASEFIELD: String + INVALID_SCREAMING_SNAKE_CASE_FIELD: String + Invalid_Upper_Snake_Case_Field: String + invalid_mixed_case_FIELD: String + InvalidCameCaseFieldName: String +} diff --git a/Magento2/Tests/GraphQL/ValidFieldNameUnitTest.php b/Magento2/Tests/GraphQL/ValidFieldNameUnitTest.php new file mode 100644 index 00000000..eebd53e3 --- /dev/null +++ b/Magento2/Tests/GraphQL/ValidFieldNameUnitTest.php @@ -0,0 +1,45 @@ + + */ + protected function getErrorList() + { + return [ + 10 => 1, + 11 => 1, + 12 => 1, + 13 => 1, + 14 => 1, + 26 => 1, + 27 => 1, + 28 => 1, + 29 => 1, + 30 => 1, + ]; + } + + /** + * @inheritDoc + */ + protected function getWarningList() + { + return []; + } +} diff --git a/Magento2/Tests/GraphQL/ValidTypeNameUnitTest.php b/Magento2/Tests/GraphQL/ValidTypeNameUnitTest.php index 0e07c91d..a04fb314 100644 --- a/Magento2/Tests/GraphQL/ValidTypeNameUnitTest.php +++ b/Magento2/Tests/GraphQL/ValidTypeNameUnitTest.php @@ -6,32 +6,12 @@ namespace Magento2\Tests\GraphQL; use PHP_CodeSniffer\Config; -use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; /** - * Covers {@link \agento2\Sniffs\GraphQL\ValidTypeNameSniff}. + * Covers {@link \Magento2\Sniffs\GraphQL\ValidTypeNameSniff}. */ -class ValidTypeNameUnitTest extends AbstractSniffUnitTest +class ValidTypeNameUnitTest extends AbstractGraphQLSniffUnitTestCase { - - protected function setUp() - { - //let parent do its job - parent::setUp(); - - //generate a config that allows ro use our GraphQL tokenizer - $config = new Config(); - $config->extensions = array_merge( - $config->extensions, - [ - 'graphqls' => 'GraphQL' - ] - ); - - //and write back to a global that is used in base class - $GLOBALS['PHP_CODESNIFFER_CONFIG'] = $config; - } - /** * Returns the lines where errors should occur. * diff --git a/PHP_CodeSniffer/Tokenizers/GraphQL.php b/PHP_CodeSniffer/Tokenizers/GraphQL.php index 2fbe2634..d3d03ecc 100644 --- a/PHP_CodeSniffer/Tokenizers/GraphQL.php +++ b/PHP_CodeSniffer/Tokenizers/GraphQL.php @@ -3,19 +3,14 @@ * Copyright © Magento. All rights reserved. * See COPYING.txt for license details. */ - namespace PHP_CodeSniffer\Tokenizers; use GraphQL\Language\Lexer; use GraphQL\Language\Source; use GraphQL\Language\Token; -use PHP_CodeSniffer\Config; -use PHP_CodeSniffer\Exceptions\TokenizerException; /** * Implements a tokenizer for GraphQL files. - * - * @todo Reimplement using the official GraphQL implementation */ class GraphQL extends Tokenizer { @@ -26,9 +21,9 @@ class GraphQL extends Tokenizer * @var array */ private $tokenTypeMap = [ - Token::AMP => null, //TODO + Token::AMP => null, //TODO Should we map this to a specific type Token::AT => 'T_DOC_COMMENT_TAG', - Token::BANG => null, //TODO + Token::BANG => null, //TODO Should we map this to a specific type Token::BLOCK_STRING => 'T_COMMENT', Token::BRACE_L => 'T_OPEN_CURLY_BRACKET', Token::BRACE_R => 'T_CLOSE_CURLY_BRACKET', @@ -39,12 +34,12 @@ class GraphQL extends Tokenizer Token::DOLLAR => 'T_DOLLAR', Token::EOF => 'T_CLOSE_TAG', Token::EQUALS => 'T_EQUAL', - Token::FLOAT => null, //TODO - Token::INT => null, //TODO + Token::FLOAT => null, //TODO Should we map this to a specific type + Token::INT => null, //TODO Should we map this to a specific type Token::NAME => 'T_STRING', Token::PAREN_L => 'T_OPEN_PARENTHESIS', Token::PAREN_R => 'T_CLOSE_PARENTHESIS', - Token::PIPE => null, //TODO + Token::PIPE => null, //TODO Should we map this to a specific type Token::SPREAD => 'T_ELLIPSIS', Token::SOF => 'T_OPEN_TAG', Token::STRING => 'T_STRING', @@ -62,37 +57,45 @@ class GraphQL extends Tokenizer 'implements' => 'T_IMPLEMENTS', 'type' => 'T_CLASS', 'union' => 'T_CLASS', - //TODO Add further types + //TODO We may have to add further types ]; - /** - * Constructor. - * - * @param string $content - * @param Config $config - * @param string $eolChar - * @throws TokenizerException - */ - public function __construct($content, Config $config, $eolChar = '\n') - { - //TODO We might want to delete this unless we need the constructor to work totally different - - //let parent do its job - parent::__construct($content, $config, $eolChar); - } - /** * @inheritDoc */ public function processAdditional() { - //NOP: Does nothing intentionally + $this->logVerbose('*** START ADDITIONAL GRAPHQL PROCESSING ***'); + + $processingEntity = false; + $numTokens = count($this->tokens); + $entityTypes = [T_CLASS, T_INTERFACE]; + + for ($i = 0; $i < $numTokens; ++$i) { + $tokenCode = $this->tokens[$i]['code']; + + //have we found a new entity or its end? + if (in_array($tokenCode, $entityTypes) && $this->tokens[$i]['content'] !== 'enum') { + $processingEntity = true; + continue; + } elseif ($tokenCode === T_CLOSE_CURLY_BRACKET) { + $processingEntity = false; + continue; + } + + //if we are processing an entity, are we currently seeing a field? + if ($processingEntity && $this->isFieldToken($i)) { + $this->tokens[$i]['code'] = T_VARIABLE; + $this->tokens[$i]['type'] = 'T_VARIABLE'; + continue; + } + } + + $this->logVerbose('*** END ADDITIONAL GRAPHQL PROCESSING ***'); } /** - * {@inheritDoc} - * - * @throws TokenizerException + * @inheritDoc */ protected function tokenize($string) { @@ -125,6 +128,7 @@ protected function tokenize($string) case Token::BRACE_R: case Token::PAREN_L: case Token::PAREN_R: + case Token::COLON: $value = $kind; break; default: @@ -142,12 +146,12 @@ protected function tokenize($string) $lexer->advance(); //if line has changed (and we're not on start of file) we have to append at least one line break to current - //tokens content otherwise PHP_CodeSniffer will screw up line numbers + //token's content otherwise PHP_CodeSniffer will screw up line numbers if ($lexer->token->line !== $line && $kind !== Token::SOF) { $token['content'] .= $this->eolChar; } $tokens[] = $token; - $tokens = array_merge( + $tokens = array_merge( $tokens, $this->getNewLineTokens($line, $lexer->token->line) ); @@ -180,6 +184,39 @@ private function getNewLineTokens($lineStart, $lineEnd) return $tokens; } + /** + * Returns whether the token under $stackPointer is a field. + * + * We consider a token to be a field if: + *
    + *
  • its direct successor is of type {@link T_COLON}
  • + *
  • it has a list of arguments followed by a {@link T_COLON}
  • + *
+ * + * @param int $stackPointer + * @return bool + */ + private function isFieldToken($stackPointer) + { + $nextToken = $this->tokens[$stackPointer + 1]; + + //if next token is an opening parenthesis, we seek for the closing parenthesis + if ($nextToken['code'] === T_OPEN_PARENTHESIS) { + $nextPointer = $stackPointer + 1; + $numTokens = count($this->tokens); + + for ($i=$nextPointer; $i<$numTokens; ++$i) { + if ($this->tokens[$i]['code'] === T_CLOSE_PARENTHESIS) { + $nextToken = $this->tokens[$i + 1]; + break; + } + } + } + + //return whether next token is a colon + return $nextToken['code'] === T_COLON; + } + /** * Logs $message if {@link PHP_CODESNIFFER_VERBOSITY} is greater than $level. * From 27e99de30626d032604f30203e46a29f84630e25 Mon Sep 17 00:00:00 2001 From: Jean-Bernard Valentaten Date: Wed, 11 Sep 2019 10:41:28 +0200 Subject: [PATCH 010/630] MC-19366: Adds sniff for argument names --- .../Sniffs/GraphQL/ValidArgumentNameSniff.php | 145 ++++++++++++++++++ .../Sniffs/GraphQL/ValidFieldNameSniff.php | 1 - .../ValidArgumentNameUnitTest.graphqls | 32 ++++ .../GraphQL/ValidArgumentNameUnitTest.php | 39 +++++ .../Tests/GraphQL/ValidFieldNameUnitTest.php | 9 +- PHP_CodeSniffer/Tokenizers/GraphQL.php | 79 ++++++---- 6 files changed, 270 insertions(+), 35 deletions(-) create mode 100644 Magento2/Sniffs/GraphQL/ValidArgumentNameSniff.php create mode 100644 Magento2/Tests/GraphQL/ValidArgumentNameUnitTest.graphqls create mode 100644 Magento2/Tests/GraphQL/ValidArgumentNameUnitTest.php diff --git a/Magento2/Sniffs/GraphQL/ValidArgumentNameSniff.php b/Magento2/Sniffs/GraphQL/ValidArgumentNameSniff.php new file mode 100644 index 00000000..6faeefb6 --- /dev/null +++ b/Magento2/Sniffs/GraphQL/ValidArgumentNameSniff.php @@ -0,0 +1,145 @@ +cameCase. + */ +class ValidArgumentNameSniff implements Sniff +{ + + /** + * Defines the tokenizers that this sniff is using. + * + * @var array + */ + public $supportedTokenizers = ['GraphQL']; + + /** + * @inheritDoc + */ + public function register() + { + return [T_OPEN_PARENTHESIS]; + } + + /** + * @inheritDoc + */ + public function process(File $phpcsFile, $stackPtr) + { + $tokens = $phpcsFile->getTokens(); + $closeParenthesisPointer = $this->getCloseParenthesisPointer($stackPtr, $tokens); + + //if we could not find the closing parenthesis pointer, we add a warning and terminate + if ($closeParenthesisPointer === false) { + $error = 'Possible parse error: Missing closing parenthesis for argument list in line %d'; + $data = [ + $tokens[$stackPtr]['line'], + ]; + $phpcsFile->addWarning($error, $stackPtr, 'UnclosedArgumentList', $data); + return; + } + + $arguments = $this->getArguments($stackPtr, $closeParenthesisPointer, $tokens); + + foreach ($arguments as $argument) { + $pointer = $argument[0]; + $name = $argument[1]; + + if (!$this->isCamelCase($name)) { + $type = 'Argument'; + $error = '%s name "%s" is not in CamelCase format'; + $data = [ + $type, + $name, + ]; + + $phpcsFile->addError($error, $pointer, 'NotCamelCase', $data); + $phpcsFile->recordMetric($pointer, 'CamelCase argument name', 'no'); + } else { + $phpcsFile->recordMetric($pointer, 'CamelCase argument name', 'yes'); + } + } + + //return stack pointer of closing parenthesis + return $closeParenthesisPointer; + } + + /** + * Finds all argument names contained in $tokens range $startPointer and + * $endPointer. + * + * @param int $startPointer + * @param int $endPointer + * @param array $tokens + * @return array[] + */ + private function getArguments($startPointer, $endPointer, array $tokens) + { + $argumentTokenPointer = null; + $argument = ''; + $names = []; + $skipTypes = [T_COMMENT, T_WHITESPACE]; + + for ($i = $startPointer + 1; $i < $endPointer; ++$i) { + //skip comment tokens + if (in_array($tokens[$i]['code'], $skipTypes)) { + continue; + } + $argument .= $tokens[$i]['content']; + + if ($argumentTokenPointer === null) { + $argumentTokenPointer = $i; + } + + if (preg_match('/^.+:.+$/', $argument)) { + list($name, $type) = explode(':', $argument); + $names[] = [$argumentTokenPointer, $name]; + $argument = ''; + $argumentTokenPointer = null; + } + } + + return $names; + } + + /** + * Seeks the next available token of type {@link T_CLOSE_PARENTHESIS} in $tokens and returns its pointer. + * + * @param int $stackPointer + * @param array $tokens + * @return bool|int + */ + private function getCloseParenthesisPointer($stackPointer, array $tokens) + { + $numTokens = count($tokens); + + for ($i = $stackPointer + 1; $i < $numTokens; ++$i) { + if ($tokens[$i]['code'] === T_CLOSE_PARENTHESIS) { + return $i; + } + } + + //if we came here we could not find the closing parenthesis + return false; + } + + /** + * Returns whether $name starts with a lower case character and is written in camel case. + * + * @param string $argumentName + * @return bool + */ + private function isCamelCase($argumentName) + { + return (preg_match('/^[a-z][a-zA-Z0-9]+$/', $argumentName) !== 0); + } +} diff --git a/Magento2/Sniffs/GraphQL/ValidFieldNameSniff.php b/Magento2/Sniffs/GraphQL/ValidFieldNameSniff.php index c8aef8c0..23d7cb1c 100644 --- a/Magento2/Sniffs/GraphQL/ValidFieldNameSniff.php +++ b/Magento2/Sniffs/GraphQL/ValidFieldNameSniff.php @@ -7,7 +7,6 @@ use PHP_CodeSniffer\Files\File; use PHP_CodeSniffer\Sniffs\Sniff; -use PHP_CodeSniffer\Util\Common; /** * Detects field names the are not specified in snake_case. diff --git a/Magento2/Tests/GraphQL/ValidArgumentNameUnitTest.graphqls b/Magento2/Tests/GraphQL/ValidArgumentNameUnitTest.graphqls new file mode 100644 index 00000000..83b4f23c --- /dev/null +++ b/Magento2/Tests/GraphQL/ValidArgumentNameUnitTest.graphqls @@ -0,0 +1,32 @@ +type Foo { + bar( + # Valid argument names + validArgumentName: Int + validArgumentNameWith1Number: Int + validArgumentNameWith12345Numbers: Int + validArgumentNameEndingWithNumber5: Int + validArgumentNameWithUPPERCASE: Int + validargumentwithlowercase: Int + # Invalid argument names + InvalidArgumentNameUpperCamelCase: Int + INVALIDARGUMENTNAMEUPPERCASE: Int + invalid_argument_name_snake_case: Int + 5invalidArgumentNameStatingWithNumber: Int + ): String +} +interface Foo { + bar( + # Valid argument names + validArgumentName: Int + validArgumentNameWith1Number: Int + validArgumentNameWith12345Numbers: Int + validArgumentNameEndingWithNumber5: Int + validArgumentNameWithUPPERCASE: Int + validargumentwithlowercase: Int + # Invalid argument names + InvalidArgumentNameUpperCamelCase: Int + INVALIDARGUMENTNAMEUPPERCASE: Int + invalid_argument_name_snake_case: Int + 5invalidArgumentNameStatingWithNumber: Int + ): String +} \ No newline at end of file diff --git a/Magento2/Tests/GraphQL/ValidArgumentNameUnitTest.php b/Magento2/Tests/GraphQL/ValidArgumentNameUnitTest.php new file mode 100644 index 00000000..746c867e --- /dev/null +++ b/Magento2/Tests/GraphQL/ValidArgumentNameUnitTest.php @@ -0,0 +1,39 @@ + 1, + 12 => 1, + 13 => 1, + 14 => 1, + 27 => 1, + 28 => 1, + 29 => 1, + 30 => 1, + ]; + } + + /** + * @inheritDoc + */ + protected function getWarningList() + { + return []; + } +} + diff --git a/Magento2/Tests/GraphQL/ValidFieldNameUnitTest.php b/Magento2/Tests/GraphQL/ValidFieldNameUnitTest.php index eebd53e3..3ded35bb 100644 --- a/Magento2/Tests/GraphQL/ValidFieldNameUnitTest.php +++ b/Magento2/Tests/GraphQL/ValidFieldNameUnitTest.php @@ -6,18 +6,13 @@ namespace Magento2\Tests\GraphQL; /** - * Covers {@link \Magento2\Sniffs\GraphQL\ValidFieldNameUnitTest}. + * Covers {@link \Magento2\Sniffs\GraphQL\ValidFieldNameSniff}. */ class ValidFieldNameUnitTest extends AbstractGraphQLSniffUnitTestCase { /** - * Returns the lines where errors should occur. - * - * The key of the array should represent the line number and the value - * should represent the number of errors that should occur on that line. - * - * @return array + * @inheritDoc */ protected function getErrorList() { diff --git a/PHP_CodeSniffer/Tokenizers/GraphQL.php b/PHP_CodeSniffer/Tokenizers/GraphQL.php index d3d03ecc..0e49cd01 100644 --- a/PHP_CodeSniffer/Tokenizers/GraphQL.php +++ b/PHP_CodeSniffer/Tokenizers/GraphQL.php @@ -3,6 +3,7 @@ * Copyright © Magento. All rights reserved. * See COPYING.txt for license details. */ + namespace PHP_CodeSniffer\Tokenizers; use GraphQL\Language\Lexer; @@ -67,29 +68,7 @@ public function processAdditional() { $this->logVerbose('*** START ADDITIONAL GRAPHQL PROCESSING ***'); - $processingEntity = false; - $numTokens = count($this->tokens); - $entityTypes = [T_CLASS, T_INTERFACE]; - - for ($i = 0; $i < $numTokens; ++$i) { - $tokenCode = $this->tokens[$i]['code']; - - //have we found a new entity or its end? - if (in_array($tokenCode, $entityTypes) && $this->tokens[$i]['content'] !== 'enum') { - $processingEntity = true; - continue; - } elseif ($tokenCode === T_CLOSE_CURLY_BRACKET) { - $processingEntity = false; - continue; - } - - //if we are processing an entity, are we currently seeing a field? - if ($processingEntity && $this->isFieldToken($i)) { - $this->tokens[$i]['code'] = T_VARIABLE; - $this->tokens[$i]['type'] = 'T_VARIABLE'; - continue; - } - } + $this->processFields(); $this->logVerbose('*** END ADDITIONAL GRAPHQL PROCESSING ***'); } @@ -203,9 +182,9 @@ private function isFieldToken($stackPointer) //if next token is an opening parenthesis, we seek for the closing parenthesis if ($nextToken['code'] === T_OPEN_PARENTHESIS) { $nextPointer = $stackPointer + 1; - $numTokens = count($this->tokens); + $numTokens = count($this->tokens); - for ($i=$nextPointer; $i<$numTokens; ++$i) { + for ($i = $nextPointer; $i < $numTokens; ++$i) { if ($this->tokens[$i]['code'] === T_CLOSE_PARENTHESIS) { $nextToken = $this->tokens[$i + 1]; break; @@ -213,8 +192,8 @@ private function isFieldToken($stackPointer) } } - //return whether next token is a colon - return $nextToken['code'] === T_COLON; + //return whether current token is a string and next token is a colon + return $this->tokens[$stackPointer]['code'] === T_STRING && $nextToken['code'] === T_COLON; } /** @@ -229,4 +208,50 @@ private function logVerbose($message, $level = 1) printf("\t%s" . PHP_EOL, $message); } } + + /** + * Processes field tokens, setting their type to {@link T_VARIABLE}. + */ + private function processFields() + { + $processingArgumentList = false; + $processingEntity = false; + $numTokens = count($this->tokens); + $entityTypes = [T_CLASS, T_INTERFACE]; + $skipTypes = [T_COMMENT, T_WHITESPACE]; + + for ($i = 0; $i < $numTokens; ++$i) { + $tokenCode = $this->tokens[$i]['code']; + + //process current token + switch (true) { + case in_array($tokenCode, $skipTypes): + //we have hit a token that needs to be skipped -> NOP + break; + case in_array($tokenCode, $entityTypes) && $this->tokens[$i]['content'] !== 'enum': + //we have hit an entity declaration + $processingEntity = true; + break; + case $tokenCode === T_CLOSE_CURLY_BRACKET: + //we have hit the end of an entity declaration + $processingEntity = false; + break; + case $tokenCode === T_OPEN_PARENTHESIS: + //we have hit an argument list + $processingArgumentList = true; + break; + case $tokenCode === T_CLOSE_PARENTHESIS: + //we have hit an argument list end + $processingArgumentList = false; + break; + case $processingEntity && !$processingArgumentList && $this->isFieldToken($i): + //we have hit a field + $this->tokens[$i]['code'] = T_VARIABLE; + $this->tokens[$i]['type'] = 'T_VARIABLE'; + break; + default: + //NOP All operations have already been executed + } + } + } } From 47fb2030cfcf97d50142c53454505f073d1a3255 Mon Sep 17 00:00:00 2001 From: Jean-Bernard Valentaten Date: Wed, 11 Sep 2019 13:10:47 +0200 Subject: [PATCH 011/630] MC-19366: Adds sniff for top level fields --- .../Sniffs/GraphQL/AbstractGraphQLSniff.php | 52 +++++++++++++++++++ .../Sniffs/GraphQL/ValidArgumentNameSniff.php | 21 +------- .../Sniffs/GraphQL/ValidFieldNameSniff.php | 20 +------ .../GraphQL/ValidTopLevelFieldNameSniff.php | 51 ++++++++++++++++++ .../Sniffs/GraphQL/ValidTypeNameSniff.php | 10 +--- .../ValidTopLevelFieldNameUnitTest.graphqls | 35 +++++++++++++ .../ValidTopLevelFieldNameUnitTest.php | 39 ++++++++++++++ Magento2/ruleset.xml | 12 +++++ PHP_CodeSniffer/Tokenizers/GraphQL.php | 2 + 9 files changed, 194 insertions(+), 48 deletions(-) create mode 100644 Magento2/Sniffs/GraphQL/AbstractGraphQLSniff.php create mode 100644 Magento2/Sniffs/GraphQL/ValidTopLevelFieldNameSniff.php create mode 100644 Magento2/Tests/GraphQL/ValidTopLevelFieldNameUnitTest.graphqls create mode 100644 Magento2/Tests/GraphQL/ValidTopLevelFieldNameUnitTest.php diff --git a/Magento2/Sniffs/GraphQL/AbstractGraphQLSniff.php b/Magento2/Sniffs/GraphQL/AbstractGraphQLSniff.php new file mode 100644 index 00000000..6d52dcfd --- /dev/null +++ b/Magento2/Sniffs/GraphQL/AbstractGraphQLSniff.php @@ -0,0 +1,52 @@ + - TechDivision GmbH + * All rights reserved + * + * This product includes proprietary software developed at TechDivision GmbH, Germany + * For more information see https://www.techdivision.com/ + * + * To obtain a valid license for using this software please contact us at license@techdivision.com + */ +namespace Magento2\Sniffs\GraphQL; + +use PHP_CodeSniffer\Sniffs\Sniff; + +/** + * Defines an abstract base class for GraphQL sniffs. + */ +abstract class AbstractGraphQLSniff implements Sniff +{ + + /** + * Defines the tokenizers that this sniff is using. + * + * @var array + */ + public $supportedTokenizers = ['GraphQL']; + + /** + * Returns whether $name starts with a lower case character and is written in camel case. + * + * @param string $name + * @return bool + */ + protected function isCamelCase($name) + { + return (preg_match('/^[a-z][a-zA-Z0-9]+$/', $name) !== 0); + } + + /** + * Returns whether $name is strictly lower case, potentially separated by underscores. + * + * @param string $name + * @return bool + */ + protected function isSnakeCase($name) + { + return preg_match('/^[a-z][a-z0-9_]*$/', $name); + } + +} diff --git a/Magento2/Sniffs/GraphQL/ValidArgumentNameSniff.php b/Magento2/Sniffs/GraphQL/ValidArgumentNameSniff.php index 6faeefb6..5a96ec77 100644 --- a/Magento2/Sniffs/GraphQL/ValidArgumentNameSniff.php +++ b/Magento2/Sniffs/GraphQL/ValidArgumentNameSniff.php @@ -3,25 +3,16 @@ * Copyright © Magento. All rights reserved. * See COPYING.txt for license details. */ - namespace Magento2\Sniffs\GraphQL; use PHP_CodeSniffer\Files\File; -use PHP_CodeSniffer\Sniffs\Sniff; /** * Detects argument names that are not specified in cameCase. */ -class ValidArgumentNameSniff implements Sniff +class ValidArgumentNameSniff extends AbstractGraphQLSniff { - /** - * Defines the tokenizers that this sniff is using. - * - * @var array - */ - public $supportedTokenizers = ['GraphQL']; - /** * @inheritDoc */ @@ -132,14 +123,4 @@ private function getCloseParenthesisPointer($stackPointer, array $tokens) return false; } - /** - * Returns whether $name starts with a lower case character and is written in camel case. - * - * @param string $argumentName - * @return bool - */ - private function isCamelCase($argumentName) - { - return (preg_match('/^[a-z][a-zA-Z0-9]+$/', $argumentName) !== 0); - } } diff --git a/Magento2/Sniffs/GraphQL/ValidFieldNameSniff.php b/Magento2/Sniffs/GraphQL/ValidFieldNameSniff.php index 23d7cb1c..91743afa 100644 --- a/Magento2/Sniffs/GraphQL/ValidFieldNameSniff.php +++ b/Magento2/Sniffs/GraphQL/ValidFieldNameSniff.php @@ -6,21 +6,13 @@ namespace Magento2\Sniffs\GraphQL; use PHP_CodeSniffer\Files\File; -use PHP_CodeSniffer\Sniffs\Sniff; /** * Detects field names the are not specified in snake_case. */ -class ValidFieldNameSniff implements Sniff +class ValidFieldNameSniff extends AbstractGraphQLSniff { - /** - * Defines the tokenizers that this sniff is using. - * - * @var array - */ - public $supportedTokenizers = ['GraphQL']; - /** * @inheritDoc */ @@ -51,14 +43,4 @@ public function process(File $phpcsFile, $stackPtr) } } - /** - * Returns whether $name is strictly lower case, potentially separated by underscores. - * - * @param string $name - * @return bool - */ - private function isSnakeCase($name) - { - return preg_match('/^[a-z][a-z0-9_]*$/', $name); - } } diff --git a/Magento2/Sniffs/GraphQL/ValidTopLevelFieldNameSniff.php b/Magento2/Sniffs/GraphQL/ValidTopLevelFieldNameSniff.php new file mode 100644 index 00000000..cbdf642b --- /dev/null +++ b/Magento2/Sniffs/GraphQL/ValidTopLevelFieldNameSniff.php @@ -0,0 +1,51 @@ +cameCase. + */ +class ValidTopLevelFieldNameSniff extends AbstractGraphQLSniff +{ + + /** + * @inheritDoc + */ + public function register() + { + return [T_FUNCTION]; + } + + /** + * @inheritDoc + */ + public function process(File $phpcsFile, $stackPtr) + { + $tokens = $phpcsFile->getTokens(); + + //compose function name by making use of the next strings that we find until we hit a non-string token + $name = ''; + for ($i=$stackPtr+1; $tokens[$i]['code'] === T_STRING; ++$i) { + $name .= $tokens[$i]['content']; + } + + if (strlen($name) > 0 && !$this->isCamelCase($name)) { + $type = ucfirst($tokens[$stackPtr]['content']); + $error = '%s name "%s" is not in PascalCase format'; + $data = [ + $type, + $name, + ]; + $phpcsFile->addError($error, $stackPtr, 'NotCamelCase', $data); + $phpcsFile->recordMetric($stackPtr, 'CamelCase top level field name', 'no'); + } else { + $phpcsFile->recordMetric($stackPtr, 'CamelCase top level field name', 'yes'); + } + } + +} diff --git a/Magento2/Sniffs/GraphQL/ValidTypeNameSniff.php b/Magento2/Sniffs/GraphQL/ValidTypeNameSniff.php index 6b639294..ca153340 100644 --- a/Magento2/Sniffs/GraphQL/ValidTypeNameSniff.php +++ b/Magento2/Sniffs/GraphQL/ValidTypeNameSniff.php @@ -6,23 +6,15 @@ namespace Magento2\Sniffs\GraphQL; use PHP_CodeSniffer\Files\File; -use PHP_CodeSniffer\Sniffs\Sniff; use PHP_CodeSniffer\Util\Common; /** * Detects types (type, interface and enum) that are not specified in * UpperCamelCase. */ -class ValidTypeNameSniff implements Sniff +class ValidTypeNameSniff extends AbstractGraphQLSniff { - /** - * Defines the tokenizers that this sniff is using. - * - * @var array - */ - public $supportedTokenizers = ['GraphQL']; - /** * @inheritDoc */ diff --git a/Magento2/Tests/GraphQL/ValidTopLevelFieldNameUnitTest.graphqls b/Magento2/Tests/GraphQL/ValidTopLevelFieldNameUnitTest.graphqls new file mode 100644 index 00000000..39d16c92 --- /dev/null +++ b/Magento2/Tests/GraphQL/ValidTopLevelFieldNameUnitTest.graphqls @@ -0,0 +1,35 @@ +# Valid names +query validCamelCaseQuery {} +mutation validCamelCaseMutation {} + +# Incorrect use of camel cyse +query InvalidCamelCaseQuery {} +query invalid_Camel_Case_Query_With_Underscores {} +mutation InvalidCamelCaseMutation {} +mutation invalid_Camel_Case_Mutation_With_Underscores {} + +# All lower case +query validlowercasequery {} +mutation validlowercasemutation {} + +# All upper case +query INVALIDUPPERCASEQUERY {} +mutation INVALIDUPPERCASEMUTATION {} + +# Mix camel case with uppercase +query validCamelCaseQueryWithUPPERCASE {} +mutation validCamelCaseMutationWithUPPERCASE {} + +# Usage of numeric characters +query validCamelCaseQueryWith1Number {} +query validCamelCaseQueryWith12345Numbers {} +query validCamelCaseQueryEndingWithNumber4 {} +query 5invalidCamelCaseQueryStartingWithNumber {} +mutation validCamelCaseMutationWith1Number {} +mutation validCamelCaseMutationWith12345Numbers {} +mutation validCamelCaseMutationEndingWithNumber4 {} +mutation 5invalidCamelCaseMutationStartingWithNumber {} + +# Empty names (valid by definition of GraphQL) +query {} +mutation {} \ No newline at end of file diff --git a/Magento2/Tests/GraphQL/ValidTopLevelFieldNameUnitTest.php b/Magento2/Tests/GraphQL/ValidTopLevelFieldNameUnitTest.php new file mode 100644 index 00000000..759e9e18 --- /dev/null +++ b/Magento2/Tests/GraphQL/ValidTopLevelFieldNameUnitTest.php @@ -0,0 +1,39 @@ + 1, + 7 => 1, + 8 => 1, + 9 => 1, + 16 => 1, + 17 => 1, + 27 => 1, + 31 => 1, + ]; + } + + /** + * @inheritDoc + */ + protected function getWarningList() + { + return []; + } + +} diff --git a/Magento2/ruleset.xml b/Magento2/ruleset.xml index adda516c..d31750fe 100644 --- a/Magento2/ruleset.xml +++ b/Magento2/ruleset.xml @@ -526,6 +526,18 @@ 6 warning
+ + 6 + warning + + + 6 + warning + + + 6 + warning + diff --git a/PHP_CodeSniffer/Tokenizers/GraphQL.php b/PHP_CodeSniffer/Tokenizers/GraphQL.php index 0e49cd01..508660fd 100644 --- a/PHP_CodeSniffer/Tokenizers/GraphQL.php +++ b/PHP_CodeSniffer/Tokenizers/GraphQL.php @@ -58,6 +58,8 @@ class GraphQL extends Tokenizer 'implements' => 'T_IMPLEMENTS', 'type' => 'T_CLASS', 'union' => 'T_CLASS', + 'query' => 'T_FUNCTION', + 'mutation' => 'T_FUNCTION', //TODO We may have to add further types ]; From 6f5d136ce1a4d98598ccbefd043158de35bd3ef2 Mon Sep 17 00:00:00 2001 From: Jean-Bernard Valentaten Date: Wed, 11 Sep 2019 13:31:36 +0200 Subject: [PATCH 012/630] MC-19366: Downgrade of package webonyx/graphql-php to match lowest php version supported by coding standard --- PHP_CodeSniffer/Tokenizers/GraphQL.php | 1 - composer.json | 2 +- composer.lock | 23 ++++++++--------------- 3 files changed, 9 insertions(+), 17 deletions(-) diff --git a/PHP_CodeSniffer/Tokenizers/GraphQL.php b/PHP_CodeSniffer/Tokenizers/GraphQL.php index 508660fd..3d2c30b1 100644 --- a/PHP_CodeSniffer/Tokenizers/GraphQL.php +++ b/PHP_CodeSniffer/Tokenizers/GraphQL.php @@ -22,7 +22,6 @@ class GraphQL extends Tokenizer * @var array */ private $tokenTypeMap = [ - Token::AMP => null, //TODO Should we map this to a specific type Token::AT => 'T_DOC_COMMENT_TAG', Token::BANG => null, //TODO Should we map this to a specific type Token::BLOCK_STRING => 'T_COMMENT', diff --git a/composer.json b/composer.json index 889a9f4e..492357e1 100644 --- a/composer.json +++ b/composer.json @@ -10,7 +10,7 @@ "require": { "php": ">=5.6.0", "squizlabs/php_codesniffer": "^3.4", - "webonyx/graphql-php": "^0.13.8" + "webonyx/graphql-php": ">=0.12.6 <1.0" }, "require-dev": { "phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0" diff --git a/composer.lock b/composer.lock index 377b98d9..de4d5a34 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": "c407f30fd32fc53345205fe5c6d3aa4d", + "content-hash": "560d5eca9cf59f965d8f3b98d2ee2a0a", "packages": [ { "name": "squizlabs/php_codesniffer", @@ -59,31 +59,24 @@ }, { "name": "webonyx/graphql-php", - "version": "v0.13.8", + "version": "v0.12.6", "source": { "type": "git", "url": "https://github.com/webonyx/graphql-php.git", - "reference": "6829ae58f4c59121df1f86915fb9917a2ec595e8" + "reference": "4c545e5ec4fc37f6eb36c19f5a0e7feaf5979c95" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/webonyx/graphql-php/zipball/6829ae58f4c59121df1f86915fb9917a2ec595e8", - "reference": "6829ae58f4c59121df1f86915fb9917a2ec595e8", + "url": "https://api.github.com/repos/webonyx/graphql-php/zipball/4c545e5ec4fc37f6eb36c19f5a0e7feaf5979c95", + "reference": "4c545e5ec4fc37f6eb36c19f5a0e7feaf5979c95", "shasum": "" }, "require": { - "ext-json": "*", "ext-mbstring": "*", - "php": "^7.1||^8.0" + "php": ">=5.6" }, "require-dev": { - "doctrine/coding-standard": "^6.0", - "phpbench/phpbench": "^0.14.0", - "phpstan/phpstan": "^0.11.4", - "phpstan/phpstan-phpunit": "^0.11.0", - "phpstan/phpstan-strict-rules": "^0.11.0", - "phpunit/phpcov": "^5.0", - "phpunit/phpunit": "^7.2", + "phpunit/phpunit": "^4.8", "psr/http-message": "^1.0", "react/promise": "2.*" }, @@ -107,7 +100,7 @@ "api", "graphql" ], - "time": "2019-08-25T10:32:47+00:00" + "time": "2018-09-02T14:59:54+00:00" } ], "packages-dev": [ From 7a5b2661b42a88aff31f23924060147ab274fb32 Mon Sep 17 00:00:00 2001 From: Jean-Bernard Valentaten Date: Wed, 11 Sep 2019 14:18:20 +0200 Subject: [PATCH 013/630] MC-19366: Fixes code style issues --- Magento2/Sniffs/GraphQL/AbstractGraphQLSniff.php | 2 -- Magento2/Sniffs/GraphQL/ValidArgumentNameSniff.php | 2 -- Magento2/Sniffs/GraphQL/ValidFieldNameSniff.php | 2 -- Magento2/Sniffs/GraphQL/ValidTopLevelFieldNameSniff.php | 2 -- Magento2/Sniffs/GraphQL/ValidTypeNameSniff.php | 1 - Magento2/Tests/GraphQL/AbstractGraphQLSniffUnitTestCase.php | 2 -- Magento2/Tests/GraphQL/ValidArgumentNameUnitTest.php | 1 - Magento2/Tests/GraphQL/ValidFieldNameUnitTest.php | 1 - Magento2/Tests/GraphQL/ValidTopLevelFieldNameUnitTest.php | 2 -- Magento2/Tests/GraphQL/ValidTypeNameUnitTest.php | 1 - 10 files changed, 16 deletions(-) diff --git a/Magento2/Sniffs/GraphQL/AbstractGraphQLSniff.php b/Magento2/Sniffs/GraphQL/AbstractGraphQLSniff.php index 6d52dcfd..b03cffe8 100644 --- a/Magento2/Sniffs/GraphQL/AbstractGraphQLSniff.php +++ b/Magento2/Sniffs/GraphQL/AbstractGraphQLSniff.php @@ -19,7 +19,6 @@ */ abstract class AbstractGraphQLSniff implements Sniff { - /** * Defines the tokenizers that this sniff is using. * @@ -48,5 +47,4 @@ protected function isSnakeCase($name) { return preg_match('/^[a-z][a-z0-9_]*$/', $name); } - } diff --git a/Magento2/Sniffs/GraphQL/ValidArgumentNameSniff.php b/Magento2/Sniffs/GraphQL/ValidArgumentNameSniff.php index 5a96ec77..ffb1f8d4 100644 --- a/Magento2/Sniffs/GraphQL/ValidArgumentNameSniff.php +++ b/Magento2/Sniffs/GraphQL/ValidArgumentNameSniff.php @@ -12,7 +12,6 @@ */ class ValidArgumentNameSniff extends AbstractGraphQLSniff { - /** * @inheritDoc */ @@ -122,5 +121,4 @@ private function getCloseParenthesisPointer($stackPointer, array $tokens) //if we came here we could not find the closing parenthesis return false; } - } diff --git a/Magento2/Sniffs/GraphQL/ValidFieldNameSniff.php b/Magento2/Sniffs/GraphQL/ValidFieldNameSniff.php index 91743afa..f638c228 100644 --- a/Magento2/Sniffs/GraphQL/ValidFieldNameSniff.php +++ b/Magento2/Sniffs/GraphQL/ValidFieldNameSniff.php @@ -12,7 +12,6 @@ */ class ValidFieldNameSniff extends AbstractGraphQLSniff { - /** * @inheritDoc */ @@ -42,5 +41,4 @@ public function process(File $phpcsFile, $stackPtr) $phpcsFile->recordMetric($stackPtr, 'SnakeCase field name', 'yes'); } } - } diff --git a/Magento2/Sniffs/GraphQL/ValidTopLevelFieldNameSniff.php b/Magento2/Sniffs/GraphQL/ValidTopLevelFieldNameSniff.php index cbdf642b..eacbc10d 100644 --- a/Magento2/Sniffs/GraphQL/ValidTopLevelFieldNameSniff.php +++ b/Magento2/Sniffs/GraphQL/ValidTopLevelFieldNameSniff.php @@ -12,7 +12,6 @@ */ class ValidTopLevelFieldNameSniff extends AbstractGraphQLSniff { - /** * @inheritDoc */ @@ -47,5 +46,4 @@ public function process(File $phpcsFile, $stackPtr) $phpcsFile->recordMetric($stackPtr, 'CamelCase top level field name', 'yes'); } } - } diff --git a/Magento2/Sniffs/GraphQL/ValidTypeNameSniff.php b/Magento2/Sniffs/GraphQL/ValidTypeNameSniff.php index ca153340..b80ada40 100644 --- a/Magento2/Sniffs/GraphQL/ValidTypeNameSniff.php +++ b/Magento2/Sniffs/GraphQL/ValidTypeNameSniff.php @@ -14,7 +14,6 @@ */ class ValidTypeNameSniff extends AbstractGraphQLSniff { - /** * @inheritDoc */ diff --git a/Magento2/Tests/GraphQL/AbstractGraphQLSniffUnitTestCase.php b/Magento2/Tests/GraphQL/AbstractGraphQLSniffUnitTestCase.php index 83f858b0..f767a25f 100644 --- a/Magento2/Tests/GraphQL/AbstractGraphQLSniffUnitTestCase.php +++ b/Magento2/Tests/GraphQL/AbstractGraphQLSniffUnitTestCase.php @@ -13,7 +13,6 @@ */ abstract class AbstractGraphQLSniffUnitTestCase extends AbstractSniffUnitTest { - protected function setUp() { //let parent do its job @@ -31,5 +30,4 @@ protected function setUp() //and write back to a global that is used in base class $GLOBALS['PHP_CODESNIFFER_CONFIG'] = $config; } - } diff --git a/Magento2/Tests/GraphQL/ValidArgumentNameUnitTest.php b/Magento2/Tests/GraphQL/ValidArgumentNameUnitTest.php index 746c867e..9c9cfa1d 100644 --- a/Magento2/Tests/GraphQL/ValidArgumentNameUnitTest.php +++ b/Magento2/Tests/GraphQL/ValidArgumentNameUnitTest.php @@ -10,7 +10,6 @@ */ class ValidArgumentNameUnitTest extends AbstractGraphQLSniffUnitTestCase { - /** * @inheritDoc */ diff --git a/Magento2/Tests/GraphQL/ValidFieldNameUnitTest.php b/Magento2/Tests/GraphQL/ValidFieldNameUnitTest.php index 3ded35bb..6e55e399 100644 --- a/Magento2/Tests/GraphQL/ValidFieldNameUnitTest.php +++ b/Magento2/Tests/GraphQL/ValidFieldNameUnitTest.php @@ -10,7 +10,6 @@ */ class ValidFieldNameUnitTest extends AbstractGraphQLSniffUnitTestCase { - /** * @inheritDoc */ diff --git a/Magento2/Tests/GraphQL/ValidTopLevelFieldNameUnitTest.php b/Magento2/Tests/GraphQL/ValidTopLevelFieldNameUnitTest.php index 759e9e18..be37ddd2 100644 --- a/Magento2/Tests/GraphQL/ValidTopLevelFieldNameUnitTest.php +++ b/Magento2/Tests/GraphQL/ValidTopLevelFieldNameUnitTest.php @@ -10,7 +10,6 @@ */ class ValidTopLevelFieldNameUnitTest extends AbstractGraphQLSniffUnitTestCase { - /** * @inheritDoc */ @@ -35,5 +34,4 @@ protected function getWarningList() { return []; } - } diff --git a/Magento2/Tests/GraphQL/ValidTypeNameUnitTest.php b/Magento2/Tests/GraphQL/ValidTypeNameUnitTest.php index a04fb314..035934e0 100644 --- a/Magento2/Tests/GraphQL/ValidTypeNameUnitTest.php +++ b/Magento2/Tests/GraphQL/ValidTypeNameUnitTest.php @@ -54,4 +54,3 @@ protected function getWarningList() return []; } } - From e310c5c80eed552966ba677a41d945ecbd7e021c Mon Sep 17 00:00:00 2001 From: Jean-Bernard Valentaten Date: Wed, 11 Sep 2019 14:25:05 +0200 Subject: [PATCH 014/630] MC-19366: Fixes code style issue --- Magento2/Tests/GraphQL/ValidArgumentNameUnitTest.php | 1 - 1 file changed, 1 deletion(-) diff --git a/Magento2/Tests/GraphQL/ValidArgumentNameUnitTest.php b/Magento2/Tests/GraphQL/ValidArgumentNameUnitTest.php index 9c9cfa1d..091a017d 100644 --- a/Magento2/Tests/GraphQL/ValidArgumentNameUnitTest.php +++ b/Magento2/Tests/GraphQL/ValidArgumentNameUnitTest.php @@ -35,4 +35,3 @@ protected function getWarningList() return []; } } - From 740410bb46a45405b065e8f63ff5d8feed9f4756 Mon Sep 17 00:00:00 2001 From: konarshankar07 Date: Wed, 11 Sep 2019 23:03:19 +0530 Subject: [PATCH 015/630] Fixed false positive finding --- .../ClassPropertyPHPDocFormattingSniff.php | 46 +++++++++++++------ .../Sniffs/Exceptions/DirectThrowSniff.php | 1 + Magento2/Sniffs/Security/SuperglobalSniff.php | 4 +- 3 files changed, 35 insertions(+), 16 deletions(-) diff --git a/Magento2/Sniffs/Commenting/ClassPropertyPHPDocFormattingSniff.php b/Magento2/Sniffs/Commenting/ClassPropertyPHPDocFormattingSniff.php index 3a08852d..a9765278 100644 --- a/Magento2/Sniffs/Commenting/ClassPropertyPHPDocFormattingSniff.php +++ b/Magento2/Sniffs/Commenting/ClassPropertyPHPDocFormattingSniff.php @@ -2,11 +2,17 @@ namespace Magento2\Sniffs\Commenting; use PHP_CodeSniffer\Files\File; -use PHP_CodeSniffer\Sniffs\Sniff; +use PHP_CodeSniffer\Sniffs\AbstractVariableSniff; -class ClassPropertyPHPDocFormattingSniff implements Sniff +/** + * Class ClassPropertyPHPDocFormattingSniff + */ +class ClassPropertyPHPDocFormattingSniff extends AbstractVariableSniff { + /** + * @var array + */ private $ignoreTokens = [ T_PUBLIC, T_PRIVATE, @@ -17,19 +23,11 @@ class ClassPropertyPHPDocFormattingSniff implements Sniff ]; /** - * @inheritDoc + * @param File $phpcsFile + * @param int $stackPtr + * @return int|void */ - public function register() - { - return [ - T_VARIABLE - ]; - } - - /** - * @inheritDoc - */ - public function process(File $phpcsFile, $stackPtr) + public function processMemberVar(File $phpcsFile, $stackPtr) { $tokens = $phpcsFile->getTokens(); @@ -69,4 +67,24 @@ public function process(File $phpcsFile, $stackPtr) return; } } + + /** + * @param File $phpcsFile + * @param int $stackPtr + * @return int|void + * phpcs:disable Magento2.CodeAnalysis.EmptyBlock + */ + protected function processVariable(File $phpcsFile, $stackPtr) + { + } + + /** + * @param File $phpcsFile + * @param int $stackPtr + * @return int|void + * phpcs:disable Magento2.CodeAnalysis.EmptyBlock + */ + protected function processVariableInString(File $phpcsFile, $stackPtr) + { + } } diff --git a/Magento2/Sniffs/Exceptions/DirectThrowSniff.php b/Magento2/Sniffs/Exceptions/DirectThrowSniff.php index 9612d84c..b50ce5d1 100644 --- a/Magento2/Sniffs/Exceptions/DirectThrowSniff.php +++ b/Magento2/Sniffs/Exceptions/DirectThrowSniff.php @@ -16,6 +16,7 @@ class DirectThrowSniff implements Sniff /** * String representation of warning. * phpcs:disable Generic.Files.LineLength.TooLong + * @var string */ protected $warningMessage = 'Direct throw of generic Exception is discouraged. Use context specific instead.'; //phpcs:enable diff --git a/Magento2/Sniffs/Security/SuperglobalSniff.php b/Magento2/Sniffs/Security/SuperglobalSniff.php index 466c1cba..c9f58300 100644 --- a/Magento2/Sniffs/Security/SuperglobalSniff.php +++ b/Magento2/Sniffs/Security/SuperglobalSniff.php @@ -42,7 +42,7 @@ class SuperglobalSniff implements Sniff protected $errorCode = 'SuperglobalUsageError'; /** - * @inheritdoc + * @var array */ protected $superGlobalErrors = [ '$GLOBALS', @@ -55,7 +55,7 @@ class SuperglobalSniff implements Sniff ]; /** - * @inheritdoc + * @var array */ protected $superGlobalWarning = [ '$_COOKIE', //sometimes need to get list of all cookies array and there are no methods to do that in M2 From 2a8d52183bb612c3e4b520fb9b6d8a664932d9a9 Mon Sep 17 00:00:00 2001 From: Jean-Bernard Valentaten Date: Thu, 12 Sep 2019 08:59:40 +0200 Subject: [PATCH 016/630] MC-19366: Deactivates field name validation --- Magento2/ruleset.xml | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Magento2/ruleset.xml b/Magento2/ruleset.xml index d31750fe..9c524658 100644 --- a/Magento2/ruleset.xml +++ b/Magento2/ruleset.xml @@ -526,10 +526,11 @@ 6 warning - - 6 - warning - + + + + + 6 warning From 505c9b25c8e974a8f430992aba3f9a8adcc6958d Mon Sep 17 00:00:00 2001 From: Jean-Bernard Valentaten Date: Thu, 12 Sep 2019 11:33:18 +0200 Subject: [PATCH 017/630] MC-19366: Adds sniff for valid enum values --- .../Sniffs/GraphQL/AbstractGraphQLSniff.php | 32 ++++- .../Sniffs/GraphQL/ValidArgumentNameSniff.php | 16 +-- .../Sniffs/GraphQL/ValidEnumValueSniff.php | 134 ++++++++++++++++++ .../GraphQL/ValidEnumValueUnitTest.graphqls | 19 +++ .../Tests/GraphQL/ValidEnumValueUnitTest.php | 34 +++++ 5 files changed, 220 insertions(+), 15 deletions(-) create mode 100644 Magento2/Sniffs/GraphQL/ValidEnumValueSniff.php create mode 100644 Magento2/Tests/GraphQL/ValidEnumValueUnitTest.graphqls create mode 100644 Magento2/Tests/GraphQL/ValidEnumValueUnitTest.php diff --git a/Magento2/Sniffs/GraphQL/AbstractGraphQLSniff.php b/Magento2/Sniffs/GraphQL/AbstractGraphQLSniff.php index b03cffe8..b9e95fae 100644 --- a/Magento2/Sniffs/GraphQL/AbstractGraphQLSniff.php +++ b/Magento2/Sniffs/GraphQL/AbstractGraphQLSniff.php @@ -10,6 +10,7 @@ * * To obtain a valid license for using this software please contact us at license@techdivision.com */ + namespace Magento2\Sniffs\GraphQL; use PHP_CodeSniffer\Sniffs\Sniff; @@ -38,13 +39,38 @@ protected function isCamelCase($name) } /** - * Returns whether $name is strictly lower case, potentially separated by underscores. + * Returns whether $name is specified in snake case (either all lower case or all upper case). * * @param string $name + * @param bool $upperCase If set to true checks for all upper case, otherwise all lower case * @return bool */ - protected function isSnakeCase($name) + protected function isSnakeCase($name, $upperCase = false) { - return preg_match('/^[a-z][a-z0-9_]*$/', $name); + $pattern = $upperCase ? '/^[A-Z][A-Z0-9_]*$/' : '/^[a-z][a-z0-9_]*$/'; + return preg_match($pattern, $name); + } + + /** + * Searches for the first token that has $tokenCode in $tokens from position + * $startPointer (excluded). + * + * @param mixed $tokenCode + * @param array $tokens + * @param int $startPointer + * @return bool|int If token was found, returns its pointer, false otherwise + */ + protected function seekToken($tokenCode, array $tokens, $startPointer = 0) + { + $numTokens = count($tokens); + + for ($i = $startPointer + 1; $i < $numTokens; ++$i) { + if ($tokens[$i]['code'] === $tokenCode) { + return $i; + } + } + + //if we came here we could not find the requested token + return false; } } diff --git a/Magento2/Sniffs/GraphQL/ValidArgumentNameSniff.php b/Magento2/Sniffs/GraphQL/ValidArgumentNameSniff.php index ffb1f8d4..03de433f 100644 --- a/Magento2/Sniffs/GraphQL/ValidArgumentNameSniff.php +++ b/Magento2/Sniffs/GraphQL/ValidArgumentNameSniff.php @@ -3,6 +3,7 @@ * Copyright © Magento. All rights reserved. * See COPYING.txt for license details. */ + namespace Magento2\Sniffs\GraphQL; use PHP_CodeSniffer\Files\File; @@ -64,7 +65,7 @@ public function process(File $phpcsFile, $stackPtr) } /** - * Finds all argument names contained in $tokens range $startPointer and + * Finds all argument names contained in $tokens in range $startPointer to * $endPointer. * * @param int $startPointer @@ -80,7 +81,7 @@ private function getArguments($startPointer, $endPointer, array $tokens) $skipTypes = [T_COMMENT, T_WHITESPACE]; for ($i = $startPointer + 1; $i < $endPointer; ++$i) { - //skip comment tokens + //skip some tokens if (in_array($tokens[$i]['code'], $skipTypes)) { continue; } @@ -110,15 +111,6 @@ private function getArguments($startPointer, $endPointer, array $tokens) */ private function getCloseParenthesisPointer($stackPointer, array $tokens) { - $numTokens = count($tokens); - - for ($i = $stackPointer + 1; $i < $numTokens; ++$i) { - if ($tokens[$i]['code'] === T_CLOSE_PARENTHESIS) { - return $i; - } - } - - //if we came here we could not find the closing parenthesis - return false; + return $this->seekToken(T_CLOSE_PARENTHESIS, $tokens, $stackPointer); } } diff --git a/Magento2/Sniffs/GraphQL/ValidEnumValueSniff.php b/Magento2/Sniffs/GraphQL/ValidEnumValueSniff.php new file mode 100644 index 00000000..b7c702c7 --- /dev/null +++ b/Magento2/Sniffs/GraphQL/ValidEnumValueSniff.php @@ -0,0 +1,134 @@ +SCREAMING_SNAKE_CASE. + */ +class ValidEnumValueSniff extends AbstractGraphQLSniff +{ + + /** + * @inheritDoc + */ + public function register() + { + return [T_CLASS]; + } + + /** + * @inheritDoc + */ + public function process(File $phpcsFile, $stackPtr) + { + $tokens = $phpcsFile->getTokens(); + + //bail out if we're not inspecting an enum + if ($tokens[$stackPtr]['content'] !== 'enum') { + return; + } + + $openingCurlyPointer = $this->getOpeningCurlyBracketPointer($stackPtr, $tokens); + $closingCurlyPointer = $this->getClosingCurlyBracketPointer($stackPtr, $tokens); + + //if we could not find the closing curly bracket pointer, we add a warning and terminate + if ($openingCurlyPointer === false || $closingCurlyPointer === false) { + $error = 'Possible parse error: %s missing opening or closing brace'; + $data = [$tokens[$stackPtr]['content']]; + $phpcsFile->addWarning($error, $stackPtr, 'MissingBrace', $data); + return; + } + + $values = $this->getValues($openingCurlyPointer, $closingCurlyPointer, $tokens, $phpcsFile->eolChar); + + foreach ($values as $value) { + $pointer = $value[0]; + $name = $value[1]; + + if (!$this->isSnakeCase($name, true)) { + $type = 'Enum value'; + $error = '%s "%s" is not in SCREAMING_SNAKE_CASE format'; + $data = [ + $type, + $name, + ]; + + $phpcsFile->addError($error, $pointer, 'NotScreamingSnakeCase', $data); + $phpcsFile->recordMetric($pointer, 'SCREAMING_SNAKE_CASE enum value', 'no'); + } else { + $phpcsFile->recordMetric($pointer, 'SCREAMING_SNAKE_CASE enum value', 'yes'); + } + } + + return $closingCurlyPointer; + } + + /** + * Seeks the next available token of type {@link T_CLOSE_CURLY_BRACKET} in $tokens and returns its + * pointer. + * + * @param int $startPointer + * @param array $tokens + * @return bool|int + */ + private function getClosingCurlyBracketPointer($startPointer, array $tokens) + { + return $this->seekToken(T_CLOSE_CURLY_BRACKET, $tokens, $startPointer); + } + + /** + * Seeks the next available token of type {@link T_OPEN_CURLY_BRACKET} in $tokens and returns its + * pointer. + * + * @param $startPointer + * @param array $tokens + * @return bool|int + */ + private function getOpeningCurlyBracketPointer($startPointer, array $tokens) + { + return $this->seekToken(T_OPEN_CURLY_BRACKET, $tokens, $startPointer); + } + + /** + * Finds all enum values contained in $tokens in range $startPointer to + * $endPointer. + * + * @param int $startPointer + * @param int $endPointer + * @param array $tokens + * @param string $eolChar + * @return array[] + */ + private function getValues($startPointer, $endPointer, array $tokens, $eolChar) + { + $valueTokenPointer = null; + $enumValue = ''; + $values = []; + $skipTypes = [T_COMMENT, T_WHITESPACE]; + + for ($i = $startPointer + 1; $i < $endPointer; ++$i) { + //skip some tokens + if (in_array($tokens[$i]['code'], $skipTypes)) { + continue; + } + $enumValue .= $tokens[$i]['content']; + + if ($valueTokenPointer === null) { + $valueTokenPointer = $i; + } + + if (strpos($enumValue, $eolChar) !== false) { + $values[] = [$valueTokenPointer, rtrim($enumValue, $eolChar)]; + $enumValue = ''; + $valueTokenPointer = null; + } + } + + return $values; + } +} diff --git a/Magento2/Tests/GraphQL/ValidEnumValueUnitTest.graphqls b/Magento2/Tests/GraphQL/ValidEnumValueUnitTest.graphqls new file mode 100644 index 00000000..994e75f2 --- /dev/null +++ b/Magento2/Tests/GraphQL/ValidEnumValueUnitTest.graphqls @@ -0,0 +1,19 @@ +enum Foo { + # Valid values + VALID_SCREAMING_SNAKE_CASE_VALUE + VALID_SCREAMING_SNAKE_CASE_VALUE_WITH_1_NUMBER + VALID_SCREAMING_SNAKE_CASE_VALUE_WITH_12345_NUMBERS + VALID_SCREAMING_SNAKE_CASE_VALUE_ENDING_WITH_NUMBER_5 + VALIDUPPERCASEVALUE + + # Invalid values + 1_INVALID_SCREAMING_SNAKE_CASE_VALUE_STARTING_WITH_NUMBER + invalidCamelCaseValue + InvalidCamelCaseCapsValue + invalidlowercasevalue +} + +# Ignored although it triggers a T_CLASS token +type Bar { + some_field: String +} \ No newline at end of file diff --git a/Magento2/Tests/GraphQL/ValidEnumValueUnitTest.php b/Magento2/Tests/GraphQL/ValidEnumValueUnitTest.php new file mode 100644 index 00000000..9d577f68 --- /dev/null +++ b/Magento2/Tests/GraphQL/ValidEnumValueUnitTest.php @@ -0,0 +1,34 @@ + 1, + 11 => 1, + 12 => 1, + 13 => 1, + ]; + } + + /** + * @inheritDoc + */ + protected function getWarningList() + { + return []; + } +} From 19cdbecfce7889dc09d4941f85649bcd42b352b8 Mon Sep 17 00:00:00 2001 From: Jean-Bernard Valentaten Date: Thu, 12 Sep 2019 11:41:02 +0200 Subject: [PATCH 018/630] MC-19366: Activates sniff for enum values --- Magento2/ruleset.xml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Magento2/ruleset.xml b/Magento2/ruleset.xml index 9c524658..8d404b05 100644 --- a/Magento2/ruleset.xml +++ b/Magento2/ruleset.xml @@ -539,6 +539,10 @@ 6 warning + + 6 + warning + From 01eee92d2c72a2433e298a17682d5aa739e7ba50 Mon Sep 17 00:00:00 2001 From: Jean-Bernard Valentaten Date: Thu, 12 Sep 2019 15:14:22 +0200 Subject: [PATCH 019/630] MC-19366: Fixes file doc --- Magento2/Sniffs/GraphQL/AbstractGraphQLSniff.php | 12 ++---------- Magento2/Tests/GraphQL/ValidEnumValueUnitTest.php | 1 - 2 files changed, 2 insertions(+), 11 deletions(-) diff --git a/Magento2/Sniffs/GraphQL/AbstractGraphQLSniff.php b/Magento2/Sniffs/GraphQL/AbstractGraphQLSniff.php index b9e95fae..1012f372 100644 --- a/Magento2/Sniffs/GraphQL/AbstractGraphQLSniff.php +++ b/Magento2/Sniffs/GraphQL/AbstractGraphQLSniff.php @@ -1,16 +1,8 @@ - TechDivision GmbH - * All rights reserved - * - * This product includes proprietary software developed at TechDivision GmbH, Germany - * For more information see https://www.techdivision.com/ - * - * To obtain a valid license for using this software please contact us at license@techdivision.com + * Copyright © Magento. All rights reserved. + * See COPYING.txt for license details. */ - namespace Magento2\Sniffs\GraphQL; use PHP_CodeSniffer\Sniffs\Sniff; diff --git a/Magento2/Tests/GraphQL/ValidEnumValueUnitTest.php b/Magento2/Tests/GraphQL/ValidEnumValueUnitTest.php index 9d577f68..aaa3e55c 100644 --- a/Magento2/Tests/GraphQL/ValidEnumValueUnitTest.php +++ b/Magento2/Tests/GraphQL/ValidEnumValueUnitTest.php @@ -3,7 +3,6 @@ * Copyright © Magento. All rights reserved. * See COPYING.txt for license details. */ - namespace Magento2\Tests\GraphQL; /** From d99c92283aa303d1c4fbb7a6af6853cb4bffc34e Mon Sep 17 00:00:00 2001 From: Jean-Bernard Valentaten Date: Fri, 13 Sep 2019 09:22:25 +0200 Subject: [PATCH 020/630] MC-19366: Fixes that tokenizer for GraphQL files could not be loaded due to PHP_CodeSniffer uppercasing tokenizer names --- Magento2/Sniffs/GraphQL/AbstractGraphQLSniff.php | 2 +- Magento2/Tests/GraphQL/AbstractGraphQLSniffUnitTestCase.php | 2 +- PHP_CodeSniffer/Tokenizers/{GraphQL.php => GRAPHQL.php} | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) rename PHP_CodeSniffer/Tokenizers/{GraphQL.php => GRAPHQL.php} (99%) diff --git a/Magento2/Sniffs/GraphQL/AbstractGraphQLSniff.php b/Magento2/Sniffs/GraphQL/AbstractGraphQLSniff.php index 1012f372..6309df08 100644 --- a/Magento2/Sniffs/GraphQL/AbstractGraphQLSniff.php +++ b/Magento2/Sniffs/GraphQL/AbstractGraphQLSniff.php @@ -17,7 +17,7 @@ abstract class AbstractGraphQLSniff implements Sniff * * @var array */ - public $supportedTokenizers = ['GraphQL']; + public $supportedTokenizers = ['GRAPHQL']; /** * Returns whether $name starts with a lower case character and is written in camel case. diff --git a/Magento2/Tests/GraphQL/AbstractGraphQLSniffUnitTestCase.php b/Magento2/Tests/GraphQL/AbstractGraphQLSniffUnitTestCase.php index f767a25f..19bcd586 100644 --- a/Magento2/Tests/GraphQL/AbstractGraphQLSniffUnitTestCase.php +++ b/Magento2/Tests/GraphQL/AbstractGraphQLSniffUnitTestCase.php @@ -23,7 +23,7 @@ protected function setUp() $config->extensions = array_merge( $config->extensions, [ - 'graphqls' => 'GraphQL' + 'graphqls' => 'GRAPHQL' ] ); diff --git a/PHP_CodeSniffer/Tokenizers/GraphQL.php b/PHP_CodeSniffer/Tokenizers/GRAPHQL.php similarity index 99% rename from PHP_CodeSniffer/Tokenizers/GraphQL.php rename to PHP_CodeSniffer/Tokenizers/GRAPHQL.php index 3d2c30b1..17c30581 100644 --- a/PHP_CodeSniffer/Tokenizers/GraphQL.php +++ b/PHP_CodeSniffer/Tokenizers/GRAPHQL.php @@ -13,7 +13,7 @@ /** * Implements a tokenizer for GraphQL files. */ -class GraphQL extends Tokenizer +class GRAPHQL extends Tokenizer { /** From 49f0b0b09924067373cfc86b2e8a210f546393c6 Mon Sep 17 00:00:00 2001 From: Jean-Bernard Valentaten Date: Fri, 13 Sep 2019 13:38:10 +0200 Subject: [PATCH 021/630] MC-19366: Fixes that agruments with directives would result in erroneous output and that arguments could be treated as fields --- .../Sniffs/GraphQL/ValidArgumentNameSniff.php | 163 +++++++++++++----- .../ValidArgumentNameUnitTest.graphqls | 19 +- .../GraphQL/ValidArgumentNameUnitTest.php | 2 + PHP_CodeSniffer/Tokenizers/GRAPHQL.php | 39 ++--- 4 files changed, 156 insertions(+), 67 deletions(-) diff --git a/Magento2/Sniffs/GraphQL/ValidArgumentNameSniff.php b/Magento2/Sniffs/GraphQL/ValidArgumentNameSniff.php index 03de433f..39cf76df 100644 --- a/Magento2/Sniffs/GraphQL/ValidArgumentNameSniff.php +++ b/Magento2/Sniffs/GraphQL/ValidArgumentNameSniff.php @@ -6,6 +6,8 @@ namespace Magento2\Sniffs\GraphQL; +use GraphQL\Error\SyntaxError; +use GraphQL\Language\AST\DocumentNode; use PHP_CodeSniffer\Files\File; /** @@ -13,12 +15,13 @@ */ class ValidArgumentNameSniff extends AbstractGraphQLSniff { + /** * @inheritDoc */ public function register() { - return [T_OPEN_PARENTHESIS]; + return [T_VARIABLE]; } /** @@ -26,11 +29,17 @@ public function register() */ public function process(File $phpcsFile, $stackPtr) { - $tokens = $phpcsFile->getTokens(); - $closeParenthesisPointer = $this->getCloseParenthesisPointer($stackPtr, $tokens); + $tokens = $phpcsFile->getTokens(); + + //get the pointer to the argument list opener or bail out if none was found since then the field does not have arguments + $openArgumentListPointer = $this->getArgumentListOpenPointer($stackPtr, $tokens); + if ($openArgumentListPointer === false) { + return; + } - //if we could not find the closing parenthesis pointer, we add a warning and terminate - if ($closeParenthesisPointer === false) { + //get the pointer to the argument list closer or add a warning and terminate as we have an unbalanced file + $closeArgumentListPointer = $this->getArgumentListClosePointer($openArgumentListPointer, $tokens); + if ($closeArgumentListPointer === false) { $error = 'Possible parse error: Missing closing parenthesis for argument list in line %d'; $data = [ $tokens[$stackPtr]['line'], @@ -39,18 +48,15 @@ public function process(File $phpcsFile, $stackPtr) return; } - $arguments = $this->getArguments($stackPtr, $closeParenthesisPointer, $tokens); + $arguments = $this->getArguments($openArgumentListPointer, $closeArgumentListPointer, $tokens); - foreach ($arguments as $argument) { - $pointer = $argument[0]; - $name = $argument[1]; - - if (!$this->isCamelCase($name)) { + foreach ($arguments as $pointer => $argument) { + if (!$this->isCamelCase($argument)) { $type = 'Argument'; $error = '%s name "%s" is not in CamelCase format'; $data = [ $type, - $name, + $argument, ]; $phpcsFile->addError($error, $pointer, 'NotCamelCase', $data); @@ -61,56 +67,131 @@ public function process(File $phpcsFile, $stackPtr) } //return stack pointer of closing parenthesis - return $closeParenthesisPointer; + return $closeArgumentListPointer; } /** - * Finds all argument names contained in $tokens in range $startPointer to - * $endPointer. + * Seeks the last token of an argument definition and returns its pointer. * - * @param int $startPointer - * @param int $endPointer + * Arguments are defined as follows: + * + * {ArgumentName}: {ArgumentType}[ = {DefaultValue}][{Directive}]* + * + * + * @param int $argumentDefinitionStartPointer * @param array $tokens - * @return array[] + * @return int */ - private function getArguments($startPointer, $endPointer, array $tokens) + private function getArgumentDefinitionEndPointer($argumentDefinitionStartPointer, array $tokens) { - $argumentTokenPointer = null; - $argument = ''; - $names = []; - $skipTypes = [T_COMMENT, T_WHITESPACE]; + $colonPointer = $this->seekToken(T_COLON, $tokens, $argumentDefinitionStartPointer); - for ($i = $startPointer + 1; $i < $endPointer; ++$i) { - //skip some tokens - if (in_array($tokens[$i]['code'], $skipTypes)) { - continue; - } - $argument .= $tokens[$i]['content']; + //the colon is always followed by a type so we can consume the token after the colon + $endPointer = $colonPointer + 1; - if ($argumentTokenPointer === null) { - $argumentTokenPointer = $i; - } + //if argument has a default value, we advance to the default definition end + if ($tokens[$endPointer + 1]['code'] === T_EQUAL) { + $endPointer += 2; + } + + //while next token starts a directive, we advance to the end of the directive + while ($tokens[$endPointer + 1]['code'] === T_DOC_COMMENT_TAG) { + //consume next two tokens + $endPointer += 2; - if (preg_match('/^.+:.+$/', $argument)) { - list($name, $type) = explode(':', $argument); - $names[] = [$argumentTokenPointer, $name]; - $argument = ''; - $argumentTokenPointer = null; + //if next token is an opening parenthesis, we consume everything up to the closing parenthesis + if ($tokens[$endPointer + 1]['code'] === T_OPEN_PARENTHESIS) { + $endPointer = $tokens[$endPointer + 1]['parenthesis_closer']; } } - return $names; + return $endPointer; + } + + /** + * Returns the closing parenthesis for the token found at $openParenthesisPointer in $tokens. + * + * @param int $openParenthesisPointer + * @param array $tokens + * @return bool|int + */ + private function getArgumentListClosePointer($openParenthesisPointer, array $tokens) + { + $openParenthesisToken = $tokens[$openParenthesisPointer]; + return $openParenthesisToken['parenthesis_closer']; } /** - * Seeks the next available token of type {@link T_CLOSE_PARENTHESIS} in $tokens and returns its pointer. + * Seeks the next available {@link T_OPEN_PARENTHESIS} token that comes directly after $stackPointer. + * token. * * @param int $stackPointer * @param array $tokens * @return bool|int */ - private function getCloseParenthesisPointer($stackPointer, array $tokens) + private function getArgumentListOpenPointer($stackPointer, array $tokens) + { + //get next open parenthesis pointer or bail out if none was found + $openParenthesisPointer = $this->seekToken(T_OPEN_PARENTHESIS, $tokens, $stackPointer); + if ($openParenthesisPointer === false) { + return false; + } + + //bail out if open parenthesis does not directly come after current stack pointer + if ($openParenthesisPointer !== $stackPointer + 1) { + return false; + } + + //we have found the appropriate opening parenthesis + return $openParenthesisPointer; + } + + /** + * Finds all argument names contained in $tokens in range $startPointer to + * $endPointer. + * + * The returned array uses token pointers as keys and argument names as values. + * + * @param int $startPointer + * @param int $endPointer + * @param array $tokens + * @return array + */ + private function getArguments($startPointer, $endPointer, array $tokens) { - return $this->seekToken(T_CLOSE_PARENTHESIS, $tokens, $stackPointer); + $argumentTokenPointer = null; + $argument = ''; + $names = []; + $skipTypes = [T_COMMENT, T_WHITESPACE]; + + for ($i = $startPointer + 1; $i < $endPointer; ++$i) { + $tokenCode = $tokens[$i]['code']; + + switch (true) { + case in_array($tokenCode, $skipTypes): + //NOP This is a toke that we have to skip + break; + case $tokenCode === T_COLON: + //we have reached the end of the argument name, thus we store its pointer and value + $names[$argumentTokenPointer] = $argument; + + //advance to end of argument definition + $i = $this->getArgumentDefinitionEndPointer($argumentTokenPointer, $tokens); + + //and reset temporary variables + $argument = ''; + $argumentTokenPointer = null; + break; + default: + //this seems to be part of the argument name + $argument .= $tokens[$i]['content']; + + if ($argumentTokenPointer === null) { + $argumentTokenPointer = $i; + } + } + } + + return $names; } } diff --git a/Magento2/Tests/GraphQL/ValidArgumentNameUnitTest.graphqls b/Magento2/Tests/GraphQL/ValidArgumentNameUnitTest.graphqls index 83b4f23c..5fa3c277 100644 --- a/Magento2/Tests/GraphQL/ValidArgumentNameUnitTest.graphqls +++ b/Magento2/Tests/GraphQL/ValidArgumentNameUnitTest.graphqls @@ -29,4 +29,21 @@ interface Foo { invalid_argument_name_snake_case: Int 5invalidArgumentNameStatingWithNumber: Int ): String -} \ No newline at end of file +} + +# +# Make sure that directives on arguments do not lead to false positives +# +type Foo @doc(descripton: "Foo Bar Baz") { + myfield ( + # Valid arguments + validArgument: String = "My fair lady" @doc( + # A comment + description: "This is a valid argument, spanned over multiple lines." + ) @foo + varlidArgumentWithDefaultValue: Int = 20 @doc(description: "This is another valid argument with a default value.") + # Invalid argument + invalid_argument: String @doc(description: "This is an invalid argument."), + invalid_argument_with_default_value: Int = 20 @doc(description: "This is another invalid argument with a default value") + ): String @doc(description: "Foo Bar") +} diff --git a/Magento2/Tests/GraphQL/ValidArgumentNameUnitTest.php b/Magento2/Tests/GraphQL/ValidArgumentNameUnitTest.php index 091a017d..8ed55cfa 100644 --- a/Magento2/Tests/GraphQL/ValidArgumentNameUnitTest.php +++ b/Magento2/Tests/GraphQL/ValidArgumentNameUnitTest.php @@ -24,6 +24,8 @@ protected function getErrorList() 28 => 1, 29 => 1, 30 => 1, + 46 => 1, + 47 => 1, ]; } diff --git a/PHP_CodeSniffer/Tokenizers/GRAPHQL.php b/PHP_CodeSniffer/Tokenizers/GRAPHQL.php index 17c30581..01345fc3 100644 --- a/PHP_CodeSniffer/Tokenizers/GRAPHQL.php +++ b/PHP_CodeSniffer/Tokenizers/GRAPHQL.php @@ -7,6 +7,7 @@ namespace PHP_CodeSniffer\Tokenizers; use GraphQL\Language\Lexer; +use GraphQL\Language\Parser; use GraphQL\Language\Source; use GraphQL\Language\Token; @@ -81,11 +82,10 @@ protected function tokenize($string) { $this->logVerbose('*** START GRAPHQL TOKENIZING ***'); - $string = str_replace($this->eolChar, "\n", $string); - $tokens = []; - $lexer = new Lexer( - new Source($string) - ); + $string = str_replace($this->eolChar, "\n", $string); + $tokens = []; + $source = new Source($string); + $lexer = new Lexer($source); do { $kind = $lexer->token->kind; @@ -178,19 +178,17 @@ private function getNewLineTokens($lineStart, $lineEnd) */ private function isFieldToken($stackPointer) { + //bail out if current token is nested in a parenthesis, since fields cannot be contained in parenthesises + if (isset($this->tokens[$stackPointer]['nested_parenthesis'])) { + return false; + } + $nextToken = $this->tokens[$stackPointer + 1]; - //if next token is an opening parenthesis, we seek for the closing parenthesis + //if next token is an opening parenthesis, we advance to the token after the closing parenthesis if ($nextToken['code'] === T_OPEN_PARENTHESIS) { - $nextPointer = $stackPointer + 1; - $numTokens = count($this->tokens); - - for ($i = $nextPointer; $i < $numTokens; ++$i) { - if ($this->tokens[$i]['code'] === T_CLOSE_PARENTHESIS) { - $nextToken = $this->tokens[$i + 1]; - break; - } - } + $nextPointer = $nextToken['parenthesis_closer'] + 1; + $nextToken = $this->tokens[$nextPointer]; } //return whether current token is a string and next token is a colon @@ -215,7 +213,6 @@ private function logVerbose($message, $level = 1) */ private function processFields() { - $processingArgumentList = false; $processingEntity = false; $numTokens = count($this->tokens); $entityTypes = [T_CLASS, T_INTERFACE]; @@ -237,15 +234,7 @@ private function processFields() //we have hit the end of an entity declaration $processingEntity = false; break; - case $tokenCode === T_OPEN_PARENTHESIS: - //we have hit an argument list - $processingArgumentList = true; - break; - case $tokenCode === T_CLOSE_PARENTHESIS: - //we have hit an argument list end - $processingArgumentList = false; - break; - case $processingEntity && !$processingArgumentList && $this->isFieldToken($i): + case $processingEntity && $this->isFieldToken($i): //we have hit a field $this->tokens[$i]['code'] = T_VARIABLE; $this->tokens[$i]['type'] = 'T_VARIABLE'; From 0b8eeaad4c41b40a5997ab7e0bf8b77b5248d8d4 Mon Sep 17 00:00:00 2001 From: Jean-Bernard Valentaten Date: Fri, 13 Sep 2019 13:50:41 +0200 Subject: [PATCH 022/630] MC-19366: Fixes that field name validation was executed although it should not --- Magento2/ruleset.xml | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/Magento2/ruleset.xml b/Magento2/ruleset.xml index 8d404b05..60186f30 100644 --- a/Magento2/ruleset.xml +++ b/Magento2/ruleset.xml @@ -526,11 +526,15 @@ 6 warning - - - - - + + + + 6 + warning + 6 warning From 571b642071ff71fe5f49f0660939b2b86c20a20d Mon Sep 17 00:00:00 2001 From: Jean-Bernard Valentaten Date: Fri, 13 Sep 2019 14:06:47 +0200 Subject: [PATCH 023/630] MC-19366: Fixes that field and argument names were marked as entities in case their name was a keyword --- PHP_CodeSniffer/Tokenizers/GRAPHQL.php | 53 +++++++++++++++++++++----- 1 file changed, 44 insertions(+), 9 deletions(-) diff --git a/PHP_CodeSniffer/Tokenizers/GRAPHQL.php b/PHP_CodeSniffer/Tokenizers/GRAPHQL.php index 01345fc3..b9056414 100644 --- a/PHP_CodeSniffer/Tokenizers/GRAPHQL.php +++ b/PHP_CodeSniffer/Tokenizers/GRAPHQL.php @@ -7,7 +7,6 @@ namespace PHP_CodeSniffer\Tokenizers; use GraphQL\Language\Lexer; -use GraphQL\Language\Parser; use GraphQL\Language\Source; use GraphQL\Language\Token; @@ -70,6 +69,7 @@ public function processAdditional() { $this->logVerbose('*** START ADDITIONAL GRAPHQL PROCESSING ***'); + $this->fixErroneousKeywordTokens(); $this->processFields(); $this->logVerbose('*** END ADDITIONAL GRAPHQL PROCESSING ***'); @@ -82,10 +82,10 @@ protected function tokenize($string) { $this->logVerbose('*** START GRAPHQL TOKENIZING ***'); - $string = str_replace($this->eolChar, "\n", $string); - $tokens = []; - $source = new Source($string); - $lexer = new Lexer($source); + $string = str_replace($this->eolChar, "\n", $string); + $tokens = []; + $source = new Source($string); + $lexer = new Lexer($source); do { $kind = $lexer->token->kind; @@ -141,6 +141,41 @@ protected function tokenize($string) return $tokens; } + /** + * Fixes that keywords may be used as field, argument etc. names and could thus have been marked as special tokens + * while tokenizing. + */ + private function fixErroneousKeywordTokens() + { + $processingCodeBlock = false; + $numTokens = count($this->tokens); + + for ($i = 0; $i < $numTokens; ++$i) { + $tokenCode = $this->tokens[$i]['code']; + $tokenContent = $this->tokens[$i]['content']; + + switch (true) { + case $tokenCode === T_OPEN_CURLY_BRACKET: + //we have hit the beginning of a code block + $processingCodeBlock = true; + break; + case $tokenCode === T_CLOSE_CURLY_BRACKET: + //we have hit the end of a code block + $processingCodeBlock = false; + break; + case $processingCodeBlock + && $tokenCode !== T_STRING + && isset($this->keywordTokenTypeMap[$tokenContent]): + //we have hit a keyword within a code block that is of wrong token type + $this->tokens[$i]['code'] = T_STRING; + $this->tokens[$i]['type'] = 'T_STRING'; + break; + default: + //NOP All operations have already been executed + } + } + } + /** * Returns tokens of empty new lines for the range $lineStart to $lineEnd * @@ -213,10 +248,10 @@ private function logVerbose($message, $level = 1) */ private function processFields() { - $processingEntity = false; - $numTokens = count($this->tokens); - $entityTypes = [T_CLASS, T_INTERFACE]; - $skipTypes = [T_COMMENT, T_WHITESPACE]; + $processingEntity = false; + $numTokens = count($this->tokens); + $entityTypes = [T_CLASS, T_INTERFACE]; + $skipTypes = [T_COMMENT, T_WHITESPACE]; for ($i = 0; $i < $numTokens; ++$i) { $tokenCode = $this->tokens[$i]['code']; From c57400364834333181731376a51bfe9951ee73cc Mon Sep 17 00:00:00 2001 From: Jean-Bernard Valentaten Date: Fri, 13 Sep 2019 14:19:44 +0200 Subject: [PATCH 024/630] MC-19366: Fixes code style issue --- Magento2/Sniffs/GraphQL/ValidArgumentNameSniff.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Magento2/Sniffs/GraphQL/ValidArgumentNameSniff.php b/Magento2/Sniffs/GraphQL/ValidArgumentNameSniff.php index 39cf76df..337bf9ff 100644 --- a/Magento2/Sniffs/GraphQL/ValidArgumentNameSniff.php +++ b/Magento2/Sniffs/GraphQL/ValidArgumentNameSniff.php @@ -31,7 +31,8 @@ public function process(File $phpcsFile, $stackPtr) { $tokens = $phpcsFile->getTokens(); - //get the pointer to the argument list opener or bail out if none was found since then the field does not have arguments + //get the pointer to the argument list opener or bail out if none was found + //since then the field does not have arguments $openArgumentListPointer = $this->getArgumentListOpenPointer($stackPtr, $tokens); if ($openArgumentListPointer === false) { return; From 97cc6618592380361685a7da507cdfcad6dc4c7c Mon Sep 17 00:00:00 2001 From: Shankar Konar Date: Sun, 15 Sep 2019 13:17:17 +0530 Subject: [PATCH 025/630] added correct formatted examples --- .../ClassPropertyPHPDocFormattingSniff.php | 2 +- .../ClassPropertyPHPDocFormattingUnitTest.inc | 28 +++++++++++++++++-- .../ClassPropertyPHPDocFormattingUnitTest.php | 2 +- 3 files changed, 28 insertions(+), 4 deletions(-) diff --git a/Magento2/Sniffs/Commenting/ClassPropertyPHPDocFormattingSniff.php b/Magento2/Sniffs/Commenting/ClassPropertyPHPDocFormattingSniff.php index a9765278..a057e5b0 100644 --- a/Magento2/Sniffs/Commenting/ClassPropertyPHPDocFormattingSniff.php +++ b/Magento2/Sniffs/Commenting/ClassPropertyPHPDocFormattingSniff.php @@ -56,7 +56,7 @@ public function processMemberVar(File $phpcsFile, $stackPtr) if ($foundVar === null) { $error = 'Missing @var tag in class property comment'; - $phpcsFile->addWarning($error, $commentEnd, 'MissingVar'); + $phpcsFile->addWarning($error, $stackPtr, 'MissingVar'); return; } diff --git a/Magento2/Tests/Commenting/ClassPropertyPHPDocFormattingUnitTest.inc b/Magento2/Tests/Commenting/ClassPropertyPHPDocFormattingUnitTest.inc index 2abc3e8f..dc40d74c 100644 --- a/Magento2/Tests/Commenting/ClassPropertyPHPDocFormattingUnitTest.inc +++ b/Magento2/Tests/Commenting/ClassPropertyPHPDocFormattingUnitTest.inc @@ -10,14 +10,14 @@ class Foo /** * Foo */ - private $_withoutClassAttribute = ''; + public $_withoutClassAttribute = ''; /** * @var Test * * Short Description */ - private $_classAttributeWithShortDescription = ''; + protected $_classAttributeWithShortDescription = ''; /** * @var @@ -33,3 +33,27 @@ class Foo private $_missingDocBlockClassAttribute = ''; } + +class Bar { + + /** + * @var correctlyFormattedPublicClassMember + * + * Short Description + */ + public $correctlyFormattedPublicClassMember; + + /** + * @var correctlyFormattedPrivateClassMember + * + * Short Description + */ + private $correctlyFormattedPrivateClassMember; + + /** + * @var correctlyFormattedProtectedClassMember + * + * Short Description + */ + protected $correctlyFormattedProtectedClassMember; +} diff --git a/Magento2/Tests/Commenting/ClassPropertyPHPDocFormattingUnitTest.php b/Magento2/Tests/Commenting/ClassPropertyPHPDocFormattingUnitTest.php index 6672d3f0..675eef4f 100644 --- a/Magento2/Tests/Commenting/ClassPropertyPHPDocFormattingUnitTest.php +++ b/Magento2/Tests/Commenting/ClassPropertyPHPDocFormattingUnitTest.php @@ -23,7 +23,7 @@ public function getErrorList() public function getWarningList() { return [ - 12 => 1, + 13 => 1, 23 => 1, 30 => 1, 34 => 1 From 43ef0a4b8d14197f8ec34cc97161a45a6d71b45a Mon Sep 17 00:00:00 2001 From: Jean-Bernard Valentaten Date: Mon, 16 Sep 2019 09:07:19 +0200 Subject: [PATCH 026/630] MC-19366: Removes obsolete TODOs --- PHP_CodeSniffer/Tokenizers/GRAPHQL.php | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/PHP_CodeSniffer/Tokenizers/GRAPHQL.php b/PHP_CodeSniffer/Tokenizers/GRAPHQL.php index b9056414..9de922df 100644 --- a/PHP_CodeSniffer/Tokenizers/GRAPHQL.php +++ b/PHP_CodeSniffer/Tokenizers/GRAPHQL.php @@ -19,11 +19,15 @@ class GRAPHQL extends Tokenizer /** * Defines how GraphQL token types are mapped to PHP token types. * + * This is a complete list of all token types supported by webonyx/graphql-php. null values + * are automatically mapped to T_STRING but are noted as null in this list to improve + * maintenance at a glance. + * * @var array */ private $tokenTypeMap = [ Token::AT => 'T_DOC_COMMENT_TAG', - Token::BANG => null, //TODO Should we map this to a specific type + Token::BANG => null, Token::BLOCK_STRING => 'T_COMMENT', Token::BRACE_L => 'T_OPEN_CURLY_BRACKET', Token::BRACE_R => 'T_CLOSE_CURLY_BRACKET', @@ -34,12 +38,12 @@ class GRAPHQL extends Tokenizer Token::DOLLAR => 'T_DOLLAR', Token::EOF => 'T_CLOSE_TAG', Token::EQUALS => 'T_EQUAL', - Token::FLOAT => null, //TODO Should we map this to a specific type - Token::INT => null, //TODO Should we map this to a specific type + Token::FLOAT => null, + Token::INT => null, Token::NAME => 'T_STRING', Token::PAREN_L => 'T_OPEN_PARENTHESIS', Token::PAREN_R => 'T_CLOSE_PARENTHESIS', - Token::PIPE => null, //TODO Should we map this to a specific type + Token::PIPE => null, Token::SPREAD => 'T_ELLIPSIS', Token::SOF => 'T_OPEN_TAG', Token::STRING => 'T_STRING', @@ -52,14 +56,13 @@ class GRAPHQL extends Tokenizer */ private $keywordTokenTypeMap = [ 'enum' => 'T_CLASS', - 'extend' => 'T_EXTENDS', //TODO This might not be the appropriate equivalent + 'extend' => 'T_EXTENDS', 'interface' => 'T_INTERFACE', 'implements' => 'T_IMPLEMENTS', 'type' => 'T_CLASS', 'union' => 'T_CLASS', 'query' => 'T_FUNCTION', 'mutation' => 'T_FUNCTION', - //TODO We may have to add further types ]; /** From c539ed44c3b93284d9bc24e5e58c0271cbaa1d40 Mon Sep 17 00:00:00 2001 From: Jean-Bernard Valentaten Date: Tue, 17 Sep 2019 09:37:32 +0200 Subject: [PATCH 027/630] MC-19366: Fixes order of rules and silences GraphQL field name validation --- Magento2/ruleset.xml | 49 ++++++++++++++++++++++---------------------- 1 file changed, 24 insertions(+), 25 deletions(-) diff --git a/Magento2/ruleset.xml b/Magento2/ruleset.xml index 60186f30..9d65e166 100644 --- a/Magento2/ruleset.xml +++ b/Magento2/ruleset.xml @@ -364,6 +364,30 @@ 6 warning + + 6 + warning + + + 6 + warning + + + + 0 + warning + + + 6 + warning + + + 6 + warning + 6 warning @@ -522,31 +546,6 @@ 0 - - 6 - warning - - - - - 6 - warning - - - 6 - warning - - - 6 - warning - - - 6 - warning - From af9c04119912bb96ccd5e067c97772d7169f53b1 Mon Sep 17 00:00:00 2001 From: Jean-Bernard Valentaten Date: Tue, 17 Sep 2019 10:28:30 +0200 Subject: [PATCH 028/630] MC-19366: Fixes that list type and non null arguments would not be parsed as expected and would thus lead to false positives --- .../Sniffs/GraphQL/ValidArgumentNameSniff.php | 17 ++++++++++++++--- .../GraphQL/ValidArgumentNameUnitTest.graphqls | 12 +++++++++++- .../Tests/GraphQL/ValidArgumentNameUnitTest.php | 9 +++++++-- PHP_CodeSniffer/Tokenizers/GRAPHQL.php | 7 +++++-- 4 files changed, 37 insertions(+), 8 deletions(-) diff --git a/Magento2/Sniffs/GraphQL/ValidArgumentNameSniff.php b/Magento2/Sniffs/GraphQL/ValidArgumentNameSniff.php index 337bf9ff..7741b675 100644 --- a/Magento2/Sniffs/GraphQL/ValidArgumentNameSniff.php +++ b/Magento2/Sniffs/GraphQL/ValidArgumentNameSniff.php @@ -85,10 +85,21 @@ public function process(File $phpcsFile, $stackPtr) */ private function getArgumentDefinitionEndPointer($argumentDefinitionStartPointer, array $tokens) { - $colonPointer = $this->seekToken(T_COLON, $tokens, $argumentDefinitionStartPointer); + $endPointer = $this->seekToken(T_COLON, $tokens, $argumentDefinitionStartPointer); + + //the colon is always followed by the type, which we can consume. it could be a list type though, thus we check + if ($tokens[$endPointer + 1]['code'] === T_OPEN_SQUARE_BRACKET) { + //consume everything up to closing bracket + $endPointer = $tokens[$endPointer + 1]['bracket_closer']; + } else { + //consume everything up to type + ++$endPointer; + } - //the colon is always followed by a type so we can consume the token after the colon - $endPointer = $colonPointer + 1; + //the type may be non null, meaning that it is followed by an exclamation mark, which we consume + if ($tokens[$endPointer + 1]['code'] === T_BOOLEAN_NOT) { + ++$endPointer; + } //if argument has a default value, we advance to the default definition end if ($tokens[$endPointer + 1]['code'] === T_EQUAL) { diff --git a/Magento2/Tests/GraphQL/ValidArgumentNameUnitTest.graphqls b/Magento2/Tests/GraphQL/ValidArgumentNameUnitTest.graphqls index 5fa3c277..8c1e12c0 100644 --- a/Magento2/Tests/GraphQL/ValidArgumentNameUnitTest.graphqls +++ b/Magento2/Tests/GraphQL/ValidArgumentNameUnitTest.graphqls @@ -41,9 +41,19 @@ type Foo @doc(descripton: "Foo Bar Baz") { # A comment description: "This is a valid argument, spanned over multiple lines." ) @foo - varlidArgumentWithDefaultValue: Int = 20 @doc(description: "This is another valid argument with a default value.") + validArgumentWithDefaultValue: Int = 20 @doc(description: "This is another valid argument with a default value.") + validArgumentListType: [String] @doc(description: "This is a valid argument that uses a list type.") + validArgumentNonNullType: String! @doc(description: "This is a valid argument that uses a non null type.") + validArgumentNonNullListType: [String]! @doc(description: "This is a valid argument that uses a non null type.") + validArgumentNonNullTypeInListType: [String!] @doc(description: "This is a valid argument that uses a non null type within a list.") + validArgumentNonNullTypeInNonNullListType: [String!]! @doc(description: "This is a valid argument that uses a non null type within a non null list type.") # Invalid argument invalid_argument: String @doc(description: "This is an invalid argument."), invalid_argument_with_default_value: Int = 20 @doc(description: "This is another invalid argument with a default value") + invalid_argument_list_type: [String] @doc(description: "This is an invalid argument that uses a list type.") + invalid_argument_non_null_type: String! @doc(description: "This is an invalid argument that uses a non null type.") + invalid_argument_non_null_list_type: [String]! @doc(description: "This is an invalid argument that uses a non null type.") + invalid_argument_non_null_type_in_list_type: [String!] @doc(description: "This is an invalid argument that uses a non null type within a list.") + invalid_argument_non_null_type_in_non_null_list_type: [String!]! @doc(description: "This is a valid argument that uses a non null type within a non null list type.") ): String @doc(description: "Foo Bar") } diff --git a/Magento2/Tests/GraphQL/ValidArgumentNameUnitTest.php b/Magento2/Tests/GraphQL/ValidArgumentNameUnitTest.php index 8ed55cfa..c0f41e5b 100644 --- a/Magento2/Tests/GraphQL/ValidArgumentNameUnitTest.php +++ b/Magento2/Tests/GraphQL/ValidArgumentNameUnitTest.php @@ -24,8 +24,13 @@ protected function getErrorList() 28 => 1, 29 => 1, 30 => 1, - 46 => 1, - 47 => 1, + 51 => 1, + 52 => 1, + 53 => 1, + 54 => 1, + 55 => 1, + 56 => 1, + 57 => 1, ]; } diff --git a/PHP_CodeSniffer/Tokenizers/GRAPHQL.php b/PHP_CodeSniffer/Tokenizers/GRAPHQL.php index 9de922df..8dd5fcae 100644 --- a/PHP_CodeSniffer/Tokenizers/GRAPHQL.php +++ b/PHP_CodeSniffer/Tokenizers/GRAPHQL.php @@ -27,12 +27,12 @@ class GRAPHQL extends Tokenizer */ private $tokenTypeMap = [ Token::AT => 'T_DOC_COMMENT_TAG', - Token::BANG => null, + Token::BANG => 'T_BOOLEAN_NOT', Token::BLOCK_STRING => 'T_COMMENT', Token::BRACE_L => 'T_OPEN_CURLY_BRACKET', Token::BRACE_R => 'T_CLOSE_CURLY_BRACKET', Token::BRACKET_L => 'T_OPEN_SQUARE_BRACKET', - Token::BRACKET_R => 'T_CLOSE_CURLY_BRACKET', + Token::BRACKET_R => 'T_CLOSE_SQUARE_BRACKET', Token::COLON => 'T_COLON', Token::COMMENT => 'T_COMMENT', Token::DOLLAR => 'T_DOLLAR', @@ -112,6 +112,9 @@ protected function tokenize($string) case Token::PAREN_L: case Token::PAREN_R: case Token::COLON: + case Token::BRACKET_L: + case Token::BRACKET_R: + case Token::BANG: $value = $kind; break; default: From c4069e0e44e3b16fc75c01df7c131d599ff8f67f Mon Sep 17 00:00:00 2001 From: Jean-Bernard Valentaten Date: Tue, 17 Sep 2019 11:54:43 +0200 Subject: [PATCH 029/630] MC-19366: Fixes that enum values with directives would be parsed as expected and would thus lead to false positives --- .../Sniffs/GraphQL/AbstractGraphQLSniff.php | 24 +++++++++++ .../Sniffs/GraphQL/ValidArgumentNameSniff.php | 10 +---- .../Sniffs/GraphQL/ValidEnumValueSniff.php | 40 ++++++++++++------- .../ValidArgumentNameUnitTest.graphqls | 2 +- .../GraphQL/ValidEnumValueUnitTest.graphqls | 8 ++++ .../Tests/GraphQL/ValidEnumValueUnitTest.php | 10 +++-- 6 files changed, 67 insertions(+), 27 deletions(-) diff --git a/Magento2/Sniffs/GraphQL/AbstractGraphQLSniff.php b/Magento2/Sniffs/GraphQL/AbstractGraphQLSniff.php index 6309df08..d15ff43a 100644 --- a/Magento2/Sniffs/GraphQL/AbstractGraphQLSniff.php +++ b/Magento2/Sniffs/GraphQL/AbstractGraphQLSniff.php @@ -43,6 +43,30 @@ protected function isSnakeCase($name, $upperCase = false) return preg_match($pattern, $name); } + /** + * Returns the pointer to the last token of a directive if the token at $startPointer starts a directive. + * + * @param array $tokens + * @param int $startPointer + * @return int The end of the directive if one is found, the start pointer otherwise + */ + protected function seekEndOfDirective(array $tokens, $startPointer) + { + $endPointer = $startPointer; + + if ($tokens[$startPointer]['code'] === T_DOC_COMMENT_TAG) { + //advance to next token + $endPointer += 1; + + //if next token is an opening parenthesis, we consume everything up to the closing parenthesis + if ($tokens[$endPointer + 1]['code'] === T_OPEN_PARENTHESIS) { + $endPointer = $tokens[$endPointer + 1]['parenthesis_closer']; + } + } + + return $endPointer; + } + /** * Searches for the first token that has $tokenCode in $tokens from position * $startPointer (excluded). diff --git a/Magento2/Sniffs/GraphQL/ValidArgumentNameSniff.php b/Magento2/Sniffs/GraphQL/ValidArgumentNameSniff.php index 7741b675..549130e4 100644 --- a/Magento2/Sniffs/GraphQL/ValidArgumentNameSniff.php +++ b/Magento2/Sniffs/GraphQL/ValidArgumentNameSniff.php @@ -108,13 +108,7 @@ private function getArgumentDefinitionEndPointer($argumentDefinitionStartPointer //while next token starts a directive, we advance to the end of the directive while ($tokens[$endPointer + 1]['code'] === T_DOC_COMMENT_TAG) { - //consume next two tokens - $endPointer += 2; - - //if next token is an opening parenthesis, we consume everything up to the closing parenthesis - if ($tokens[$endPointer + 1]['code'] === T_OPEN_PARENTHESIS) { - $endPointer = $tokens[$endPointer + 1]['parenthesis_closer']; - } + $endPointer = $this->seekEndOfDirective($tokens, $endPointer + 1); } return $endPointer; @@ -181,7 +175,7 @@ private function getArguments($startPointer, $endPointer, array $tokens) switch (true) { case in_array($tokenCode, $skipTypes): - //NOP This is a toke that we have to skip + //NOP This is a token that we have to skip break; case $tokenCode === T_COLON: //we have reached the end of the argument name, thus we store its pointer and value diff --git a/Magento2/Sniffs/GraphQL/ValidEnumValueSniff.php b/Magento2/Sniffs/GraphQL/ValidEnumValueSniff.php index b7c702c7..a9c5f245 100644 --- a/Magento2/Sniffs/GraphQL/ValidEnumValueSniff.php +++ b/Magento2/Sniffs/GraphQL/ValidEnumValueSniff.php @@ -3,6 +3,7 @@ * Copyright © Magento. All rights reserved. * See COPYING.txt for license details. */ + namespace Magento2\Sniffs\GraphQL; use PHP_CodeSniffer\Files\File; @@ -46,16 +47,14 @@ public function process(File $phpcsFile, $stackPtr) $values = $this->getValues($openingCurlyPointer, $closingCurlyPointer, $tokens, $phpcsFile->eolChar); - foreach ($values as $value) { - $pointer = $value[0]; - $name = $value[1]; + foreach ($values as $pointer => $value) { - if (!$this->isSnakeCase($name, true)) { + if (!$this->isSnakeCase($value, true)) { $type = 'Enum value'; $error = '%s "%s" is not in SCREAMING_SNAKE_CASE format'; $data = [ $type, - $name, + $value, ]; $phpcsFile->addError($error, $pointer, 'NotScreamingSnakeCase', $data); @@ -98,11 +97,13 @@ private function getOpeningCurlyBracketPointer($startPointer, array $tokens) * Finds all enum values contained in $tokens in range $startPointer to * $endPointer. * + * The returned array uses token pointers as keys and value names as values. + * * @param int $startPointer * @param int $endPointer * @param array $tokens * @param string $eolChar - * @return array[] + * @return array */ private function getValues($startPointer, $endPointer, array $tokens, $eolChar) { @@ -112,20 +113,31 @@ private function getValues($startPointer, $endPointer, array $tokens, $eolChar) $skipTypes = [T_COMMENT, T_WHITESPACE]; for ($i = $startPointer + 1; $i < $endPointer; ++$i) { - //skip some tokens if (in_array($tokens[$i]['code'], $skipTypes)) { + //NOP This is a token that we have to skip continue; } - $enumValue .= $tokens[$i]['content']; - if ($valueTokenPointer === null) { - $valueTokenPointer = $i; + //add current tokens content to enum value if we have a string + if ($tokens[$i]['code'] === T_STRING) { + $enumValue .= $tokens[$i]['content']; + + //and store the pointer if we have not done it already + if ($valueTokenPointer === null) { + $valueTokenPointer = $i; + } + } + + //consume directive if we have found one + if ($tokens[$i]['code'] === T_DOC_COMMENT_TAG) { + $i = $this->seekEndOfDirective($tokens, $i); } - if (strpos($enumValue, $eolChar) !== false) { - $values[] = [$valueTokenPointer, rtrim($enumValue, $eolChar)]; - $enumValue = ''; - $valueTokenPointer = null; + //if current token has a line break, we have found the end of the value definition + if (strpos($tokens[$i]['content'], $eolChar) !== false) { + $values[$valueTokenPointer] = trim($enumValue); + $enumValue = ''; + $valueTokenPointer = null; } } diff --git a/Magento2/Tests/GraphQL/ValidArgumentNameUnitTest.graphqls b/Magento2/Tests/GraphQL/ValidArgumentNameUnitTest.graphqls index 8c1e12c0..e2128c9b 100644 --- a/Magento2/Tests/GraphQL/ValidArgumentNameUnitTest.graphqls +++ b/Magento2/Tests/GraphQL/ValidArgumentNameUnitTest.graphqls @@ -40,7 +40,7 @@ type Foo @doc(descripton: "Foo Bar Baz") { validArgument: String = "My fair lady" @doc( # A comment description: "This is a valid argument, spanned over multiple lines." - ) @foo + ) @unparametrizedDirective validArgumentWithDefaultValue: Int = 20 @doc(description: "This is another valid argument with a default value.") validArgumentListType: [String] @doc(description: "This is a valid argument that uses a list type.") validArgumentNonNullType: String! @doc(description: "This is a valid argument that uses a non null type.") diff --git a/Magento2/Tests/GraphQL/ValidEnumValueUnitTest.graphqls b/Magento2/Tests/GraphQL/ValidEnumValueUnitTest.graphqls index 994e75f2..5f70754a 100644 --- a/Magento2/Tests/GraphQL/ValidEnumValueUnitTest.graphqls +++ b/Magento2/Tests/GraphQL/ValidEnumValueUnitTest.graphqls @@ -5,12 +5,20 @@ enum Foo { VALID_SCREAMING_SNAKE_CASE_VALUE_WITH_12345_NUMBERS VALID_SCREAMING_SNAKE_CASE_VALUE_ENDING_WITH_NUMBER_5 VALIDUPPERCASEVALUE + VALID_SCREMING_CASE_VALUE_WITH_DIRECTIVE @doc(description: "This is a valid enum value with a directive") + VALID_SCREMING_CASE_VALUE_WITH_TWO_DIRECTIVES @doc( + description: "This is a valid enum value with a directive" + ) @unparametrizedDirective # Invalid values 1_INVALID_SCREAMING_SNAKE_CASE_VALUE_STARTING_WITH_NUMBER invalidCamelCaseValue InvalidCamelCaseCapsValue invalidlowercasevalue + invalidCamelCaseValueWithDirective @doc(description: "This is an invalid enum value with a directive") + invalidCamelCaseValueWithTwoDirectives @doc( + description: "This is an invalid enum value with a directive" + ) @unparametrizedDirective } # Ignored although it triggers a T_CLASS token diff --git a/Magento2/Tests/GraphQL/ValidEnumValueUnitTest.php b/Magento2/Tests/GraphQL/ValidEnumValueUnitTest.php index aaa3e55c..57e6ffed 100644 --- a/Magento2/Tests/GraphQL/ValidEnumValueUnitTest.php +++ b/Magento2/Tests/GraphQL/ValidEnumValueUnitTest.php @@ -16,10 +16,12 @@ class ValidEnumValueUnitTest extends AbstractGraphQLSniffUnitTestCase protected function getErrorList() { return [ - 10 => 1, - 11 => 1, - 12 => 1, - 13 => 1, + 14 => 1, + 15 => 1, + 16 => 1, + 17 => 1, + 18 => 1, + 19 => 1, ]; } From 874c9d78dc304bb02ce1ef47f41bf2ad29add04d Mon Sep 17 00:00:00 2001 From: Jean-Bernard Valentaten Date: Tue, 17 Sep 2019 12:54:17 +0200 Subject: [PATCH 030/630] MC-19366: Fixes code style issue --- Magento2/Sniffs/GraphQL/AbstractGraphQLSniff.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Magento2/Sniffs/GraphQL/AbstractGraphQLSniff.php b/Magento2/Sniffs/GraphQL/AbstractGraphQLSniff.php index d15ff43a..2c0448f0 100644 --- a/Magento2/Sniffs/GraphQL/AbstractGraphQLSniff.php +++ b/Magento2/Sniffs/GraphQL/AbstractGraphQLSniff.php @@ -56,7 +56,7 @@ protected function seekEndOfDirective(array $tokens, $startPointer) if ($tokens[$startPointer]['code'] === T_DOC_COMMENT_TAG) { //advance to next token - $endPointer += 1; + ++$endPointer; //if next token is an opening parenthesis, we consume everything up to the closing parenthesis if ($tokens[$endPointer + 1]['code'] === T_OPEN_PARENTHESIS) { From 4d99ee4797c2e881bd1e75bee78e5faeef2f2dd2 Mon Sep 17 00:00:00 2001 From: Jean-Bernard Valentaten Date: Wed, 18 Sep 2019 14:25:06 +0200 Subject: [PATCH 031/630] MC-19366: Fixes warning when composer install was run --- composer.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.lock b/composer.lock index de4d5a34..3bc96315 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": "560d5eca9cf59f965d8f3b98d2ee2a0a", + "content-hash": "397eb37a3ebf83c48685aeb1c77f12b7", "packages": [ { "name": "squizlabs/php_codesniffer", From e252b1946a0ac34c7454bb76359d091dddaac570 Mon Sep 17 00:00:00 2001 From: Jean-Bernard Valentaten Date: Thu, 19 Sep 2019 09:45:15 +0200 Subject: [PATCH 032/630] MC-19366: Fixes invalid tag in PHPDoc --- Magento2/Sniffs/GraphQL/ValidArgumentNameSniff.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Magento2/Sniffs/GraphQL/ValidArgumentNameSniff.php b/Magento2/Sniffs/GraphQL/ValidArgumentNameSniff.php index 549130e4..d7a19621 100644 --- a/Magento2/Sniffs/GraphQL/ValidArgumentNameSniff.php +++ b/Magento2/Sniffs/GraphQL/ValidArgumentNameSniff.php @@ -75,9 +75,9 @@ public function process(File $phpcsFile, $stackPtr) * Seeks the last token of an argument definition and returns its pointer. * * Arguments are defined as follows: - * + *
      *   {ArgumentName}: {ArgumentType}[ = {DefaultValue}][{Directive}]*
-     * 
+     * 
* * @param int $argumentDefinitionStartPointer * @param array $tokens From 0f59dcab0415e1d30af1cab916b4b76ec77e17df Mon Sep 17 00:00:00 2001 From: Lena Orobei Date: Fri, 27 Sep 2019 14:38:21 +0300 Subject: [PATCH 033/630] magento/magento-coding-standard#144: Using coding standard as s reference is causing error --- .../Commenting/PHPDocFormattingValidator.php | 2 +- .../Commenting/ClassAndInterfacePHPDocFormattingSniff.php | 1 + .../Sniffs/Commenting/ConstantsPHPDocFormattingSniff.php | 1 + composer.json | 5 ++++- 4 files changed, 7 insertions(+), 2 deletions(-) rename Magento2/{Sniffs => Helpers}/Commenting/PHPDocFormattingValidator.php (99%) diff --git a/Magento2/Sniffs/Commenting/PHPDocFormattingValidator.php b/Magento2/Helpers/Commenting/PHPDocFormattingValidator.php similarity index 99% rename from Magento2/Sniffs/Commenting/PHPDocFormattingValidator.php rename to Magento2/Helpers/Commenting/PHPDocFormattingValidator.php index cafdbf70..9b462e36 100644 --- a/Magento2/Sniffs/Commenting/PHPDocFormattingValidator.php +++ b/Magento2/Helpers/Commenting/PHPDocFormattingValidator.php @@ -4,7 +4,7 @@ * Copyright © Magento. All rights reserved. * See COPYING.txt for license details. */ -namespace Magento2\Sniffs\Commenting; +namespace Magento2\Helpers\Commenting; use PHP_CodeSniffer\Files\File; diff --git a/Magento2/Sniffs/Commenting/ClassAndInterfacePHPDocFormattingSniff.php b/Magento2/Sniffs/Commenting/ClassAndInterfacePHPDocFormattingSniff.php index 57204cdb..8976d67f 100644 --- a/Magento2/Sniffs/Commenting/ClassAndInterfacePHPDocFormattingSniff.php +++ b/Magento2/Sniffs/Commenting/ClassAndInterfacePHPDocFormattingSniff.php @@ -6,6 +6,7 @@ */ namespace Magento2\Sniffs\Commenting; +use Magento2\Helpers\Commenting\PHPDocFormattingValidator; use PHP_CodeSniffer\Sniffs\Sniff; use PHP_CodeSniffer\Files\File; diff --git a/Magento2/Sniffs/Commenting/ConstantsPHPDocFormattingSniff.php b/Magento2/Sniffs/Commenting/ConstantsPHPDocFormattingSniff.php index c18857ac..c56e3c65 100644 --- a/Magento2/Sniffs/Commenting/ConstantsPHPDocFormattingSniff.php +++ b/Magento2/Sniffs/Commenting/ConstantsPHPDocFormattingSniff.php @@ -5,6 +5,7 @@ */ namespace Magento2\Sniffs\Commenting; +use Magento2\Helpers\Commenting\PHPDocFormattingValidator; use PHP_CodeSniffer\Sniffs\Sniff; use PHP_CodeSniffer\Files\File; diff --git a/composer.json b/composer.json index 492357e1..22357234 100644 --- a/composer.json +++ b/composer.json @@ -18,7 +18,10 @@ "autoload": { "classmap": [ "PHP_CodeSniffer/Tokenizers/" - ] + ], + "psr-4": { + "Magento2\\": "Magento2/" + } }, "scripts": { "post-install-cmd": "vendor/bin/phpcs --config-set installed_paths ../../..", From 519fc72f414838d5ad64f5ace2f2cc77c81836f2 Mon Sep 17 00:00:00 2001 From: Shankar Konar Date: Sun, 29 Sep 2019 19:42:53 +0530 Subject: [PATCH 034/630] Warning raised if class member already have meaningful description --- .../ClassPropertyPHPDocFormattingSniff.php | 8 ++++++ .../ClassPropertyPHPDocFormattingUnitTest.inc | 28 +++++++++++++++---- .../ClassPropertyPHPDocFormattingUnitTest.php | 8 ++++-- 3 files changed, 37 insertions(+), 7 deletions(-) diff --git a/Magento2/Sniffs/Commenting/ClassPropertyPHPDocFormattingSniff.php b/Magento2/Sniffs/Commenting/ClassPropertyPHPDocFormattingSniff.php index a057e5b0..846c3cfd 100644 --- a/Magento2/Sniffs/Commenting/ClassPropertyPHPDocFormattingSniff.php +++ b/Magento2/Sniffs/Commenting/ClassPropertyPHPDocFormattingSniff.php @@ -66,6 +66,14 @@ public function processMemberVar(File $phpcsFile, $stackPtr) $phpcsFile->addWarning($error, $foundVar, 'EmptyVar'); return; } + + // Check if class has already have meaningful description + $isShortDescription = $phpcsFile->findPrevious(T_DOC_COMMENT_STRING, $commentEnd, $foundVar, false); + if ($tokens[$string]['line'] !== $tokens[$isShortDescription]['line']) { + $error = 'Variable member already have meaningful name'; + $phpcsFile->addWarning($error, $isShortDescription, 'AlreadyMeaningFulNameVar'); + return; + } } /** diff --git a/Magento2/Tests/Commenting/ClassPropertyPHPDocFormattingUnitTest.inc b/Magento2/Tests/Commenting/ClassPropertyPHPDocFormattingUnitTest.inc index dc40d74c..24e84eab 100644 --- a/Magento2/Tests/Commenting/ClassPropertyPHPDocFormattingUnitTest.inc +++ b/Magento2/Tests/Commenting/ClassPropertyPHPDocFormattingUnitTest.inc @@ -37,23 +37,41 @@ class Foo class Bar { /** - * @var correctlyFormattedPublicClassMember + * @var variablehasAlreadyhaveProtectedClassMember * * Short Description */ - public $correctlyFormattedPublicClassMember; + public $variablehasAlreadyhavePublicClassMember; /** - * @var correctlyFormattedPrivateClassMember + * @var variablehasAlreadyhavePrivateClassMember * * Short Description */ - private $correctlyFormattedPrivateClassMember; + private $variablehasAlreadyhavePrivateClassMember; /** - * @var correctlyFormattedProtectedClassMember + * @var variablehasAlreadyhaveProtectedClassMember * * Short Description */ + protected $variablehasAlreadyhaveProtectedClassMember; +} + +class correctlyFormattedClassMemberDocBlock +{ + /** + * @var correctlyFormattedPublicClassMember + */ + public $correctlyFormattedPublicClassMember; + + /** + * @var correctlyFormattedPrivateClassMember + */ + private $correctlyFormattedPrivateClassMember; + + /** + * @var correctlyFormattedProtectedClassMember + */ protected $correctlyFormattedProtectedClassMember; } diff --git a/Magento2/Tests/Commenting/ClassPropertyPHPDocFormattingUnitTest.php b/Magento2/Tests/Commenting/ClassPropertyPHPDocFormattingUnitTest.php index 675eef4f..a1c4e068 100644 --- a/Magento2/Tests/Commenting/ClassPropertyPHPDocFormattingUnitTest.php +++ b/Magento2/Tests/Commenting/ClassPropertyPHPDocFormattingUnitTest.php @@ -24,9 +24,13 @@ public function getWarningList() { return [ 13 => 1, + 18 => 1, 23 => 1, - 30 => 1, - 34 => 1 + 30 => 2, + 34 => 1, + 42 => 1, + 49 => 1, + 56 => 1 ]; } } From 93ceb188ed53713b6ef7b44f58a67f4f6e39faa4 Mon Sep 17 00:00:00 2001 From: Shankar Konar Date: Sun, 13 Oct 2019 12:29:51 +0530 Subject: [PATCH 035/630] use of PHPDocFormattingValidator --- .../ClassPropertyPHPDocFormattingSniff.php | 29 ++++++++++++++++--- .../ClassPropertyPHPDocFormattingUnitTest.php | 4 +-- 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/Magento2/Sniffs/Commenting/ClassPropertyPHPDocFormattingSniff.php b/Magento2/Sniffs/Commenting/ClassPropertyPHPDocFormattingSniff.php index 846c3cfd..72e6967f 100644 --- a/Magento2/Sniffs/Commenting/ClassPropertyPHPDocFormattingSniff.php +++ b/Magento2/Sniffs/Commenting/ClassPropertyPHPDocFormattingSniff.php @@ -3,6 +3,7 @@ use PHP_CodeSniffer\Files\File; use PHP_CodeSniffer\Sniffs\AbstractVariableSniff; +use PHP_CodeSniffer\Util\Tokens; /** * Class ClassPropertyPHPDocFormattingSniff @@ -22,6 +23,28 @@ class ClassPropertyPHPDocFormattingSniff extends AbstractVariableSniff T_WHITESPACE, ]; + /** + * @var PHPDocFormattingValidator + */ + private $PHPDocFormattingValidator; + + /** + * Constructs an AbstractVariableTest. + */ + public function __construct() + { + $scopes = Tokens::$ooScopeTokens; + $this->PHPDocFormattingValidator = new PHPDocFormattingValidator(); + $listen = [ + T_VARIABLE, + T_DOUBLE_QUOTED_STRING, + T_HEREDOC, + ]; + + parent::__construct($scopes, $listen, true); + + } + /** * @param File $phpcsFile * @param int $stackPtr @@ -39,9 +62,7 @@ public function processMemberVar(File $phpcsFile, $stackPtr) $phpcsFile->addWarning('Missing class property doc comment', $stackPtr, 'Missing'); return; } - $commentStart = $tokens[$commentEnd]['comment_opener']; - $foundVar = null; foreach ($tokens[$commentStart]['comment_tags'] as $tag) { if ($tokens[$tag]['content'] === '@var') { @@ -69,9 +90,9 @@ public function processMemberVar(File $phpcsFile, $stackPtr) // Check if class has already have meaningful description $isShortDescription = $phpcsFile->findPrevious(T_DOC_COMMENT_STRING, $commentEnd, $foundVar, false); - if ($tokens[$string]['line'] !== $tokens[$isShortDescription]['line']) { + if ($this->PHPDocFormattingValidator->providesMeaning($isShortDescription, $commentStart, $tokens) !== true) { $error = 'Variable member already have meaningful name'; - $phpcsFile->addWarning($error, $isShortDescription, 'AlreadyMeaningFulNameVar'); + $phpcsFile->addWarning($error, $isShortDescription, 'AlreadyHaveMeaningFulNameVar'); return; } } diff --git a/Magento2/Tests/Commenting/ClassPropertyPHPDocFormattingUnitTest.php b/Magento2/Tests/Commenting/ClassPropertyPHPDocFormattingUnitTest.php index a1c4e068..ba70a2d1 100644 --- a/Magento2/Tests/Commenting/ClassPropertyPHPDocFormattingUnitTest.php +++ b/Magento2/Tests/Commenting/ClassPropertyPHPDocFormattingUnitTest.php @@ -26,11 +26,11 @@ public function getWarningList() 13 => 1, 18 => 1, 23 => 1, - 30 => 2, + 30 => 1, 34 => 1, 42 => 1, 49 => 1, - 56 => 1 + 56 => 1, ]; } } From 7f3a89fce97582671e06da9d755affb889812e0c Mon Sep 17 00:00:00 2001 From: Shankar Konar Date: Sun, 13 Oct 2019 15:24:39 +0530 Subject: [PATCH 036/630] Fixed static build tests --- .../Sniffs/Commenting/ClassPropertyPHPDocFormattingSniff.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Magento2/Sniffs/Commenting/ClassPropertyPHPDocFormattingSniff.php b/Magento2/Sniffs/Commenting/ClassPropertyPHPDocFormattingSniff.php index 72e6967f..ebd3105c 100644 --- a/Magento2/Sniffs/Commenting/ClassPropertyPHPDocFormattingSniff.php +++ b/Magento2/Sniffs/Commenting/ClassPropertyPHPDocFormattingSniff.php @@ -29,7 +29,7 @@ class ClassPropertyPHPDocFormattingSniff extends AbstractVariableSniff private $PHPDocFormattingValidator; /** - * Constructs an AbstractVariableTest. + * Constructs an ClassPropertyPHPDocFormattingSniff. */ public function __construct() { @@ -42,7 +42,6 @@ public function __construct() ]; parent::__construct($scopes, $listen, true); - } /** From 9185a9f89eeb53bf9919757fa0e1d80c312e9cbc Mon Sep 17 00:00:00 2001 From: Shankar Konar Date: Sun, 13 Oct 2019 18:36:53 +0530 Subject: [PATCH 037/630] import static test ruleset --- .../Sniffs/Namespaces/UseDeclarationSniff.php | 51 +++++++++++++++++++ .../Namespaces/UseDeclarationUnitTest.inc | 4 ++ .../Namespaces/UseDeclarationUnitTest.php | 30 +++++++++++ Magento2/ruleset.xml | 4 ++ 4 files changed, 89 insertions(+) create mode 100644 Magento2/Sniffs/Namespaces/UseDeclarationSniff.php create mode 100644 Magento2/Tests/Namespaces/UseDeclarationUnitTest.inc create mode 100644 Magento2/Tests/Namespaces/UseDeclarationUnitTest.php diff --git a/Magento2/Sniffs/Namespaces/UseDeclarationSniff.php b/Magento2/Sniffs/Namespaces/UseDeclarationSniff.php new file mode 100644 index 00000000..b7b52b8b --- /dev/null +++ b/Magento2/Sniffs/Namespaces/UseDeclarationSniff.php @@ -0,0 +1,51 @@ +findNext([T_COMMA, T_SEMICOLON, T_OPEN_USE_GROUP, T_CLOSE_TAG], ($stackPtr + 1)); + $getTokenAsContent = $phpcsFile->getTokensAsString($stackPtr, ($next - $stackPtr)); + if (strpos($getTokenAsContent, $this->_prohibitNamespace) !== false) { + $phpcsFile->addWarning($this->warningMessage, $stackPtr, $this->warningCode); + } + } +} diff --git a/Magento2/Tests/Namespaces/UseDeclarationUnitTest.inc b/Magento2/Tests/Namespaces/UseDeclarationUnitTest.inc new file mode 100644 index 00000000..553f55ec --- /dev/null +++ b/Magento2/Tests/Namespaces/UseDeclarationUnitTest.inc @@ -0,0 +1,4 @@ + 1]; + } +} diff --git a/Magento2/ruleset.xml b/Magento2/ruleset.xml index 9d65e166..8f6f495f 100644 --- a/Magento2/ruleset.xml +++ b/Magento2/ruleset.xml @@ -189,6 +189,10 @@ *Test.php */tests/*
+ + 8 + warning + 8 warning From 2706fafc7f151b78bb55ef4e6f812902612a8267 Mon Sep 17 00:00:00 2001 From: "Leandro F. L" Date: Tue, 15 Oct 2019 13:08:26 -0300 Subject: [PATCH 038/630] How to use phpcbf How to use phpcbf Co-Authored-By: Lena Orobei --- README.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/README.md b/README.md index f31135c2..dfc6e391 100644 --- a/README.md +++ b/README.md @@ -42,6 +42,14 @@ Once installed, you can run `phpcs` from the command-line to analyse your code ` ``` $ vendor/bin/phpcs --standard=Magento2 app/code/MyAwesomeExtension ``` + +### Fixing issues automatically +Also you can run `phpcbf` from the command-line to fix your code `MyAwesomeExtension` for warnings like + "PHPCBF CAN FIX THE [0-9]+ MARKED SNIFF VIOLATIONS AUTOMATICALLY" +``` +$ vendor/bin/phpcbf --standard=Magento2 app/code/MyAwesomeExtension +``` + ## Where to contribute - Documentation of existing rules. See [ExtDN PHP CodeSniffer rules for Magento 2](https://github.com/extdn/extdn-phpcs) as a good example. - Bug fixes and improvements of existing rules. From f38abf53e586420ffd84772e679ddf0b23dbf259 Mon Sep 17 00:00:00 2001 From: "Leandro F. L" Date: Tue, 15 Oct 2019 15:19:58 -0300 Subject: [PATCH 039/630] Git ignore for IDE files --- .gitignore | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.gitignore b/.gitignore index eece033d..ba13e90d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,8 @@ /vendor/* /bin/* + +# IDE files +.idea/ +.project/ +.settings/ +.vscode/ From 705cac5d2a472ef1083d2b050de6be6cc0b69a1b Mon Sep 17 00:00:00 2001 From: Shankar Konar Date: Wed, 16 Oct 2019 23:44:06 +0530 Subject: [PATCH 040/630] Feedback changes --- .../ClassPropertyPHPDocFormattingUnitTest.inc | 19 +++++++++++++------ .../ClassPropertyPHPDocFormattingUnitTest.php | 1 + 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/Magento2/Tests/Commenting/ClassPropertyPHPDocFormattingUnitTest.inc b/Magento2/Tests/Commenting/ClassPropertyPHPDocFormattingUnitTest.inc index 24e84eab..e166a0e0 100644 --- a/Magento2/Tests/Commenting/ClassPropertyPHPDocFormattingUnitTest.inc +++ b/Magento2/Tests/Commenting/ClassPropertyPHPDocFormattingUnitTest.inc @@ -37,25 +37,32 @@ class Foo class Bar { /** - * @var variablehasAlreadyhaveProtectedClassMember + * @var variableHasAlreadyHaveProtectedClassMember * * Short Description */ - public $variablehasAlreadyhavePublicClassMember; + public $variableHasAlreadyHavePublicClassMember; /** - * @var variablehasAlreadyhavePrivateClassMember + * @var variableHasAlreadyHavePrivateClassMember * * Short Description */ - private $variablehasAlreadyhavePrivateClassMember; + private $variableHasAlreadyHavePrivateClassMember; /** - * @var variablehasAlreadyhaveProtectedClassMember + * @var variableHasAlreadyHaveProtectedClassMember * * Short Description */ - protected $variablehasAlreadyhaveProtectedClassMember; + protected $variableHasAlreadyHaveProtectedClassMember; + + /** + * @var className + * + * Variable name + */ + private $variableName; } class correctlyFormattedClassMemberDocBlock diff --git a/Magento2/Tests/Commenting/ClassPropertyPHPDocFormattingUnitTest.php b/Magento2/Tests/Commenting/ClassPropertyPHPDocFormattingUnitTest.php index ba70a2d1..6974eabe 100644 --- a/Magento2/Tests/Commenting/ClassPropertyPHPDocFormattingUnitTest.php +++ b/Magento2/Tests/Commenting/ClassPropertyPHPDocFormattingUnitTest.php @@ -31,6 +31,7 @@ public function getWarningList() 42 => 1, 49 => 1, 56 => 1, + 63 => 1 ]; } } From 80bfe89d15f2540c69f337ca78f5e6b7c3704531 Mon Sep 17 00:00:00 2001 From: Shankar Konar Date: Thu, 17 Oct 2019 00:23:26 +0530 Subject: [PATCH 041/630] Readme file and feedback changes --- .../Namespaces/ImportsFromTestNamespaceSniff.md | 13 +++++++++++++ ...nSniff.php => ImportsFromTestNamespaceSniff.php} | 10 +++++----- ...est.inc => ImportsFromTestNamespaceUnitTest.inc} | 2 +- ...est.php => ImportsFromTestNamespaceUnitTest.php} | 2 +- Magento2/ruleset.xml | 2 +- 5 files changed, 21 insertions(+), 8 deletions(-) create mode 100644 Magento2/Sniffs/Namespaces/ImportsFromTestNamespaceSniff.md rename Magento2/Sniffs/Namespaces/{UseDeclarationSniff.php => ImportsFromTestNamespaceSniff.php} (72%) rename Magento2/Tests/Namespaces/{UseDeclarationUnitTest.inc => ImportsFromTestNamespaceUnitTest.inc} (69%) rename Magento2/Tests/Namespaces/{UseDeclarationUnitTest.php => ImportsFromTestNamespaceUnitTest.php} (86%) diff --git a/Magento2/Sniffs/Namespaces/ImportsFromTestNamespaceSniff.md b/Magento2/Sniffs/Namespaces/ImportsFromTestNamespaceSniff.md new file mode 100644 index 00000000..113e4ec6 --- /dev/null +++ b/Magento2/Sniffs/Namespaces/ImportsFromTestNamespaceSniff.md @@ -0,0 +1,13 @@ +# Rule: Do not import from `Test` namespaces +## Background +Sometimes IDE imports the namespace with `Test` automatically for return data type like string, float etc or any other means. + +## Reasoning +Time to time we're getting issue with running tests on PRs in magento/magento2 repository because someone imported `\Magento\Tests\NamingConvention\true\string` by mistake. As result - we have "No build reports available" for "Database Compare build", "Functional Tests build", "Sample Data Tests build" while Static tests are shown as "failing" but in results - we don't really have reason + +## How it works +Any occurrence starts with `Magento\Tests` in import from the namespace will raise the warning. + +## How to fix + +Remove `Magento\Tests` from the imported namespaces diff --git a/Magento2/Sniffs/Namespaces/UseDeclarationSniff.php b/Magento2/Sniffs/Namespaces/ImportsFromTestNamespaceSniff.php similarity index 72% rename from Magento2/Sniffs/Namespaces/UseDeclarationSniff.php rename to Magento2/Sniffs/Namespaces/ImportsFromTestNamespaceSniff.php index b7b52b8b..b1078611 100644 --- a/Magento2/Sniffs/Namespaces/UseDeclarationSniff.php +++ b/Magento2/Sniffs/Namespaces/ImportsFromTestNamespaceSniff.php @@ -11,23 +11,23 @@ /** * Detects static test namespace. */ -class UseDeclarationSniff implements Sniff +class ImportsFromTestNamespaceSniff implements Sniff { /** * @var string */ - private $_prohibitNamespace = 'Magento\Tests'; + private $prohibitNamespace = 'Magento\Tests'; /** * @var string */ - protected $warningMessage = 'Incorrect namespace has been imported.'; + protected $warningMessage = 'Application modules should not use classed from test modules.'; /** * @var string */ - protected $warningCode = 'WrongImportNamespaces'; + protected $warningCode = 'WrongImport'; /** * @inheritdoc @@ -44,7 +44,7 @@ public function process(File $phpcsFile, $stackPtr) { $next = $phpcsFile->findNext([T_COMMA, T_SEMICOLON, T_OPEN_USE_GROUP, T_CLOSE_TAG], ($stackPtr + 1)); $getTokenAsContent = $phpcsFile->getTokensAsString($stackPtr, ($next - $stackPtr)); - if (strpos($getTokenAsContent, $this->_prohibitNamespace) !== false) { + if (strpos($getTokenAsContent, $this->prohibitNamespace) !== false) { $phpcsFile->addWarning($this->warningMessage, $stackPtr, $this->warningCode); } } diff --git a/Magento2/Tests/Namespaces/UseDeclarationUnitTest.inc b/Magento2/Tests/Namespaces/ImportsFromTestNamespaceUnitTest.inc similarity index 69% rename from Magento2/Tests/Namespaces/UseDeclarationUnitTest.inc rename to Magento2/Tests/Namespaces/ImportsFromTestNamespaceUnitTest.inc index 553f55ec..13c889c8 100644 --- a/Magento2/Tests/Namespaces/UseDeclarationUnitTest.inc +++ b/Magento2/Tests/Namespaces/ImportsFromTestNamespaceUnitTest.inc @@ -1,4 +1,4 @@ *Test.php */tests/* - + 8 warning From 785f0c32a6aa424303430ebbb8d141208bca9d6b Mon Sep 17 00:00:00 2001 From: Shankar Konar Date: Mon, 28 Oct 2019 13:50:12 +0530 Subject: [PATCH 042/630] Fixed PHPDocFormattingValidator class not found issue --- .../Sniffs/Commenting/ClassPropertyPHPDocFormattingSniff.php | 1 + 1 file changed, 1 insertion(+) diff --git a/Magento2/Sniffs/Commenting/ClassPropertyPHPDocFormattingSniff.php b/Magento2/Sniffs/Commenting/ClassPropertyPHPDocFormattingSniff.php index ebd3105c..b77a3761 100644 --- a/Magento2/Sniffs/Commenting/ClassPropertyPHPDocFormattingSniff.php +++ b/Magento2/Sniffs/Commenting/ClassPropertyPHPDocFormattingSniff.php @@ -4,6 +4,7 @@ use PHP_CodeSniffer\Files\File; use PHP_CodeSniffer\Sniffs\AbstractVariableSniff; use PHP_CodeSniffer\Util\Tokens; +use Magento2\Helpers\Commenting\PHPDocFormattingValidator; /** * Class ClassPropertyPHPDocFormattingSniff From 08cc5e7d6719d934beb29ff83713b0595969e990 Mon Sep 17 00:00:00 2001 From: korostii <24894168+korostii@users.noreply.github.com> Date: Tue, 29 Oct 2019 20:38:10 +0000 Subject: [PATCH 043/630] Fix typo in DiscouragedFunctionSniff --- Magento2/Sniffs/Functions/DiscouragedFunctionSniff.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Magento2/Sniffs/Functions/DiscouragedFunctionSniff.php b/Magento2/Sniffs/Functions/DiscouragedFunctionSniff.php index c3b9c037..a5a583ac 100644 --- a/Magento2/Sniffs/Functions/DiscouragedFunctionSniff.php +++ b/Magento2/Sniffs/Functions/DiscouragedFunctionSniff.php @@ -113,7 +113,7 @@ class DiscouragedFunctionSniff extends ForbiddenFunctionsSniff '^readlink$' => null, '^register_shutdown_function$' => null, '^register_tick_function$' => null, - '^rename$' => 'Magento\Framework\Filesystem\DriverInterface::raname()', + '^rename$' => 'Magento\Framework\Filesystem\DriverInterface::rename()', '^rmdir$' => 'Magento\Framework\Filesystem\DriverInterface::deleteDirectory()', '^scandir$' => null, '^session_.*$' => null, From c32d97db864584caa69450d90dcd512970cbe321 Mon Sep 17 00:00:00 2001 From: Lena Orobei Date: Mon, 4 Nov 2019 12:07:50 -0600 Subject: [PATCH 044/630] V5 release --- composer.json | 2 +- composer.lock | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 22357234..2c9a1844 100644 --- a/composer.json +++ b/composer.json @@ -6,7 +6,7 @@ "AFL-3.0" ], "type": "phpcodesniffer-standard", - "version": "4", + "version": "5", "require": { "php": ">=5.6.0", "squizlabs/php_codesniffer": "^3.4", diff --git a/composer.lock b/composer.lock index 3bc96315..34b78adc 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": "397eb37a3ebf83c48685aeb1c77f12b7", + "content-hash": "de90fd51a20a688a7385615a0fd7d86e", "packages": [ { "name": "squizlabs/php_codesniffer", From 17e993be460db53c4e83baedeb19f6580a41effc Mon Sep 17 00:00:00 2001 From: Shankar Konar Date: Sat, 9 Nov 2019 00:36:38 +0530 Subject: [PATCH 045/630] Feedback suggestions --- .../Commenting/ClassPropertyPHPDocFormattingSniff.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Magento2/Sniffs/Commenting/ClassPropertyPHPDocFormattingSniff.php b/Magento2/Sniffs/Commenting/ClassPropertyPHPDocFormattingSniff.php index b77a3761..b488438e 100644 --- a/Magento2/Sniffs/Commenting/ClassPropertyPHPDocFormattingSniff.php +++ b/Magento2/Sniffs/Commenting/ClassPropertyPHPDocFormattingSniff.php @@ -59,7 +59,7 @@ public function processMemberVar(File $phpcsFile, $stackPtr) || ($tokens[$commentEnd]['code'] !== T_DOC_COMMENT_CLOSE_TAG && $tokens[$commentEnd]['code'] !== T_COMMENT) ) { - $phpcsFile->addWarning('Missing class property doc comment', $stackPtr, 'Missing'); + $phpcsFile->addWarning('Missing PHP DocBlock for class property.', $stackPtr, 'Missing'); return; } $commentStart = $tokens[$commentEnd]['comment_opener']; @@ -67,7 +67,7 @@ public function processMemberVar(File $phpcsFile, $stackPtr) foreach ($tokens[$commentStart]['comment_tags'] as $tag) { if ($tokens[$tag]['content'] === '@var') { if ($foundVar !== null) { - $error = 'Only one @var tag is allowed in a class property comment'; + $error = 'Only one @var tag is allowed for class property declaration.'; $phpcsFile->addWarning($error, $tag, 'DuplicateVar'); } else { $foundVar = $tag; @@ -76,14 +76,14 @@ public function processMemberVar(File $phpcsFile, $stackPtr) } if ($foundVar === null) { - $error = 'Missing @var tag in class property comment'; + $error = 'Class properties must have type declaration using @var tag.'; $phpcsFile->addWarning($error, $stackPtr, 'MissingVar'); return; } $string = $phpcsFile->findNext(T_DOC_COMMENT_STRING, $foundVar, $commentEnd); if ($string === false || $tokens[$string]['line'] !== $tokens[$foundVar]['line']) { - $error = 'Content missing for @var tag in class property comment'; + $error = 'Content missing for @var tag in class property declaration.'; $phpcsFile->addWarning($error, $foundVar, 'EmptyVar'); return; } @@ -91,7 +91,7 @@ public function processMemberVar(File $phpcsFile, $stackPtr) // Check if class has already have meaningful description $isShortDescription = $phpcsFile->findPrevious(T_DOC_COMMENT_STRING, $commentEnd, $foundVar, false); if ($this->PHPDocFormattingValidator->providesMeaning($isShortDescription, $commentStart, $tokens) !== true) { - $error = 'Variable member already have meaningful name'; + $error = 'Short description duplicates class property name.'; $phpcsFile->addWarning($error, $isShortDescription, 'AlreadyHaveMeaningFulNameVar'); return; } From 88a5e7568540111ba2d127731c38008d207fc93d Mon Sep 17 00:00:00 2001 From: Shankar Konar Date: Sat, 16 Nov 2019 19:42:20 +0530 Subject: [PATCH 046/630] Feedback changes --- .../ClassPropertyPHPDocFormattingSniff.php | 27 ++++++++++++++++--- .../ClassPropertyPHPDocFormattingUnitTest.inc | 18 +++++++++++++ .../ClassPropertyPHPDocFormattingUnitTest.php | 3 ++- 3 files changed, 43 insertions(+), 5 deletions(-) diff --git a/Magento2/Sniffs/Commenting/ClassPropertyPHPDocFormattingSniff.php b/Magento2/Sniffs/Commenting/ClassPropertyPHPDocFormattingSniff.php index b488438e..cf006d56 100644 --- a/Magento2/Sniffs/Commenting/ClassPropertyPHPDocFormattingSniff.php +++ b/Magento2/Sniffs/Commenting/ClassPropertyPHPDocFormattingSniff.php @@ -88,11 +88,30 @@ public function processMemberVar(File $phpcsFile, $stackPtr) return; } - // Check if class has already have meaningful description - $isShortDescription = $phpcsFile->findPrevious(T_DOC_COMMENT_STRING, $commentEnd, $foundVar, false); - if ($this->PHPDocFormattingValidator->providesMeaning($isShortDescription, $commentStart, $tokens) !== true) { + // Check if class has already have meaningful description after @var tag + $isShortDescriptionAfterVar = $phpcsFile->findNext(T_DOC_COMMENT_STRING, $foundVar + 4, $commentEnd, false, + null, + false); + if ($this->PHPDocFormattingValidator->providesMeaning($isShortDescriptionAfterVar, $commentStart, $tokens) !== true) { + preg_match('`^((?:\|?(?:array\([^\)]*\)|[\\\\\[\]]+))*)( .*)?`i', $tokens[($foundVar + 2)]['content'], $varParts); + if ($varParts[1]) { + return; + } + $error = 'Short description duplicates class property name.'; + $phpcsFile->addWarning($error, $isShortDescriptionAfterVar, 'AlreadyHaveMeaningFulNameVar'); + return; + } + // Check if class has already have meaningful description before @var tag + $isShortDescriptionPreviousVar = $phpcsFile->findPrevious(T_DOC_COMMENT_STRING, $foundVar, $commentStart, false, + null, + false); + if ($this->PHPDocFormattingValidator->providesMeaning($isShortDescriptionPreviousVar, $commentStart, $tokens) !== true) { + preg_match('`^((?:\|?(?:array\([^\)]*\)|[\\\\\[\]]+))*)( .*)?`i', $tokens[($foundVar + 2)]['content'], $varParts); + if ($varParts[1]) { + return; + } $error = 'Short description duplicates class property name.'; - $phpcsFile->addWarning($error, $isShortDescription, 'AlreadyHaveMeaningFulNameVar'); + $phpcsFile->addWarning($error, $isShortDescriptionPreviousVar, 'AlreadyHaveMeaningFulNameVar'); return; } } diff --git a/Magento2/Tests/Commenting/ClassPropertyPHPDocFormattingUnitTest.inc b/Magento2/Tests/Commenting/ClassPropertyPHPDocFormattingUnitTest.inc index e166a0e0..6dcccf65 100644 --- a/Magento2/Tests/Commenting/ClassPropertyPHPDocFormattingUnitTest.inc +++ b/Magento2/Tests/Commenting/ClassPropertyPHPDocFormattingUnitTest.inc @@ -63,6 +63,13 @@ class Bar { * Variable name */ private $variableName; + + /** + * Some more invalid description + * + * @var test + */ + protected $test; } class correctlyFormattedClassMemberDocBlock @@ -81,4 +88,15 @@ class correctlyFormattedClassMemberDocBlock * @var correctlyFormattedProtectedClassMember */ protected $correctlyFormattedProtectedClassMember; + + /** + * @var Array|\Foo_BAR + */ + protected $array; + + /** + * @var \FOO\BAR\TEST\Class\\FooBarInterface| + * \FooObject_TEST_C + */ + private $testObject; } diff --git a/Magento2/Tests/Commenting/ClassPropertyPHPDocFormattingUnitTest.php b/Magento2/Tests/Commenting/ClassPropertyPHPDocFormattingUnitTest.php index 6974eabe..8817ab3b 100644 --- a/Magento2/Tests/Commenting/ClassPropertyPHPDocFormattingUnitTest.php +++ b/Magento2/Tests/Commenting/ClassPropertyPHPDocFormattingUnitTest.php @@ -31,7 +31,8 @@ public function getWarningList() 42 => 1, 49 => 1, 56 => 1, - 63 => 1 + 63 => 1, + 68 => 1 ]; } } From 975977da7f566c0445c85623f72990d96d05130f Mon Sep 17 00:00:00 2001 From: Shankar Konar Date: Sun, 17 Nov 2019 18:52:08 +0530 Subject: [PATCH 047/630] Sniff added for grouped namespace --- .../ImportsFromTestNamespaceSniff.php | 19 +++++++++++++++++++ .../ImportsFromTestNamespaceUnitTest.inc | 4 +++- .../ImportsFromTestNamespaceUnitTest.php | 5 ++++- Magento2/ruleset.xml | 2 +- 4 files changed, 27 insertions(+), 3 deletions(-) diff --git a/Magento2/Sniffs/Namespaces/ImportsFromTestNamespaceSniff.php b/Magento2/Sniffs/Namespaces/ImportsFromTestNamespaceSniff.php index b1078611..8d976b4b 100644 --- a/Magento2/Sniffs/Namespaces/ImportsFromTestNamespaceSniff.php +++ b/Magento2/Sniffs/Namespaces/ImportsFromTestNamespaceSniff.php @@ -7,6 +7,7 @@ use PHP_CodeSniffer\Sniffs\Sniff; use PHP_CodeSniffer\Files\File; +use PHP_CodeSniffer\Util\Tokens; /** * Detects static test namespace. @@ -43,9 +44,27 @@ public function register() public function process(File $phpcsFile, $stackPtr) { $next = $phpcsFile->findNext([T_COMMA, T_SEMICOLON, T_OPEN_USE_GROUP, T_CLOSE_TAG], ($stackPtr + 1)); + $tokens = $phpcsFile->getTokens(); $getTokenAsContent = $phpcsFile->getTokensAsString($stackPtr, ($next - $stackPtr)); if (strpos($getTokenAsContent, $this->prohibitNamespace) !== false) { $phpcsFile->addWarning($this->warningMessage, $stackPtr, $this->warningCode); } + if ($next !== false + && $tokens[$next]['code'] !== T_SEMICOLON + && $tokens[$next]['code'] !== T_CLOSE_TAG + ) { + $baseUse = rtrim($phpcsFile->getTokensAsString($stackPtr, ($next - $stackPtr))); + $baseUse = str_replace('use \\', '', $baseUse); + $closingCurly = $phpcsFile->findNext(T_CLOSE_USE_GROUP, ($next + 1)); + do { + $next = $phpcsFile->findNext(Tokens::$emptyTokens, ($next + 1), $closingCurly, true); + $groupedAsContent = $baseUse. $tokens[$next]['content']; + $next = $phpcsFile->findNext(T_COMMA, ($next + 1), $closingCurly); + if (strpos($groupedAsContent, $this->prohibitNamespace) !== false) { + $phpcsFile->addWarning($this->warningMessage, $stackPtr, $this->warningCode); + return; + } + } while ($next != false); + } } } diff --git a/Magento2/Tests/Namespaces/ImportsFromTestNamespaceUnitTest.inc b/Magento2/Tests/Namespaces/ImportsFromTestNamespaceUnitTest.inc index 13c889c8..50d339a1 100644 --- a/Magento2/Tests/Namespaces/ImportsFromTestNamespaceUnitTest.inc +++ b/Magento2/Tests/Namespaces/ImportsFromTestNamespaceUnitTest.inc @@ -1,4 +1,6 @@ 1]; + return [ + 2 => 1, + 5 => 1 + ]; } } diff --git a/Magento2/ruleset.xml b/Magento2/ruleset.xml index 9810723b..70c26495 100644 --- a/Magento2/ruleset.xml +++ b/Magento2/ruleset.xml @@ -189,7 +189,7 @@ *Test.php */tests/* - + 8 warning From 199057a8ca960e0bb191ec8fd7a409fbd91c8a51 Mon Sep 17 00:00:00 2001 From: Ihor Sviziev Date: Wed, 4 Dec 2019 09:00:32 +0200 Subject: [PATCH 048/630] magento/magento-coding-standard#149 No imports from test namespace Exclude running for tests --- Magento2/ruleset.xml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Magento2/ruleset.xml b/Magento2/ruleset.xml index 70c26495..c4fc6580 100644 --- a/Magento2/ruleset.xml +++ b/Magento2/ruleset.xml @@ -192,6 +192,11 @@ 8 warning + */_files/* + */Fixtures/* + */Test/* + *Test.php + */tests/* 8 From 4040cd53b27dd10379341fdcad3df726a956691e Mon Sep 17 00:00:00 2001 From: Lena Orobei Date: Wed, 11 Dec 2019 13:53:27 -0600 Subject: [PATCH 049/630] magento/magento-coding-standard#142: [New Rule] No imports from static tests namespaces --- Magento2/Sniffs/Namespaces/ImportsFromTestNamespaceSniff.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Magento2/Sniffs/Namespaces/ImportsFromTestNamespaceSniff.php b/Magento2/Sniffs/Namespaces/ImportsFromTestNamespaceSniff.php index 8d976b4b..3e5dbce7 100644 --- a/Magento2/Sniffs/Namespaces/ImportsFromTestNamespaceSniff.php +++ b/Magento2/Sniffs/Namespaces/ImportsFromTestNamespaceSniff.php @@ -14,7 +14,6 @@ */ class ImportsFromTestNamespaceSniff implements Sniff { - /** * @var string */ @@ -53,7 +52,7 @@ public function process(File $phpcsFile, $stackPtr) && $tokens[$next]['code'] !== T_SEMICOLON && $tokens[$next]['code'] !== T_CLOSE_TAG ) { - $baseUse = rtrim($phpcsFile->getTokensAsString($stackPtr, ($next - $stackPtr))); + $baseUse = rtrim($phpcsFile->getTokensAsString($stackPtr, ($next - $stackPtr))); $baseUse = str_replace('use \\', '', $baseUse); $closingCurly = $phpcsFile->findNext(T_CLOSE_USE_GROUP, ($next + 1)); do { @@ -64,7 +63,7 @@ public function process(File $phpcsFile, $stackPtr) $phpcsFile->addWarning($this->warningMessage, $stackPtr, $this->warningCode); return; } - } while ($next != false); + } while ($next !== false); } } } From 1eeb017ba2e4ca331ae923c805a53da52ffef851 Mon Sep 17 00:00:00 2001 From: Daniel Ruf Date: Tue, 7 Jan 2020 08:56:26 +0100 Subject: [PATCH 050/630] Use lowercase file extension --- LICENSE.TXT => LICENSE.txt | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename LICENSE.TXT => LICENSE.txt (100%) diff --git a/LICENSE.TXT b/LICENSE.txt similarity index 100% rename from LICENSE.TXT rename to LICENSE.txt From be311024d7df8bdbea4327742d5b58d189b2073b Mon Sep 17 00:00:00 2001 From: rishatiwari Date: Sun, 2 Feb 2020 14:17:26 +0530 Subject: [PATCH 051/630] cleanup: doc url updated in comment --- Magento2/Sniffs/Security/XssTemplateSniff.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Magento2/Sniffs/Security/XssTemplateSniff.php b/Magento2/Sniffs/Security/XssTemplateSniff.php index 330999e9..aa2accbe 100644 --- a/Magento2/Sniffs/Security/XssTemplateSniff.php +++ b/Magento2/Sniffs/Security/XssTemplateSniff.php @@ -161,7 +161,7 @@ private function findSpecialAnnotation($stackPtr) /** * Find unescaped statement by following rules: * - * See http://devdocs.magento.com/guides/v2.0/frontend-dev-guide/templates/template-security.html + * See https://devdocs.magento.com/guides/v2.3/extension-dev-guide/xss-protection.html * * @param array $statement * @return void From 7a06fb38f205d847ca5e2445eb93975bb8390469 Mon Sep 17 00:00:00 2001 From: Lena Orobei Date: Mon, 10 Feb 2020 11:05:33 -0600 Subject: [PATCH 052/630] Fixed confusing message --- .../Commenting/ClassAndInterfacePHPDocFormattingSniff.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Magento2/Sniffs/Commenting/ClassAndInterfacePHPDocFormattingSniff.php b/Magento2/Sniffs/Commenting/ClassAndInterfacePHPDocFormattingSniff.php index 8976d67f..e757fe5c 100644 --- a/Magento2/Sniffs/Commenting/ClassAndInterfacePHPDocFormattingSniff.php +++ b/Magento2/Sniffs/Commenting/ClassAndInterfacePHPDocFormattingSniff.php @@ -65,7 +65,7 @@ public function process(File $phpcsFile, $stackPtr) if ($this->PHPDocFormattingValidator->providesMeaning($namePtr, $commentStartPtr, $tokens) !== true) { $phpcsFile->addWarning( sprintf( - '%s description should contain additional information beyond the name already supplies.', + '%s description must contain meaningful information beyond what the class name provides or be removed.', ucfirst($tokens[$stackPtr]['content']) ), $stackPtr, From 8244534a62b8e1dc38622f904f47c6f6feac1369 Mon Sep 17 00:00:00 2001 From: Lena Orobei Date: Mon, 10 Feb 2020 11:08:20 -0600 Subject: [PATCH 053/630] Fixed confusing message --- .../Commenting/ClassAndInterfacePHPDocFormattingSniff.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Magento2/Sniffs/Commenting/ClassAndInterfacePHPDocFormattingSniff.php b/Magento2/Sniffs/Commenting/ClassAndInterfacePHPDocFormattingSniff.php index e757fe5c..48426a1a 100644 --- a/Magento2/Sniffs/Commenting/ClassAndInterfacePHPDocFormattingSniff.php +++ b/Magento2/Sniffs/Commenting/ClassAndInterfacePHPDocFormattingSniff.php @@ -65,7 +65,7 @@ public function process(File $phpcsFile, $stackPtr) if ($this->PHPDocFormattingValidator->providesMeaning($namePtr, $commentStartPtr, $tokens) !== true) { $phpcsFile->addWarning( sprintf( - '%s description must contain meaningful information beyond what the class name provides or be removed.', + '%s description must contain meaningful information beyond what its name provides or be removed.', ucfirst($tokens[$stackPtr]['content']) ), $stackPtr, From 2adeb479b06c86a41d32f05da2d8569df5379fff Mon Sep 17 00:00:00 2001 From: Lena Orobei Date: Fri, 20 Mar 2020 13:26:19 -0500 Subject: [PATCH 054/630] Added CODE_OF_CONDUCT.md and CONTRIBUTING.md --- .github/CODE_OF_CONDUCT.md | 46 ++++++++++++++++++++++++++++++++++++ .github/CONTRIBUTING.md | 48 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 94 insertions(+) create mode 100644 .github/CODE_OF_CONDUCT.md create mode 100644 .github/CONTRIBUTING.md diff --git a/.github/CODE_OF_CONDUCT.md b/.github/CODE_OF_CONDUCT.md new file mode 100644 index 00000000..8d5fa291 --- /dev/null +++ b/.github/CODE_OF_CONDUCT.md @@ -0,0 +1,46 @@ +# Contributor Covenant Code of Conduct + +## Our Pledge + +In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation. + +## Our Standards + +Examples of behavior that contributes to creating a positive environment include: + +* Using welcoming and inclusive language. +* Being respectful of differing viewpoints and experiences. +* Gracefully accepting constructive criticism. +* Focusing on what is best for the community. +* Showing empathy towards other community members. + +Examples of unacceptable behavior by participants include: + +* The use of sexualized language or imagery and unwelcome sexual attention or advances. +* Trolling, insulting/derogatory comments, and personal or political attacks. +* Public or private harassment. +* Publishing others' private information, such as a physical or electronic address, without explicit permission. +* Other conduct which could reasonably be considered inappropriate in a professional setting. + +## Our Responsibilities + +Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior. + +Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful. + +## Scope + +This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers. + +## Enforcement + +Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at engcom@magento.com. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately. + +Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership. + +## Attribution + +This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version]. + +[homepage]: http://contributor-covenant.org +[version]: http://contributor-covenant.org/version/1/4/ diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md new file mode 100644 index 00000000..630b827e --- /dev/null +++ b/.github/CONTRIBUTING.md @@ -0,0 +1,48 @@ +# Contributing to Magento Coding Standard code + +Contributions to the Magento Coding Standard codebase are done using the fork & pull model. +This contribution model has contributors maintaining their own fork of the Magento Coding Standard repository. +The forked repository is then used to submit a request to the base repository to “pull” a set of changes. +For more information on pull requests please refer to [GitHub Help](https://help.github.com/articles/about-pull-requests/). + +Contributions can take the form of new components or features, changes to existing features, tests, documentation (such as developer guides, user guides, examples, or specifications), bug fixes or optimizations. + +The Magento Coding Standard development team or community maintainers will review all issues and contributions submitted by the community of developers in the first in, first out order. +During the review we might require clarifications from the contributor. +If there is no response from the contributor within two weeks, the pull request will be closed. + +For more detailed information on contribution please read our [beginners guide](https://github.com/magento/magento2/wiki/Getting-Started). + +## Contribution requirements + +1. Contributions must adhere to the [Magento coding standards](https://devdocs.magento.com/guides/v2.3/coding-standards/bk-coding-standards.html). +2. Pull requests (PRs) must be accompanied by a meaningful description of their purpose. Comprehensive descriptions increase the chances of a pull request being merged quickly and without additional clarification requests. +3. Commits must be accompanied by meaningful commit messages. +4. PRs which include bug fixes must be accompanied with a step-by-step description of how to reproduce the bug. +3. PRs which include new logic or new rules must be submitted along with: +* Unit test coverage +* Proposed [documentation](https://devdocs.magento.com) updates. Documentation contributions can be submitted via the [devdocs GitHub](https://github.com/magento/devdocs). +4. For larger features or changes, please [open an issue](https://github.com/magento/magento-coding-standard/issues) to discuss the proposed changes prior to development. This may prevent duplicate or unnecessary effort and allow other contributors to provide input. +5. All automated tests must pass (all builds on [Travis CI](https://travis-ci.com/github/magento/magento-coding-standard) must be green). + +## Contribution process + +If you are a new GitHub user, we recommend that you create your own [free github account](https://github.com/signup/free). +This will allow you to collaborate with the Magento Coding Standard development team, fork the Magento Coding Standard project and send pull requests. + +1. Search current [listed issues](https://github.com/magento/magento-coding-standard/issues) (open or closed) for similar proposals of intended contribution before starting work on a new contribution. +2. Review the [Contributor License Agreement](https://magento.com/legaldocuments/mca) if this is your first time contributing. +3. Create and test your work. +4. Fork the Magento Coding Standard repository according to the [Fork A Repository instructions](https://devdocs.magento.com/guides/v2.3/contributor-guide/contributing.html#fork) and when you are ready to send us a pull request – follow the [Create A Pull Request instructions](https://devdocs.magento.com/guides/v2.3/contributor-guide/contributing.html#pull_request). +5. Once your contribution is received the Magento Coding Standard development team will review the contribution and collaborate with you as needed. + +## Code of Conduct + +Please note that this project is released with a Contributor Code of Conduct. We expect you to agree to its terms when participating in this project. +The full text is available in the repository [Wiki](https://github.com/magento/magento2/wiki/Magento-Code-of-Conduct). + +## Connecting with Community! + +If you have any questions, join us in [#beginners](https://magentocommeng.slack.com/messages/CH8BGFX9D) Slack chat. If you are not on our slack, [click here](http://tinyurl.com/engcom-slack) to join. + +Need to find a project? Check out the [Slack Channels](https://github.com/magento/magento2/wiki/Slack-Channels) (with listed project info) and the [Magento Community Portal](https://opensource.magento.com/). From f17991156d9c9b1cebb1eedc24d2a23aa0f931f8 Mon Sep 17 00:00:00 2001 From: Lena Orobei Date: Fri, 20 Mar 2020 14:04:37 -0500 Subject: [PATCH 055/630] Updated CLA link in the CONTRIBUTING.md --- .github/CONTRIBUTING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index 630b827e..36a99355 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -31,7 +31,7 @@ If you are a new GitHub user, we recommend that you create your own [free github This will allow you to collaborate with the Magento Coding Standard development team, fork the Magento Coding Standard project and send pull requests. 1. Search current [listed issues](https://github.com/magento/magento-coding-standard/issues) (open or closed) for similar proposals of intended contribution before starting work on a new contribution. -2. Review the [Contributor License Agreement](https://magento.com/legaldocuments/mca) if this is your first time contributing. +2. Review the [Contributor License Agreement](https://opensource.adobe.com/cla.html) if this is your first time contributing. 3. Create and test your work. 4. Fork the Magento Coding Standard repository according to the [Fork A Repository instructions](https://devdocs.magento.com/guides/v2.3/contributor-guide/contributing.html#fork) and when you are ready to send us a pull request – follow the [Create A Pull Request instructions](https://devdocs.magento.com/guides/v2.3/contributor-guide/contributing.html#pull_request). 5. Once your contribution is received the Magento Coding Standard development team will review the contribution and collaborate with you as needed. From bd837c51ce32693489036d797ae31033ce663381 Mon Sep 17 00:00:00 2001 From: Andrii Beziazychnyi Date: Sat, 4 Apr 2020 15:00:05 +0300 Subject: [PATCH 056/630] Fixed the discouraged functions --- .../Functions/DiscouragedFunctionSniff.php | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/Magento2/Sniffs/Functions/DiscouragedFunctionSniff.php b/Magento2/Sniffs/Functions/DiscouragedFunctionSniff.php index a5a583ac..e1db0341 100644 --- a/Magento2/Sniffs/Functions/DiscouragedFunctionSniff.php +++ b/Magento2/Sniffs/Functions/DiscouragedFunctionSniff.php @@ -58,17 +58,21 @@ class DiscouragedFunctionSniff extends ForbiddenFunctionsSniff '^dngettext$' => null, '^domxml_.*$' => null, '^fbsql_.*$' => null, + '^fbsql$' => null, '^fdf_add_doc_javascript$' => null, '^fdf_open$' => null, '^fopen$' => 'Magento\Framework\Filesystem\DriverInterface::fileOpen()', '^fclose$' => 'Magento\Framework\Filesystem\DriverInterface::fileClose()', - '^fsockopen$' => null, + '^fsockopen$' => 'Magento\Framework\Filesystem\Driver\Http::open()', '^ftp_.*$' => null, '^fwrite$' => 'Magento\Framework\Filesystem\DriverInterface::fileWrite()', - '^gettext$' => null, + '^fputs$' => 'Magento\Framework\Filesystem\DriverInterface::fileWrite()', + '^gettext$' => 'Magento\Framework\Translate\AdapterInterface::translate()', + '^_$' => 'Magento\Framework\Translate\AdapterInterface::translate()', '^gz.*$' => null, '^header$' => null, '^highlight_file$' => null, + '^show_source$' => null, '^ibase_.*$' => null, '^id3_set_tag$' => null, '^ifx_.*$' => null, @@ -88,6 +92,7 @@ class DiscouragedFunctionSniff extends ForbiddenFunctionsSniff '^msql_.*$' => null, '^mssql_.*$' => null, '^mysql_.*$' => null, + '^mysql.*$' => null, '^odbc_.*$' => null, '^opendir$' => null, '^openlog$' => null, @@ -119,9 +124,10 @@ class DiscouragedFunctionSniff extends ForbiddenFunctionsSniff '^session_.*$' => null, '^set_include_path$' => null, '^ini_set$' => null, + '^ini_alter$' => null, '^set_time_limit$' => null, '^setcookie$' => null, - '^setlocale$' => null, + '^setlocale$' => 'Magento\Framework\Translate\AdapterInterface::setlocale()', '^setrawcookie$' => null, '^sleep$' => null, '^socket_.*$' => null, @@ -135,7 +141,9 @@ class DiscouragedFunctionSniff extends ForbiddenFunctionsSniff '^vprintf$' => null, '^mysqli.*$' => null, '^oci_connect$' => null, + '^ocilogon$' => null, '^oci_pconnect$' => null, + '^ociplogon$' => null, '^quotemeta$' => null, '^sqlite_popen$' => null, '^time_nanosleep$' => null, @@ -168,6 +176,7 @@ class DiscouragedFunctionSniff extends ForbiddenFunctionsSniff '^ircg_nickname_unescape$' => null, '^ldap_get_values$' => null, '^mb_decode_mimeheader$' => null, + '^i18n_mime_header_decode$' => null, '^mb_parse_str$' => null, '^mcrypt_decrypt$' => null, '^mdecrypt_generic$' => null, @@ -201,7 +210,6 @@ class DiscouragedFunctionSniff extends ForbiddenFunctionsSniff '^stat$' => null, '^lchgrp$' => null, '^lchown$' => null, - '^show_source$' => null, '^is_dir$' => 'Magento\Framework\Filesystem\DriverInterface::isDirectory()', '^is_executable$' => null, '^is_file$' => 'Magento\Framework\Filesystem\DriverInterface::isFile()', From e4cbc97f5a041c79226981f212fd9788c60a6cb3 Mon Sep 17 00:00:00 2001 From: Sinisa Nedeljkovic Date: Sat, 4 Apr 2020 21:35:58 +0200 Subject: [PATCH 057/630] #147 - Fixed include / exclude patterns in ruleset.xml --- Magento2/ruleset.xml | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/Magento2/ruleset.xml b/Magento2/ruleset.xml index c4fc6580..96188ad7 100644 --- a/Magento2/ruleset.xml +++ b/Magento2/ruleset.xml @@ -13,7 +13,7 @@ 10 error - *.phtml + *\.phtml$ 10 @@ -76,7 +76,7 @@ error - *.phtml + *\.phtml$ 10 @@ -99,7 +99,7 @@ 10 error - *.phtml + *\.phtml$ 10 @@ -122,7 +122,7 @@ */tests/* - *.phtml + *\.phtml$ 9 warning @@ -207,7 +207,7 @@ warning - *.phtml + *\.phtml$ 8 warning @@ -302,7 +302,7 @@ 7 warning - *.phtml + *\.phtml$ 7 @@ -404,7 +404,7 @@ 6 warning - *.phtml + *\.phtml$ 6 @@ -483,7 +483,7 @@ - *.phtml + *\.phtml$ 6 @@ -533,7 +533,7 @@ 6 warning - *.phtml + *\.phtml$ 6 From 6a3f52f57df5c6227944e17d8342fd43b5153398 Mon Sep 17 00:00:00 2001 From: Sinisa Nedeljkovic Date: Sat, 4 Apr 2020 22:27:13 +0200 Subject: [PATCH 058/630] #162 Modified @deprecated validator to consider it valid if comment is absent but @see tag is set --- .../Helpers/Commenting/PHPDocFormattingValidator.php | 9 +++++++-- .../ClassAndInterfacePHPDocFormattingUnitTest.1.inc | 9 +++++++++ .../Commenting/ConstantsPHPDocFormattingUnitTest.1.inc | 6 ++++++ 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/Magento2/Helpers/Commenting/PHPDocFormattingValidator.php b/Magento2/Helpers/Commenting/PHPDocFormattingValidator.php index 9b462e36..74ff72ab 100644 --- a/Magento2/Helpers/Commenting/PHPDocFormattingValidator.php +++ b/Magento2/Helpers/Commenting/PHPDocFormattingValidator.php @@ -122,13 +122,18 @@ public function hasDeprecatedWellFormatted($commentStartPtr, $tokens) return true; } + $seeTagRequired = false; if ($tokens[$deprecatedPtr + 2]['code'] !== T_DOC_COMMENT_STRING) { - return false; + $seeTagRequired = true; } $seePtr = $this->getTagPosition('@see', $commentStartPtr, $tokens); if ($seePtr === -1) { - return true; + if ($seeTagRequired) { + return false; + } else { + return true; + } } if ($tokens[$seePtr + 2]['code'] !== T_DOC_COMMENT_STRING) { return false; diff --git a/Magento2/Tests/Commenting/ClassAndInterfacePHPDocFormattingUnitTest.1.inc b/Magento2/Tests/Commenting/ClassAndInterfacePHPDocFormattingUnitTest.1.inc index 14ba369a..e5895e32 100644 --- a/Magento2/Tests/Commenting/ClassAndInterfacePHPDocFormattingUnitTest.1.inc +++ b/Magento2/Tests/Commenting/ClassAndInterfacePHPDocFormattingUnitTest.1.inc @@ -153,3 +153,12 @@ class DoNotCareHandler { } + +/** + * @deprecated + * @see Magento\Framework\NewHandler + */ +class OldHandler +{ + +} diff --git a/Magento2/Tests/Commenting/ConstantsPHPDocFormattingUnitTest.1.inc b/Magento2/Tests/Commenting/ConstantsPHPDocFormattingUnitTest.1.inc index 05dfdb52..6e0b16f0 100644 --- a/Magento2/Tests/Commenting/ConstantsPHPDocFormattingUnitTest.1.inc +++ b/Magento2/Tests/Commenting/ConstantsPHPDocFormattingUnitTest.1.inc @@ -38,6 +38,12 @@ class Profiler */ const COMPUTER = 'Deep Thought'; + /** + * @deprecated + * @see \ComputationalMatrix\Mars + */ + const KEYBOARD = 'Ergonomic'; + /** * @see */ From 080046c85e5c32648df661d760850f7d62c9bb56 Mon Sep 17 00:00:00 2001 From: sergey-nechaev Date: Sat, 25 Apr 2020 22:50:22 +0500 Subject: [PATCH 059/630] README fixes - typos, layout, markdown, urls --- README.md | 92 +++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 58 insertions(+), 34 deletions(-) diff --git a/README.md b/README.md index dfc6e391..5150e045 100644 --- a/README.md +++ b/README.md @@ -2,14 +2,18 @@ A set of Magento rules for [PHP_CodeSniffer](https://github.com/squizlabs/PHP_CodeSniffer) tool. -#### Installation within a Magento 2 site +## Installation within a Magento 2 site + To use within your Magento 2 project you can use: -```` + +```bash composer require --dev magento/magento-coding-standard -```` +``` + Due to security, when installed this way the Magento standard for phpcs cannot be added automatically. You can achieve this by adding the following to your project's `composer.json`: -```` + +```json "scripts": { "post-install-cmd": [ "([ $COMPOSER_DEV_MODE -eq 0 ] || vendor/bin/phpcs --config-set installed_paths ../../magento/magento-coding-standard/)" @@ -18,65 +22,85 @@ You can achieve this by adding the following to your project's `composer.json`: "([ $COMPOSER_DEV_MODE -eq 0 ] || vendor/bin/phpcs --config-set installed_paths ../../magento/magento-coding-standard/)" ] } -```` +``` ### Installation for development -You can install Magento Coding Standard by cloning this GitHub repo -``` -$ git clone git@github.com:magento/magento-coding-standard.git -$ cd magento-coding-standard -$ composer install + +You can install Magento Coding Standard by cloning this GitHub repo: + +```bash +git clone git@github.com:magento/magento-coding-standard.git +cd magento-coding-standard +composer install ``` + It is possible also to install a standalone application via [Composer](https://getcomposer.org) -``` -$ composer create-project magento/magento-coding-standard --stability=dev magento-coding-standard + +```bash +composer create-project magento/magento-coding-standard --stability=dev magento-coding-standard ``` -#### Verify installation +### Verify installation + Command should return the list of installed coding standards including Magento2. + +```bash +vendor/bin/phpcs -i ``` -$ vendor/bin/phpcs -i -``` -### Usage -Once installed, you can run `phpcs` from the command-line to analyse your code `MyAwesomeExtension` -``` -$ vendor/bin/phpcs --standard=Magento2 app/code/MyAwesomeExtension + +## Usage + +Once installed, you can run `phpcs` from the command-line to analyze your code `MyAwesomeExtension` + +```bash +vendor/bin/phpcs --standard=Magento2 app/code/MyAwesomeExtension ``` ### Fixing issues automatically -Also you can run `phpcbf` from the command-line to fix your code `MyAwesomeExtension` for warnings like - "PHPCBF CAN FIX THE [0-9]+ MARKED SNIFF VIOLATIONS AUTOMATICALLY" + +Also, you can run `phpcbf` from the command-line to fix your code `MyAwesomeExtension` for warnings like "PHPCBF CAN FIX THE [0-9]+ MARKED SNIFF VIOLATIONS AUTOMATICALLY" + +```bash +vendor/bin/phpcbf --standard=Magento2 app/code/MyAwesomeExtension ``` -$ vendor/bin/phpcbf --standard=Magento2 app/code/MyAwesomeExtension -``` - -## Where to contribute + +## Contribution + +See the community [contribution model](https://github.com/magento/magento-coding-standard/blob/develop/.github/CONTRIBUTING.md). + +### Where to contribute + - Documentation of existing rules. See [ExtDN PHP CodeSniffer rules for Magento 2](https://github.com/extdn/extdn-phpcs) as a good example. - Bug fixes and improvements of existing rules. - Creation of new PHP CodeSniffer rules. - Discussions on new rules (through periodic hangouts or discussions per GitHub issue). -## How to contribute +### How to contribute + 1) Start with looking into [Community Dashboard](https://github.com/magento/magento-coding-standard/projects/1). Any ticket in `Up for grabs` is a good candidate to start. 2) Didn't satisfy your requirements? [Create one of three types of issues](https://github.com/magento/magento-coding-standard/issues/new/choose): - **Bug report** - Found a bug in the code? Let us know! - **Existing rule enhancement** - Know how to improve existing rules? Open an issue describe how to enhance Magento Coding Standard. - **New rule proposal** - Know how to improve Magento ecosystem code quality? Do not hesitate to open a proposal. -3) The issue will appear in the `Backlog` column of the [Community Dashboard](https://github.com/magento/magento-coding-standard/projects/1). Once it will be discussed and get `Accepted` label the issue will appear in the `Up for grabs` column. +3) The issue will appear in the `Backlog` column of the [Community Dashboard](https://github.com/magento/magento-coding-standard/projects/1). Once it will be discussed and get `accepted` label the issue will appear in the `Up for grabs` column. ## Testing -All rules should be covered by unit tests. Each `Test.php` class should be accompanied by a `Test.inc` file to allow for unit testing based upon the PHP CodeSniffer parent class `AbstractSniffUnitTest`. + +All rules should be covered by unit tests. Each `Test.php` class should be accompanied by a `Test.inc` file to allow for unit testing based upon the PHP_CodeSniffer parent class `AbstractSniffUnitTest`. You can verify your code by running -``` -$ vendor/bin/phpunit + +```bash +vendor/bin/phpunit ``` Also, verify that the sniffer code itself is written according to the Magento Coding Standard: -``` -$ vendor/bin/phpcs --standard=Magento2 Magento2/ --extensions=php + +```bash +vendor/bin/phpcs --standard=Magento2 Magento2/ --extensions=php ``` ## License -Each Magento source file included in this distribution is licensed under OSL-3.0 license. -Please see [LICENSE.txt](https://github.com/magento/magento-coding-standard/blob/master/LICENSE.txt) for the full text of the [Open Software License v. 3.0 (OSL-3.0)](http://opensource.org/licenses/osl-3.0.php). +Each Magento source file included in this distribution is licensed under the OSL-3.0 license. + +Please see [LICENSE.txt](https://github.com/magento/magento-coding-standard/blob/master/LICENSE.txt) for the full text of the [Open Software License v. 3.0 (OSL-3.0)](https://opensource.org/licenses/osl-3.0.php). From c6bc189ebf7dbc063e52df3408678c363afd94d4 Mon Sep 17 00:00:00 2001 From: Sinisa Nedeljkovic Date: Tue, 28 Apr 2020 21:56:19 +0200 Subject: [PATCH 060/630] #162 Reduced code around IF condition on seeTagRequired variable --- Magento2/Helpers/Commenting/PHPDocFormattingValidator.php | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/Magento2/Helpers/Commenting/PHPDocFormattingValidator.php b/Magento2/Helpers/Commenting/PHPDocFormattingValidator.php index 74ff72ab..a656051c 100644 --- a/Magento2/Helpers/Commenting/PHPDocFormattingValidator.php +++ b/Magento2/Helpers/Commenting/PHPDocFormattingValidator.php @@ -129,11 +129,7 @@ public function hasDeprecatedWellFormatted($commentStartPtr, $tokens) $seePtr = $this->getTagPosition('@see', $commentStartPtr, $tokens); if ($seePtr === -1) { - if ($seeTagRequired) { - return false; - } else { - return true; - } + return !$seeTagRequired; } if ($tokens[$seePtr + 2]['code'] !== T_DOC_COMMENT_STRING) { return false; From 466aecfca171d93194f6733a3af3f28cafa53cdf Mon Sep 17 00:00:00 2001 From: Fabian Schmengler Date: Thu, 7 May 2020 11:11:32 +0200 Subject: [PATCH 061/630] Suggest \Magento\Framework\Shell::execute as alternative to exec --- Magento2/Sniffs/Security/InsecureFunctionSniff.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Magento2/Sniffs/Security/InsecureFunctionSniff.php b/Magento2/Sniffs/Security/InsecureFunctionSniff.php index 16c69030..b5253193 100644 --- a/Magento2/Sniffs/Security/InsecureFunctionSniff.php +++ b/Magento2/Sniffs/Security/InsecureFunctionSniff.php @@ -20,7 +20,7 @@ class InsecureFunctionSniff extends ForbiddenFunctionsSniff public $forbiddenFunctions = [ 'assert' => null, 'create_function' => null, - 'exec' => null, + 'exec' => '\Magento\Framework\Shell::execute', 'md5' => 'improved hash functions (SHA-256, SHA-512 etc.)', 'passthru' => null, 'pcntl_exec' => null, From 1d380aa40c92491d2c0b751aa3211f1e0c99ccb0 Mon Sep 17 00:00:00 2001 From: milindsingh Date: Sun, 24 May 2020 00:03:32 +0530 Subject: [PATCH 062/630] Added sniff for deprecated model methods. #187 --- .../Methods/DeprecatedModelMethodSniff.php | 79 +++++++++++++++++++ .../Methods/DeprecatedModelMethodUnitTest.inc | 4 + .../Methods/DeprecatedModelMethodUnitTest.php | 31 ++++++++ Magento2/ruleset.xml | 4 + 4 files changed, 118 insertions(+) create mode 100644 Magento2/Sniffs/Methods/DeprecatedModelMethodSniff.php create mode 100644 Magento2/Tests/Methods/DeprecatedModelMethodUnitTest.inc create mode 100644 Magento2/Tests/Methods/DeprecatedModelMethodUnitTest.php diff --git a/Magento2/Sniffs/Methods/DeprecatedModelMethodSniff.php b/Magento2/Sniffs/Methods/DeprecatedModelMethodSniff.php new file mode 100644 index 00000000..08ee94d3 --- /dev/null +++ b/Magento2/Sniffs/Methods/DeprecatedModelMethodSniff.php @@ -0,0 +1,79 @@ +getTokens(); + $methodPosition = $phpcsFile->findNext(T_STRING, $stackPtr + 1); + + if ($methodPosition !== false && + in_array($tokens[$methodPosition]['content'], $this->methods) + ) { + $resourcePosition = $phpcsFile->findPrevious([T_STRING, T_VARIABLE], $stackPtr - 1); + if ($resourcePosition !== false) { + $methodName = $tokens[$resourcePosition]['content']; + if ($methodName === "getResource") { + $phpcsFile->addWarning( + sprintf($this->warningMessage, $tokens[$methodPosition]['content']), + $stackPtr, + $this->warningCode + ); + } + } + } + } +} diff --git a/Magento2/Tests/Methods/DeprecatedModelMethodUnitTest.inc b/Magento2/Tests/Methods/DeprecatedModelMethodUnitTest.inc new file mode 100644 index 00000000..e81954f3 --- /dev/null +++ b/Magento2/Tests/Methods/DeprecatedModelMethodUnitTest.inc @@ -0,0 +1,4 @@ +getResource()->save(); +$model->getResource()->load(); +$model->getResource()->delete(); \ No newline at end of file diff --git a/Magento2/Tests/Methods/DeprecatedModelMethodUnitTest.php b/Magento2/Tests/Methods/DeprecatedModelMethodUnitTest.php new file mode 100644 index 00000000..024c660a --- /dev/null +++ b/Magento2/Tests/Methods/DeprecatedModelMethodUnitTest.php @@ -0,0 +1,31 @@ + 1, + 3 => 1, + 4 => 1 + ]; + } +} diff --git a/Magento2/ruleset.xml b/Magento2/ruleset.xml index 96188ad7..0a0bed7b 100644 --- a/Magento2/ruleset.xml +++ b/Magento2/ruleset.xml @@ -215,6 +215,10 @@ 8 warning + + 8 + warning + From a5b372313356548e2e9183fabd7d3285e6e3182b Mon Sep 17 00:00:00 2001 From: milindsingh Date: Wed, 27 May 2020 09:52:22 +0530 Subject: [PATCH 063/630] code review fixes --- .../Methods/DeprecatedModelMethodSniff.php | 36 ++++++++++--------- .../Methods/DeprecatedModelMethodUnitTest.inc | 9 +++-- .../Methods/DeprecatedModelMethodUnitTest.php | 4 +-- 3 files changed, 27 insertions(+), 22 deletions(-) diff --git a/Magento2/Sniffs/Methods/DeprecatedModelMethodSniff.php b/Magento2/Sniffs/Methods/DeprecatedModelMethodSniff.php index 08ee94d3..283d74ad 100644 --- a/Magento2/Sniffs/Methods/DeprecatedModelMethodSniff.php +++ b/Magento2/Sniffs/Methods/DeprecatedModelMethodSniff.php @@ -14,6 +14,8 @@ */ class DeprecatedModelMethodSniff implements Sniff { + const RESOURCE_METHOD = "getResource"; + /** * String representation of warning. * @@ -48,8 +50,7 @@ class DeprecatedModelMethodSniff implements Sniff public function register() { return [ - T_OBJECT_OPERATOR, - T_DOUBLE_COLON + T_OBJECT_OPERATOR ]; } /** @@ -58,21 +59,22 @@ public function register() public function process(File $phpcsFile, $stackPtr) { $tokens = $phpcsFile->getTokens(); - $methodPosition = $phpcsFile->findNext(T_STRING, $stackPtr + 1); - - if ($methodPosition !== false && - in_array($tokens[$methodPosition]['content'], $this->methods) - ) { - $resourcePosition = $phpcsFile->findPrevious([T_STRING, T_VARIABLE], $stackPtr - 1); - if ($resourcePosition !== false) { - $methodName = $tokens[$resourcePosition]['content']; - if ($methodName === "getResource") { - $phpcsFile->addWarning( - sprintf($this->warningMessage, $tokens[$methodPosition]['content']), - $stackPtr, - $this->warningCode - ); - } + $endOfStatement = $phpcsFile->findEndOfStatement($stackPtr); + $resourcePosition = $phpcsFile->findNext( + T_STRING, + $stackPtr + 1, + $endOfStatement, + false, + self::RESOURCE_METHOD + ); + if ($resourcePosition !== false) { + $methodPosition = $phpcsFile->findNext([T_STRING, T_VARIABLE], $resourcePosition + 1, $endOfStatement); + if ($methodPosition !== false && in_array($tokens[$methodPosition]['content'], $this->methods)) { + $phpcsFile->addWarning( + sprintf($this->warningMessage, $tokens[$methodPosition]['content']), + $stackPtr, + $this->warningCode + ); } } } diff --git a/Magento2/Tests/Methods/DeprecatedModelMethodUnitTest.inc b/Magento2/Tests/Methods/DeprecatedModelMethodUnitTest.inc index e81954f3..322df84c 100644 --- a/Magento2/Tests/Methods/DeprecatedModelMethodUnitTest.inc +++ b/Magento2/Tests/Methods/DeprecatedModelMethodUnitTest.inc @@ -1,4 +1,7 @@ getResource()->save(); -$model->getResource()->load(); -$model->getResource()->delete(); \ No newline at end of file + +$model->getResource()->save($model); + +$model->getResource()->load($model, $id); + +$model->getResource()->delete($model); diff --git a/Magento2/Tests/Methods/DeprecatedModelMethodUnitTest.php b/Magento2/Tests/Methods/DeprecatedModelMethodUnitTest.php index 024c660a..43d88dd3 100644 --- a/Magento2/Tests/Methods/DeprecatedModelMethodUnitTest.php +++ b/Magento2/Tests/Methods/DeprecatedModelMethodUnitTest.php @@ -23,9 +23,9 @@ public function getErrorList() public function getWarningList() { return [ - 2 => 1, 3 => 1, - 4 => 1 + 5 => 1, + 7 => 1, ]; } } From eb170637dc659f38095f0232dc6b1c5b98e1f445 Mon Sep 17 00:00:00 2001 From: Ihor Sviziev Date: Mon, 17 Aug 2020 15:45:43 +0300 Subject: [PATCH 064/630] Added sniff for deprecated model methods Add few negative cases --- Magento2/Tests/Methods/DeprecatedModelMethodUnitTest.inc | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Magento2/Tests/Methods/DeprecatedModelMethodUnitTest.inc b/Magento2/Tests/Methods/DeprecatedModelMethodUnitTest.inc index 322df84c..38e7a817 100644 --- a/Magento2/Tests/Methods/DeprecatedModelMethodUnitTest.inc +++ b/Magento2/Tests/Methods/DeprecatedModelMethodUnitTest.inc @@ -5,3 +5,9 @@ $model->getResource()->save($model); $model->getResource()->load($model, $id); $model->getResource()->delete($model); + +$model->getResource()->myCustomMethod(); + +$model->myCustomMethod(); + +$model->anotherMethodWithResource()->save($model); From dd9dd328f17f092dda302f3defd45cf80efb9467 Mon Sep 17 00:00:00 2001 From: Ihor Sviziev Date: Mon, 17 Aug 2020 15:48:09 +0300 Subject: [PATCH 065/630] Run tests on php 7.4 --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 0de98557..5db8871f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,6 +5,7 @@ php: - 7.1 - 7.2 - 7.3 + - 7.4 install: composer install --no-interaction --prefer-source script: - vendor/bin/phpunit From 902b134d4911ac2e29541b5521f4219b898d8cd1 Mon Sep 17 00:00:00 2001 From: Lena Orobei Date: Mon, 17 Aug 2020 15:10:46 -0500 Subject: [PATCH 066/630] magento/magento-coding-standard#187: Added sniff for deprecated model methods - minor fixes --- Magento2/Sniffs/Methods/DeprecatedModelMethodSniff.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/Magento2/Sniffs/Methods/DeprecatedModelMethodSniff.php b/Magento2/Sniffs/Methods/DeprecatedModelMethodSniff.php index 283d74ad..94bfc2d5 100644 --- a/Magento2/Sniffs/Methods/DeprecatedModelMethodSniff.php +++ b/Magento2/Sniffs/Methods/DeprecatedModelMethodSniff.php @@ -7,7 +7,6 @@ use PHP_CodeSniffer\Sniffs\Sniff; use PHP_CodeSniffer\Files\File; -use PHP_CodeSniffer\Util\Tokens; /** * Detects possible use of deprecated model methods. @@ -21,8 +20,7 @@ class DeprecatedModelMethodSniff implements Sniff * * @var string */ - protected $warningMessage = "Possible use of the deprecated model method 'getResource()'" . - " to '%s' the data detected."; + protected $warningMessage = "The use of the deprecated method 'getResource()' to '%s' the data detected."; /** * Warning violation code. @@ -69,7 +67,7 @@ public function process(File $phpcsFile, $stackPtr) ); if ($resourcePosition !== false) { $methodPosition = $phpcsFile->findNext([T_STRING, T_VARIABLE], $resourcePosition + 1, $endOfStatement); - if ($methodPosition !== false && in_array($tokens[$methodPosition]['content'], $this->methods)) { + if ($methodPosition !== false && in_array($tokens[$methodPosition]['content'], $this->methods, true)) { $phpcsFile->addWarning( sprintf($this->warningMessage, $tokens[$methodPosition]['content']), $stackPtr, From b35e3a4527112c6b8caeae60ee66a86a06331f76 Mon Sep 17 00:00:00 2001 From: Lena Orobei Date: Mon, 17 Aug 2020 16:29:30 -0500 Subject: [PATCH 067/630] magento/magento-coding-standard#191: PHP 7.4 compatibility - update PHP_CodeSniffer version --- composer.json | 2 +- composer.lock | 16 +++++++++------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/composer.json b/composer.json index 2c9a1844..a700503a 100644 --- a/composer.json +++ b/composer.json @@ -9,7 +9,7 @@ "version": "5", "require": { "php": ">=5.6.0", - "squizlabs/php_codesniffer": "^3.4", + "squizlabs/php_codesniffer": "^3.5", "webonyx/graphql-php": ">=0.12.6 <1.0" }, "require-dev": { diff --git a/composer.lock b/composer.lock index 34b78adc..8a7111b9 100644 --- a/composer.lock +++ b/composer.lock @@ -4,20 +4,20 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "de90fd51a20a688a7385615a0fd7d86e", + "content-hash": "45be18e23c6041ce36bc5d0ffb9c85d6", "packages": [ { "name": "squizlabs/php_codesniffer", - "version": "3.4.2", + "version": "3.5.6", "source": { "type": "git", "url": "https://github.com/squizlabs/PHP_CodeSniffer.git", - "reference": "b8a7362af1cc1aadb5bd36c3defc4dda2cf5f0a8" + "reference": "e97627871a7eab2f70e59166072a6b767d5834e0" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/squizlabs/PHP_CodeSniffer/zipball/b8a7362af1cc1aadb5bd36c3defc4dda2cf5f0a8", - "reference": "b8a7362af1cc1aadb5bd36c3defc4dda2cf5f0a8", + "url": "https://api.github.com/repos/squizlabs/PHP_CodeSniffer/zipball/e97627871a7eab2f70e59166072a6b767d5834e0", + "reference": "e97627871a7eab2f70e59166072a6b767d5834e0", "shasum": "" }, "require": { @@ -55,7 +55,7 @@ "phpcs", "standards" ], - "time": "2019-04-10T23:49:02+00:00" + "time": "2020-08-10T04:50:15+00:00" }, { "name": "webonyx/graphql-php", @@ -659,6 +659,7 @@ "keywords": [ "tokenizer" ], + "abandoned": true, "time": "2017-12-04T08:55:13+00:00" }, { @@ -1492,5 +1493,6 @@ "platform": { "php": ">=5.6.0" }, - "platform-dev": [] + "platform-dev": [], + "plugin-api-version": "1.1.0" } From 1f62186588909bab53a4d02c6c9ba0c4d3d7dffe Mon Sep 17 00:00:00 2001 From: Ihor Sviziev Date: Tue, 18 Aug 2020 07:11:59 +0300 Subject: [PATCH 068/630] Speed up composer install on travis --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 5db8871f..10321df9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,7 +6,7 @@ php: - 7.2 - 7.3 - 7.4 -install: composer install --no-interaction --prefer-source +install: composer install --no-interaction --prefer-dist script: - vendor/bin/phpunit - vendor/bin/phpcs --standard=Magento2 Magento2/ --extensions=php From aee022ffa2e7fe9573f756fba2a3ce5beeecc90b Mon Sep 17 00:00:00 2001 From: Ihor Sviziev Date: Tue, 18 Aug 2020 07:19:15 +0300 Subject: [PATCH 069/630] Speed up composer install on travis Add caching between builds --- .travis.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.travis.yml b/.travis.yml index 10321df9..ea3eb825 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,6 +6,9 @@ php: - 7.2 - 7.3 - 7.4 +cache: + directories: + - $HOME/.composer/cache/files install: composer install --no-interaction --prefer-dist script: - vendor/bin/phpunit From 4bd41131fbb5771c9abf2a28199ff253b56d1622 Mon Sep 17 00:00:00 2001 From: Lena Orobei Date: Wed, 2 Sep 2020 15:46:15 -0500 Subject: [PATCH 070/630] magento/magento-coding-standard#162: @deprecated without @see tag false positive - simplified logic --- Magento2/Helpers/Commenting/PHPDocFormattingValidator.php | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/Magento2/Helpers/Commenting/PHPDocFormattingValidator.php b/Magento2/Helpers/Commenting/PHPDocFormattingValidator.php index a656051c..fb98db7c 100644 --- a/Magento2/Helpers/Commenting/PHPDocFormattingValidator.php +++ b/Magento2/Helpers/Commenting/PHPDocFormattingValidator.php @@ -126,16 +126,11 @@ public function hasDeprecatedWellFormatted($commentStartPtr, $tokens) if ($tokens[$deprecatedPtr + 2]['code'] !== T_DOC_COMMENT_STRING) { $seeTagRequired = true; } - $seePtr = $this->getTagPosition('@see', $commentStartPtr, $tokens); if ($seePtr === -1) { return !$seeTagRequired; } - if ($tokens[$seePtr + 2]['code'] !== T_DOC_COMMENT_STRING) { - return false; - } - - return true; + return $tokens[$seePtr + 2]['code'] === T_DOC_COMMENT_STRING; } /** From 30ed54ffbf7c2f908e16ef1b8b2b3833e09dc85f Mon Sep 17 00:00:00 2001 From: Ihor Sviziev Date: Fri, 11 Sep 2020 15:42:29 +0300 Subject: [PATCH 071/630] Better solution for fixing array_merge in loop --- Magento2/Sniffs/Performance/ForeachArrayMergeSniff.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Magento2/Sniffs/Performance/ForeachArrayMergeSniff.md b/Magento2/Sniffs/Performance/ForeachArrayMergeSniff.md index 90bc6211..55f6969c 100644 --- a/Magento2/Sniffs/Performance/ForeachArrayMergeSniff.md +++ b/Magento2/Sniffs/Performance/ForeachArrayMergeSniff.md @@ -15,12 +15,11 @@ Typical example when `array_merge` is being used in the loop: In order to reduce execution time `array_merge` can be called only once: ``` php - $options = [[]]; + $options = []; foreach ($configurationSources as $source) { // code here $options[] = $source->getOptions(); } - // PHP 5.6+ - $options = array_merge(...$options); + $options = array_merge([], ...$options); ``` From 94c155c24db0cea187707bf2de85bb5883793aca Mon Sep 17 00:00:00 2001 From: Oleh Posyniak Date: Thu, 12 Nov 2020 10:25:32 -0600 Subject: [PATCH 072/630] MC-38508: Add static checks for PHP FS calls --- Magento2/Sniffs/Functions/DiscouragedFunctionSniff.php | 1 + 1 file changed, 1 insertion(+) diff --git a/Magento2/Sniffs/Functions/DiscouragedFunctionSniff.php b/Magento2/Sniffs/Functions/DiscouragedFunctionSniff.php index e1db0341..bced9283 100644 --- a/Magento2/Sniffs/Functions/DiscouragedFunctionSniff.php +++ b/Magento2/Sniffs/Functions/DiscouragedFunctionSniff.php @@ -228,5 +228,6 @@ class DiscouragedFunctionSniff extends ForbiddenFunctionsSniff '^intval$' => '(int) construction', '^strval$' => '(string) construction', '^htmlspecialchars$' => '\Magento\Framework\Escaper->escapeHtml', + 'getimagesize' => 'getimagesizefromstring', ]; } From 7959427e0a6f81150c5082610179831f48c4b0bd Mon Sep 17 00:00:00 2001 From: Oleh Posyniak Date: Thu, 19 Nov 2020 09:56:30 -0600 Subject: [PATCH 073/630] MC-38508: Add static checks for PHP FS calls --- Magento2/Sniffs/Functions/DiscouragedFunctionSniff.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Magento2/Sniffs/Functions/DiscouragedFunctionSniff.php b/Magento2/Sniffs/Functions/DiscouragedFunctionSniff.php index bced9283..55001802 100644 --- a/Magento2/Sniffs/Functions/DiscouragedFunctionSniff.php +++ b/Magento2/Sniffs/Functions/DiscouragedFunctionSniff.php @@ -228,6 +228,6 @@ class DiscouragedFunctionSniff extends ForbiddenFunctionsSniff '^intval$' => '(int) construction', '^strval$' => '(string) construction', '^htmlspecialchars$' => '\Magento\Framework\Escaper->escapeHtml', - 'getimagesize' => 'getimagesizefromstring', + '^getimagesize$' => 'getimagesizefromstring', ]; } From dc1e4b330ad2d47d4d0d9c394c56ffef2dd4ba0b Mon Sep 17 00:00:00 2001 From: Oleh Posyniak Date: Mon, 30 Nov 2020 15:55:50 -0600 Subject: [PATCH 074/630] MC-38508: Add static checks for PHP FS calls --- Magento2/Sniffs/Functions/DiscouragedFunctionSniff.md | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 Magento2/Sniffs/Functions/DiscouragedFunctionSniff.md diff --git a/Magento2/Sniffs/Functions/DiscouragedFunctionSniff.md b/Magento2/Sniffs/Functions/DiscouragedFunctionSniff.md new file mode 100644 index 00000000..603d7def --- /dev/null +++ b/Magento2/Sniffs/Functions/DiscouragedFunctionSniff.md @@ -0,0 +1,11 @@ +# Rule: getimagesize() is discouraged + +## Reason + +[getimagesize()](https://www.php.net/manual/en/function.getimagesize.php) function works only with local and supported streams. +With introduction of more advanced storages, like AWS S3 or Azure Blob Storage this function will cause issues where file is not accessible. + +## How to fix + +[getimagesizefromstring](https://www.php.net/manual/en/function.getimagesizefromstring.php) can be used instead to retrieve all the information from file. +This function works with data strings, so you should read the file content using specific adapter before using it. From 98e9fffb693c0a072f0bc19c1f7e700295652029 Mon Sep 17 00:00:00 2001 From: Oleh Posyniak Date: Tue, 1 Dec 2020 09:49:54 -0600 Subject: [PATCH 075/630] MC-38508: Add static checks for PHP FS calls --- Magento2/Sniffs/Functions/DiscouragedFunctionSniff.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Magento2/Sniffs/Functions/DiscouragedFunctionSniff.md b/Magento2/Sniffs/Functions/DiscouragedFunctionSniff.md index 603d7def..ceb49e4c 100644 --- a/Magento2/Sniffs/Functions/DiscouragedFunctionSniff.md +++ b/Magento2/Sniffs/Functions/DiscouragedFunctionSniff.md @@ -2,7 +2,7 @@ ## Reason -[getimagesize()](https://www.php.net/manual/en/function.getimagesize.php) function works only with local and supported streams. +[getimagesize](https://www.php.net/manual/en/function.getimagesize.php) function works only with local and supported streams. With introduction of more advanced storages, like AWS S3 or Azure Blob Storage this function will cause issues where file is not accessible. ## How to fix From d25936146cecf68baff394a85dadd4a28751258d Mon Sep 17 00:00:00 2001 From: Sergii Ivashchenko Date: Thu, 3 Dec 2020 14:25:15 +0000 Subject: [PATCH 076/630] Version 6 --- composer.json | 2 +- composer.lock | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index a700503a..bdc7b5be 100644 --- a/composer.json +++ b/composer.json @@ -6,7 +6,7 @@ "AFL-3.0" ], "type": "phpcodesniffer-standard", - "version": "5", + "version": "6", "require": { "php": ">=5.6.0", "squizlabs/php_codesniffer": "^3.5", diff --git a/composer.lock b/composer.lock index 8a7111b9..fa66436c 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": "45be18e23c6041ce36bc5d0ffb9c85d6", + "content-hash": "3384f4bb74dc1b1c36fa3c7cc697a28b", "packages": [ { "name": "squizlabs/php_codesniffer", From 5e9eb9fc83912e39c668b0a676dddf0f09640132 Mon Sep 17 00:00:00 2001 From: Dan Wallis Date: Wed, 3 Feb 2021 00:01:24 +0000 Subject: [PATCH 077/630] Avoid infinite loop when Parse Error occurs --- Magento2/Sniffs/Security/XssTemplateSniff.php | 6 ++++-- Magento2/Tests/Security/XssTemplateUnitTest.inc | 3 +++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/Magento2/Sniffs/Security/XssTemplateSniff.php b/Magento2/Sniffs/Security/XssTemplateSniff.php index aa2accbe..43bdfecc 100644 --- a/Magento2/Sniffs/Security/XssTemplateSniff.php +++ b/Magento2/Sniffs/Security/XssTemplateSniff.php @@ -249,8 +249,10 @@ private function parseLineStatement($start, $end) $posOfLastInlineThen = $this->findLastInScope(T_INLINE_THEN, $start, $end); if ($posOfLastInlineThen !== false) { $posOfInlineElse = $this->file->findNext(T_INLINE_ELSE, $posOfLastInlineThen, $end); - $this->addStatement($posOfLastInlineThen + 1, $posOfInlineElse); - $this->addStatement($posOfInlineElse + 1, $end); + if ($posOfInlineElse !== false) { + $this->addStatement($posOfLastInlineThen + 1, $posOfInlineElse); + $this->addStatement($posOfInlineElse + 1, $end); + } $parsed = true; } else { do { diff --git a/Magento2/Tests/Security/XssTemplateUnitTest.inc b/Magento2/Tests/Security/XssTemplateUnitTest.inc index eefb2c70..6a9f225d 100644 --- a/Magento2/Tests/Security/XssTemplateUnitTest.inc +++ b/Magento2/Tests/Security/XssTemplateUnitTest.inc @@ -57,3 +57,6 @@ echo $var; escapeCss($css); ?> getJsLayout($jsLayout); ?> + + +escapeUrl($block->getUrl('no-route')) getBaseUrl() ?> From 437f8f3e2dad835edf4738c3c2f26238017f0095 Mon Sep 17 00:00:00 2001 From: Dan Wallis Date: Mon, 24 May 2021 16:21:00 +0100 Subject: [PATCH 078/630] Fix PHP TypeError Fatal error: Uncaught TypeError: vsprintf(): Argument #2 ($values) must be of type array, int given in /srv/www/vendor/squizlabs/php_codesniffer/src/Files/File.php:1056 Stack trace: #0 /srv/www/vendor/squizlabs/php_codesniffer/src/Files/File.php(1056): vsprintf('Direct throw of...', 531) #1 /srv/www/vendor/squizlabs/php_codesniffer/src/Files/File.php(706): PHP_CodeSniffer\Files\File->addMessage(false, 'Direct throw of...', 67, 4, 'FoundDirectThro...', 531, 8, false) #2 /srv/www/vendor/magento/magento-coding-standard/Magento2/Sniffs/Exceptions/DirectThrowSniff.php(48): PHP_CodeSniffer\Files\File->addWarning('Direct throw of...', 526, 'FoundDirectThro...', 531) #3 /srv/www/vendor/squizlabs/php_codesniffer/src/Files/File.php(498): Magento2\Sniffs\Exceptions\DirectThrowSniff->process(Object(PHP_CodeSniffer\Files\LocalFile), 526) #4 /srv/www/vendor/squizlabs/php_codesniffer/src/Files/LocalFile.php(92): PHP_CodeSniffer\Files\File->process() #5 /srv/www/vendor/squizlabs/php_codesniffer/src/Runner.php(630): PHP_CodeSniffer\Files\LocalFile->process() #6 /srv/www/vendor/squizlabs/php_codesniffer/src/Runner.php(434): PHP_CodeSniffer\Runner->processFile(Object(PHP_CodeSniffer\Files\LocalFile)) #7 /srv/www/vendor/squizlabs/php_codesniffer/src/Runner.php(114): PHP_CodeSniffer\Runner->run() #8 /srv/www/vendor/squizlabs/php_codesniffer/bin/phpcs(18): PHP_CodeSniffer\Runner->runPHPCS() #9 {main} thrown in /srv/www/vendor/squizlabs/php_codesniffer/src/Files/File.php on line 1056 --- Magento2/Sniffs/Exceptions/DirectThrowSniff.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Magento2/Sniffs/Exceptions/DirectThrowSniff.php b/Magento2/Sniffs/Exceptions/DirectThrowSniff.php index 9612d84c..d5ce80c1 100644 --- a/Magento2/Sniffs/Exceptions/DirectThrowSniff.php +++ b/Magento2/Sniffs/Exceptions/DirectThrowSniff.php @@ -48,7 +48,7 @@ public function process(File $phpcsFile, $stackPtr) $this->warningMessage, $stackPtr, $this->warningCode, - $posOfException + [$posOfException] ); } } From 9901dcffbb32a48d051b7bc9fdf1613367f250c8 Mon Sep 17 00:00:00 2001 From: Dan Wallis Date: Mon, 24 May 2021 16:23:05 +0100 Subject: [PATCH 079/630] Make argument type clearer --- Magento2/Sniffs/Legacy/MageEntitySniff.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Magento2/Sniffs/Legacy/MageEntitySniff.php b/Magento2/Sniffs/Legacy/MageEntitySniff.php index 13bc8beb..637c3b1c 100644 --- a/Magento2/Sniffs/Legacy/MageEntitySniff.php +++ b/Magento2/Sniffs/Legacy/MageEntitySniff.php @@ -77,7 +77,7 @@ public function process(File $phpcsFile, $stackPtr) return; } $entityName = $tokens[$stackPtr]['content']; - $error = [$entityName . $tokens[$oldPosition]['content']]; + $error = $entityName . $tokens[$oldPosition]['content']; } else { $oldPosition = $stackPtr; $stackPtr = $phpcsFile->findNext(T_STRING, $oldPosition + 1, null, false, null, true); @@ -85,14 +85,14 @@ public function process(File $phpcsFile, $stackPtr) return; } $entityName = $tokens[$stackPtr]['content']; - $error = [$tokens[$oldPosition]['content'] . ' ' . $entityName]; + $error = $tokens[$oldPosition]['content'] . ' ' . $entityName; } if ($entityName === $this->legacyEntity || $this->isPrefixLegacy($entityName)) { $phpcsFile->addError( $this->errorMessage, $stackPtr, $this->errorCode, - $error + [$error] ); } } From e106351b626c33bafdd41cdd838290ecac18ee9f Mon Sep 17 00:00:00 2001 From: Adarsh Manickam Date: Sun, 20 Jun 2021 15:47:31 +0530 Subject: [PATCH 080/630] Updated webonyx/graphql-php to ^14.9 --- composer.json | 2 +- composer.lock | 41 +++++++++++++++++++++++++++++++---------- 2 files changed, 32 insertions(+), 11 deletions(-) diff --git a/composer.json b/composer.json index bdc7b5be..e958d572 100644 --- a/composer.json +++ b/composer.json @@ -10,7 +10,7 @@ "require": { "php": ">=5.6.0", "squizlabs/php_codesniffer": "^3.5", - "webonyx/graphql-php": ">=0.12.6 <1.0" + "webonyx/graphql-php": "^14.9" }, "require-dev": { "phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0" diff --git a/composer.lock b/composer.lock index fa66436c..39e43998 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": "3384f4bb74dc1b1c36fa3c7cc697a28b", + "content-hash": "f0408a03c988315899dcc124b8c4cdef", "packages": [ { "name": "squizlabs/php_codesniffer", @@ -59,26 +59,37 @@ }, { "name": "webonyx/graphql-php", - "version": "v0.12.6", + "version": "v14.9.0", "source": { "type": "git", "url": "https://github.com/webonyx/graphql-php.git", - "reference": "4c545e5ec4fc37f6eb36c19f5a0e7feaf5979c95" + "reference": "36b83621deb5eae354347a2e86dc7aec81b32a82" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/webonyx/graphql-php/zipball/4c545e5ec4fc37f6eb36c19f5a0e7feaf5979c95", - "reference": "4c545e5ec4fc37f6eb36c19f5a0e7feaf5979c95", + "url": "https://api.github.com/repos/webonyx/graphql-php/zipball/36b83621deb5eae354347a2e86dc7aec81b32a82", + "reference": "36b83621deb5eae354347a2e86dc7aec81b32a82", "shasum": "" }, "require": { + "ext-json": "*", "ext-mbstring": "*", - "php": ">=5.6" + "php": "^7.1||^8.0" }, "require-dev": { - "phpunit/phpunit": "^4.8", + "amphp/amp": "^2.3", + "doctrine/coding-standard": "^6.0", + "nyholm/psr7": "^1.2", + "phpbench/phpbench": "^0.16.10", + "phpstan/extension-installer": "^1.0", + "phpstan/phpstan": "0.12.82", + "phpstan/phpstan-phpunit": "0.12.18", + "phpstan/phpstan-strict-rules": "0.12.9", + "phpunit/phpunit": "^7.2|^8.5", "psr/http-message": "^1.0", - "react/promise": "2.*" + "react/promise": "2.*", + "simpod/php-coveralls-mirror": "^3.0", + "squizlabs/php_codesniffer": "3.5.4" }, "suggest": { "psr/http-message": "To use standard GraphQL server", @@ -100,7 +111,17 @@ "api", "graphql" ], - "time": "2018-09-02T14:59:54+00:00" + "support": { + "issues": "https://github.com/webonyx/graphql-php/issues", + "source": "https://github.com/webonyx/graphql-php/tree/v14.9.0" + }, + "funding": [ + { + "url": "https://opencollective.com/webonyx-graphql-php", + "type": "open_collective" + } + ], + "time": "2021-06-15T16:14:17+00:00" } ], "packages-dev": [ @@ -1494,5 +1515,5 @@ "php": ">=5.6.0" }, "platform-dev": [], - "plugin-api-version": "1.1.0" + "plugin-api-version": "2.0.0" } From a460bda519dc96454d861de32406bd21b22bf698 Mon Sep 17 00:00:00 2001 From: Jose Orsini Date: Tue, 29 Jun 2021 14:37:13 -0500 Subject: [PATCH 081/630] MTS-2096: Added functions marked as insecure by Sec Team. --- Magento2/Sniffs/Security/InsecureFunctionSniff.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/Magento2/Sniffs/Security/InsecureFunctionSniff.php b/Magento2/Sniffs/Security/InsecureFunctionSniff.php index b5253193..66b6f5f0 100644 --- a/Magento2/Sniffs/Security/InsecureFunctionSniff.php +++ b/Magento2/Sniffs/Security/InsecureFunctionSniff.php @@ -33,5 +33,19 @@ class InsecureFunctionSniff extends ForbiddenFunctionsSniff 'srand' => null, 'mt_srand' => null, 'mt_rand' => 'random_int', + // Custom Rules - MTS-2096 + 'eval' => null, + 'preg_replace' => null, + 'preg_replace_callback' => null, + 'preg_replace_callback_array' => null, + 'include' => null, + 'include_once' => null, + 'require' => null, + 'require_once' => null, + 'proc_nice' => null, + 'proc_open' => null, + 'proc_close' => null, + 'proc_terminate' => null, + 'proc_get_status' => null, ]; } From 0ab21436453cb30ab47540336e9fe4b1320c4f0d Mon Sep 17 00:00:00 2001 From: Jose Orsini Date: Tue, 29 Jun 2021 15:40:54 -0500 Subject: [PATCH 082/630] exclude vendor folder --- phpunit.xml.dist | 1 + 1 file changed, 1 insertion(+) diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 6d1afb07..ecee1f73 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -8,4 +8,5 @@ + */vendor/* From cacb2dea8b612cc00059580029e8e4ce76ad29d0 Mon Sep 17 00:00:00 2001 From: Jose Orsini Date: Tue, 29 Jun 2021 16:09:07 -0500 Subject: [PATCH 083/630] discard --- phpunit.xml.dist | 1 - 1 file changed, 1 deletion(-) diff --git a/phpunit.xml.dist b/phpunit.xml.dist index ecee1f73..6d1afb07 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -8,5 +8,4 @@ - */vendor/* From f256543381a439e24dde9fb2f679eb3d048de9a2 Mon Sep 17 00:00:00 2001 From: Ihor Sviziev Date: Fri, 23 Jul 2021 16:17:01 +0300 Subject: [PATCH 084/630] Run tests on Github Actions --- .github/workflows/php.yml | 47 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 .github/workflows/php.yml diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml new file mode 100644 index 00000000..0b159a9d --- /dev/null +++ b/.github/workflows/php.yml @@ -0,0 +1,47 @@ +name: CI + +on: + push: + branches: [ master, develop ] + pull_request: + branches: [ master, develop ] + +jobs: + build: + + runs-on: ubuntu-latest + strategy: + matrix: + php-versions: ['5.6', '7.0', '7.0', '7.1', '7.2', '7.3', '7.4'] + name: Tests with PHP ${{ matrix.php-versions }} + + steps: + - uses: actions/checkout@v2 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php-versions }} + env: + COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Validate composer + run: composer validate + + - name: Cache Composer packages + id: composer-cache + uses: actions/cache@v2 + with: + path: vendor + key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} + restore-keys: | + ${{ runner.os }}-composer- + - name: Install dependencies + if: steps.composer-cache.outputs.cache-hit != 'true' + run: composer install --prefer-dist --no-interaction + + - name: Run unit tests suite + run: vendor/bin/phpunit + + - name: Run code style suite + run: vendor/bin/phpcs --standard=Magento2 Magento2/ --extensions=php From 74323730b9c33a6e558320fd1b2e544795abfcad Mon Sep 17 00:00:00 2001 From: Ihor Sviziev Date: Fri, 23 Jul 2021 16:25:45 +0300 Subject: [PATCH 085/630] Run tests on Github Actions Fix php 7.0 duplication --- .github/workflows/php.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index 0b159a9d..de2e2d85 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -12,7 +12,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - php-versions: ['5.6', '7.0', '7.0', '7.1', '7.2', '7.3', '7.4'] + php-versions: ['5.6', '7.0', '7.1', '7.2', '7.3', '7.4'] name: Tests with PHP ${{ matrix.php-versions }} steps: From 60fed78a406b7d3990ff21e635853bf4b0547ef4 Mon Sep 17 00:00:00 2001 From: Ihor Sviziev Date: Mon, 26 Jul 2021 11:23:52 +0300 Subject: [PATCH 086/630] Run tests on Github Actions Disable fail fast --- .github/workflows/php.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index de2e2d85..be39f0dd 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -11,6 +11,7 @@ jobs: runs-on: ubuntu-latest strategy: + fail-fast: false matrix: php-versions: ['5.6', '7.0', '7.1', '7.2', '7.3', '7.4'] name: Tests with PHP ${{ matrix.php-versions }} From 6a362030e034431b520c6afbf3fa58cee9f324c0 Mon Sep 17 00:00:00 2001 From: Sergii Ivashchenko Date: Mon, 26 Jul 2021 20:29:18 +0100 Subject: [PATCH 087/630] magento/magento-coding-standard#206: Updated minimal required PHP version to 7.1 --- .github/workflows/php.yml | 2 +- .travis.yml | 15 - composer.json | 4 +- composer.lock | 1046 ++++++++++++++++++++++++------------- 4 files changed, 685 insertions(+), 382 deletions(-) delete mode 100644 .travis.yml diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index be39f0dd..2f7f46c3 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -13,7 +13,7 @@ jobs: strategy: fail-fast: false matrix: - php-versions: ['5.6', '7.0', '7.1', '7.2', '7.3', '7.4'] + php-versions: ['7.1', '7.2', '7.3', '7.4'] name: Tests with PHP ${{ matrix.php-versions }} steps: diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index ea3eb825..00000000 --- a/.travis.yml +++ /dev/null @@ -1,15 +0,0 @@ -language: php -php: - - 5.6 - - 7.0 - - 7.1 - - 7.2 - - 7.3 - - 7.4 -cache: - directories: - - $HOME/.composer/cache/files -install: composer install --no-interaction --prefer-dist -script: - - vendor/bin/phpunit - - vendor/bin/phpcs --standard=Magento2 Magento2/ --extensions=php diff --git a/composer.json b/composer.json index e958d572..c3b6c654 100644 --- a/composer.json +++ b/composer.json @@ -8,12 +8,12 @@ "type": "phpcodesniffer-standard", "version": "6", "require": { - "php": ">=5.6.0", + "php": ">=7.1", "squizlabs/php_codesniffer": "^3.5", "webonyx/graphql-php": "^14.9" }, "require-dev": { - "phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0" + "phpunit/phpunit": "^7.0" }, "autoload": { "classmap": [ diff --git a/composer.lock b/composer.lock index 39e43998..fa96e115 100644 --- a/composer.lock +++ b/composer.lock @@ -4,20 +4,20 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "f0408a03c988315899dcc124b8c4cdef", + "content-hash": "1552fa061d5ee668ccf28b11417cd28e", "packages": [ { "name": "squizlabs/php_codesniffer", - "version": "3.5.6", + "version": "3.6.0", "source": { "type": "git", "url": "https://github.com/squizlabs/PHP_CodeSniffer.git", - "reference": "e97627871a7eab2f70e59166072a6b767d5834e0" + "reference": "ffced0d2c8fa8e6cdc4d695a743271fab6c38625" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/squizlabs/PHP_CodeSniffer/zipball/e97627871a7eab2f70e59166072a6b767d5834e0", - "reference": "e97627871a7eab2f70e59166072a6b767d5834e0", + "url": "https://api.github.com/repos/squizlabs/PHP_CodeSniffer/zipball/ffced0d2c8fa8e6cdc4d695a743271fab6c38625", + "reference": "ffced0d2c8fa8e6cdc4d695a743271fab6c38625", "shasum": "" }, "require": { @@ -55,7 +55,12 @@ "phpcs", "standards" ], - "time": "2020-08-10T04:50:15+00:00" + "support": { + "issues": "https://github.com/squizlabs/PHP_CodeSniffer/issues", + "source": "https://github.com/squizlabs/PHP_CodeSniffer", + "wiki": "https://github.com/squizlabs/PHP_CodeSniffer/wiki" + }, + "time": "2021-04-09T00:54:41+00:00" }, { "name": "webonyx/graphql-php", @@ -127,34 +132,31 @@ "packages-dev": [ { "name": "doctrine/instantiator", - "version": "1.0.5", + "version": "1.4.0", "source": { "type": "git", "url": "https://github.com/doctrine/instantiator.git", - "reference": "8e884e78f9f0eb1329e445619e04456e64d8051d" + "reference": "d56bf6102915de5702778fe20f2de3b2fe570b5b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/doctrine/instantiator/zipball/8e884e78f9f0eb1329e445619e04456e64d8051d", - "reference": "8e884e78f9f0eb1329e445619e04456e64d8051d", + "url": "https://api.github.com/repos/doctrine/instantiator/zipball/d56bf6102915de5702778fe20f2de3b2fe570b5b", + "reference": "d56bf6102915de5702778fe20f2de3b2fe570b5b", "shasum": "" }, "require": { - "php": ">=5.3,<8.0-DEV" + "php": "^7.1 || ^8.0" }, "require-dev": { - "athletic/athletic": "~0.1.8", + "doctrine/coding-standard": "^8.0", "ext-pdo": "*", "ext-phar": "*", - "phpunit/phpunit": "~4.0", - "squizlabs/php_codesniffer": "~2.0" + "phpbench/phpbench": "^0.13 || 1.0.0-alpha2", + "phpstan/phpstan": "^0.12", + "phpstan/phpstan-phpunit": "^0.12", + "phpunit/phpunit": "^7.0 || ^8.0 || ^9.0" }, "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.0.x-dev" - } - }, "autoload": { "psr-4": { "Doctrine\\Instantiator\\": "src/Doctrine/Instantiator/" @@ -168,38 +170,59 @@ { "name": "Marco Pivetta", "email": "ocramius@gmail.com", - "homepage": "http://ocramius.github.com/" + "homepage": "https://ocramius.github.io/" } ], "description": "A small, lightweight utility to instantiate objects in PHP without invoking their constructors", - "homepage": "https://github.com/doctrine/instantiator", + "homepage": "https://www.doctrine-project.org/projects/instantiator.html", "keywords": [ "constructor", "instantiate" ], - "time": "2015-06-14T21:17:01+00:00" + "support": { + "issues": "https://github.com/doctrine/instantiator/issues", + "source": "https://github.com/doctrine/instantiator/tree/1.4.0" + }, + "funding": [ + { + "url": "https://www.doctrine-project.org/sponsorship.html", + "type": "custom" + }, + { + "url": "https://www.patreon.com/phpdoctrine", + "type": "patreon" + }, + { + "url": "https://tidelift.com/funding/github/packagist/doctrine%2Finstantiator", + "type": "tidelift" + } + ], + "time": "2020-11-10T18:47:58+00:00" }, { "name": "myclabs/deep-copy", - "version": "1.7.0", + "version": "1.10.2", "source": { "type": "git", "url": "https://github.com/myclabs/DeepCopy.git", - "reference": "3b8a3a99ba1f6a3952ac2747d989303cbd6b7a3e" + "reference": "776f831124e9c62e1a2c601ecc52e776d8bb7220" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/3b8a3a99ba1f6a3952ac2747d989303cbd6b7a3e", - "reference": "3b8a3a99ba1f6a3952ac2747d989303cbd6b7a3e", + "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/776f831124e9c62e1a2c601ecc52e776d8bb7220", + "reference": "776f831124e9c62e1a2c601ecc52e776d8bb7220", "shasum": "" }, "require": { - "php": "^5.6 || ^7.0" + "php": "^7.1 || ^8.0" + }, + "replace": { + "myclabs/deep-copy": "self.version" }, "require-dev": { "doctrine/collections": "^1.0", "doctrine/common": "^2.6", - "phpunit/phpunit": "^4.1" + "phpunit/phpunit": "^7.1" }, "type": "library", "autoload": { @@ -222,39 +245,154 @@ "object", "object graph" ], - "time": "2017-10-19T19:58:43+00:00" + "support": { + "issues": "https://github.com/myclabs/DeepCopy/issues", + "source": "https://github.com/myclabs/DeepCopy/tree/1.10.2" + }, + "funding": [ + { + "url": "https://tidelift.com/funding/github/packagist/myclabs/deep-copy", + "type": "tidelift" + } + ], + "time": "2020-11-13T09:40:50+00:00" + }, + { + "name": "phar-io/manifest", + "version": "1.0.3", + "source": { + "type": "git", + "url": "https://github.com/phar-io/manifest.git", + "reference": "7761fcacf03b4d4f16e7ccb606d4879ca431fcf4" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phar-io/manifest/zipball/7761fcacf03b4d4f16e7ccb606d4879ca431fcf4", + "reference": "7761fcacf03b4d4f16e7ccb606d4879ca431fcf4", + "shasum": "" + }, + "require": { + "ext-dom": "*", + "ext-phar": "*", + "phar-io/version": "^2.0", + "php": "^5.6 || ^7.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Arne Blankerts", + "email": "arne@blankerts.de", + "role": "Developer" + }, + { + "name": "Sebastian Heuer", + "email": "sebastian@phpeople.de", + "role": "Developer" + }, + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "Developer" + } + ], + "description": "Component for reading phar.io manifest information from a PHP Archive (PHAR)", + "support": { + "issues": "https://github.com/phar-io/manifest/issues", + "source": "https://github.com/phar-io/manifest/tree/master" + }, + "time": "2018-07-08T19:23:20+00:00" + }, + { + "name": "phar-io/version", + "version": "2.0.1", + "source": { + "type": "git", + "url": "https://github.com/phar-io/version.git", + "reference": "45a2ec53a73c70ce41d55cedef9063630abaf1b6" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phar-io/version/zipball/45a2ec53a73c70ce41d55cedef9063630abaf1b6", + "reference": "45a2ec53a73c70ce41d55cedef9063630abaf1b6", + "shasum": "" + }, + "require": { + "php": "^5.6 || ^7.0" + }, + "type": "library", + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Arne Blankerts", + "email": "arne@blankerts.de", + "role": "Developer" + }, + { + "name": "Sebastian Heuer", + "email": "sebastian@phpeople.de", + "role": "Developer" + }, + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "Developer" + } + ], + "description": "Library for handling version information and constraints", + "support": { + "issues": "https://github.com/phar-io/version/issues", + "source": "https://github.com/phar-io/version/tree/master" + }, + "time": "2018-07-08T19:19:57+00:00" }, { "name": "phpdocumentor/reflection-common", - "version": "1.0.1", + "version": "2.2.0", "source": { "type": "git", "url": "https://github.com/phpDocumentor/ReflectionCommon.git", - "reference": "21bdeb5f65d7ebf9f43b1b25d404f87deab5bfb6" + "reference": "1d01c49d4ed62f25aa84a747ad35d5a16924662b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpDocumentor/ReflectionCommon/zipball/21bdeb5f65d7ebf9f43b1b25d404f87deab5bfb6", - "reference": "21bdeb5f65d7ebf9f43b1b25d404f87deab5bfb6", + "url": "https://api.github.com/repos/phpDocumentor/ReflectionCommon/zipball/1d01c49d4ed62f25aa84a747ad35d5a16924662b", + "reference": "1d01c49d4ed62f25aa84a747ad35d5a16924662b", "shasum": "" }, "require": { - "php": ">=5.5" - }, - "require-dev": { - "phpunit/phpunit": "^4.6" + "php": "^7.2 || ^8.0" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "1.0.x-dev" + "dev-2.x": "2.x-dev" } }, "autoload": { "psr-4": { - "phpDocumentor\\Reflection\\": [ - "src" - ] + "phpDocumentor\\Reflection\\": "src/" } }, "notification-url": "https://packagist.org/downloads/", @@ -276,38 +414,45 @@ "reflection", "static analysis" ], - "time": "2017-09-11T18:02:19+00:00" + "support": { + "issues": "https://github.com/phpDocumentor/ReflectionCommon/issues", + "source": "https://github.com/phpDocumentor/ReflectionCommon/tree/2.x" + }, + "time": "2020-06-27T09:03:43+00:00" }, { "name": "phpdocumentor/reflection-docblock", - "version": "3.3.2", + "version": "5.2.2", "source": { "type": "git", "url": "https://github.com/phpDocumentor/ReflectionDocBlock.git", - "reference": "bf329f6c1aadea3299f08ee804682b7c45b326a2" + "reference": "069a785b2141f5bcf49f3e353548dc1cce6df556" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/bf329f6c1aadea3299f08ee804682b7c45b326a2", - "reference": "bf329f6c1aadea3299f08ee804682b7c45b326a2", + "url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/069a785b2141f5bcf49f3e353548dc1cce6df556", + "reference": "069a785b2141f5bcf49f3e353548dc1cce6df556", "shasum": "" }, "require": { - "php": "^5.6 || ^7.0", - "phpdocumentor/reflection-common": "^1.0.0", - "phpdocumentor/type-resolver": "^0.4.0", - "webmozart/assert": "^1.0" + "ext-filter": "*", + "php": "^7.2 || ^8.0", + "phpdocumentor/reflection-common": "^2.2", + "phpdocumentor/type-resolver": "^1.3", + "webmozart/assert": "^1.9.1" }, "require-dev": { - "mockery/mockery": "^0.9.4", - "phpunit/phpunit": "^4.4" + "mockery/mockery": "~1.3.2" }, "type": "library", + "extra": { + "branch-alias": { + "dev-master": "5.x-dev" + } + }, "autoload": { "psr-4": { - "phpDocumentor\\Reflection\\": [ - "src/" - ] + "phpDocumentor\\Reflection\\": "src" } }, "notification-url": "https://packagist.org/downloads/", @@ -318,44 +463,49 @@ { "name": "Mike van Riel", "email": "me@mikevanriel.com" + }, + { + "name": "Jaap van Otterdijk", + "email": "account@ijaap.nl" } ], "description": "With this component, a library can provide support for annotations via DocBlocks or otherwise retrieve information that is embedded in a DocBlock.", - "time": "2017-11-10T14:09:06+00:00" + "support": { + "issues": "https://github.com/phpDocumentor/ReflectionDocBlock/issues", + "source": "https://github.com/phpDocumentor/ReflectionDocBlock/tree/master" + }, + "time": "2020-09-03T19:13:55+00:00" }, { "name": "phpdocumentor/type-resolver", - "version": "0.4.0", + "version": "1.4.0", "source": { "type": "git", "url": "https://github.com/phpDocumentor/TypeResolver.git", - "reference": "9c977708995954784726e25d0cd1dddf4e65b0f7" + "reference": "6a467b8989322d92aa1c8bf2bebcc6e5c2ba55c0" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/9c977708995954784726e25d0cd1dddf4e65b0f7", - "reference": "9c977708995954784726e25d0cd1dddf4e65b0f7", + "url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/6a467b8989322d92aa1c8bf2bebcc6e5c2ba55c0", + "reference": "6a467b8989322d92aa1c8bf2bebcc6e5c2ba55c0", "shasum": "" }, "require": { - "php": "^5.5 || ^7.0", - "phpdocumentor/reflection-common": "^1.0" + "php": "^7.2 || ^8.0", + "phpdocumentor/reflection-common": "^2.0" }, "require-dev": { - "mockery/mockery": "^0.9.4", - "phpunit/phpunit": "^5.2||^4.8.24" + "ext-tokenizer": "*" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "1.0.x-dev" + "dev-1.x": "1.x-dev" } }, "autoload": { "psr-4": { - "phpDocumentor\\Reflection\\": [ - "src/" - ] + "phpDocumentor\\Reflection\\": "src" } }, "notification-url": "https://packagist.org/downloads/", @@ -368,42 +518,47 @@ "email": "me@mikevanriel.com" } ], - "time": "2017-07-14T14:27:02+00:00" + "description": "A PSR-5 based resolver of Class names, Types and Structural Element Names", + "support": { + "issues": "https://github.com/phpDocumentor/TypeResolver/issues", + "source": "https://github.com/phpDocumentor/TypeResolver/tree/1.4.0" + }, + "time": "2020-09-17T18:55:26+00:00" }, { "name": "phpspec/prophecy", - "version": "1.8.0", + "version": "1.13.0", "source": { "type": "git", "url": "https://github.com/phpspec/prophecy.git", - "reference": "4ba436b55987b4bf311cb7c6ba82aa528aac0a06" + "reference": "be1996ed8adc35c3fd795488a653f4b518be70ea" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpspec/prophecy/zipball/4ba436b55987b4bf311cb7c6ba82aa528aac0a06", - "reference": "4ba436b55987b4bf311cb7c6ba82aa528aac0a06", + "url": "https://api.github.com/repos/phpspec/prophecy/zipball/be1996ed8adc35c3fd795488a653f4b518be70ea", + "reference": "be1996ed8adc35c3fd795488a653f4b518be70ea", "shasum": "" }, "require": { - "doctrine/instantiator": "^1.0.2", - "php": "^5.3|^7.0", - "phpdocumentor/reflection-docblock": "^2.0|^3.0.2|^4.0", - "sebastian/comparator": "^1.1|^2.0|^3.0", - "sebastian/recursion-context": "^1.0|^2.0|^3.0" + "doctrine/instantiator": "^1.2", + "php": "^7.2 || ~8.0, <8.1", + "phpdocumentor/reflection-docblock": "^5.2", + "sebastian/comparator": "^3.0 || ^4.0", + "sebastian/recursion-context": "^3.0 || ^4.0" }, "require-dev": { - "phpspec/phpspec": "^2.5|^3.2", - "phpunit/phpunit": "^4.8.35 || ^5.7 || ^6.5 || ^7.1" + "phpspec/phpspec": "^6.0", + "phpunit/phpunit": "^8.0 || ^9.0" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "1.8.x-dev" + "dev-master": "1.11.x-dev" } }, "autoload": { - "psr-0": { - "Prophecy\\": "src/" + "psr-4": { + "Prophecy\\": "src/Prophecy" } }, "notification-url": "https://packagist.org/downloads/", @@ -431,44 +586,48 @@ "spy", "stub" ], - "time": "2018-08-05T17:53:17+00:00" + "support": { + "issues": "https://github.com/phpspec/prophecy/issues", + "source": "https://github.com/phpspec/prophecy/tree/1.13.0" + }, + "time": "2021-03-17T13:42:18+00:00" }, { "name": "phpunit/php-code-coverage", - "version": "4.0.8", + "version": "6.1.4", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-code-coverage.git", - "reference": "ef7b2f56815df854e66ceaee8ebe9393ae36a40d" + "reference": "807e6013b00af69b6c5d9ceb4282d0393dbb9d8d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/ef7b2f56815df854e66ceaee8ebe9393ae36a40d", - "reference": "ef7b2f56815df854e66ceaee8ebe9393ae36a40d", + "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/807e6013b00af69b6c5d9ceb4282d0393dbb9d8d", + "reference": "807e6013b00af69b6c5d9ceb4282d0393dbb9d8d", "shasum": "" }, "require": { "ext-dom": "*", "ext-xmlwriter": "*", - "php": "^5.6 || ^7.0", - "phpunit/php-file-iterator": "^1.3", - "phpunit/php-text-template": "^1.2", - "phpunit/php-token-stream": "^1.4.2 || ^2.0", - "sebastian/code-unit-reverse-lookup": "^1.0", - "sebastian/environment": "^1.3.2 || ^2.0", - "sebastian/version": "^1.0 || ^2.0" + "php": "^7.1", + "phpunit/php-file-iterator": "^2.0", + "phpunit/php-text-template": "^1.2.1", + "phpunit/php-token-stream": "^3.0", + "sebastian/code-unit-reverse-lookup": "^1.0.1", + "sebastian/environment": "^3.1 || ^4.0", + "sebastian/version": "^2.0.1", + "theseer/tokenizer": "^1.1" }, "require-dev": { - "ext-xdebug": "^2.1.4", - "phpunit/phpunit": "^5.7" + "phpunit/phpunit": "^7.0" }, "suggest": { - "ext-xdebug": "^2.5.1" + "ext-xdebug": "^2.6.0" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "4.0.x-dev" + "dev-master": "6.1-dev" } }, "autoload": { @@ -483,7 +642,7 @@ "authors": [ { "name": "Sebastian Bergmann", - "email": "sb@sebastian-bergmann.de", + "email": "sebastian@phpunit.de", "role": "lead" } ], @@ -494,29 +653,36 @@ "testing", "xunit" ], - "time": "2017-04-02T07:44:40+00:00" + "support": { + "issues": "https://github.com/sebastianbergmann/php-code-coverage/issues", + "source": "https://github.com/sebastianbergmann/php-code-coverage/tree/master" + }, + "time": "2018-10-31T16:06:48+00:00" }, { "name": "phpunit/php-file-iterator", - "version": "1.4.5", + "version": "2.0.4", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-file-iterator.git", - "reference": "730b01bc3e867237eaac355e06a36b85dd93a8b4" + "reference": "28af674ff175d0768a5a978e6de83f697d4a7f05" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/730b01bc3e867237eaac355e06a36b85dd93a8b4", - "reference": "730b01bc3e867237eaac355e06a36b85dd93a8b4", + "url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/28af674ff175d0768a5a978e6de83f697d4a7f05", + "reference": "28af674ff175d0768a5a978e6de83f697d4a7f05", "shasum": "" }, "require": { - "php": ">=5.3.3" + "php": ">=7.1" + }, + "require-dev": { + "phpunit/phpunit": "^8.5" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "1.4.x-dev" + "dev-master": "2.0.x-dev" } }, "autoload": { @@ -531,7 +697,7 @@ "authors": [ { "name": "Sebastian Bergmann", - "email": "sb@sebastian-bergmann.de", + "email": "sebastian@phpunit.de", "role": "lead" } ], @@ -541,7 +707,17 @@ "filesystem", "iterator" ], - "time": "2017-11-27T13:52:08+00:00" + "support": { + "issues": "https://github.com/sebastianbergmann/php-file-iterator/issues", + "source": "https://github.com/sebastianbergmann/php-file-iterator/tree/2.0.4" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2021-07-19T06:46:01+00:00" }, { "name": "phpunit/php-text-template", @@ -582,32 +758,36 @@ "keywords": [ "template" ], + "support": { + "issues": "https://github.com/sebastianbergmann/php-text-template/issues", + "source": "https://github.com/sebastianbergmann/php-text-template/tree/1.2.1" + }, "time": "2015-06-21T13:50:34+00:00" }, { "name": "phpunit/php-timer", - "version": "1.0.9", + "version": "2.1.3", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-timer.git", - "reference": "3dcf38ca72b158baf0bc245e9184d3fdffa9c46f" + "reference": "2454ae1765516d20c4ffe103d85a58a9a3bd5662" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-timer/zipball/3dcf38ca72b158baf0bc245e9184d3fdffa9c46f", - "reference": "3dcf38ca72b158baf0bc245e9184d3fdffa9c46f", + "url": "https://api.github.com/repos/sebastianbergmann/php-timer/zipball/2454ae1765516d20c4ffe103d85a58a9a3bd5662", + "reference": "2454ae1765516d20c4ffe103d85a58a9a3bd5662", "shasum": "" }, "require": { - "php": "^5.3.3 || ^7.0" + "php": ">=7.1" }, "require-dev": { - "phpunit/phpunit": "^4.8.35 || ^5.7 || ^6.0" + "phpunit/phpunit": "^8.5" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "1.0-dev" + "dev-master": "2.1-dev" } }, "autoload": { @@ -622,7 +802,7 @@ "authors": [ { "name": "Sebastian Bergmann", - "email": "sb@sebastian-bergmann.de", + "email": "sebastian@phpunit.de", "role": "lead" } ], @@ -631,33 +811,43 @@ "keywords": [ "timer" ], - "time": "2017-02-26T11:10:40+00:00" + "support": { + "issues": "https://github.com/sebastianbergmann/php-timer/issues", + "source": "https://github.com/sebastianbergmann/php-timer/tree/2.1.3" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2020-11-30T08:20:02+00:00" }, { "name": "phpunit/php-token-stream", - "version": "1.4.12", + "version": "3.1.3", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-token-stream.git", - "reference": "1ce90ba27c42e4e44e6d8458241466380b51fa16" + "reference": "9c1da83261628cb24b6a6df371b6e312b3954768" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-token-stream/zipball/1ce90ba27c42e4e44e6d8458241466380b51fa16", - "reference": "1ce90ba27c42e4e44e6d8458241466380b51fa16", + "url": "https://api.github.com/repos/sebastianbergmann/php-token-stream/zipball/9c1da83261628cb24b6a6df371b6e312b3954768", + "reference": "9c1da83261628cb24b6a6df371b6e312b3954768", "shasum": "" }, "require": { "ext-tokenizer": "*", - "php": ">=5.3.3" + "php": ">=7.1" }, "require-dev": { - "phpunit/phpunit": "~4.2" + "phpunit/phpunit": "^7.0" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "1.4-dev" + "dev-master": "3.1-dev" } }, "autoload": { @@ -680,56 +870,68 @@ "keywords": [ "tokenizer" ], + "support": { + "issues": "https://github.com/sebastianbergmann/php-token-stream/issues", + "source": "https://github.com/sebastianbergmann/php-token-stream/tree/3.1.3" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], "abandoned": true, - "time": "2017-12-04T08:55:13+00:00" + "time": "2021-07-26T12:15:06+00:00" }, { "name": "phpunit/phpunit", - "version": "5.7.27", + "version": "7.5.20", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "b7803aeca3ccb99ad0a506fa80b64cd6a56bbc0c" + "reference": "9467db479d1b0487c99733bb1e7944d32deded2c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/b7803aeca3ccb99ad0a506fa80b64cd6a56bbc0c", - "reference": "b7803aeca3ccb99ad0a506fa80b64cd6a56bbc0c", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/9467db479d1b0487c99733bb1e7944d32deded2c", + "reference": "9467db479d1b0487c99733bb1e7944d32deded2c", "shasum": "" }, "require": { + "doctrine/instantiator": "^1.1", "ext-dom": "*", "ext-json": "*", "ext-libxml": "*", "ext-mbstring": "*", "ext-xml": "*", - "myclabs/deep-copy": "~1.3", - "php": "^5.6 || ^7.0", - "phpspec/prophecy": "^1.6.2", - "phpunit/php-code-coverage": "^4.0.4", - "phpunit/php-file-iterator": "~1.4", - "phpunit/php-text-template": "~1.2", - "phpunit/php-timer": "^1.0.6", - "phpunit/phpunit-mock-objects": "^3.2", - "sebastian/comparator": "^1.2.4", - "sebastian/diff": "^1.4.3", - "sebastian/environment": "^1.3.4 || ^2.0", - "sebastian/exporter": "~2.0", - "sebastian/global-state": "^1.1", - "sebastian/object-enumerator": "~2.0", - "sebastian/resource-operations": "~1.0", - "sebastian/version": "^1.0.6|^2.0.1", - "symfony/yaml": "~2.1|~3.0|~4.0" + "myclabs/deep-copy": "^1.7", + "phar-io/manifest": "^1.0.2", + "phar-io/version": "^2.0", + "php": "^7.1", + "phpspec/prophecy": "^1.7", + "phpunit/php-code-coverage": "^6.0.7", + "phpunit/php-file-iterator": "^2.0.1", + "phpunit/php-text-template": "^1.2.1", + "phpunit/php-timer": "^2.1", + "sebastian/comparator": "^3.0", + "sebastian/diff": "^3.0", + "sebastian/environment": "^4.0", + "sebastian/exporter": "^3.1", + "sebastian/global-state": "^2.0", + "sebastian/object-enumerator": "^3.0.3", + "sebastian/resource-operations": "^2.0", + "sebastian/version": "^2.0.1" }, "conflict": { - "phpdocumentor/reflection-docblock": "3.0.2" + "phpunit/phpunit-mock-objects": "*" }, "require-dev": { "ext-pdo": "*" }, "suggest": { + "ext-soap": "*", "ext-xdebug": "*", - "phpunit/php-invoker": "~1.1" + "phpunit/php-invoker": "^2.0" }, "bin": [ "phpunit" @@ -737,7 +939,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "5.7.x-dev" + "dev-master": "7.5-dev" } }, "autoload": { @@ -763,87 +965,31 @@ "testing", "xunit" ], - "time": "2018-02-01T05:50:59+00:00" - }, - { - "name": "phpunit/phpunit-mock-objects", - "version": "3.4.4", - "source": { - "type": "git", - "url": "https://github.com/sebastianbergmann/phpunit-mock-objects.git", - "reference": "a23b761686d50a560cc56233b9ecf49597cc9118" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit-mock-objects/zipball/a23b761686d50a560cc56233b9ecf49597cc9118", - "reference": "a23b761686d50a560cc56233b9ecf49597cc9118", - "shasum": "" - }, - "require": { - "doctrine/instantiator": "^1.0.2", - "php": "^5.6 || ^7.0", - "phpunit/php-text-template": "^1.2", - "sebastian/exporter": "^1.2 || ^2.0" - }, - "conflict": { - "phpunit/phpunit": "<5.4.0" - }, - "require-dev": { - "phpunit/phpunit": "^5.4" - }, - "suggest": { - "ext-soap": "*" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "3.2.x-dev" - } - }, - "autoload": { - "classmap": [ - "src/" - ] + "support": { + "issues": "https://github.com/sebastianbergmann/phpunit/issues", + "source": "https://github.com/sebastianbergmann/phpunit/tree/7.5.20" }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Sebastian Bergmann", - "email": "sb@sebastian-bergmann.de", - "role": "lead" - } - ], - "description": "Mock Object library for PHPUnit", - "homepage": "https://github.com/sebastianbergmann/phpunit-mock-objects/", - "keywords": [ - "mock", - "xunit" - ], - "abandoned": true, - "time": "2017-06-30T09:13:00+00:00" + "time": "2020-01-08T08:45:45+00:00" }, { "name": "sebastian/code-unit-reverse-lookup", - "version": "1.0.1", + "version": "1.0.2", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/code-unit-reverse-lookup.git", - "reference": "4419fcdb5eabb9caa61a27c7a1db532a6b55dd18" + "reference": "1de8cd5c010cb153fcd68b8d0f64606f523f7619" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/code-unit-reverse-lookup/zipball/4419fcdb5eabb9caa61a27c7a1db532a6b55dd18", - "reference": "4419fcdb5eabb9caa61a27c7a1db532a6b55dd18", + "url": "https://api.github.com/repos/sebastianbergmann/code-unit-reverse-lookup/zipball/1de8cd5c010cb153fcd68b8d0f64606f523f7619", + "reference": "1de8cd5c010cb153fcd68b8d0f64606f523f7619", "shasum": "" }, "require": { - "php": "^5.6 || ^7.0" + "php": ">=5.6" }, "require-dev": { - "phpunit/phpunit": "^5.7 || ^6.0" + "phpunit/phpunit": "^8.5" }, "type": "library", "extra": { @@ -868,34 +1014,44 @@ ], "description": "Looks up which function or method a line of code belongs to", "homepage": "https://github.com/sebastianbergmann/code-unit-reverse-lookup/", - "time": "2017-03-04T06:30:41+00:00" + "support": { + "issues": "https://github.com/sebastianbergmann/code-unit-reverse-lookup/issues", + "source": "https://github.com/sebastianbergmann/code-unit-reverse-lookup/tree/1.0.2" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2020-11-30T08:15:22+00:00" }, { "name": "sebastian/comparator", - "version": "1.2.4", + "version": "3.0.3", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/comparator.git", - "reference": "2b7424b55f5047b47ac6e5ccb20b2aea4011d9be" + "reference": "1071dfcef776a57013124ff35e1fc41ccd294758" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/2b7424b55f5047b47ac6e5ccb20b2aea4011d9be", - "reference": "2b7424b55f5047b47ac6e5ccb20b2aea4011d9be", + "url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/1071dfcef776a57013124ff35e1fc41ccd294758", + "reference": "1071dfcef776a57013124ff35e1fc41ccd294758", "shasum": "" }, "require": { - "php": ">=5.3.3", - "sebastian/diff": "~1.2", - "sebastian/exporter": "~1.2 || ~2.0" + "php": ">=7.1", + "sebastian/diff": "^3.0", + "sebastian/exporter": "^3.1" }, "require-dev": { - "phpunit/phpunit": "~4.4" + "phpunit/phpunit": "^8.5" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "1.2.x-dev" + "dev-master": "3.0-dev" } }, "autoload": { @@ -908,6 +1064,10 @@ "BSD-3-Clause" ], "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + }, { "name": "Jeff Welch", "email": "whatthejeff@gmail.com" @@ -919,45 +1079,52 @@ { "name": "Bernhard Schussek", "email": "bschussek@2bepublished.at" - }, - { - "name": "Sebastian Bergmann", - "email": "sebastian@phpunit.de" } ], "description": "Provides the functionality to compare PHP values for equality", - "homepage": "http://www.github.com/sebastianbergmann/comparator", + "homepage": "https://github.com/sebastianbergmann/comparator", "keywords": [ "comparator", "compare", "equality" ], - "time": "2017-01-29T09:50:25+00:00" + "support": { + "issues": "https://github.com/sebastianbergmann/comparator/issues", + "source": "https://github.com/sebastianbergmann/comparator/tree/3.0.3" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2020-11-30T08:04:30+00:00" }, { "name": "sebastian/diff", - "version": "1.4.3", + "version": "3.0.3", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/diff.git", - "reference": "7f066a26a962dbe58ddea9f72a4e82874a3975a4" + "reference": "14f72dd46eaf2f2293cbe79c93cc0bc43161a211" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/7f066a26a962dbe58ddea9f72a4e82874a3975a4", - "reference": "7f066a26a962dbe58ddea9f72a4e82874a3975a4", + "url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/14f72dd46eaf2f2293cbe79c93cc0bc43161a211", + "reference": "14f72dd46eaf2f2293cbe79c93cc0bc43161a211", "shasum": "" }, "require": { - "php": "^5.3.3 || ^7.0" + "php": ">=7.1" }, "require-dev": { - "phpunit/phpunit": "^4.8.35 || ^5.7 || ^6.0" + "phpunit/phpunit": "^7.5 || ^8.0", + "symfony/process": "^2 || ^3.3 || ^4" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "1.4-dev" + "dev-master": "3.0-dev" } }, "autoload": { @@ -970,46 +1137,62 @@ "BSD-3-Clause" ], "authors": [ - { - "name": "Kore Nordmann", - "email": "mail@kore-nordmann.de" - }, { "name": "Sebastian Bergmann", "email": "sebastian@phpunit.de" + }, + { + "name": "Kore Nordmann", + "email": "mail@kore-nordmann.de" } ], "description": "Diff implementation", "homepage": "https://github.com/sebastianbergmann/diff", "keywords": [ - "diff" + "diff", + "udiff", + "unidiff", + "unified diff" + ], + "support": { + "issues": "https://github.com/sebastianbergmann/diff/issues", + "source": "https://github.com/sebastianbergmann/diff/tree/3.0.3" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } ], - "time": "2017-05-22T07:24:03+00:00" + "time": "2020-11-30T07:59:04+00:00" }, { "name": "sebastian/environment", - "version": "2.0.0", + "version": "4.2.4", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/environment.git", - "reference": "5795ffe5dc5b02460c3e34222fee8cbe245d8fac" + "reference": "d47bbbad83711771f167c72d4e3f25f7fcc1f8b0" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/5795ffe5dc5b02460c3e34222fee8cbe245d8fac", - "reference": "5795ffe5dc5b02460c3e34222fee8cbe245d8fac", + "url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/d47bbbad83711771f167c72d4e3f25f7fcc1f8b0", + "reference": "d47bbbad83711771f167c72d4e3f25f7fcc1f8b0", "shasum": "" }, "require": { - "php": "^5.6 || ^7.0" + "php": ">=7.1" }, "require-dev": { - "phpunit/phpunit": "^5.0" + "phpunit/phpunit": "^7.5" + }, + "suggest": { + "ext-posix": "*" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "2.0.x-dev" + "dev-master": "4.2-dev" } }, "autoload": { @@ -1034,34 +1217,44 @@ "environment", "hhvm" ], - "time": "2016-11-26T07:53:53+00:00" + "support": { + "issues": "https://github.com/sebastianbergmann/environment/issues", + "source": "https://github.com/sebastianbergmann/environment/tree/4.2.4" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2020-11-30T07:53:42+00:00" }, { "name": "sebastian/exporter", - "version": "2.0.0", + "version": "3.1.3", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/exporter.git", - "reference": "ce474bdd1a34744d7ac5d6aad3a46d48d9bac4c4" + "reference": "6b853149eab67d4da22291d36f5b0631c0fd856e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/ce474bdd1a34744d7ac5d6aad3a46d48d9bac4c4", - "reference": "ce474bdd1a34744d7ac5d6aad3a46d48d9bac4c4", + "url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/6b853149eab67d4da22291d36f5b0631c0fd856e", + "reference": "6b853149eab67d4da22291d36f5b0631c0fd856e", "shasum": "" }, "require": { - "php": ">=5.3.3", - "sebastian/recursion-context": "~2.0" + "php": ">=7.0", + "sebastian/recursion-context": "^3.0" }, "require-dev": { "ext-mbstring": "*", - "phpunit/phpunit": "~4.4" + "phpunit/phpunit": "^6.0" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "2.0.x-dev" + "dev-master": "3.1.x-dev" } }, "autoload": { @@ -1074,6 +1267,10 @@ "BSD-3-Clause" ], "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + }, { "name": "Jeff Welch", "email": "whatthejeff@gmail.com" @@ -1082,17 +1279,13 @@ "name": "Volker Dusch", "email": "github@wallbash.com" }, - { - "name": "Bernhard Schussek", - "email": "bschussek@2bepublished.at" - }, - { - "name": "Sebastian Bergmann", - "email": "sebastian@phpunit.de" - }, { "name": "Adam Harvey", "email": "aharvey@php.net" + }, + { + "name": "Bernhard Schussek", + "email": "bschussek@gmail.com" } ], "description": "Provides the functionality to export PHP variables for visualization", @@ -1101,27 +1294,37 @@ "export", "exporter" ], - "time": "2016-11-19T08:54:04+00:00" + "support": { + "issues": "https://github.com/sebastianbergmann/exporter/issues", + "source": "https://github.com/sebastianbergmann/exporter/tree/3.1.3" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2020-11-30T07:47:53+00:00" }, { "name": "sebastian/global-state", - "version": "1.1.1", + "version": "2.0.0", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/global-state.git", - "reference": "bc37d50fea7d017d3d340f230811c9f1d7280af4" + "reference": "e8ba02eed7bbbb9e59e43dedd3dddeff4a56b0c4" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/global-state/zipball/bc37d50fea7d017d3d340f230811c9f1d7280af4", - "reference": "bc37d50fea7d017d3d340f230811c9f1d7280af4", + "url": "https://api.github.com/repos/sebastianbergmann/global-state/zipball/e8ba02eed7bbbb9e59e43dedd3dddeff4a56b0c4", + "reference": "e8ba02eed7bbbb9e59e43dedd3dddeff4a56b0c4", "shasum": "" }, "require": { - "php": ">=5.3.3" + "php": "^7.0" }, "require-dev": { - "phpunit/phpunit": "~4.2" + "phpunit/phpunit": "^6.0" }, "suggest": { "ext-uopz": "*" @@ -1129,7 +1332,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "1.0-dev" + "dev-master": "2.0-dev" } }, "autoload": { @@ -1152,33 +1355,38 @@ "keywords": [ "global state" ], - "time": "2015-10-12T03:26:01+00:00" + "support": { + "issues": "https://github.com/sebastianbergmann/global-state/issues", + "source": "https://github.com/sebastianbergmann/global-state/tree/2.0.0" + }, + "time": "2017-04-27T15:39:26+00:00" }, { "name": "sebastian/object-enumerator", - "version": "2.0.1", + "version": "3.0.4", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/object-enumerator.git", - "reference": "1311872ac850040a79c3c058bea3e22d0f09cbb7" + "reference": "e67f6d32ebd0c749cf9d1dbd9f226c727043cdf2" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/object-enumerator/zipball/1311872ac850040a79c3c058bea3e22d0f09cbb7", - "reference": "1311872ac850040a79c3c058bea3e22d0f09cbb7", + "url": "https://api.github.com/repos/sebastianbergmann/object-enumerator/zipball/e67f6d32ebd0c749cf9d1dbd9f226c727043cdf2", + "reference": "e67f6d32ebd0c749cf9d1dbd9f226c727043cdf2", "shasum": "" }, "require": { - "php": ">=5.6", - "sebastian/recursion-context": "~2.0" + "php": ">=7.0", + "sebastian/object-reflector": "^1.1.1", + "sebastian/recursion-context": "^3.0" }, "require-dev": { - "phpunit/phpunit": "~5" + "phpunit/phpunit": "^6.0" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "2.0.x-dev" + "dev-master": "3.0.x-dev" } }, "autoload": { @@ -1198,32 +1406,97 @@ ], "description": "Traverses array structures and object graphs to enumerate all referenced objects", "homepage": "https://github.com/sebastianbergmann/object-enumerator/", - "time": "2017-02-18T15:18:39+00:00" + "support": { + "issues": "https://github.com/sebastianbergmann/object-enumerator/issues", + "source": "https://github.com/sebastianbergmann/object-enumerator/tree/3.0.4" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2020-11-30T07:40:27+00:00" + }, + { + "name": "sebastian/object-reflector", + "version": "1.1.2", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/object-reflector.git", + "reference": "9b8772b9cbd456ab45d4a598d2dd1a1bced6363d" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/object-reflector/zipball/9b8772b9cbd456ab45d4a598d2dd1a1bced6363d", + "reference": "9b8772b9cbd456ab45d4a598d2dd1a1bced6363d", + "shasum": "" + }, + "require": { + "php": ">=7.0" + }, + "require-dev": { + "phpunit/phpunit": "^6.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.1-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Allows reflection of object attributes, including inherited and non-public ones", + "homepage": "https://github.com/sebastianbergmann/object-reflector/", + "support": { + "issues": "https://github.com/sebastianbergmann/object-reflector/issues", + "source": "https://github.com/sebastianbergmann/object-reflector/tree/1.1.2" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2020-11-30T07:37:18+00:00" }, { "name": "sebastian/recursion-context", - "version": "2.0.0", + "version": "3.0.1", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/recursion-context.git", - "reference": "2c3ba150cbec723aa057506e73a8d33bdb286c9a" + "reference": "367dcba38d6e1977be014dc4b22f47a484dac7fb" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/recursion-context/zipball/2c3ba150cbec723aa057506e73a8d33bdb286c9a", - "reference": "2c3ba150cbec723aa057506e73a8d33bdb286c9a", + "url": "https://api.github.com/repos/sebastianbergmann/recursion-context/zipball/367dcba38d6e1977be014dc4b22f47a484dac7fb", + "reference": "367dcba38d6e1977be014dc4b22f47a484dac7fb", "shasum": "" }, "require": { - "php": ">=5.3.3" + "php": ">=7.0" }, "require-dev": { - "phpunit/phpunit": "~4.4" + "phpunit/phpunit": "^6.0" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "2.0.x-dev" + "dev-master": "3.0.x-dev" } }, "autoload": { @@ -1236,14 +1509,14 @@ "BSD-3-Clause" ], "authors": [ - { - "name": "Jeff Welch", - "email": "whatthejeff@gmail.com" - }, { "name": "Sebastian Bergmann", "email": "sebastian@phpunit.de" }, + { + "name": "Jeff Welch", + "email": "whatthejeff@gmail.com" + }, { "name": "Adam Harvey", "email": "aharvey@php.net" @@ -1251,29 +1524,39 @@ ], "description": "Provides functionality to recursively process PHP variables", "homepage": "http://www.github.com/sebastianbergmann/recursion-context", - "time": "2016-11-19T07:33:16+00:00" + "support": { + "issues": "https://github.com/sebastianbergmann/recursion-context/issues", + "source": "https://github.com/sebastianbergmann/recursion-context/tree/3.0.1" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2020-11-30T07:34:24+00:00" }, { "name": "sebastian/resource-operations", - "version": "1.0.0", + "version": "2.0.2", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/resource-operations.git", - "reference": "ce990bb21759f94aeafd30209e8cfcdfa8bc3f52" + "reference": "31d35ca87926450c44eae7e2611d45a7a65ea8b3" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/resource-operations/zipball/ce990bb21759f94aeafd30209e8cfcdfa8bc3f52", - "reference": "ce990bb21759f94aeafd30209e8cfcdfa8bc3f52", + "url": "https://api.github.com/repos/sebastianbergmann/resource-operations/zipball/31d35ca87926450c44eae7e2611d45a7a65ea8b3", + "reference": "31d35ca87926450c44eae7e2611d45a7a65ea8b3", "shasum": "" }, "require": { - "php": ">=5.6.0" + "php": ">=7.1" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "1.0.x-dev" + "dev-master": "2.0-dev" } }, "autoload": { @@ -1293,7 +1576,18 @@ ], "description": "Provides a list of PHP built-in functions that operate on resources", "homepage": "https://www.github.com/sebastianbergmann/resource-operations", - "time": "2015-07-28T20:34:47+00:00" + "support": { + "issues": "https://github.com/sebastianbergmann/resource-operations/issues", + "source": "https://github.com/sebastianbergmann/resource-operations/tree/2.0.2" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "abandoned": true, + "time": "2020-11-30T07:30:19+00:00" }, { "name": "sebastian/version", @@ -1336,24 +1630,28 @@ ], "description": "Library that helps with managing the version number of Git-hosted PHP projects", "homepage": "https://github.com/sebastianbergmann/version", + "support": { + "issues": "https://github.com/sebastianbergmann/version/issues", + "source": "https://github.com/sebastianbergmann/version/tree/master" + }, "time": "2016-10-03T07:35:21+00:00" }, { "name": "symfony/polyfill-ctype", - "version": "v1.10.0", + "version": "v1.23.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-ctype.git", - "reference": "e3d826245268269cd66f8326bd8bc066687b4a19" + "reference": "46cd95797e9df938fdd2b03693b5fca5e64b01ce" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/e3d826245268269cd66f8326bd8bc066687b4a19", - "reference": "e3d826245268269cd66f8326bd8bc066687b4a19", + "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/46cd95797e9df938fdd2b03693b5fca5e64b01ce", + "reference": "46cd95797e9df938fdd2b03693b5fca5e64b01ce", "shasum": "" }, "require": { - "php": ">=5.3.3" + "php": ">=7.1" }, "suggest": { "ext-ctype": "For best performance" @@ -1361,7 +1659,11 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "1.9-dev" + "dev-main": "1.23-dev" + }, + "thanks": { + "name": "symfony/polyfill", + "url": "https://github.com/symfony/polyfill" } }, "autoload": { @@ -1378,12 +1680,12 @@ ], "authors": [ { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" + "name": "Gert de Pagter", + "email": "BackEndTea@gmail.com" }, { - "name": "Gert de Pagter", - "email": "backendtea@gmail.com" + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" } ], "description": "Symfony polyfill for ctype functions", @@ -1394,92 +1696,104 @@ "polyfill", "portable" ], - "time": "2018-08-06T14:22:27+00:00" + "support": { + "source": "https://github.com/symfony/polyfill-ctype/tree/v1.23.0" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2021-02-19T12:13:01+00:00" }, { - "name": "symfony/yaml", - "version": "v3.4.20", + "name": "theseer/tokenizer", + "version": "1.2.0", "source": { "type": "git", - "url": "https://github.com/symfony/yaml.git", - "reference": "291e13d808bec481eab83f301f7bff3e699ef603" + "url": "https://github.com/theseer/tokenizer.git", + "reference": "75a63c33a8577608444246075ea0af0d052e452a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/yaml/zipball/291e13d808bec481eab83f301f7bff3e699ef603", - "reference": "291e13d808bec481eab83f301f7bff3e699ef603", + "url": "https://api.github.com/repos/theseer/tokenizer/zipball/75a63c33a8577608444246075ea0af0d052e452a", + "reference": "75a63c33a8577608444246075ea0af0d052e452a", "shasum": "" }, "require": { - "php": "^5.5.9|>=7.0.8", - "symfony/polyfill-ctype": "~1.8" - }, - "conflict": { - "symfony/console": "<3.4" - }, - "require-dev": { - "symfony/console": "~3.4|~4.0" - }, - "suggest": { - "symfony/console": "For validating YAML files using the lint command" + "ext-dom": "*", + "ext-tokenizer": "*", + "ext-xmlwriter": "*", + "php": "^7.2 || ^8.0" }, "type": "library", - "extra": { - "branch-alias": { - "dev-master": "3.4-dev" - } - }, "autoload": { - "psr-4": { - "Symfony\\Component\\Yaml\\": "" - }, - "exclude-from-classmap": [ - "/Tests/" + "classmap": [ + "src/" ] }, "notification-url": "https://packagist.org/downloads/", "license": [ - "MIT" + "BSD-3-Clause" ], "authors": [ { - "name": "Fabien Potencier", - "email": "fabien@symfony.com" - }, + "name": "Arne Blankerts", + "email": "arne@blankerts.de", + "role": "Developer" + } + ], + "description": "A small library for converting tokenized PHP source code into XML and potentially other formats", + "support": { + "issues": "https://github.com/theseer/tokenizer/issues", + "source": "https://github.com/theseer/tokenizer/tree/master" + }, + "funding": [ { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" + "url": "https://github.com/theseer", + "type": "github" } ], - "description": "Symfony Yaml Component", - "homepage": "https://symfony.com", - "time": "2018-11-11T19:48:54+00:00" + "time": "2020-07-12T23:59:07+00:00" }, { "name": "webmozart/assert", - "version": "1.3.0", + "version": "1.10.0", "source": { "type": "git", - "url": "https://github.com/webmozart/assert.git", - "reference": "0df1908962e7a3071564e857d86874dad1ef204a" + "url": "https://github.com/webmozarts/assert.git", + "reference": "6964c76c7804814a842473e0c8fd15bab0f18e25" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/webmozart/assert/zipball/0df1908962e7a3071564e857d86874dad1ef204a", - "reference": "0df1908962e7a3071564e857d86874dad1ef204a", + "url": "https://api.github.com/repos/webmozarts/assert/zipball/6964c76c7804814a842473e0c8fd15bab0f18e25", + "reference": "6964c76c7804814a842473e0c8fd15bab0f18e25", "shasum": "" }, "require": { - "php": "^5.3.3 || ^7.0" + "php": "^7.2 || ^8.0", + "symfony/polyfill-ctype": "^1.8" + }, + "conflict": { + "phpstan/phpstan": "<0.12.20", + "vimeo/psalm": "<4.6.1 || 4.6.2" }, "require-dev": { - "phpunit/phpunit": "^4.6", - "sebastian/version": "^1.0.1" + "phpunit/phpunit": "^8.5.13" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "1.3-dev" + "dev-master": "1.10-dev" } }, "autoload": { @@ -1503,7 +1817,11 @@ "check", "validate" ], - "time": "2018-01-29T19:49:41+00:00" + "support": { + "issues": "https://github.com/webmozarts/assert/issues", + "source": "https://github.com/webmozarts/assert/tree/1.10.0" + }, + "time": "2021-03-09T10:59:23+00:00" } ], "aliases": [], @@ -1512,7 +1830,7 @@ "prefer-stable": false, "prefer-lowest": false, "platform": { - "php": ">=5.6.0" + "php": ">=7.1" }, "platform-dev": [], "plugin-api-version": "2.0.0" From e80e696bd6dc65649b539b8caa90cb7e2c5e106d Mon Sep 17 00:00:00 2001 From: Sergii Ivashchenko Date: Mon, 26 Jul 2021 20:32:46 +0100 Subject: [PATCH 088/630] magento/magento-coding-standard#206: Updated minimal required PHP version to 7.2 --- .github/workflows/php.yml | 2 +- composer.json | 2 +- composer.lock | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index 2f7f46c3..eee1bfeb 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -13,7 +13,7 @@ jobs: strategy: fail-fast: false matrix: - php-versions: ['7.1', '7.2', '7.3', '7.4'] + php-versions: ['7.2', '7.3', '7.4'] name: Tests with PHP ${{ matrix.php-versions }} steps: diff --git a/composer.json b/composer.json index c3b6c654..89c193c8 100644 --- a/composer.json +++ b/composer.json @@ -8,7 +8,7 @@ "type": "phpcodesniffer-standard", "version": "6", "require": { - "php": ">=7.1", + "php": ">=7.2", "squizlabs/php_codesniffer": "^3.5", "webonyx/graphql-php": "^14.9" }, diff --git a/composer.lock b/composer.lock index fa96e115..0bbf81ae 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": "1552fa061d5ee668ccf28b11417cd28e", + "content-hash": "ded4734336bc43d824498918b37b815c", "packages": [ { "name": "squizlabs/php_codesniffer", @@ -1830,7 +1830,7 @@ "prefer-stable": false, "prefer-lowest": false, "platform": { - "php": ">=7.1" + "php": ">=7.2" }, "platform-dev": [], "plugin-api-version": "2.0.0" From b4c0fa542efc3ee786b5336c941c5e976a0aca63 Mon Sep 17 00:00:00 2001 From: Ihor Sviziev Date: Tue, 27 Jul 2021 13:20:21 +0300 Subject: [PATCH 089/630] Test on lowest and highest dependencies --- .github/workflows/php.yml | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index eee1bfeb..133cec38 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -10,11 +10,25 @@ jobs: build: runs-on: ubuntu-latest + continue-on-error: ${{ matrix.experimental }} strategy: fail-fast: false matrix: - php-versions: ['7.2', '7.3', '7.4'] - name: Tests with PHP ${{ matrix.php-versions }} + php-version: + - "7.2" + - "7.3" + - "7.4" + dependencies: + - "lowest" + - "highest" + experimental: + - false + include: + - php-version: "8.0" + dependencies: "highest" + composer-options: "--ignore-platform-reqs" + experimental: true + name: Tests with PHP ${{ matrix.php-version }} and ${{ matrix.dependencies }} dependencies steps: - uses: actions/checkout@v2 @@ -22,24 +36,18 @@ jobs: - name: Setup PHP uses: shivammathur/setup-php@v2 with: - php-version: ${{ matrix.php-versions }} + php-version: ${{ matrix.php-version }} env: COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: Validate composer run: composer validate - - name: Cache Composer packages - id: composer-cache - uses: actions/cache@v2 + - name: Composer install + uses: "ramsey/composer-install@v1" with: - path: vendor - key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} - restore-keys: | - ${{ runner.os }}-composer- - - name: Install dependencies - if: steps.composer-cache.outputs.cache-hit != 'true' - run: composer install --prefer-dist --no-interaction + dependency-versions: "${{ matrix.dependencies }}" + composer-options: "${{ matrix.composer-options }}" - name: Run unit tests suite run: vendor/bin/phpunit From 3d68361dde3d2eba32be4b42b20465258da79479 Mon Sep 17 00:00:00 2001 From: Marc Ginesta Date: Wed, 28 Jul 2021 12:33:34 +0200 Subject: [PATCH 090/630] AC-201: Move phpcs checks from magento2 to magento-coding-standard repo - Move files from Annotation folder --- .../Annotation/AnnotationFormatValidator.php | 374 ++++++++++ .../MethodAnnotationStructureSniff.php | 86 +++ .../Annotation/MethodArgumentsSniff.php | 684 ++++++++++++++++++ Magento2/ruleset.xml | 5 + 4 files changed, 1149 insertions(+) create mode 100644 Magento2/Sniffs/Annotation/AnnotationFormatValidator.php create mode 100644 Magento2/Sniffs/Annotation/MethodAnnotationStructureSniff.php create mode 100644 Magento2/Sniffs/Annotation/MethodArgumentsSniff.php diff --git a/Magento2/Sniffs/Annotation/AnnotationFormatValidator.php b/Magento2/Sniffs/Annotation/AnnotationFormatValidator.php new file mode 100644 index 00000000..cd4c8689 --- /dev/null +++ b/Magento2/Sniffs/Annotation/AnnotationFormatValidator.php @@ -0,0 +1,374 @@ +getTokens(); + $shortPtrEnd = $shortPtr; + for ($i = ($shortPtr + 1); $i < $commentEndPtr; $i++) { + if ($tokens[$i]['code'] === T_DOC_COMMENT_STRING) { + if ($tokens[$i]['line'] === $tokens[$shortPtrEnd]['line'] + 1) { + $shortPtrEnd = $i; + } else { + break; + } + } + } + return $shortPtrEnd; + } + + /** + * Validates whether the short description has multi lines in description + * + * @param File $phpcsFile + * @param int $shortPtr + * @param int $commentEndPtr + */ + private function validateMultiLinesInShortDescription( + File $phpcsFile, + int $shortPtr, + int $commentEndPtr + ): void { + $tokens = $phpcsFile->getTokens(); + $shortPtrEnd = $this->getShortDescriptionEndPosition( + $phpcsFile, + (int)$shortPtr, + $commentEndPtr + ); + $shortPtrEndContent = $tokens[$shortPtrEnd]['content']; + if (preg_match('/^[a-z]/', $shortPtrEndContent) + && $shortPtrEnd != $shortPtr + && !preg_match('/\bSee\b/', $shortPtrEndContent) + && $tokens[$shortPtr]['line'] + 1 === $tokens[$shortPtrEnd]['line'] + && $tokens[$shortPtrEnd]['code'] !== T_DOC_COMMENT_TAG + ) { + $error = 'Short description should not be in multi lines'; + $phpcsFile->addFixableError($error, $shortPtrEnd + 1, 'MethodAnnotation'); + } + } + + /** + * Validates whether the spacing between short and long descriptions + * + * @param File $phpcsFile + * @param int $shortPtr + * @param int $commentEndPtr + * @param array $emptyTypeTokens + */ + private function validateSpacingBetweenShortAndLongDescriptions( + File $phpcsFile, + int $shortPtr, + int $commentEndPtr, + array $emptyTypeTokens + ): void { + $tokens = $phpcsFile->getTokens(); + $shortPtrEnd = $this->getShortDescriptionEndPosition( + $phpcsFile, + (int)$shortPtr, + $commentEndPtr + ); + $shortPtrEndContent = $tokens[$shortPtrEnd]['content']; + if (preg_match('/^[A-Z]/', $shortPtrEndContent) + && !preg_match('/\bSee\b/', $shortPtrEndContent) + && $tokens[$shortPtr]['line'] + 1 === $tokens[$shortPtrEnd]['line'] + && $tokens[$shortPtrEnd]['code'] !== T_DOC_COMMENT_TAG + ) { + $error = 'There must be exactly one blank line between lines short and long descriptions'; + $phpcsFile->addFixableError($error, $shortPtrEnd + 1, 'MethodAnnotation'); + } + if ($shortPtrEnd != $shortPtr) { + $this->validateLongDescriptionFormat($phpcsFile, $shortPtrEnd, $commentEndPtr, $emptyTypeTokens); + } else { + $this->validateLongDescriptionFormat($phpcsFile, $shortPtr, $commentEndPtr, $emptyTypeTokens); + } + } + + /** + * Validates short description format + * + * @param File $phpcsFile + * @param int $shortPtr + * @param int $stackPtr + * @param int $commentEndPtr + * @param array $emptyTypeTokens + */ + private function validateShortDescriptionFormat( + File $phpcsFile, + int $shortPtr, + int $stackPtr, + int $commentEndPtr, + array $emptyTypeTokens + ): void { + $tokens = $phpcsFile->getTokens(); + if ($tokens[$shortPtr]['line'] !== $tokens[$stackPtr]['line'] + 1) { + $error = 'No blank lines are allowed before short description'; + $phpcsFile->addFixableError($error, $shortPtr, 'MethodAnnotation'); + } + if (strtolower($tokens[$shortPtr]['content']) === '{@inheritdoc}') { + $error = 'If the @inheritdoc not inline it shouldn’t have braces'; + $phpcsFile->addFixableError($error, $shortPtr, 'MethodAnnotation'); + } + $shortPtrContent = $tokens[$shortPtr]['content']; + if (preg_match('/^\p{Ll}/u', $shortPtrContent) === 1) { + $error = 'Short description must start with a capital letter'; + $phpcsFile->addFixableError($error, $shortPtr, 'MethodAnnotation'); + } + $this->validateNoExtraNewLineBeforeShortDescription( + $phpcsFile, + $stackPtr, + $commentEndPtr, + $emptyTypeTokens + ); + $this->validateSpacingBetweenShortAndLongDescriptions( + $phpcsFile, + $shortPtr, + $commentEndPtr, + $emptyTypeTokens + ); + $this->validateMultiLinesInShortDescription( + $phpcsFile, + $shortPtr, + $commentEndPtr + ); + } + + /** + * Validates long description format + * + * @param File $phpcsFile + * @param int $shortPtrEnd + * @param int $commentEndPtr + * @param array $emptyTypeTokens + */ + private function validateLongDescriptionFormat( + File $phpcsFile, + int $shortPtrEnd, + int $commentEndPtr, + array $emptyTypeTokens + ): void { + $tokens = $phpcsFile->getTokens(); + $longPtr = $phpcsFile->findNext($emptyTypeTokens, $shortPtrEnd + 1, $commentEndPtr - 1, true); + if (strtolower($tokens[$longPtr]['content']) === '@inheritdoc') { + $error = '@inheritdoc imports only short description, annotation must have long description'; + $phpcsFile->addFixableError($error, $longPtr, 'MethodAnnotation'); + } + if ($longPtr !== false && $tokens[$longPtr]['code'] === T_DOC_COMMENT_STRING) { + if ($tokens[$longPtr]['line'] !== $tokens[$shortPtrEnd]['line'] + 2) { + $error = 'There must be exactly one blank line between descriptions'; + $phpcsFile->addFixableError($error, $longPtr, 'MethodAnnotation'); + } + if (preg_match('/^\p{Ll}/u', $tokens[$longPtr]['content']) === 1) { + $error = 'Long description must start with a capital letter'; + $phpcsFile->addFixableError($error, $longPtr, 'MethodAnnotation'); + } + } + } + + /** + * Validates tags spacing format + * + * @param File $phpcsFile + * @param int $commentStartPtr + * @param array $emptyTypeTokens + */ + public function validateTagsSpacingFormat(File $phpcsFile, int $commentStartPtr, array $emptyTypeTokens): void + { + $tokens = $phpcsFile->getTokens(); + if (isset($tokens[$commentStartPtr]['comment_tags'][0])) { + $firstTagPtr = $tokens[$commentStartPtr]['comment_tags'][0]; + $commentTagPtrContent = $tokens[$firstTagPtr]['content']; + $prevPtr = $phpcsFile->findPrevious($emptyTypeTokens, $firstTagPtr - 1, $commentStartPtr, true); + if ($tokens[$firstTagPtr]['line'] !== $tokens[$prevPtr]['line'] + 2 + && strtolower($commentTagPtrContent) !== '@inheritdoc' + ) { + $error = 'There must be exactly one blank line before tags'; + $phpcsFile->addFixableError($error, $firstTagPtr, 'MethodAnnotation'); + } + } + } + + /** + * Validates tag grouping format + * + * @param File $phpcsFile + * @param int $commentStartPtr + */ + public function validateTagGroupingFormat(File $phpcsFile, int $commentStartPtr): void + { + $tokens = $phpcsFile->getTokens(); + $tagGroups = []; + $groupId = 0; + $paramGroupId = null; + foreach ($tokens[$commentStartPtr]['comment_tags'] as $position => $tag) { + if ($position > 0) { + $prevPtr = $phpcsFile->findPrevious( + T_DOC_COMMENT_STRING, + $tag - 1, + $tokens[$commentStartPtr]['comment_tags'][$position - 1] + ); + if ($prevPtr === false) { + $prevPtr = $tokens[$commentStartPtr]['comment_tags'][$position - 1]; + } + + if ($tokens[$prevPtr]['line'] !== $tokens[$tag]['line'] - 1) { + $groupId++; + } + } + + if (strtolower($tokens[$tag]['content']) === '@param') { + if ($paramGroupId !== null + && $paramGroupId !== $groupId) { + $error = 'Parameter tags must be grouped together'; + $phpcsFile->addFixableError($error, $tag, 'MethodAnnotation'); + } + if ($paramGroupId === null) { + $paramGroupId = $groupId; + } + } + $tagGroups[$groupId][] = $tag; + } + } + + /** + * Validates tag aligning format + * + * @param File $phpcsFile + * @param int $commentStartPtr + */ + public function validateTagAligningFormat(File $phpcsFile, int $commentStartPtr): void + { + $tokens = $phpcsFile->getTokens(); + $noAlignmentPositions = []; + $actualPositions = []; + $stackPtr = null; + foreach ($tokens[$commentStartPtr]['comment_tags'] as $tag) { + $content = $tokens[$tag]['content']; + if (preg_match('/^@/', $content) && ($tokens[$tag]['line'] === $tokens[$tag + 2]['line'])) { + $noAlignmentPositions[] = $tokens[$tag + 1]['column'] + 1; + $actualPositions[] = $tokens[$tag + 2]['column']; + $stackPtr = $stackPtr ?? $tag; + } + } + + if (!$this->allTagsAligned($actualPositions) + && !$this->noneTagsAligned($actualPositions, $noAlignmentPositions)) { + $phpcsFile->addFixableError( + 'Tags visual alignment must be consistent', + $stackPtr, + 'MethodArguments' + ); + } + } + + /** + * Check whether all docblock params are aligned. + * + * @param array $actualPositions + * @return bool + */ + private function allTagsAligned(array $actualPositions): bool + { + return count(array_unique($actualPositions)) === 1; + } + + /** + * Check whether all docblock params are not aligned. + * + * @param array $actualPositions + * @param array $noAlignmentPositions + * @return bool + */ + private function noneTagsAligned(array $actualPositions, array $noAlignmentPositions): bool + { + return $actualPositions === $noAlignmentPositions; + } + + /** + * Validates extra newline before short description + * + * @param File $phpcsFile + * @param int $commentStartPtr + * @param int $commentEndPtr + * @param array $emptyTypeTokens + */ + private function validateNoExtraNewLineBeforeShortDescription( + File $phpcsFile, + int $commentStartPtr, + int $commentEndPtr, + array $emptyTypeTokens + ): void { + $tokens = $phpcsFile->getTokens(); + $prevPtr = $phpcsFile->findPrevious($emptyTypeTokens, $commentEndPtr - 1, $commentStartPtr, true); + if ($tokens[$prevPtr]['line'] < ($tokens[$commentEndPtr]['line'] - 1)) { + $error = 'Additional blank lines found at end of the annotation block'; + $phpcsFile->addFixableError($error, $commentEndPtr, 'MethodAnnotation'); + } + } + + /** + * Validates structure description format + * + * @param File $phpcsFile + * @param int $commentStartPtr + * @param int $shortPtr + * @param int $commentEndPtr + * @param array $emptyTypeTokens + */ + public function validateDescriptionFormatStructure( + File $phpcsFile, + int $commentStartPtr, + int $shortPtr, + int $commentEndPtr, + array $emptyTypeTokens + ): void { + $tokens = $phpcsFile->getTokens(); + if (isset($tokens[$commentStartPtr]['comment_tags'][0]) + ) { + $commentTagPtr = $tokens[$commentStartPtr]['comment_tags'][0]; + $commentTagPtrContent = $tokens[$commentTagPtr]['content']; + if ($tokens[$shortPtr]['code'] !== T_DOC_COMMENT_STRING + && strtolower($commentTagPtrContent) !== '@inheritdoc' + ) { + $error = 'Missing short description'; + $phpcsFile->addFixableError($error, $commentStartPtr, 'MethodAnnotation'); + } else { + $this->validateShortDescriptionFormat( + $phpcsFile, + (int)$shortPtr, + (int)$commentStartPtr, + (int)$commentEndPtr, + $emptyTypeTokens + ); + } + } else { + $this->validateShortDescriptionFormat( + $phpcsFile, + (int)$shortPtr, + $commentStartPtr, + $commentEndPtr, + $emptyTypeTokens + ); + } + } +} diff --git a/Magento2/Sniffs/Annotation/MethodAnnotationStructureSniff.php b/Magento2/Sniffs/Annotation/MethodAnnotationStructureSniff.php new file mode 100644 index 00000000..3df07533 --- /dev/null +++ b/Magento2/Sniffs/Annotation/MethodAnnotationStructureSniff.php @@ -0,0 +1,86 @@ +annotationFormatValidator = new AnnotationFormatValidator(); + } + + /** + * @inheritdoc + */ + public function register() + { + return [ + T_FUNCTION + ]; + } + + /** + * @inheritdoc + */ + public function process(File $phpcsFile, $stackPtr) + { + $tokens = $phpcsFile->getTokens(); + $commentStartPtr = $phpcsFile->findPrevious(T_DOC_COMMENT_OPEN_TAG, ($stackPtr), 0); + $commentEndPtr = $phpcsFile->findPrevious(T_DOC_COMMENT_CLOSE_TAG, ($stackPtr), 0); + if (!$commentStartPtr) { + $phpcsFile->addError('Comment block is missing', $stackPtr, 'MethodArguments'); + return; + } + $commentCloserPtr = $tokens[$commentStartPtr]['comment_closer']; + $functionPtrContent = $tokens[$stackPtr + 2]['content']; + if (preg_match('/(?i)__construct/', $functionPtrContent)) { + return; + } + $emptyTypeTokens = [ + T_DOC_COMMENT_WHITESPACE, + T_DOC_COMMENT_STAR + ]; + $shortPtr = $phpcsFile->findNext($emptyTypeTokens, $commentStartPtr + 1, $commentCloserPtr, true); + if ($shortPtr === false) { + $error = 'Annotation block is empty'; + $phpcsFile->addError($error, $commentStartPtr, 'MethodAnnotation'); + } else { + $this->annotationFormatValidator->validateDescriptionFormatStructure( + $phpcsFile, + $commentStartPtr, + (int)$shortPtr, + $commentEndPtr, + $emptyTypeTokens + ); + if (empty($tokens[$commentStartPtr]['comment_tags'])) { + return; + } + $this->annotationFormatValidator->validateTagsSpacingFormat( + $phpcsFile, + $commentStartPtr, + $emptyTypeTokens + ); + $this->annotationFormatValidator->validateTagGroupingFormat($phpcsFile, $commentStartPtr); + $this->annotationFormatValidator->validateTagAligningFormat($phpcsFile, $commentStartPtr); + } + } +} diff --git a/Magento2/Sniffs/Annotation/MethodArgumentsSniff.php b/Magento2/Sniffs/Annotation/MethodArgumentsSniff.php new file mode 100644 index 00000000..54e10100 --- /dev/null +++ b/Magento2/Sniffs/Annotation/MethodArgumentsSniff.php @@ -0,0 +1,684 @@ +validTokensBeforeClosingCommentTag); + } + + /** + * Validates whether comment block exists + * + * @param File $phpcsFile + * @param int $previousCommentClosePtr + * @param int $stackPtr + * @return bool + */ + private function validateCommentBlockExists(File $phpcsFile, int $previousCommentClosePtr, int $stackPtr): bool + { + $tokens = $phpcsFile->getTokens(); + for ($tempPtr = $previousCommentClosePtr + 1; $tempPtr < $stackPtr; $tempPtr++) { + if (!$this->isTokenBeforeClosingCommentTagValid($tokens[$tempPtr]['type'])) { + return false; + } + } + return true; + } + + /** + * Checks whether the parameter type is invalid + * + * @param string $type + * @return bool + */ + private function isInvalidType(string $type): bool + { + return in_array(strtolower($type), $this->invalidTypes); + } + + /** + * Get arguments from method signature + * + * @param File $phpcsFile + * @param int $openParenthesisPtr + * @param int $closedParenthesisPtr + * @return array + */ + private function getMethodArguments(File $phpcsFile, int $openParenthesisPtr, int $closedParenthesisPtr): array + { + $tokens = $phpcsFile->getTokens(); + $methodArguments = []; + for ($i = $openParenthesisPtr; $i < $closedParenthesisPtr; $i++) { + $argumentsPtr = $phpcsFile->findNext(T_VARIABLE, $i + 1, $closedParenthesisPtr); + if ($argumentsPtr === false) { + break; + } elseif ($argumentsPtr < $closedParenthesisPtr) { + $arguments = $tokens[$argumentsPtr]['content']; + $methodArguments[] = $arguments; + $i = $argumentsPtr - 1; + } + } + return $methodArguments; + } + + /** + * Get parameters from method annotation + * + * @param array $paramDefinitions + * @return array + */ + private function getMethodParameters(array $paramDefinitions): array + { + $paramName = []; + foreach ($paramDefinitions as $paramDefinition) { + if (isset($paramDefinition['paramName'])) { + $paramName[] = $paramDefinition['paramName']; + } + } + return $paramName; + } + + /** + * Validates whether @inheritdoc without braces [@inheritdoc] exists or not + * + * @param File $phpcsFile + * @param int $previousCommentOpenPtr + * @param int $previousCommentClosePtr + */ + private function validateInheritdocAnnotationWithoutBracesExists( + File $phpcsFile, + int $previousCommentOpenPtr, + int $previousCommentClosePtr + ): bool { + return $this->validateInheritdocAnnotationExists( + $phpcsFile, + $previousCommentOpenPtr, + $previousCommentClosePtr, + '@inheritdoc' + ); + } + + /** + * Validates whether @inheritdoc with braces [{@inheritdoc}] exists or not + * + * @param File $phpcsFile + * @param int $previousCommentOpenPtr + * @param int $previousCommentClosePtr + */ + private function validateInheritdocAnnotationWithBracesExists( + File $phpcsFile, + int $previousCommentOpenPtr, + int $previousCommentClosePtr + ): bool { + return $this->validateInheritdocAnnotationExists( + $phpcsFile, + $previousCommentOpenPtr, + $previousCommentClosePtr, + '{@inheritdoc}' + ); + } + + /** + * Validates inheritdoc annotation exists + * + * @param File $phpcsFile + * @param int $previousCommentOpenPtr + * @param int $previousCommentClosePtr + * @param string $inheritdocAnnotation + * @return bool + */ + private function validateInheritdocAnnotationExists( + File $phpcsFile, + int $previousCommentOpenPtr, + int $previousCommentClosePtr, + string $inheritdocAnnotation + ): bool { + $tokens = $phpcsFile->getTokens(); + for ($ptr = $previousCommentOpenPtr; $ptr < $previousCommentClosePtr; $ptr++) { + if (strtolower($tokens[$ptr]['content']) === $inheritdocAnnotation) { + return true; + } + } + return false; + } + + /** + * Validates if annotation exists for parameter in method annotation + * + * @param File $phpcsFile + * @param int $argumentsCount + * @param int $parametersCount + * @param int $previousCommentOpenPtr + * @param int $previousCommentClosePtr + * @param int $stackPtr + */ + private function validateParameterAnnotationForArgumentExists( + File $phpcsFile, + int $argumentsCount, + int $parametersCount, + int $previousCommentOpenPtr, + int $previousCommentClosePtr, + int $stackPtr + ): void { + if ($argumentsCount > 0 && $parametersCount === 0) { + $inheritdocAnnotationWithoutBracesExists = $this->validateInheritdocAnnotationWithoutBracesExists( + $phpcsFile, + $previousCommentOpenPtr, + $previousCommentClosePtr + ); + $inheritdocAnnotationWithBracesExists = $this->validateInheritdocAnnotationWithBracesExists( + $phpcsFile, + $previousCommentOpenPtr, + $previousCommentClosePtr + ); + if ($inheritdocAnnotationWithBracesExists) { + $phpcsFile->addFixableError( + '{@inheritdoc} does not import parameter annotation', + $stackPtr, + 'MethodArguments' + ); + } elseif ($this->validateCommentBlockExists($phpcsFile, $previousCommentClosePtr, $stackPtr) + && !$inheritdocAnnotationWithoutBracesExists + ) { + $phpcsFile->addFixableError( + 'Missing @param for argument in method annotation', + $stackPtr, + 'MethodArguments' + ); + } + } + } + + /** + * Validates whether comment block have extra the parameters listed in method annotation + * + * @param File $phpcsFile + * @param int $argumentsCount + * @param int $parametersCount + * @param int $stackPtr + */ + private function validateCommentBlockDoesnotHaveExtraParameterAnnotation( + File $phpcsFile, + int $argumentsCount, + int $parametersCount, + int $stackPtr + ): void { + if ($argumentsCount < $parametersCount && $argumentsCount > 0) { + $phpcsFile->addFixableError( + 'Extra @param found in method annotation', + $stackPtr, + 'MethodArguments' + ); + } elseif ($argumentsCount > 0 && $argumentsCount != $parametersCount && $parametersCount != 0) { + $phpcsFile->addFixableError( + '@param is not found for one or more params in method annotation', + $stackPtr, + 'MethodArguments' + ); + } + } + + /** + * Validates whether the argument name exists in method parameter annotation + * + * @param int $stackPtr + * @param int $ptr + * @param File $phpcsFile + * @param array $methodArguments + * @param array $paramDefinitions + */ + private function validateArgumentNameInParameterAnnotationExists( + int $stackPtr, + int $ptr, + File $phpcsFile, + array $methodArguments, + array $paramDefinitions + ): void { + $parameterNames = $this->getMethodParameters($paramDefinitions); + if (!in_array($methodArguments[$ptr], $parameterNames)) { + $error = $methodArguments[$ptr] . ' parameter is missing in method annotation'; + $phpcsFile->addFixableError($error, $stackPtr, 'MethodArguments'); + } + } + + /** + * Validates whether parameter present in method signature + * + * @param int $ptr + * @param int $paramDefinitionsArguments + * @param array $methodArguments + * @param File $phpcsFile + * @param array $paramPointers + */ + private function validateParameterPresentInMethodSignature( + int $ptr, + string $paramDefinitionsArguments, + array $methodArguments, + File $phpcsFile, + array $paramPointers + ): void { + if (!in_array($paramDefinitionsArguments, $methodArguments)) { + $phpcsFile->addFixableError( + $paramDefinitionsArguments . ' parameter is missing in method arguments signature', + $paramPointers[$ptr], + 'MethodArguments' + ); + } + } + + /** + * Validates whether the parameters are in order or not in method annotation + * + * @param array $paramDefinitions + * @param array $methodArguments + * @param File $phpcsFile + * @param array $paramPointers + */ + private function validateParameterOrderIsCorrect( + array $paramDefinitions, + array $methodArguments, + File $phpcsFile, + array $paramPointers + ): void { + $parameterNames = $this->getMethodParameters($paramDefinitions); + $paramDefinitionsCount = count($paramDefinitions); + for ($ptr = 0; $ptr < $paramDefinitionsCount; $ptr++) { + if (isset($methodArguments[$ptr]) && isset($parameterNames[$ptr]) + && in_array($methodArguments[$ptr], $parameterNames) + ) { + if ($methodArguments[$ptr] != $parameterNames[$ptr]) { + $phpcsFile->addFixableError( + $methodArguments[$ptr] . ' parameter is not in order', + $paramPointers[$ptr], + 'MethodArguments' + ); + } + } + } + } + + /** + * Validate whether duplicate annotation present in method annotation + * + * @param int $stackPtr + * @param array $paramDefinitions + * @param array $paramPointers + * @param File $phpcsFile + * @param array $methodArguments + */ + private function validateDuplicateAnnotationDoesnotExists( + int $stackPtr, + array $paramDefinitions, + array $paramPointers, + File $phpcsFile, + array $methodArguments + ): void { + $argumentsCount = count($methodArguments); + $parametersCount = count($paramPointers); + if ($argumentsCount <= $parametersCount && $argumentsCount > 0) { + $duplicateParameters = []; + foreach ($paramDefinitions as $i => $paramDefinition) { + if (isset($paramDefinition['paramName'])) { + $parameterContent = $paramDefinition['paramName']; + foreach (array_slice($paramDefinitions, $i + 1) as $nextParamDefinition) { + if (isset($nextParamDefinition['paramName']) + && $parameterContent === $nextParamDefinition['paramName'] + ) { + $duplicateParameters[] = $parameterContent; + } + } + } + } + foreach ($duplicateParameters as $value) { + $phpcsFile->addFixableError( + $value . ' duplicate found in method annotation', + $stackPtr, + 'MethodArguments' + ); + } + } + } + + /** + * Validate parameter annotation format is correct or not + * + * @param int $ptr + * @param File $phpcsFile + * @param array $methodArguments + * @param array $paramDefinitions + * @param array $paramPointers + */ + private function validateParameterAnnotationFormatIsCorrect( + int $ptr, + File $phpcsFile, + array $methodArguments, + array $paramDefinitions, + array $paramPointers + ): void { + switch (count($paramDefinitions)) { + case 0: + $phpcsFile->addFixableError( + 'Missing both type and parameter', + $paramPointers[$ptr], + 'MethodArguments' + ); + break; + case 1: + if (preg_match('/^\$.*/', $paramDefinitions[0])) { + $phpcsFile->addError( + 'Type is not specified', + $paramPointers[$ptr], + 'MethodArguments' + ); + } + break; + case 2: + if ($this->isInvalidType($paramDefinitions[0])) { + $phpcsFile->addFixableError( + $paramDefinitions[0] . ' is not a valid PHP type', + $paramPointers[$ptr], + 'MethodArguments' + ); + } + $this->validateParameterPresentInMethodSignature( + $ptr, + ltrim($paramDefinitions[1], '&'), + $methodArguments, + $phpcsFile, + $paramPointers + ); + break; + default: + if (preg_match('/^\$.*/', $paramDefinitions[0])) { + $phpcsFile->addError( + 'Type is not specified', + $paramPointers[$ptr], + 'MethodArguments' + ); + if ($this->isInvalidType($paramDefinitions[0])) { + $phpcsFile->addFixableError( + $paramDefinitions[0] . ' is not a valid PHP type', + $paramPointers[$ptr], + 'MethodArguments' + ); + } + } + break; + } + } + + /** + * Validate method parameter annotations + * + * @param int $stackPtr + * @param array $paramDefinitions + * @param array $paramPointers + * @param File $phpcsFile + * @param array $methodArguments + * @param int $previousCommentOpenPtr + * @param int $previousCommentClosePtr + * + * @SuppressWarnings(PHPMD.UnusedLocalVariable) + */ + private function validateMethodParameterAnnotations( + int $stackPtr, + array $paramDefinitions, + array $paramPointers, + File $phpcsFile, + array $methodArguments, + int $previousCommentOpenPtr, + int $previousCommentClosePtr + ): void { + $argumentCount = count($methodArguments); + $paramCount = count($paramPointers); + $this->validateParameterAnnotationForArgumentExists( + $phpcsFile, + $argumentCount, + $paramCount, + $previousCommentOpenPtr, + $previousCommentClosePtr, + $stackPtr + ); + $this->validateCommentBlockDoesnotHaveExtraParameterAnnotation( + $phpcsFile, + $argumentCount, + $paramCount, + $stackPtr + ); + $this->validateDuplicateAnnotationDoesnotExists( + $stackPtr, + $paramDefinitions, + $paramPointers, + $phpcsFile, + $methodArguments + ); + $this->validateParameterOrderIsCorrect( + $paramDefinitions, + $methodArguments, + $phpcsFile, + $paramPointers + ); + $this->validateFormattingConsistency( + $paramDefinitions, + $methodArguments, + $phpcsFile, + $paramPointers + ); + $tokens = $phpcsFile->getTokens(); + + foreach ($methodArguments as $ptr => $methodArgument) { + if (isset($paramPointers[$ptr])) { + $this->validateArgumentNameInParameterAnnotationExists( + $stackPtr, + $ptr, + $phpcsFile, + $methodArguments, + $paramDefinitions + ); + $paramContent = $tokens[$paramPointers[$ptr] + 2]['content']; + $paramContentExplode = explode(' ', $paramContent); + $this->validateParameterAnnotationFormatIsCorrect( + $ptr, + $phpcsFile, + $methodArguments, + $paramContentExplode, + $paramPointers + ); + } + } + } + + /** + * @inheritdoc + */ + public function process(File $phpcsFile, $stackPtr) + { + $tokens = $phpcsFile->getTokens(); + $numTokens = count($tokens); + $previousCommentOpenPtr = $phpcsFile->findPrevious(T_DOC_COMMENT_OPEN_TAG, $stackPtr - 1, 0); + $previousCommentClosePtr = $phpcsFile->findPrevious(T_DOC_COMMENT_CLOSE_TAG, $stackPtr - 1, 0); + if ($previousCommentClosePtr && $previousCommentOpenPtr) { + if (!$this->validateCommentBlockExists($phpcsFile, $previousCommentClosePtr, $stackPtr)) { + $phpcsFile->addError('Comment block is missing', $stackPtr, 'MethodArguments'); + return; + } + } else { + return; + } + $openParenthesisPtr = $phpcsFile->findNext(T_OPEN_PARENTHESIS, $stackPtr + 1, $numTokens); + $closedParenthesisPtr = $phpcsFile->findNext(T_CLOSE_PARENTHESIS, $stackPtr + 1, $numTokens); + $methodArguments = $this->getMethodArguments($phpcsFile, $openParenthesisPtr, $closedParenthesisPtr); + $paramPointers = $paramDefinitions = []; + for ($tempPtr = $previousCommentOpenPtr; $tempPtr < $previousCommentClosePtr; $tempPtr++) { + if (strtolower($tokens[$tempPtr]['content']) === '@param') { + $paramPointers[] = $tempPtr; + $content = preg_replace('/\s+/', ' ', $tokens[$tempPtr + 2]['content'], 2); + $paramAnnotationParts = explode(' ', $content, 3); + if (count($paramAnnotationParts) === 1) { + if ((preg_match('/^\$.*/', $paramAnnotationParts[0]))) { + $paramDefinitions[] = [ + 'type' => null, + 'paramName' => rtrim(ltrim($tokens[$tempPtr + 2]['content'], '&'), ','), + 'comment' => null + ]; + } else { + $paramDefinitions[] = [ + 'type' => $tokens[$tempPtr + 2]['content'], + 'paramName' => null, + 'comment' => null + ]; + } + } else { + $paramDefinitions[] = [ + 'type' => $paramAnnotationParts[0], + 'paramName' => rtrim(ltrim($paramAnnotationParts[1], '&'), ','), + 'comment' => $paramAnnotationParts[2] ?? null, + ]; + } + } + } + $this->validateMethodParameterAnnotations( + $stackPtr, + $paramDefinitions, + $paramPointers, + $phpcsFile, + $methodArguments, + $previousCommentOpenPtr, + $previousCommentClosePtr + ); + } + + /** + * Validates function params format consistency. + * + * @param array $paramDefinitions + * @param array $methodArguments + * @param File $phpcsFile + * @param array $paramPointers + * + * @SuppressWarnings(PHPMD.UnusedLocalVariable) + * + * @see https://devdocs.magento.com/guides/v2.4/coding-standards/docblock-standard-general.html#format-consistency + */ + private function validateFormattingConsistency( + array $paramDefinitions, + array $methodArguments, + File $phpcsFile, + array $paramPointers + ): void { + $argumentPositions = []; + $commentPositions = []; + $tokens = $phpcsFile->getTokens(); + foreach ($methodArguments as $ptr => $methodArgument) { + if (isset($paramPointers[$ptr])) { + $paramContent = $tokens[$paramPointers[$ptr] + 2]['content']; + $paramDefinition = $paramDefinitions[$ptr]; + $argumentPositions[] = strpos($paramContent, $paramDefinition['paramName']); + $commentPositions[] = $paramDefinition['comment'] + ? strrpos($paramContent, $paramDefinition['comment']) : null; + } + } + if (!$this->allParamsAligned($argumentPositions, $commentPositions) + && !$this->noneParamsAligned($argumentPositions, $commentPositions, $paramDefinitions)) { + $phpcsFile->addFixableError( + 'Method arguments visual alignment must be consistent', + $paramPointers[0], + 'MethodArguments' + ); + } + } + + /** + * Check all params are aligned. + * + * @param array $argumentPositions + * @param array $commentPositions + * @return bool + */ + private function allParamsAligned(array $argumentPositions, array $commentPositions): bool + { + return count(array_unique($argumentPositions)) === 1 + && count(array_unique(array_filter($commentPositions))) <= 1; + } + + /** + * Check none of params are aligned. + * + * @param array $argumentPositions + * @param array $commentPositions + * @param array $paramDefinitions + * @return bool + */ + private function noneParamsAligned(array $argumentPositions, array $commentPositions, array $paramDefinitions): bool + { + $flag = true; + foreach ($argumentPositions as $index => $argumentPosition) { + $commentPosition = $commentPositions[$index]; + $type = $paramDefinitions[$index]['type']; + if ($type === null) { + continue; + } + $paramName = $paramDefinitions[$index]['paramName']; + if (($argumentPosition !== strlen($type) + 1) || + (isset($commentPosition) && ($commentPosition !== $argumentPosition + strlen($paramName) + 1))) { + $flag = false; + break; + } + } + + return $flag; + } +} diff --git a/Magento2/ruleset.xml b/Magento2/ruleset.xml index 0a0bed7b..ef9b9aca 100644 --- a/Magento2/ruleset.xml +++ b/Magento2/ruleset.xml @@ -580,4 +580,9 @@ 5 warning + + */_files/* + */Test/* + *Test.php + From 73181d9d8bdd0a738efca49c773a4bc4dfe9c53f Mon Sep 17 00:00:00 2001 From: Marc Ginesta Date: Wed, 28 Jul 2021 12:45:01 +0200 Subject: [PATCH 091/630] AC-201: Move phpcs checks from magento2 to magento-coding-standard repo - Move files from Html folder --- Magento2/Sniffs/Html/HtmlBindingSniff.php | 91 +++++++ Magento2/Sniffs/Html/HtmlDirectiveSniff.php | 257 ++++++++++++++++++++ 2 files changed, 348 insertions(+) create mode 100644 Magento2/Sniffs/Html/HtmlBindingSniff.php create mode 100644 Magento2/Sniffs/Html/HtmlDirectiveSniff.php diff --git a/Magento2/Sniffs/Html/HtmlBindingSniff.php b/Magento2/Sniffs/Html/HtmlBindingSniff.php new file mode 100644 index 00000000..1d09b7a6 --- /dev/null +++ b/Magento2/Sniffs/Html/HtmlBindingSniff.php @@ -0,0 +1,91 @@ +getTokensAsString($stackPointer, count($file->getTokens())); + $dom = new \DOMDocument(); + try { + // phpcs:disable Generic.PHP.NoSilencedErrors + @$dom->loadHTML($html); + return $dom; + } catch (\Throwable $exception) { + return null; + } + } + + return null; + } + + /** + * @inheritDoc + * + * Find HTML data bindings and check variables used. + */ + public function process(File $phpcsFile, $stackPtr) + { + if (!$dom = $this->loadHtmlDocument($stackPtr, $phpcsFile)) { + return; + } + + /** @var string[] $htmlBindings */ + $htmlBindings = []; + $domXpath = new \DOMXPath($dom); + $dataBindAttributes = $domXpath->query('//@*[name() = "data-bind"]'); + foreach ($dataBindAttributes as $dataBindAttribute) { + $knockoutBinding = $dataBindAttribute->nodeValue; + preg_match('/^(.+\s*?)?html\s*?\:(.+)/ims', $knockoutBinding, $htmlBindingStart); + if ($htmlBindingStart) { + $htmlBinding = trim(preg_replace('/\,[a-z0-9\_\s]+\:.+/ims', '', $htmlBindingStart[2])); + $htmlBindings[] = $htmlBinding; + } + } + $htmlAttributes = $domXpath->query('//@*[name() = "html"]'); + foreach ($htmlAttributes as $htmlAttribute) { + $magentoBinding = $htmlAttribute->nodeValue; + $htmlBindings[] = trim($magentoBinding); + } + foreach ($htmlBindings as $htmlBinding) { + if (!preg_match('/^[0-9\\\'\"]/ims', $htmlBinding) + && !preg_match('/UnsanitizedHtml(\(.*?\))*?$/', $htmlBinding) + ) { + $phpcsFile->addError( + 'Variables/functions used for HTML binding must have UnsanitizedHtml suffix' + . ' - "' . $htmlBinding . '" doesn\'t,' . PHP_EOL + . 'consider using text binding if the value is supposed to be text', + null, + 'UIComponentTemplate.KnockoutBinding.HtmlSuffix' + ); + } + } + } +} diff --git a/Magento2/Sniffs/Html/HtmlDirectiveSniff.php b/Magento2/Sniffs/Html/HtmlDirectiveSniff.php new file mode 100644 index 00000000..33ffdf29 --- /dev/null +++ b/Magento2/Sniffs/Html/HtmlDirectiveSniff.php @@ -0,0 +1,257 @@ +usedVariables = []; + $this->unfilteredVariables = []; + if ($stackPtr !== 0) { + return; + } + + $html = $phpcsFile->getTokensAsString($stackPtr, count($phpcsFile->getTokens())); + + if (empty($html)) { + return; + } + + $html = $this->processIfDirectives($html, $phpcsFile); + $html = $this->processDependDirectives($html, $phpcsFile); + $html = $this->processForDirectives($html, $phpcsFile); + $html = $this->processVarDirectivesAndParams($html, $phpcsFile); + + $this->validateDefinedVariables($phpcsFile, $html); + } + + /** + * Process the {{if}} directives in the file + * + * @param string $html + * @param File $phpcsFile + * @return string The processed template + */ + private function processIfDirectives(string $html, File $phpcsFile): string + { + if (preg_match_all(Template::CONSTRUCTION_IF_PATTERN, $html, $constructions, PREG_SET_ORDER)) { + foreach ($constructions as $construction) { + // validate {{if }} + $this->validateVariableUsage($phpcsFile, $construction[1]); + $html = str_replace($construction[0], $construction[2] . ($construction[4] ?? ''), $html); + } + } + + return $html; + } + + /** + * Process the {{depend}} directives in the file + * + * @param string $html + * @param File $phpcsFile + * @return string The processed template + */ + private function processDependDirectives(string $html, File $phpcsFile): string + { + if (preg_match_all(Template::CONSTRUCTION_DEPEND_PATTERN, $html, $constructions, PREG_SET_ORDER)) { + foreach ($constructions as $construction) { + // validate {{depend }} + $this->validateVariableUsage($phpcsFile, $construction[1]); + $html = str_replace($construction[0], $construction[2], $html); + } + } + + return $html; + } + + /** + * Process the {{for}} directives in the file + * + * @param string $html + * @param File $phpcsFile + * @return string The processed template + */ + private function processForDirectives(string $html, File $phpcsFile): string + { + if (preg_match_all(Template::LOOP_PATTERN, $html, $constructions, PREG_SET_ORDER)) { + foreach ($constructions as $construction) { + // validate {{for in }} + $this->validateVariableUsage($phpcsFile, $construction['loopData']); + $html = str_replace($construction[0], $construction['loopBody'], $html); + } + } + + return $html; + } + + /** + * Process the all var directives and var directive params in the file + * + * @param string $html + * @param File $phpcsFile + * @return string The processed template + */ + private function processVarDirectivesAndParams(string $html, File $phpcsFile): string + { + if (preg_match_all(Template::CONSTRUCTION_PATTERN, $html, $constructions, PREG_SET_ORDER)) { + foreach ($constructions as $construction) { + if (empty($construction[2])) { + continue; + } + + if ($construction[1] === 'var') { + $this->validateVariableUsage($phpcsFile, $construction[2]); + } else { + $this->validateDirectiveBody($phpcsFile, $construction[2]); + } + } + } + + return $html; + } + + /** + * Validate directive body is valid. e.g. {{somedir }} + * + * @param File $phpcsFile + * @param string $body + */ + private function validateDirectiveBody(File $phpcsFile, string $body): void + { + $parameterTokenizer = new Template\Tokenizer\Parameter(); + $parameterTokenizer->setString($body); + $params = $parameterTokenizer->tokenize(); + + foreach ($params as $param) { + if (substr($param, 0, 1) === '$') { + $this->validateVariableUsage($phpcsFile, substr($param, 1)); + } + } + } + + /** + * Validate directive variable usage is valid. e.g. {{var }} or {{somedir some_param="$foo.bar()"}} + * + * @param File $phpcsFile + * @param string $body + */ + private function validateVariableUsage(File $phpcsFile, string $body): void + { + $this->usedVariables[] = 'var ' . trim($body); + if (strpos($body, '|') !== false) { + $this->unfilteredVariables[] = 'var ' . trim(explode('|', $body, 2)[0]); + } + $variableTokenizer = new Template\Tokenizer\Variable(); + $variableTokenizer->setString($body); + $stack = $variableTokenizer->tokenize(); + + if (empty($stack)) { + return; + } + + foreach ($stack as $token) { + // As a static analyzer there are no data types to know if this is a DataObject so allow all get* methods + if ($token['type'] === 'method' && substr($token['name'], 0, 3) !== 'get') { + $phpcsFile->addError( + 'Template directives may not invoke methods. Only scalar array access is allowed.' . PHP_EOL + . 'Found "' . trim($body) . '"', + null, + 'HtmlTemplates.DirectiveUsage.ProhibitedMethodCall' + ); + } + } + } + + /** + * Validate the variables defined in the template comment block match the variables actually used in the template + * + * @param File $phpcsFile + * @param string $templateText + */ + private function validateDefinedVariables(File $phpcsFile, string $templateText): void + { + preg_match('//us', $templateText, $matches); + + $definedVariables = []; + + if (!empty($matches[1])) { + $definedVariables = json_decode(str_replace("\n", '', $matches[1]), true); + if (json_last_error()) { + $phpcsFile->addError( + 'Template @vars comment block contains invalid JSON.', + null, + 'HtmlTemplates.DirectiveUsage.InvalidVarsJSON' + ); + return; + } + + foreach ($definedVariables as $var => $label) { + if (empty($label)) { + $phpcsFile->addError( + 'Template @vars comment block contains invalid label.' . PHP_EOL + . 'Label for variable "' . $var . '" is empty.', + null, + 'HtmlTemplates.DirectiveUsage.InvalidVariableLabel' + ); + } + } + + $definedVariables = array_keys($definedVariables); + foreach ($definedVariables as $definedVariable) { + if (strpos($definedVariable, '|') !== false) { + $definedVariables[] = trim(explode('|', $definedVariable, 2)[0]); + } + } + } + + $undefinedVariables = array_diff($this->usedVariables, $definedVariables, $this->unfilteredVariables); + foreach ($undefinedVariables as $undefinedVariable) { + $phpcsFile->addError( + 'Template @vars comment block is missing a variable used in the template.' . PHP_EOL + . 'Missing variable: ' . $undefinedVariable, + null, + 'HtmlTemplates.DirectiveUsage.UndefinedVariable' + ); + } + } +} From 8054864f6418000db921332ac7234dc283d3f768 Mon Sep 17 00:00:00 2001 From: Marc Ginesta Date: Wed, 28 Jul 2021 12:46:28 +0200 Subject: [PATCH 092/630] AC-201: Move phpcs checks from magento2 to magento-coding-standard repo - Move files from Less folder --- Magento2/Sniffs/Less/AvoidIdSniff.php | 100 ++++++++ .../Sniffs/Less/BracesFormattingSniff.php | 88 +++++++ Magento2/Sniffs/Less/ClassNamingSniff.php | 68 ++++++ Magento2/Sniffs/Less/ColonSpacingSniff.php | 113 +++++++++ .../Sniffs/Less/ColourDefinitionSniff.php | 65 ++++++ .../Less/CombinatorIndentationSniff.php | 49 ++++ Magento2/Sniffs/Less/CommentLevelsSniff.php | 214 ++++++++++++++++++ .../Sniffs/Less/ImportantPropertySniff.php | 51 +++++ Magento2/Sniffs/Less/IndentationSniff.php | 107 +++++++++ .../Sniffs/Less/PropertiesLineBreakSniff.php | 52 +++++ .../Sniffs/Less/PropertiesSortingSniff.php | 119 ++++++++++ Magento2/Sniffs/Less/QuotesSniff.php | 46 ++++ .../Sniffs/Less/SelectorDelimiterSniff.php | 90 ++++++++ .../Sniffs/Less/SemicolonSpacingSniff.php | 115 ++++++++++ .../Sniffs/Less/TokenizerSymbolsInterface.php | 27 +++ .../Less/TypeSelectorConcatenationSniff.php | 56 +++++ Magento2/Sniffs/Less/TypeSelectorsSniff.php | 98 ++++++++ Magento2/Sniffs/Less/VariablesSniff.php | 80 +++++++ Magento2/Sniffs/Less/ZeroUnitsSniff.php | 78 +++++++ 19 files changed, 1616 insertions(+) create mode 100644 Magento2/Sniffs/Less/AvoidIdSniff.php create mode 100644 Magento2/Sniffs/Less/BracesFormattingSniff.php create mode 100644 Magento2/Sniffs/Less/ClassNamingSniff.php create mode 100644 Magento2/Sniffs/Less/ColonSpacingSniff.php create mode 100644 Magento2/Sniffs/Less/ColourDefinitionSniff.php create mode 100644 Magento2/Sniffs/Less/CombinatorIndentationSniff.php create mode 100644 Magento2/Sniffs/Less/CommentLevelsSniff.php create mode 100644 Magento2/Sniffs/Less/ImportantPropertySniff.php create mode 100644 Magento2/Sniffs/Less/IndentationSniff.php create mode 100644 Magento2/Sniffs/Less/PropertiesLineBreakSniff.php create mode 100644 Magento2/Sniffs/Less/PropertiesSortingSniff.php create mode 100644 Magento2/Sniffs/Less/QuotesSniff.php create mode 100644 Magento2/Sniffs/Less/SelectorDelimiterSniff.php create mode 100644 Magento2/Sniffs/Less/SemicolonSpacingSniff.php create mode 100644 Magento2/Sniffs/Less/TokenizerSymbolsInterface.php create mode 100644 Magento2/Sniffs/Less/TypeSelectorConcatenationSniff.php create mode 100644 Magento2/Sniffs/Less/TypeSelectorsSniff.php create mode 100644 Magento2/Sniffs/Less/VariablesSniff.php create mode 100644 Magento2/Sniffs/Less/ZeroUnitsSniff.php diff --git a/Magento2/Sniffs/Less/AvoidIdSniff.php b/Magento2/Sniffs/Less/AvoidIdSniff.php new file mode 100644 index 00000000..bfdeee24 --- /dev/null +++ b/Magento2/Sniffs/Less/AvoidIdSniff.php @@ -0,0 +1,100 @@ + div, + * #foo ~ div, + * #foo\3Abar ~ div, + * #foo\:bar ~ div, + * #foo.bar .baz, + * div#foo { + * blah: 'abc'; + * } + */ + public function process(File $phpcsFile, $stackPtr) + { + $tokens = $phpcsFile->getTokens(); + + // Find the next non-selector token + $nextToken = $phpcsFile->findNext($this->selectorTokens, $stackPtr + 1, null, true); + + // Anything except a { or a , means this is not a selector + if ($nextToken !== false && in_array($tokens[$nextToken]['code'], [T_OPEN_CURLY_BRACKET, T_COMMA])) { + $phpcsFile->addError('Id selector is used', $stackPtr, 'IdSelectorUsage'); + } + } +} diff --git a/Magento2/Sniffs/Less/BracesFormattingSniff.php b/Magento2/Sniffs/Less/BracesFormattingSniff.php new file mode 100644 index 00000000..3ca941c8 --- /dev/null +++ b/Magento2/Sniffs/Less/BracesFormattingSniff.php @@ -0,0 +1,88 @@ +getTokens(); + + if (T_OPEN_CURLY_BRACKET === $tokens[$stackPtr]['code']) { + if (TokenizerSymbolsInterface::WHITESPACE !== $tokens[$stackPtr - 1]['content']) { + $phpcsFile->addError('Space before opening brace is missing', $stackPtr, 'SpacingBeforeOpen'); + } + + return; + } + + $next = $phpcsFile->findNext(T_WHITESPACE, ($stackPtr + 1), null, true); + if ($next === false) { + return; + } + + if (!in_array($tokens[$next]['code'], [T_CLOSE_TAG, T_CLOSE_CURLY_BRACKET])) { + $found = (($tokens[$next]['line'] - $tokens[$stackPtr]['line']) - 1); + if ($found !== 1) { + $error = 'Expected one blank line after closing brace of class definition; %s found'; + $data = [$found]; + // Will be implemented in MAGETWO-49778 + //$phpcsFile->addWarning($error, $stackPtr, 'SpacingAfterClose', $data); + } + } + + // Ignore nested style definitions from here on. The spacing before the closing brace + // (a single blank line) will be enforced by the above check, which ensures there is a + // blank line after the last nested class. + $found = $phpcsFile->findPrevious( + T_CLOSE_CURLY_BRACKET, + ($stackPtr - 1), + $tokens[$stackPtr]['bracket_opener'] + ); + + if ($found !== false) { + return; + } + + $prev = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($stackPtr - 1), null, true); + if ($prev !== false && $tokens[$prev]['line'] !== ($tokens[$stackPtr]['line'] - 1)) { + $num = ($tokens[$stackPtr]['line'] - $tokens[$prev]['line'] - 1); + $error = 'Expected 0 blank lines before closing brace of class definition; %s found'; + $data = [$num]; + $phpcsFile->addError($error, $stackPtr, 'SpacingBeforeClose', $data); + } + } +} diff --git a/Magento2/Sniffs/Less/ClassNamingSniff.php b/Magento2/Sniffs/Less/ClassNamingSniff.php new file mode 100644 index 00000000..c20c79b4 --- /dev/null +++ b/Magento2/Sniffs/Less/ClassNamingSniff.php @@ -0,0 +1,68 @@ +getTokens(); + + if (T_WHITESPACE !== $tokens[$stackPtr - 1]['code'] + && !in_array( + $tokens[$stackPtr - 1]['content'], + [ + TokenizerSymbolsInterface::INDENT_SPACES, + TokenizerSymbolsInterface::NEW_LINE, + ] + ) + ) { + return; + } + + $className = $tokens[$stackPtr + 1]['content']; + if (preg_match_all('/[^a-z0-9\-_]/U', $className, $matches)) { + $phpcsFile->addError('Class name contains not allowed symbols', $stackPtr, 'NotAllowedSymbol', $matches); + } + } +} diff --git a/Magento2/Sniffs/Less/ColonSpacingSniff.php b/Magento2/Sniffs/Less/ColonSpacingSniff.php new file mode 100644 index 00000000..31ef0a8e --- /dev/null +++ b/Magento2/Sniffs/Less/ColonSpacingSniff.php @@ -0,0 +1,113 @@ +getTokens(); + + if ($this->needValidateSpaces($phpcsFile, $stackPtr, $tokens)) { + $this->validateSpaces($phpcsFile, $stackPtr, $tokens); + } + } + + /** + * Check is it need to check spaces + * + * @param File $phpcsFile + * @param int $stackPtr + * @param array $tokens + * + * @return bool + */ + private function needValidateSpaces(File $phpcsFile, $stackPtr, $tokens) + { + $nextSemicolon = $phpcsFile->findNext(T_SEMICOLON, $stackPtr); + + if (false === $nextSemicolon + || ($tokens[$nextSemicolon]['line'] !== $tokens[$stackPtr]['line']) + || TokenizerSymbolsInterface::BITWISE_AND === $tokens[$stackPtr - 1]['content'] + ) { + return false; + } + + $prev = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($stackPtr - 1), null, true); + if ($tokens[$prev]['code'] !== T_STYLE) { + // The colon is not part of a style definition. + return false; + } + + if ($tokens[$prev]['content'] === 'progid') { + // Special case for IE filters. + return false; + } + + return true; + } + + /** + * Validate Colon Spacing according to requirements + * + * @param File $phpcsFile + * @param int $stackPtr + * @param array $tokens + * + * @return void + */ + private function validateSpaces(File $phpcsFile, $stackPtr, array $tokens) + { + if (T_WHITESPACE === $tokens[($stackPtr - 1)]['code']) { + $phpcsFile->addError('There must be no space before a colon in a style definition', $stackPtr, 'Before'); + } + + if (T_WHITESPACE !== $tokens[($stackPtr + 1)]['code']) { + $phpcsFile->addError('Expected 1 space after colon in style definition; 0 found', $stackPtr, 'NoneAfter'); + } else { + $content = $tokens[($stackPtr + 1)]['content']; + if (false === strpos($content, $phpcsFile->eolChar)) { + $length = strlen($content); + if ($length !== 1) { + $error = 'Expected 1 space after colon in style definition; %s found'; + $phpcsFile->addError($error, $stackPtr, 'After'); + } + } else { + $error = 'Expected 1 space after colon in style definition; newline found'; + $phpcsFile->addError($error, $stackPtr, 'AfterNewline'); + } + } + } +} diff --git a/Magento2/Sniffs/Less/ColourDefinitionSniff.php b/Magento2/Sniffs/Less/ColourDefinitionSniff.php new file mode 100644 index 00000000..60cea825 --- /dev/null +++ b/Magento2/Sniffs/Less/ColourDefinitionSniff.php @@ -0,0 +1,65 @@ +getTokens(); + $colour = $tokens[$stackPtr]['content']; + + $variablePtr = $phpcsFile->findPrevious(T_ASPERAND, $stackPtr); + if ((false === $variablePtr) || ($tokens[$stackPtr]['line'] !== $tokens[$variablePtr]['line'])) { + $phpcsFile->addError('Hexadecimal value should be used for variable', $stackPtr, 'NotInVariable'); + } + + $expected = strtolower($colour); + if ($colour !== $expected) { + $error = 'CSS colours must be defined in lowercase; expected %s but found %s'; + $phpcsFile->addError($error, $stackPtr, 'NotLower', [$expected, $colour]); + } + + // Now check if shorthand can be used. + if (strlen($colour) !== 7) { + return; + } + + if ($colour[1] === $colour[2] && $colour[3] === $colour[4] && $colour[5] === $colour[6]) { + $expected = '#' . $colour[1] . $colour[3] . $colour[5]; + $error = 'CSS colours must use shorthand if available; expected %s but found %s'; + $phpcsFile->addError($error, $stackPtr, 'Shorthand', [$expected, $colour]); + } + } +} diff --git a/Magento2/Sniffs/Less/CombinatorIndentationSniff.php b/Magento2/Sniffs/Less/CombinatorIndentationSniff.php new file mode 100644 index 00000000..776e0533 --- /dev/null +++ b/Magento2/Sniffs/Less/CombinatorIndentationSniff.php @@ -0,0 +1,49 @@ +getTokens(); + + $prevPtr = $stackPtr - 1; + $nextPtr = $stackPtr + 1; + + if (($tokens[$prevPtr]['code'] !== T_WHITESPACE) || ($tokens[$nextPtr]['code'] !== T_WHITESPACE)) { + $phpcsFile->addError('Spaces should be before and after combinators', $stackPtr, 'NoSpaces'); + } + } +} diff --git a/Magento2/Sniffs/Less/CommentLevelsSniff.php b/Magento2/Sniffs/Less/CommentLevelsSniff.php new file mode 100644 index 00000000..b53aa81a --- /dev/null +++ b/Magento2/Sniffs/Less/CommentLevelsSniff.php @@ -0,0 +1,214 @@ + T_STRING, + self::SECOND_LEVEL_COMMENT => T_DEC, + ]; + + /** + * A list of tokenizers this sniff supports. + * + * @var array + */ + public $supportedTokenizers = [TokenizerSymbolsInterface::TOKENIZER_CSS]; + + /** + * @inheritdoc + */ + public function register() + { + return [T_STRING]; + } + + /** + * @inheritdoc + */ + public function process(File $phpcsFile, $stackPtr) + { + $tokens = $phpcsFile->getTokens(); + + if ((T_STRING !== $tokens[$stackPtr]['code']) + || (self::COMMENT_STRING !== $tokens[$stackPtr]['content']) + || (1 === $tokens[$stackPtr]['line']) + ) { + return; + } + + $textInSameLine = $phpcsFile->findPrevious([T_STRING, T_STYLE], $stackPtr - 1); + + // is inline comment + if ((false !== $textInSameLine) + && ($tokens[$textInSameLine]['line'] === $tokens[$stackPtr]['line']) + ) { + $this->validateInlineComment($phpcsFile, $stackPtr, $tokens); + return; + } + + $this->validateCommentLevel($phpcsFile, $stackPtr, $tokens); + + if (!$this->isNthLevelComment($phpcsFile, $stackPtr, $tokens)) { + return; + } + + if (!$this->checkNthLevelComment($phpcsFile, $stackPtr, $tokens)) { + $phpcsFile->addError( + 'First and second level comments must be surrounded by empty lines', + $stackPtr, + 'SpaceMissed' + ); + } + } + + /** + * Validate that inline comment responds to given requirements + * + * @param File $phpcsFile + * @param int $stackPtr + * @param array $tokens + * @return bool + */ + private function validateInlineComment(File $phpcsFile, $stackPtr, array $tokens) + { + if ($tokens[$stackPtr + 1]['content'] !== TokenizerSymbolsInterface::WHITESPACE) { + $phpcsFile->addError('Inline comment should have 1 space after "//"', $stackPtr, 'SpaceMissedAfter'); + } + if ($tokens[$stackPtr - 1]['content'] !== TokenizerSymbolsInterface::WHITESPACE) { + $phpcsFile->addError('Inline comment should have 1 space before "//"', $stackPtr, 'SpaceMissedBefore'); + } + } + + /** + * Check is it n-th level comment was found + * + * @param File $phpcsFile + * @param int $stackPtr + * @param array $tokens + * @return bool + */ + private function isNthLevelComment(File $phpcsFile, $stackPtr, array $tokens) + { + $nthLevelCommentFound = false; + $levelComment = 0; + + foreach ($this->levelComments as $code => $comment) { + $levelComment = $phpcsFile->findNext($comment, $stackPtr, null, false, $code); + if (false !== $levelComment) { + $nthLevelCommentFound = true; + break; + } + } + + if (false === $nthLevelCommentFound) { + return false; + } + + $currentLine = $tokens[$stackPtr]['line']; + $levelCommentLine = $tokens[$levelComment]['line']; + + if ($currentLine !== $levelCommentLine) { + return false; + } + + return true; + } + + /** + * Check is it n-th level comment is correct + * + * @param File $phpcsFile + * @param int $stackPtr + * @param array $tokens + * @return bool + */ + private function checkNthLevelComment(File $phpcsFile, $stackPtr, array $tokens) + { + $correct = false; + + $nextLine = $phpcsFile->findNext( + T_WHITESPACE, + $stackPtr, + null, + false, + TokenizerSymbolsInterface::NEW_LINE + ); + + if (false === $nextLine) { + return $correct; + } + + if (($tokens[$nextLine]['content'] !== TokenizerSymbolsInterface::NEW_LINE) + || ($tokens[$nextLine + 1]['content'] !== TokenizerSymbolsInterface::NEW_LINE) + ) { + return $correct; + } + + $commentLinePtr = $stackPtr; + while ($tokens[$commentLinePtr - 2]['line'] > 1) { + $commentLinePtr = $phpcsFile->findPrevious(T_STRING, $commentLinePtr - 1, null, false, '//'); + + if (false === $commentLinePtr) { + continue; + } + + if (($tokens[$commentLinePtr - 1]['content'] === TokenizerSymbolsInterface::NEW_LINE) + && ($tokens[$commentLinePtr - 2]['content'] === TokenizerSymbolsInterface::NEW_LINE) + ) { + $correct = true; + break; + } + } + + return $correct; + } + + /** + * Validation of comment level. + * + * @param File $phpcsFile + * @param int $stackPtr + * @param array $tokens + */ + private function validateCommentLevel(File $phpcsFile, int $stackPtr, array $tokens): void + { + if ($tokens[$stackPtr + 2]['content'] !== 'magento_import' && + !in_array( + $tokens[$stackPtr + 1]['content'], + [ + TokenizerSymbolsInterface::DOUBLE_WHITESPACE, + TokenizerSymbolsInterface::NEW_LINE, + ], + true + ) + ) { + $phpcsFile->addError('Level\'s comment does not have 2 spaces after "//"', $stackPtr, 'SpacesMissed'); + } + } +} diff --git a/Magento2/Sniffs/Less/ImportantPropertySniff.php b/Magento2/Sniffs/Less/ImportantPropertySniff.php new file mode 100644 index 00000000..17120f7f --- /dev/null +++ b/Magento2/Sniffs/Less/ImportantPropertySniff.php @@ -0,0 +1,51 @@ +getTokens(); + + // Will be implemented in MAGETWO-49778 + //$phpcsFile->addWarning('!important is used', $stackPtr, '!ImportantIsUsed'); + + if (($tokens[$stackPtr + 1]['content'] === 'important') + && ($tokens[$stackPtr - 1]['content'] !== TokenizerSymbolsInterface::WHITESPACE) + ) { + $phpcsFile->addError('Space before !important is missing', $stackPtr, 'NoSpace'); + } + } +} diff --git a/Magento2/Sniffs/Less/IndentationSniff.php b/Magento2/Sniffs/Less/IndentationSniff.php new file mode 100644 index 00000000..811f877e --- /dev/null +++ b/Magento2/Sniffs/Less/IndentationSniff.php @@ -0,0 +1,107 @@ +getTokens(); + + $numTokens = (count($tokens) - 2); + $indentLevel = 0; + for ($i = 1; $i < $numTokens; $i++) { + if ($tokens[$i]['code'] === T_COMMENT) { + // Don't check the indent of comments. + continue; + } + + if ($tokens[$i]['code'] === T_OPEN_CURLY_BRACKET) { + $indentLevel++; + } elseif ($tokens[($i + 1)]['code'] === T_CLOSE_CURLY_BRACKET) { + $indentLevel--; + } + + if ($tokens[$i]['column'] !== 1) { + continue; + } + + // We started a new line, so check indent. + if ($tokens[$i]['code'] === T_WHITESPACE) { + $content = str_replace($phpcsFile->eolChar, '', $tokens[$i]['content']); + $foundIndent = strlen($content); + } else { + $foundIndent = 0; + } + + $expectedIndent = ($indentLevel * $this->indent); + if (!($expectedIndent > 0 && strpos($tokens[$i]['content'], $phpcsFile->eolChar) !== false) + && ($foundIndent !== $expectedIndent) + && (!in_array($tokens[$i + 1]['code'], $this->styleCodesToSkip)) + ) { + $error = 'Line indented incorrectly; expected %s spaces, found %s'; + $phpcsFile->addError($error, $i, 'Incorrect', [$expectedIndent, $foundIndent]); + } + + // phpcs:ignore Magento2.CodeAnalysis.EmptyBlock + if ($indentLevel > $this->maxIndentLevel) { + // Will be implemented in MAGETWO-49778 + // $phpcsFile->addWarning('Avoid using more than three levels of nesting', $i, 'IncorrectNestingLevel'); + } + } + } +} diff --git a/Magento2/Sniffs/Less/PropertiesLineBreakSniff.php b/Magento2/Sniffs/Less/PropertiesLineBreakSniff.php new file mode 100644 index 00000000..98b81f95 --- /dev/null +++ b/Magento2/Sniffs/Less/PropertiesLineBreakSniff.php @@ -0,0 +1,52 @@ +getTokens(); + + $prevPtr = $phpcsFile->findPrevious(T_SEMICOLON, ($stackPtr - 1)); + if (false === $prevPtr) { + return; + } + + if ($tokens[$prevPtr]['line'] === $tokens[$stackPtr]['line']) { + $error = 'Each property must be on a line by itself'; + $phpcsFile->addError($error, $stackPtr, 'SameLine'); + } + } +} diff --git a/Magento2/Sniffs/Less/PropertiesSortingSniff.php b/Magento2/Sniffs/Less/PropertiesSortingSniff.php new file mode 100644 index 00000000..8757207f --- /dev/null +++ b/Magento2/Sniffs/Less/PropertiesSortingSniff.php @@ -0,0 +1,119 @@ +getTokens(); + $currentToken = $tokens[$stackPtr]; + + // if variables, mixins, extends area used - skip + if ((T_ASPERAND === $tokens[$stackPtr - 1]['code']) + || in_array($tokens[$stackPtr]['content'], $this->styleSymbolsToSkip) + ) { + return; + } + + $nextCurlyBracket = $phpcsFile->findNext(T_OPEN_CURLY_BRACKET, $stackPtr + 1); + if (in_array($currentToken['code'], [T_OPEN_CURLY_BRACKET, T_CLOSE_CURLY_BRACKET]) + || ((false !== $nextCurlyBracket) && ($tokens[$nextCurlyBracket]['line'] === $tokens[$stackPtr]['line'])) + ) { + if ($this->properties) { + // validate collected properties before erase them + $this->validatePropertiesSorting($phpcsFile, $stackPtr, $this->properties); + } + + $this->properties = []; + return; + } + + if (T_STYLE === $currentToken['code']) { + $this->properties[] = $currentToken['content']; + } + } + + /** + * Validate sorting of properties of class + * + * @param File $phpcsFile + * @param int $stackPtr + * @param array $properties + * + * @return void + */ + private function validatePropertiesSorting(File $phpcsFile, $stackPtr, array $properties) + { + // Fix needed for cases when incorrect properties passed for validation due to bug in PHP tokens. + $symbolsForSkip = ['(', 'block', 'field']; + $properties = array_filter( + $properties, + function ($var) use ($symbolsForSkip) { + return !in_array($var, $symbolsForSkip); + } + ); + + $originalProperties = $properties; + sort($properties); + + if ($originalProperties !== $properties) { + $delimiter = $phpcsFile->findPrevious(T_SEMICOLON, $stackPtr); + $phpcsFile->addError('Properties sorted not alphabetically', $delimiter, 'PropertySorting'); + } + } +} diff --git a/Magento2/Sniffs/Less/QuotesSniff.php b/Magento2/Sniffs/Less/QuotesSniff.php new file mode 100644 index 00000000..d605cc13 --- /dev/null +++ b/Magento2/Sniffs/Less/QuotesSniff.php @@ -0,0 +1,46 @@ +getTokens(); + + if (false !== strpos($tokens[$stackPtr]['content'], '"')) { + $phpcsFile->addError('Use single quotes', $stackPtr, 'DoubleQuotes'); + } + } +} diff --git a/Magento2/Sniffs/Less/SelectorDelimiterSniff.php b/Magento2/Sniffs/Less/SelectorDelimiterSniff.php new file mode 100644 index 00000000..6318eeab --- /dev/null +++ b/Magento2/Sniffs/Less/SelectorDelimiterSniff.php @@ -0,0 +1,90 @@ +getTokens(); + + // Check that there's no spaces before delimiter + if ($tokens[$stackPtr - 1]['code'] === T_WHITESPACE) { + $phpcsFile->addError('Spaces should not be before delimiter', $stackPtr - 1, 'SpacesBeforeDelimiter'); + } + + $this->validateParenthesis($phpcsFile, $stackPtr, $tokens); + } + + /** + * Parenthesis validation. + * + * @param File $phpcsFile + * @param int $stackPtr + * @param array $tokens + * @return void + */ + private function validateParenthesis(File $phpcsFile, $stackPtr, array $tokens) + { + $nextPtr = $stackPtr + 1; + + $nextClassPtr = $phpcsFile->findNext(T_STRING_CONCAT, $nextPtr); + $nextOpenBrace = $phpcsFile->findNext(T_OPEN_CURLY_BRACKET, $nextPtr); + + if ($nextClassPtr === false || $nextOpenBrace === false) { + return; + } + + $stackLine = $tokens[$stackPtr]['line']; + $nextClassLine = $tokens[$nextPtr]['line']; + $nextOpenBraceLine = $tokens[$nextOpenBrace]['line']; + + // Check that each class declaration goes from new line + if (($stackLine === $nextClassLine) && ($stackLine === $nextOpenBraceLine)) { + $prevParenthesis = $phpcsFile->findPrevious(T_OPEN_PARENTHESIS, $stackPtr); + $nextParenthesis = $phpcsFile->findNext(T_OPEN_PARENTHESIS, $stackPtr); + + if ((false !== $prevParenthesis) && (false !== $nextParenthesis) + && ($tokens[$prevParenthesis]['line'] === $tokens[$stackPtr]['line']) + && ($tokens[$nextParenthesis]['line'] === $tokens[$stackPtr]['line']) + ) { + return; + } + + $error = 'Add a line break after each selector delimiter'; + $phpcsFile->addError($error, $nextOpenBrace, 'LineBreakAfterDelimiter'); + } + } +} diff --git a/Magento2/Sniffs/Less/SemicolonSpacingSniff.php b/Magento2/Sniffs/Less/SemicolonSpacingSniff.php new file mode 100644 index 00000000..16967cf7 --- /dev/null +++ b/Magento2/Sniffs/Less/SemicolonSpacingSniff.php @@ -0,0 +1,115 @@ +getTokens(); + + if (in_array($tokens[$stackPtr]['content'], $this->styleSymbolsToSkip)) { + return; + } + + $semicolonPtr = $phpcsFile->findNext(T_SEMICOLON, ($stackPtr + 1)); + if ($tokens[$semicolonPtr]['line'] !== $tokens[$stackPtr]['line']) { + $semicolonPtr = $phpcsFile->findNext(T_STYLE, ($stackPtr + 1), null, false, ";"); + } + + $this->validateSemicolon($phpcsFile, $stackPtr, $tokens, $semicolonPtr); + $this->validateSpaces($phpcsFile, $stackPtr, $tokens, $semicolonPtr); + } + + /** + * Semicolon validation. + * + * @param File $phpcsFile + * @param int $stackPtr + * @param array $tokens + * @param int $semicolonPtr + * @return void + */ + private function validateSemicolon(File $phpcsFile, $stackPtr, array $tokens, $semicolonPtr) + { + if ((false === $semicolonPtr || $tokens[$semicolonPtr]['line'] !== $tokens[$stackPtr]['line']) + && (isset($tokens[$stackPtr - 1]) && !in_array($tokens[$stackPtr - 1]['code'], $this->styleCodesToSkip)) + && (T_COLON !== $tokens[$stackPtr + 1]['code']) + ) { + $error = 'Style definitions must end with a semicolon'; + $phpcsFile->addError($error, $stackPtr, 'NotAtEnd'); + } + } + + /** + * Spaces validation. + * + * @param File $phpcsFile + * @param int $stackPtr + * @param array $tokens + * @param int $semicolonPtr + * @return void + */ + private function validateSpaces(File $phpcsFile, $stackPtr, array $tokens, $semicolonPtr) + { + if (!isset($tokens[($semicolonPtr - 1)])) { + return; + } + + if ($tokens[($semicolonPtr - 1)]['code'] === T_WHITESPACE) { + $length = strlen($tokens[($semicolonPtr - 1)]['content']); + $error = 'Expected 0 spaces before semicolon in style definition; %s found'; + $data = [$length]; + $phpcsFile->addError($error, $stackPtr, 'SpaceFound', $data); + } + } +} diff --git a/Magento2/Sniffs/Less/TokenizerSymbolsInterface.php b/Magento2/Sniffs/Less/TokenizerSymbolsInterface.php new file mode 100644 index 00000000..db6a2fe1 --- /dev/null +++ b/Magento2/Sniffs/Less/TokenizerSymbolsInterface.php @@ -0,0 +1,27 @@ +getTokens(); + + if (0 === strpos($tokens[$stackPtr + 1]['content'], '-') + && in_array($tokens[$stackPtr - 1]['content'], $this->symbolsBeforeConcat) + ) { + $phpcsFile->addError('Concatenation is used', $stackPtr, 'ConcatenationUsage'); + } + } +} diff --git a/Magento2/Sniffs/Less/TypeSelectorsSniff.php b/Magento2/Sniffs/Less/TypeSelectorsSniff.php new file mode 100644 index 00000000..95a45b80 --- /dev/null +++ b/Magento2/Sniffs/Less/TypeSelectorsSniff.php @@ -0,0 +1,98 @@ +getTokens(); + + $bracketPtr = $phpcsFile->findNext(T_OPEN_CURLY_BRACKET, $stackPtr); + + if (false === $bracketPtr) { + return; + } + + $isBracketOnSameLane = (bool)($tokens[$bracketPtr]['line'] === $tokens[$stackPtr]['line']); + + if (!$isBracketOnSameLane) { + return; + } + + // phpcs:ignore Magento2.CodeAnalysis.EmptyBlock + if ((T_STRING === $tokens[$stackPtr - 1]['code']) + && in_array($tokens[$stackPtr - 1]['content'], $this->tags) + ) { + // Will be implemented in MAGETWO-49778 + //$phpcsFile->addWarning('Type selector is used', $stackPtr, 'TypeSelector'); + } + + for ($i = $stackPtr; $i < $bracketPtr; $i++) { + if (preg_match('/[A-Z]/', $tokens[$i]['content'])) { + $phpcsFile->addError('Selector contains uppercase symbols', $stackPtr, 'UpperCaseSelector'); + } + } + } +} diff --git a/Magento2/Sniffs/Less/VariablesSniff.php b/Magento2/Sniffs/Less/VariablesSniff.php new file mode 100644 index 00000000..ec9f5108 --- /dev/null +++ b/Magento2/Sniffs/Less/VariablesSniff.php @@ -0,0 +1,80 @@ +getTokens(); + $currentToken = $tokens[$stackPtr]; + + $nextColon = $phpcsFile->findNext(T_COLON, $stackPtr); + $nextSemicolon = $phpcsFile->findNext(T_SEMICOLON, $stackPtr); + if ((false === $nextColon) || (false === $nextSemicolon)) { + return; + } + + $isVariableDeclaration = ($currentToken['line'] === $tokens[$nextColon]['line']) + && ($currentToken['line'] === $tokens[$nextSemicolon]['line']) + && (T_STRING === $tokens[$stackPtr + 1]['code']) + && (T_COLON === $tokens[$stackPtr + 2]['code']); + + if (!$isVariableDeclaration) { + return; + } + + $classBefore = $phpcsFile->findPrevious(T_STYLE, $stackPtr); + if (false !== $classBefore) { + $phpcsFile->addError( + 'Variable declaration located not in the beginning of general comments', + $stackPtr, + 'VariableLocation' + ); + } + + $variableName = $tokens[$stackPtr + 1]['content']; + if (preg_match('/[A-Z]/', $variableName)) { + $phpcsFile->addError( + 'Variable declaration contains uppercase symbols', + $stackPtr, + 'VariableUppercase' + ); + } + } +} diff --git a/Magento2/Sniffs/Less/ZeroUnitsSniff.php b/Magento2/Sniffs/Less/ZeroUnitsSniff.php new file mode 100644 index 00000000..7cf3bfb2 --- /dev/null +++ b/Magento2/Sniffs/Less/ZeroUnitsSniff.php @@ -0,0 +1,78 @@ +getTokens(); + $tokenCode = $tokens[$stackPtr]['code']; + $tokenContent = $tokens[$stackPtr]['content']; + + $nextToken = $tokens[$stackPtr + 1]; + + if (T_LNUMBER === $tokenCode + && "0" === $tokenContent + && T_STRING === $nextToken['code'] + && in_array($nextToken['content'], $this->units) + ) { + $phpcsFile->addError('Units specified for "0" value', $stackPtr, 'ZeroUnitFound'); + } + + if ((T_DNUMBER === $tokenCode) + && 0 === strpos($tokenContent, "0") + && ((float)$tokenContent < 1) + ) { + $phpcsFile->addError('Values starts from "0"', $stackPtr, 'ZeroUnitFound'); + } + } +} From 6cfce180b53adcbef97e4b257da586c61a955cfa Mon Sep 17 00:00:00 2001 From: Marc Ginesta Date: Wed, 28 Jul 2021 15:43:23 +0200 Subject: [PATCH 093/630] AC-201: Move phpcs checks from magento2 to magento-coding-standard repo - Fix namespace --- Magento2/Sniffs/Annotation/AnnotationFormatValidator.php | 2 +- Magento2/Sniffs/Annotation/MethodAnnotationStructureSniff.php | 2 +- Magento2/Sniffs/Annotation/MethodArgumentsSniff.php | 2 +- Magento2/Sniffs/Html/HtmlBindingSniff.php | 2 +- Magento2/Sniffs/Html/HtmlDirectiveSniff.php | 2 +- Magento2/Sniffs/Less/AvoidIdSniff.php | 2 +- Magento2/Sniffs/Less/BracesFormattingSniff.php | 2 +- Magento2/Sniffs/Less/ClassNamingSniff.php | 2 +- Magento2/Sniffs/Less/ColonSpacingSniff.php | 2 +- Magento2/Sniffs/Less/ColourDefinitionSniff.php | 2 +- Magento2/Sniffs/Less/CombinatorIndentationSniff.php | 2 +- Magento2/Sniffs/Less/CommentLevelsSniff.php | 2 +- Magento2/Sniffs/Less/ImportantPropertySniff.php | 2 +- Magento2/Sniffs/Less/IndentationSniff.php | 2 +- Magento2/Sniffs/Less/PropertiesLineBreakSniff.php | 2 +- Magento2/Sniffs/Less/PropertiesSortingSniff.php | 2 +- Magento2/Sniffs/Less/QuotesSniff.php | 2 +- Magento2/Sniffs/Less/SelectorDelimiterSniff.php | 2 +- Magento2/Sniffs/Less/SemicolonSpacingSniff.php | 2 +- Magento2/Sniffs/Less/TokenizerSymbolsInterface.php | 2 +- Magento2/Sniffs/Less/TypeSelectorConcatenationSniff.php | 2 +- Magento2/Sniffs/Less/TypeSelectorsSniff.php | 2 +- Magento2/Sniffs/Less/VariablesSniff.php | 2 +- Magento2/Sniffs/Less/ZeroUnitsSniff.php | 2 +- 24 files changed, 24 insertions(+), 24 deletions(-) diff --git a/Magento2/Sniffs/Annotation/AnnotationFormatValidator.php b/Magento2/Sniffs/Annotation/AnnotationFormatValidator.php index cd4c8689..220d1a19 100644 --- a/Magento2/Sniffs/Annotation/AnnotationFormatValidator.php +++ b/Magento2/Sniffs/Annotation/AnnotationFormatValidator.php @@ -5,7 +5,7 @@ */ declare(strict_types=1); -namespace Magento\Sniffs\Annotation; +namespace Magento2\Sniffs\Annotation; use PHP_CodeSniffer\Files\File; diff --git a/Magento2/Sniffs/Annotation/MethodAnnotationStructureSniff.php b/Magento2/Sniffs/Annotation/MethodAnnotationStructureSniff.php index 3df07533..fed274a9 100644 --- a/Magento2/Sniffs/Annotation/MethodAnnotationStructureSniff.php +++ b/Magento2/Sniffs/Annotation/MethodAnnotationStructureSniff.php @@ -5,7 +5,7 @@ */ declare(strict_types=1); -namespace Magento\Sniffs\Annotation; +namespace Magento2\Sniffs\Annotation; use PHP_CodeSniffer\Files\File; use PHP_CodeSniffer\Sniffs\Sniff; diff --git a/Magento2/Sniffs/Annotation/MethodArgumentsSniff.php b/Magento2/Sniffs/Annotation/MethodArgumentsSniff.php index 54e10100..2ebb12d4 100644 --- a/Magento2/Sniffs/Annotation/MethodArgumentsSniff.php +++ b/Magento2/Sniffs/Annotation/MethodArgumentsSniff.php @@ -5,7 +5,7 @@ */ declare(strict_types=1); -namespace Magento\Sniffs\Annotation; +namespace Magento2\Sniffs\Annotation; use PHP_CodeSniffer\Files\File; use PHP_CodeSniffer\Sniffs\Sniff; diff --git a/Magento2/Sniffs/Html/HtmlBindingSniff.php b/Magento2/Sniffs/Html/HtmlBindingSniff.php index 1d09b7a6..63718b5b 100644 --- a/Magento2/Sniffs/Html/HtmlBindingSniff.php +++ b/Magento2/Sniffs/Html/HtmlBindingSniff.php @@ -4,7 +4,7 @@ * See COPYING.txt for license details. */ -namespace Magento\Sniffs\Html; +namespace Magento2\Sniffs\Html; use PHP_CodeSniffer\Sniffs\Sniff; use PHP_CodeSniffer\Files\File; diff --git a/Magento2/Sniffs/Html/HtmlDirectiveSniff.php b/Magento2/Sniffs/Html/HtmlDirectiveSniff.php index 33ffdf29..6179f90f 100644 --- a/Magento2/Sniffs/Html/HtmlDirectiveSniff.php +++ b/Magento2/Sniffs/Html/HtmlDirectiveSniff.php @@ -6,7 +6,7 @@ declare(strict_types=1); -namespace Magento\Sniffs\Html; +namespace Magento2\Sniffs\Html; use Magento\Framework\Filter\Template; use PHP_CodeSniffer\Sniffs\Sniff; diff --git a/Magento2/Sniffs/Less/AvoidIdSniff.php b/Magento2/Sniffs/Less/AvoidIdSniff.php index bfdeee24..d4e1b213 100644 --- a/Magento2/Sniffs/Less/AvoidIdSniff.php +++ b/Magento2/Sniffs/Less/AvoidIdSniff.php @@ -3,7 +3,7 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ -namespace Magento\Sniffs\Less; +namespace Magento2\Sniffs\Less; use PHP_CodeSniffer\Sniffs\Sniff; use PHP_CodeSniffer\Files\File; diff --git a/Magento2/Sniffs/Less/BracesFormattingSniff.php b/Magento2/Sniffs/Less/BracesFormattingSniff.php index 3ca941c8..54575160 100644 --- a/Magento2/Sniffs/Less/BracesFormattingSniff.php +++ b/Magento2/Sniffs/Less/BracesFormattingSniff.php @@ -3,7 +3,7 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ -namespace Magento\Sniffs\Less; +namespace Magento2\Sniffs\Less; use PHP_CodeSniffer\Sniffs\Sniff; use PHP_CodeSniffer\Files\File; diff --git a/Magento2/Sniffs/Less/ClassNamingSniff.php b/Magento2/Sniffs/Less/ClassNamingSniff.php index c20c79b4..90d44280 100644 --- a/Magento2/Sniffs/Less/ClassNamingSniff.php +++ b/Magento2/Sniffs/Less/ClassNamingSniff.php @@ -3,7 +3,7 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ -namespace Magento\Sniffs\Less; +namespace Magento2\Sniffs\Less; use PHP_CodeSniffer\Sniffs\Sniff; use PHP_CodeSniffer\Files\File; diff --git a/Magento2/Sniffs/Less/ColonSpacingSniff.php b/Magento2/Sniffs/Less/ColonSpacingSniff.php index 31ef0a8e..6ada0fac 100644 --- a/Magento2/Sniffs/Less/ColonSpacingSniff.php +++ b/Magento2/Sniffs/Less/ColonSpacingSniff.php @@ -3,7 +3,7 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ -namespace Magento\Sniffs\Less; +namespace Magento2\Sniffs\Less; use PHP_CodeSniffer\Sniffs\Sniff; use PHP_CodeSniffer\Files\File; diff --git a/Magento2/Sniffs/Less/ColourDefinitionSniff.php b/Magento2/Sniffs/Less/ColourDefinitionSniff.php index 60cea825..82568824 100644 --- a/Magento2/Sniffs/Less/ColourDefinitionSniff.php +++ b/Magento2/Sniffs/Less/ColourDefinitionSniff.php @@ -3,7 +3,7 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ -namespace Magento\Sniffs\Less; +namespace Magento2\Sniffs\Less; use PHP_CodeSniffer\Sniffs\Sniff; use PHP_CodeSniffer\Files\File; diff --git a/Magento2/Sniffs/Less/CombinatorIndentationSniff.php b/Magento2/Sniffs/Less/CombinatorIndentationSniff.php index 776e0533..e6954c31 100644 --- a/Magento2/Sniffs/Less/CombinatorIndentationSniff.php +++ b/Magento2/Sniffs/Less/CombinatorIndentationSniff.php @@ -3,7 +3,7 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ -namespace Magento\Sniffs\Less; +namespace Magento2\Sniffs\Less; use PHP_CodeSniffer\Sniffs\Sniff; use PHP_CodeSniffer\Files\File; diff --git a/Magento2/Sniffs/Less/CommentLevelsSniff.php b/Magento2/Sniffs/Less/CommentLevelsSniff.php index b53aa81a..e192f659 100644 --- a/Magento2/Sniffs/Less/CommentLevelsSniff.php +++ b/Magento2/Sniffs/Less/CommentLevelsSniff.php @@ -3,7 +3,7 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ -namespace Magento\Sniffs\Less; +namespace Magento2\Sniffs\Less; use PHP_CodeSniffer\Files\File; use PHP_CodeSniffer\Sniffs\Sniff; diff --git a/Magento2/Sniffs/Less/ImportantPropertySniff.php b/Magento2/Sniffs/Less/ImportantPropertySniff.php index 17120f7f..ad1fd10c 100644 --- a/Magento2/Sniffs/Less/ImportantPropertySniff.php +++ b/Magento2/Sniffs/Less/ImportantPropertySniff.php @@ -3,7 +3,7 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ -namespace Magento\Sniffs\Less; +namespace Magento2\Sniffs\Less; use PHP_CodeSniffer\Sniffs\Sniff; use PHP_CodeSniffer\Files\File; diff --git a/Magento2/Sniffs/Less/IndentationSniff.php b/Magento2/Sniffs/Less/IndentationSniff.php index 811f877e..76a6fbcc 100644 --- a/Magento2/Sniffs/Less/IndentationSniff.php +++ b/Magento2/Sniffs/Less/IndentationSniff.php @@ -3,7 +3,7 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ -namespace Magento\Sniffs\Less; +namespace Magento2\Sniffs\Less; use PHP_CodeSniffer\Sniffs\Sniff; use PHP_CodeSniffer\Files\File; diff --git a/Magento2/Sniffs/Less/PropertiesLineBreakSniff.php b/Magento2/Sniffs/Less/PropertiesLineBreakSniff.php index 98b81f95..06eb9c6a 100644 --- a/Magento2/Sniffs/Less/PropertiesLineBreakSniff.php +++ b/Magento2/Sniffs/Less/PropertiesLineBreakSniff.php @@ -3,7 +3,7 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ -namespace Magento\Sniffs\Less; +namespace Magento2\Sniffs\Less; use PHP_CodeSniffer\Sniffs\Sniff; use PHP_CodeSniffer\Files\File; diff --git a/Magento2/Sniffs/Less/PropertiesSortingSniff.php b/Magento2/Sniffs/Less/PropertiesSortingSniff.php index 8757207f..d1c7c387 100644 --- a/Magento2/Sniffs/Less/PropertiesSortingSniff.php +++ b/Magento2/Sniffs/Less/PropertiesSortingSniff.php @@ -3,7 +3,7 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ -namespace Magento\Sniffs\Less; +namespace Magento2\Sniffs\Less; use PHP_CodeSniffer\Sniffs\Sniff; use PHP_CodeSniffer\Files\File; diff --git a/Magento2/Sniffs/Less/QuotesSniff.php b/Magento2/Sniffs/Less/QuotesSniff.php index d605cc13..a1328c51 100644 --- a/Magento2/Sniffs/Less/QuotesSniff.php +++ b/Magento2/Sniffs/Less/QuotesSniff.php @@ -3,7 +3,7 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ -namespace Magento\Sniffs\Less; +namespace Magento2\Sniffs\Less; use PHP_CodeSniffer\Sniffs\Sniff; use PHP_CodeSniffer\Files\File; diff --git a/Magento2/Sniffs/Less/SelectorDelimiterSniff.php b/Magento2/Sniffs/Less/SelectorDelimiterSniff.php index 6318eeab..cdbd5117 100644 --- a/Magento2/Sniffs/Less/SelectorDelimiterSniff.php +++ b/Magento2/Sniffs/Less/SelectorDelimiterSniff.php @@ -3,7 +3,7 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ -namespace Magento\Sniffs\Less; +namespace Magento2\Sniffs\Less; use PHP_CodeSniffer\Sniffs\Sniff; use PHP_CodeSniffer\Files\File; diff --git a/Magento2/Sniffs/Less/SemicolonSpacingSniff.php b/Magento2/Sniffs/Less/SemicolonSpacingSniff.php index 16967cf7..cad13290 100644 --- a/Magento2/Sniffs/Less/SemicolonSpacingSniff.php +++ b/Magento2/Sniffs/Less/SemicolonSpacingSniff.php @@ -3,7 +3,7 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ -namespace Magento\Sniffs\Less; +namespace Magento2\Sniffs\Less; use PHP_CodeSniffer\Sniffs\Sniff; use PHP_CodeSniffer\Files\File; diff --git a/Magento2/Sniffs/Less/TokenizerSymbolsInterface.php b/Magento2/Sniffs/Less/TokenizerSymbolsInterface.php index db6a2fe1..da690f79 100644 --- a/Magento2/Sniffs/Less/TokenizerSymbolsInterface.php +++ b/Magento2/Sniffs/Less/TokenizerSymbolsInterface.php @@ -3,7 +3,7 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ -namespace Magento\Sniffs\Less; +namespace Magento2\Sniffs\Less; /** * Interface TokenizerSymbolsInterface diff --git a/Magento2/Sniffs/Less/TypeSelectorConcatenationSniff.php b/Magento2/Sniffs/Less/TypeSelectorConcatenationSniff.php index 8928028c..5b42c9b2 100644 --- a/Magento2/Sniffs/Less/TypeSelectorConcatenationSniff.php +++ b/Magento2/Sniffs/Less/TypeSelectorConcatenationSniff.php @@ -3,7 +3,7 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ -namespace Magento\Sniffs\Less; +namespace Magento2\Sniffs\Less; use PHP_CodeSniffer\Sniffs\Sniff; use PHP_CodeSniffer\Files\File; diff --git a/Magento2/Sniffs/Less/TypeSelectorsSniff.php b/Magento2/Sniffs/Less/TypeSelectorsSniff.php index 95a45b80..00c8b35c 100644 --- a/Magento2/Sniffs/Less/TypeSelectorsSniff.php +++ b/Magento2/Sniffs/Less/TypeSelectorsSniff.php @@ -3,7 +3,7 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ -namespace Magento\Sniffs\Less; +namespace Magento2\Sniffs\Less; use PHP_CodeSniffer\Sniffs\Sniff; use PHP_CodeSniffer\Files\File; diff --git a/Magento2/Sniffs/Less/VariablesSniff.php b/Magento2/Sniffs/Less/VariablesSniff.php index ec9f5108..ec9986a6 100644 --- a/Magento2/Sniffs/Less/VariablesSniff.php +++ b/Magento2/Sniffs/Less/VariablesSniff.php @@ -3,7 +3,7 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ -namespace Magento\Sniffs\Less; +namespace Magento2\Sniffs\Less; use PHP_CodeSniffer\Sniffs\Sniff; use PHP_CodeSniffer\Files\File; diff --git a/Magento2/Sniffs/Less/ZeroUnitsSniff.php b/Magento2/Sniffs/Less/ZeroUnitsSniff.php index 7cf3bfb2..51971c78 100644 --- a/Magento2/Sniffs/Less/ZeroUnitsSniff.php +++ b/Magento2/Sniffs/Less/ZeroUnitsSniff.php @@ -3,7 +3,7 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ -namespace Magento\Sniffs\Less; +namespace Magento2\Sniffs\Less; use PHP_CodeSniffer\Sniffs\Sniff; use PHP_CodeSniffer\Files\File; From ebc647dfc099fd03fb8eec352538e5c4dd046ac3 Mon Sep 17 00:00:00 2001 From: Marc Ginesta Date: Wed, 28 Jul 2021 17:31:32 +0200 Subject: [PATCH 094/630] AC-201: Move phpcs checks from magento2 to magento-coding-standard repo - WIP: Update ruleset.xml --- Magento2/ruleset.xml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Magento2/ruleset.xml b/Magento2/ruleset.xml index ef9b9aca..cf1ca9b0 100644 --- a/Magento2/ruleset.xml +++ b/Magento2/ruleset.xml @@ -585,4 +585,8 @@ */Test/* *Test.php + + + + From 491f1cb62f4a0848611187ca3f35cafb91b3d867 Mon Sep 17 00:00:00 2001 From: Ihor Sviziev Date: Wed, 28 Jul 2021 22:59:50 +0300 Subject: [PATCH 095/630] Test on lowest and highest dependencies Remove experimental flag --- .github/workflows/php.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index 133cec38..5a7cb023 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -10,7 +10,6 @@ jobs: build: runs-on: ubuntu-latest - continue-on-error: ${{ matrix.experimental }} strategy: fail-fast: false matrix: @@ -27,7 +26,6 @@ jobs: - php-version: "8.0" dependencies: "highest" composer-options: "--ignore-platform-reqs" - experimental: true name: Tests with PHP ${{ matrix.php-version }} and ${{ matrix.dependencies }} dependencies steps: From db1745af0ac497e8ad3e01ab5f8b0fd610302011 Mon Sep 17 00:00:00 2001 From: Marc Ginesta Date: Thu, 29 Jul 2021 11:26:49 +0200 Subject: [PATCH 096/630] AC-201: Move phpcs checks from magento2 to magento-coding-standard repo - Add other rules from previous ruleset files on Magento --- Magento2/ruleset.xml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Magento2/ruleset.xml b/Magento2/ruleset.xml index cf1ca9b0..8eef795c 100644 --- a/Magento2/ruleset.xml +++ b/Magento2/ruleset.xml @@ -589,4 +589,8 @@ + + 0 + + From 0d84b92d98e1e804ce8042b49a2e37425c74807c Mon Sep 17 00:00:00 2001 From: Marc Ginesta Date: Thu, 29 Jul 2021 11:42:39 +0200 Subject: [PATCH 097/630] AC-201: Move phpcs checks from magento2 to magento-coding-standard repo - Clean XML code --- Magento2/ruleset.xml | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/Magento2/ruleset.xml b/Magento2/ruleset.xml index 8eef795c..f77859e9 100644 --- a/Magento2/ruleset.xml +++ b/Magento2/ruleset.xml @@ -585,10 +585,8 @@ */Test/* *Test.php - - - - + + 0 From 832be5377133de56fc2fa84a35c7c9e25bc6c927 Mon Sep 17 00:00:00 2001 From: Marc Ginesta Date: Thu, 29 Jul 2021 17:04:50 +0200 Subject: [PATCH 098/630] AC-201: Move phpcs checks from magento2 to magento-coding-standard repo - Add missing comment block --- Magento2/Tests/GraphQL/AbstractGraphQLSniffUnitTestCase.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Magento2/Tests/GraphQL/AbstractGraphQLSniffUnitTestCase.php b/Magento2/Tests/GraphQL/AbstractGraphQLSniffUnitTestCase.php index 19bcd586..dc921b17 100644 --- a/Magento2/Tests/GraphQL/AbstractGraphQLSniffUnitTestCase.php +++ b/Magento2/Tests/GraphQL/AbstractGraphQLSniffUnitTestCase.php @@ -13,6 +13,9 @@ */ abstract class AbstractGraphQLSniffUnitTestCase extends AbstractSniffUnitTest { + /** + * @inheritDoc + */ protected function setUp() { //let parent do its job From b0f13657a80cec2ab5d5cf2b46a7cf4a1e2b3606 Mon Sep 17 00:00:00 2001 From: Marc Ginesta Date: Thu, 29 Jul 2021 17:56:02 +0200 Subject: [PATCH 099/630] AC-201: Move phpcs checks from magento2 to magento-coding-standard repo - Fix CS errors --- Magento2/Sniffs/GraphQL/ValidArgumentNameSniff.php | 3 +-- Magento2/Sniffs/GraphQL/ValidEnumValueSniff.php | 8 +++----- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/Magento2/Sniffs/GraphQL/ValidArgumentNameSniff.php b/Magento2/Sniffs/GraphQL/ValidArgumentNameSniff.php index d7a19621..34c6831d 100644 --- a/Magento2/Sniffs/GraphQL/ValidArgumentNameSniff.php +++ b/Magento2/Sniffs/GraphQL/ValidArgumentNameSniff.php @@ -128,8 +128,7 @@ private function getArgumentListClosePointer($openParenthesisPointer, array $tok } /** - * Seeks the next available {@link T_OPEN_PARENTHESIS} token that comes directly after $stackPointer. - * token. + * Seeks the next available {@link T_OPEN_PARENTHESIS} token that comes directly after $stackPointer token. * * @param int $stackPointer * @param array $tokens diff --git a/Magento2/Sniffs/GraphQL/ValidEnumValueSniff.php b/Magento2/Sniffs/GraphQL/ValidEnumValueSniff.php index a9c5f245..1e64dcf4 100644 --- a/Magento2/Sniffs/GraphQL/ValidEnumValueSniff.php +++ b/Magento2/Sniffs/GraphQL/ValidEnumValueSniff.php @@ -68,8 +68,7 @@ public function process(File $phpcsFile, $stackPtr) } /** - * Seeks the next available token of type {@link T_CLOSE_CURLY_BRACKET} in $tokens and returns its - * pointer. + * Seeks the next available token of type {@link T_CLOSE_CURLY_BRACKET} in $tokens and returns its pointer. * * @param int $startPointer * @param array $tokens @@ -81,10 +80,9 @@ private function getClosingCurlyBracketPointer($startPointer, array $tokens) } /** - * Seeks the next available token of type {@link T_OPEN_CURLY_BRACKET} in $tokens and returns its - * pointer. + * Seeks the next available token of type {@link T_OPEN_CURLY_BRACKET} in $tokens and returns its pointer. * - * @param $startPointer + * @param int $startPointer * @param array $tokens * @return bool|int */ From 6fb644fd0e7d185447030bdd49aef39fa30e0269 Mon Sep 17 00:00:00 2001 From: Marc Ginesta Date: Fri, 30 Jul 2021 12:33:42 +0200 Subject: [PATCH 100/630] AC-201: Move phpcs checks from magento2 to magento-coding-standard repo - Format multi-line comments --- Magento2/Sniffs/GraphQL/ValidArgumentNameSniff.php | 5 ++++- Magento2/Sniffs/GraphQL/ValidEnumValueSniff.php | 10 ++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/Magento2/Sniffs/GraphQL/ValidArgumentNameSniff.php b/Magento2/Sniffs/GraphQL/ValidArgumentNameSniff.php index 34c6831d..f127cf17 100644 --- a/Magento2/Sniffs/GraphQL/ValidArgumentNameSniff.php +++ b/Magento2/Sniffs/GraphQL/ValidArgumentNameSniff.php @@ -128,7 +128,10 @@ private function getArgumentListClosePointer($openParenthesisPointer, array $tok } /** - * Seeks the next available {@link T_OPEN_PARENTHESIS} token that comes directly after $stackPointer token. + * Find the argument list open pointer + * + * Seeks the next available {@link T_OPEN_PARENTHESIS} token + * that comes directly after $stackPointer token. * * @param int $stackPointer * @param array $tokens diff --git a/Magento2/Sniffs/GraphQL/ValidEnumValueSniff.php b/Magento2/Sniffs/GraphQL/ValidEnumValueSniff.php index 1e64dcf4..466f2c27 100644 --- a/Magento2/Sniffs/GraphQL/ValidEnumValueSniff.php +++ b/Magento2/Sniffs/GraphQL/ValidEnumValueSniff.php @@ -68,7 +68,10 @@ public function process(File $phpcsFile, $stackPtr) } /** - * Seeks the next available token of type {@link T_CLOSE_CURLY_BRACKET} in $tokens and returns its pointer. + * Find the closing curly bracket pointer + * + * Seeks the next available token of type {@link T_CLOSE_CURLY_BRACKET} + * in $tokens and returns its pointer. * * @param int $startPointer * @param array $tokens @@ -80,7 +83,10 @@ private function getClosingCurlyBracketPointer($startPointer, array $tokens) } /** - * Seeks the next available token of type {@link T_OPEN_CURLY_BRACKET} in $tokens and returns its pointer. + * Find the opening curly bracket pointer + * + * Seeks the next available token of type {@link T_OPEN_CURLY_BRACKET} + * in $tokens and returns its pointer. * * @param int $startPointer * @param array $tokens From 1a0f854aca74ae46dab828ce8898c0f89c3700fe Mon Sep 17 00:00:00 2001 From: Asheem Patro Date: Mon, 2 Aug 2021 14:30:14 +0530 Subject: [PATCH 101/630] #210: Fixed HtmlDirectiveSniff.php from causing the Fatal Error for class not found --- Magento2/Sniffs/Html/HtmlDirectiveSniff.php | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/Magento2/Sniffs/Html/HtmlDirectiveSniff.php b/Magento2/Sniffs/Html/HtmlDirectiveSniff.php index 6179f90f..b14ae7ba 100644 --- a/Magento2/Sniffs/Html/HtmlDirectiveSniff.php +++ b/Magento2/Sniffs/Html/HtmlDirectiveSniff.php @@ -8,7 +8,6 @@ namespace Magento2\Sniffs\Html; -use Magento\Framework\Filter\Template; use PHP_CodeSniffer\Sniffs\Sniff; use PHP_CodeSniffer\Files\File; @@ -17,6 +16,11 @@ */ class HtmlDirectiveSniff implements Sniff { + const CONSTRUCTION_DEPEND_PATTERN = '/{{depend\s*(.*?)}}(.*?){{\\/depend\s*}}/si'; + const CONSTRUCTION_IF_PATTERN = '/{{if\s*(.*?)}}(.*?)({{else}}(.*?))?{{\\/if\s*}}/si'; + const LOOP_PATTERN = '/{{for(?P.*? )(in)(?P.*?)}}(?P.*?){{\/for}}/si'; + const CONSTRUCTION_PATTERN = '/{{([a-z]{0,10})(.*?)}}(?:(.*?)(?:{{\/(?:\\1)}}))?/si'; + /** * @var array */ @@ -73,7 +77,7 @@ public function process(File $phpcsFile, $stackPtr) */ private function processIfDirectives(string $html, File $phpcsFile): string { - if (preg_match_all(Template::CONSTRUCTION_IF_PATTERN, $html, $constructions, PREG_SET_ORDER)) { + if (preg_match_all(self::CONSTRUCTION_IF_PATTERN, $html, $constructions, PREG_SET_ORDER)) { foreach ($constructions as $construction) { // validate {{if }} $this->validateVariableUsage($phpcsFile, $construction[1]); @@ -93,7 +97,7 @@ private function processIfDirectives(string $html, File $phpcsFile): string */ private function processDependDirectives(string $html, File $phpcsFile): string { - if (preg_match_all(Template::CONSTRUCTION_DEPEND_PATTERN, $html, $constructions, PREG_SET_ORDER)) { + if (preg_match_all(self::CONSTRUCTION_DEPEND_PATTERN, $html, $constructions, PREG_SET_ORDER)) { foreach ($constructions as $construction) { // validate {{depend }} $this->validateVariableUsage($phpcsFile, $construction[1]); @@ -113,7 +117,7 @@ private function processDependDirectives(string $html, File $phpcsFile): string */ private function processForDirectives(string $html, File $phpcsFile): string { - if (preg_match_all(Template::LOOP_PATTERN, $html, $constructions, PREG_SET_ORDER)) { + if (preg_match_all(self::LOOP_PATTERN, $html, $constructions, PREG_SET_ORDER)) { foreach ($constructions as $construction) { // validate {{for in }} $this->validateVariableUsage($phpcsFile, $construction['loopData']); @@ -133,7 +137,7 @@ private function processForDirectives(string $html, File $phpcsFile): string */ private function processVarDirectivesAndParams(string $html, File $phpcsFile): string { - if (preg_match_all(Template::CONSTRUCTION_PATTERN, $html, $constructions, PREG_SET_ORDER)) { + if (preg_match_all(self::CONSTRUCTION_PATTERN, $html, $constructions, PREG_SET_ORDER)) { foreach ($constructions as $construction) { if (empty($construction[2])) { continue; From 825857b83a4be6d891e95448f658bc4417214168 Mon Sep 17 00:00:00 2001 From: Eduard Muradov Date: Mon, 9 Aug 2021 17:11:24 +0300 Subject: [PATCH 102/630] Fix magento/magento-coding-standard#214 with class not found --- .../Helpers/Tokenizer/AbstractTokenizer.php | 128 +++++++ Magento2/Helpers/Tokenizer/Parameter.php | 76 ++++ Magento2/Helpers/Tokenizer/Variable.php | 326 ++++++++++++++++++ Magento2/Sniffs/Html/HtmlDirectiveSniff.php | 6 +- 4 files changed, 533 insertions(+), 3 deletions(-) create mode 100644 Magento2/Helpers/Tokenizer/AbstractTokenizer.php create mode 100644 Magento2/Helpers/Tokenizer/Parameter.php create mode 100644 Magento2/Helpers/Tokenizer/Variable.php diff --git a/Magento2/Helpers/Tokenizer/AbstractTokenizer.php b/Magento2/Helpers/Tokenizer/AbstractTokenizer.php new file mode 100644 index 00000000..f49c753f --- /dev/null +++ b/Magento2/Helpers/Tokenizer/AbstractTokenizer.php @@ -0,0 +1,128 @@ +_currentIndex + 1 >= strlen($this->_string)) { + return false; + } + + $this->_currentIndex++; + return true; + } + + /** + * Move current index to previous char. + * + * If index out of bounds returns false + * + * @return boolean + */ + public function prev() + { + if ($this->_currentIndex - 1 < 0) { + return false; + } + + $this->_currentIndex--; + return true; + } + + /** + * Move current index backwards. + * + * If index out of bounds returns false + * + * @param int $distance number of characters to backtrack + * @return bool + */ + public function back($distance) + { + if ($this->_currentIndex - $distance < 0) { + return false; + } + + $this->_currentIndex -= $distance; + return true; + } + + /** + * Return current char + * + * @return string + */ + public function char() + { + return $this->_string[$this->_currentIndex]; + } + + /** + * Set string for tokenize + * + * @param string $value + * @return void + */ + public function setString($value) + { + //phpcs:ignore Magento2.Functions.DiscouragedFunction + $this->_string = rawurldecode($value); + $this->reset(); + } + + /** + * Move char index to begin of string + * + * @return void + */ + public function reset() + { + $this->_currentIndex = 0; + } + + /** + * Return true if current char is white-space + * + * @return boolean + */ + public function isWhiteSpace() + { + return $this->_string === '' ?: trim($this->char()) !== $this->char(); + } + + /** + * Tokenize string + * + * @return array + */ + abstract public function tokenize(); +} diff --git a/Magento2/Helpers/Tokenizer/Parameter.php b/Magento2/Helpers/Tokenizer/Parameter.php new file mode 100644 index 00000000..ec3a3564 --- /dev/null +++ b/Magento2/Helpers/Tokenizer/Parameter.php @@ -0,0 +1,76 @@ +isWhiteSpace()) { + continue; + } + + if ($this->char() !== '=') { + $parameterName .= $this->char(); + } else { + $parameters[$parameterName] = $this->getValue(); + $parameterName = ''; + } + } while ($this->next()); + return $parameters; + } + + /** + * Get string value in parameters through tokenize + * + * @return string + * @SuppressWarnings(PHPMD.CyclomaticComplexity) + */ + public function getValue() + { + $this->next(); + $value = ''; + if ($this->isWhiteSpace()) { + return $value; + } + $quoteStart = $this->char() == "'" || $this->char() == '"'; + + if ($quoteStart) { + $breakSymbol = $this->char(); + } else { + $breakSymbol = false; + $value .= $this->char(); + } + + while ($this->next()) { + if (!$breakSymbol && $this->isWhiteSpace()) { + break; + } elseif ($breakSymbol && $this->char() == $breakSymbol) { + break; + } elseif ($this->char() == '\\') { + $this->next(); + if ($this->char() != '\\') { + $value .= '\\'; + } + $value .= $this->char(); + } else { + $value .= $this->char(); + } + } + return $value; + } +} diff --git a/Magento2/Helpers/Tokenizer/Variable.php b/Magento2/Helpers/Tokenizer/Variable.php new file mode 100644 index 00000000..81c8b1d8 --- /dev/null +++ b/Magento2/Helpers/Tokenizer/Variable.php @@ -0,0 +1,326 @@ +isWhiteSpace()) { + // Ignore white spaces + continue; + } elseif ($this->char() != '.' && $this->char() != '(') { + // Property or method name + $parameterName .= $this->char(); + } elseif ($this->char() == '(') { + // Method declaration + $methodArgs = $this->getMethodArgs(); + $actions[] = ['type' => 'method', 'name' => $parameterName, 'args' => $methodArgs]; + $parameterName = ''; + } elseif ($parameterName != '') { + // Property or variable declaration + if ($variableSet) { + $actions[] = ['type' => 'property', 'name' => $parameterName]; + } else { + $variableSet = true; + $actions[] = ['type' => 'variable', 'name' => $parameterName]; + } + $parameterName = ''; + } + } while ($this->next()); + + if ($parameterName != '') { + if ($variableSet) { + $actions[] = ['type' => 'property', 'name' => $parameterName]; + } else { + $actions[] = ['type' => 'variable', 'name' => $parameterName]; + } + } + + return $actions; + } + + /** + * Get string value for method args + * + * @return string + */ + public function getString() + { + $value = ''; + if ($this->isWhiteSpace()) { + return $value; + } + $quoteStart = $this->isQuote(); + + if ($quoteStart) { + $breakSymbol = $this->char(); + } else { + $breakSymbol = false; + $value .= $this->char(); + } + + while ($this->next()) { + if (!$breakSymbol && $this->isStringBreak()) { + $this->prev(); + break; + } elseif ($breakSymbol && $this->char() == $breakSymbol) { + break; + } elseif ($this->char() == '\\') { + $this->next(); + $value .= $this->char(); + } else { + $value .= $this->char(); + } + } + + return $value; + } + + /** + * Get array member key or return false if none present + * + * @return bool|string + */ + public function getMemberKey() + { + $value = ''; + if ($this->isWhiteSpace()) { + return $value; + } + + $quoteStart = $this->isQuote(); + + if ($quoteStart) { + $closeQuote = $this->char(); + } else { + $closeQuote = false; + $value .= $this->char(); + } + + while ($this->next()) { + if ($closeQuote) { + if ($this->char() == $closeQuote) { + $closeQuote = false; + continue; + } + $value .= $this->char(); + } elseif ($this->char() == ':') { + $this->next(); + + return $value; + } elseif ($this->isStringBreak()) { + $this->prev(); + break; + } else { + $value .= $this->char(); + } + } + + if ($quoteStart) { + $this->back(strlen($value) + 1); + } else { + $this->back(strlen($value) - 1); + } + + return false; + } + + /** + * Get array value for method args + * + * Parses arrays demarcated via open/closing brackets. Keys/value pairs are separated by a + * single colon character. Multi-dimensional arrays are supported. Example input: + * + * [key:value, "key2":"value2", [ + * [123, foo], + * ]] + * + * @return array + */ + public function getArray() + { + $values = []; + if (!$this->isArray()) { + return $values; + } + + $this->incArrayDepth(); + + while ($this->next()) { + if ($this->char() == ']') { + break; + } elseif ($this->isWhiteSpace() || $this->char() == ',') { + continue; + } + + $key = $this->getMemberKey(); + + if ($this->isNumeric()) { + $val = $this->getNumber(); + } elseif ($this->isArray()) { + $val = $this->getArray(); + } else { + $val = $this->getString(); + } + + if ($key) { + $values[$key] = $val; + } else { + $values[] = $val; + } + } + + $this->decArrayDepth(); + + return $values; + } + + /** + * Return the internal array depth counter + * + * @return int + */ + protected function getArrayDepth() + { + return $this->arrayDepth; + } + + /** + * Increment the internal array depth counter + * + * @return void + */ + protected function incArrayDepth() + { + $this->arrayDepth++; + } + + /** + * Decrement the internal array depth counter + * + * If depth is already 0 do nothing + * + * @return void + */ + protected function decArrayDepth() + { + if ($this->arrayDepth == 0) { + return; + } + $this->arrayDepth--; + } + + /** + * Return true if current char is a number + * + * @return boolean + */ + public function isNumeric() + { + return $this->char() >= '0' && $this->char() <= '9'; + } + + /** + * Return true if current char is quote or apostrophe + * + * @return boolean + */ + public function isQuote() + { + return $this->char() == '"' || $this->char() == "'"; + } + + /** + * Retrun true if current char is opening boundary for an array + * + * @return bool + */ + public function isArray() + { + return $this->char() == '['; + } + + /** + * Return true if current char is closing boundary for string + * + * @return bool + */ + public function isStringBreak() + { + if ($this->getArrayDepth() == 0 && ($this->isWhiteSpace() || $this->char() == ',' || $this->char() == ')')) { + return true; + } elseif ($this->getArrayDepth() > 0 && ($this->char() == ',' || $this->char() == ']')) { + return true; + } + + return false; + } + + /** + * Return array of arguments for method + * + * @return array + */ + public function getMethodArgs() + { + $value = []; + + while ($this->next() && $this->char() != ')') { + if ($this->isWhiteSpace() || $this->char() == ',') { + continue; + } elseif ($this->isNumeric()) { + $value[] = $this->getNumber(); + } elseif ($this->isArray()) { + $value[] = $this->getArray(); + } else { + $value[] = $this->getString(); + } + } + + return $value; + } + + /** + * Return number value for method args + * + * @return float + */ + public function getNumber() + { + $value = $this->char(); + while (($this->isNumeric() || $this->char() == '.') && $this->next()) { + $value .= $this->char(); + } + + if (!$this->isNumeric()) { + $this->prev(); + } + + return (float)$value; + } +} diff --git a/Magento2/Sniffs/Html/HtmlDirectiveSniff.php b/Magento2/Sniffs/Html/HtmlDirectiveSniff.php index b14ae7ba..62267ec1 100644 --- a/Magento2/Sniffs/Html/HtmlDirectiveSniff.php +++ b/Magento2/Sniffs/Html/HtmlDirectiveSniff.php @@ -20,7 +20,7 @@ class HtmlDirectiveSniff implements Sniff const CONSTRUCTION_IF_PATTERN = '/{{if\s*(.*?)}}(.*?)({{else}}(.*?))?{{\\/if\s*}}/si'; const LOOP_PATTERN = '/{{for(?P.*? )(in)(?P.*?)}}(?P.*?){{\/for}}/si'; const CONSTRUCTION_PATTERN = '/{{([a-z]{0,10})(.*?)}}(?:(.*?)(?:{{\/(?:\\1)}}))?/si'; - + /** * @var array */ @@ -162,7 +162,7 @@ private function processVarDirectivesAndParams(string $html, File $phpcsFile): s */ private function validateDirectiveBody(File $phpcsFile, string $body): void { - $parameterTokenizer = new Template\Tokenizer\Parameter(); + $parameterTokenizer = new \Magento2\Helpers\Tokenizer\Parameter(); $parameterTokenizer->setString($body); $params = $parameterTokenizer->tokenize(); @@ -185,7 +185,7 @@ private function validateVariableUsage(File $phpcsFile, string $body): void if (strpos($body, '|') !== false) { $this->unfilteredVariables[] = 'var ' . trim(explode('|', $body, 2)[0]); } - $variableTokenizer = new Template\Tokenizer\Variable(); + $variableTokenizer = new \Magento2\Helpers\Tokenizer\Variable(); $variableTokenizer->setString($body); $stack = $variableTokenizer->tokenize(); From 276fabcf6617ed851225f9151a3ce8dcaadce3ea Mon Sep 17 00:00:00 2001 From: Ihor Sviziev Date: Tue, 10 Aug 2021 14:53:31 +0300 Subject: [PATCH 103/630] Run tests for all file types --- .github/workflows/php.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index 5a7cb023..c226c73e 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -51,4 +51,4 @@ jobs: run: vendor/bin/phpunit - name: Run code style suite - run: vendor/bin/phpcs --standard=Magento2 Magento2/ --extensions=php + run: vendor/bin/phpcs --standard=Magento2 Magento2/Helpers/ Magento2/Sniffs From 68369d6d28a6e4fcc060c365cd226849394905e5 Mon Sep 17 00:00:00 2001 From: Ihor Sviziev Date: Tue, 10 Aug 2021 16:19:48 +0300 Subject: [PATCH 104/630] Add test coverage from HtmlBindingSniff --- Magento2/Sniffs/Html/HtmlBindingSniff.php | 2 +- .../Tests/Html/HtmlBindingSniffUnitTest.1.inc | 30 +++++++++++++++++++ Magento2/Tests/Html/HtmlBindingUnitTest.php | 27 +++++++++++++++++ 3 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 Magento2/Tests/Html/HtmlBindingSniffUnitTest.1.inc create mode 100644 Magento2/Tests/Html/HtmlBindingUnitTest.php diff --git a/Magento2/Sniffs/Html/HtmlBindingSniff.php b/Magento2/Sniffs/Html/HtmlBindingSniff.php index 63718b5b..cf498da1 100644 --- a/Magento2/Sniffs/Html/HtmlBindingSniff.php +++ b/Magento2/Sniffs/Html/HtmlBindingSniff.php @@ -83,7 +83,7 @@ public function process(File $phpcsFile, $stackPtr) . ' - "' . $htmlBinding . '" doesn\'t,' . PHP_EOL . 'consider using text binding if the value is supposed to be text', null, - 'UIComponentTemplate.KnockoutBinding.HtmlSuffix' + 'KnockoutBindingHtmlSuffix' ); } } diff --git a/Magento2/Tests/Html/HtmlBindingSniffUnitTest.1.inc b/Magento2/Tests/Html/HtmlBindingSniffUnitTest.1.inc new file mode 100644 index 00000000..37e71322 --- /dev/null +++ b/Magento2/Tests/Html/HtmlBindingSniffUnitTest.1.inc @@ -0,0 +1,30 @@ + + +
+

Test

+ +
+

+
+
+

+ +
+ +
+

+
+
+

diff --git a/Magento2/Tests/Html/HtmlBindingUnitTest.php b/Magento2/Tests/Html/HtmlBindingUnitTest.php new file mode 100644 index 00000000..fe033afd --- /dev/null +++ b/Magento2/Tests/Html/HtmlBindingUnitTest.php @@ -0,0 +1,27 @@ + 6]; + } + + /** + * @inheritdoc + */ + public function getWarningList() + { + return []; + } +} From 9d650e1778c84a456b7f9baa15d08d6a1c4288f2 Mon Sep 17 00:00:00 2001 From: Elisea Cornejo Date: Thu, 19 Aug 2021 10:02:56 +0200 Subject: [PATCH 105/630] AC-601: Create phpcs static check for AbstractBlockTest --- Magento2/Sniffs/Legacy/AbstractBlockSniff.php | 88 +++++++++++++++++++ .../Tests/Legacy/AbstractBlockUnitTest.inc | 36 ++++++++ .../Tests/Legacy/AbstractBlockUnitTest.php | 33 +++++++ Magento2/ruleset.xml | 4 + 4 files changed, 161 insertions(+) create mode 100644 Magento2/Sniffs/Legacy/AbstractBlockSniff.php create mode 100644 Magento2/Tests/Legacy/AbstractBlockUnitTest.inc create mode 100644 Magento2/Tests/Legacy/AbstractBlockUnitTest.php diff --git a/Magento2/Sniffs/Legacy/AbstractBlockSniff.php b/Magento2/Sniffs/Legacy/AbstractBlockSniff.php new file mode 100644 index 00000000..be4d2fad --- /dev/null +++ b/Magento2/Sniffs/Legacy/AbstractBlockSniff.php @@ -0,0 +1,88 @@ +getTokens()[$stackPtr + 1]['content'])) { + return; + } + $content = $phpcsFile->getTokens()[$stackPtr + 1]['content']; + $isTheNextMethodGetChildSomething = in_array( + $content, + [ + self::CHILD_HTML_METHOD, + self::CHILD_CHILD_HTML_METHOD + ] + ); + if (!$isTheNextMethodGetChildSomething) { + return; + } + + $paramsCount = $this->getParametersCount($phpcsFile, $stackPtr + 1); + if ($content === self::CHILD_HTML_METHOD && $paramsCount >= 3) { + $phpcsFile->addError( + '3rd parameter is not needed anymore for getChildHtml()', + $stackPtr, + $this->errorCode + ); + } + if ($content === self::CHILD_CHILD_HTML_METHOD && $paramsCount >= 4) { + $phpcsFile->addError( + '4th parameter is not needed anymore for getChildChildHtml()', + $stackPtr, + $this->errorCode + ); + } + } + + /** + * @param File $phpcsFile + * @param int $methodHtmlPosition + * @return int + */ + private function getParametersCount(File $phpcsFile, int $methodHtmlPosition): int + { + $closePosition = $phpcsFile->getTokens()[$methodHtmlPosition +1]['parenthesis_closer']; + $getTokenAsContent = $phpcsFile->getTokensAsString( + $methodHtmlPosition + 2, + ($closePosition - $methodHtmlPosition) - 2 + ); + if ($getTokenAsContent) { + $parameters = explode(',' , $getTokenAsContent); + return count($parameters); + } + return 0; + } +} diff --git a/Magento2/Tests/Legacy/AbstractBlockUnitTest.inc b/Magento2/Tests/Legacy/AbstractBlockUnitTest.inc new file mode 100644 index 00000000..ca350548 --- /dev/null +++ b/Magento2/Tests/Legacy/AbstractBlockUnitTest.inc @@ -0,0 +1,36 @@ +getChildHtml( + function($param){ + $param->something(); + }, + 'aa' +); + +$this->getChildHtml( + function($param){ + $param->something(); + }, + 'aa', + 2 +); + +return $this->getChildHtml('aa', 'bb'); + +return $this->getChildHtml('aa', 'bb', 1, true); + +$this->getChildHtml(); + +$this->testMethod()->getChildHtml('aa', 'bb', 'cc'); + +$this->getChildChildHtml('aa', true, 'cc'); + +$this->getChildChildHtml('aa', true, 'cc', 1); + +$this->getChildChildHtml('aa' . 'bb', !(1 + 1) * (int) $this, 'cc', 1); + +private function getChildHtml($aa, $bb, $cc = 'cc') +{ +} + +$this->getChilChilddHtml(); diff --git a/Magento2/Tests/Legacy/AbstractBlockUnitTest.php b/Magento2/Tests/Legacy/AbstractBlockUnitTest.php new file mode 100644 index 00000000..62e9517c --- /dev/null +++ b/Magento2/Tests/Legacy/AbstractBlockUnitTest.php @@ -0,0 +1,33 @@ + 1, + 20 => 1, + 24 => 1, + 28 => 1, + 30 => 1 + ]; + } + + /** + * @inheritdoc + */ + public function getWarningList() + { + return []; + } +} diff --git a/Magento2/ruleset.xml b/Magento2/ruleset.xml index f77859e9..3ea0c969 100644 --- a/Magento2/ruleset.xml +++ b/Magento2/ruleset.xml @@ -105,6 +105,10 @@ 10 error
+ + 10 + error + From 515563ce0d7c83c112494d63420e57f1af4e3d48 Mon Sep 17 00:00:00 2001 From: Elisea Cornejo Date: Thu, 19 Aug 2021 10:25:27 +0200 Subject: [PATCH 106/630] AC-601: Create phpcs static check for AbstractBlockTest --- Magento2/Sniffs/Legacy/AbstractBlockSniff.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Magento2/Sniffs/Legacy/AbstractBlockSniff.php b/Magento2/Sniffs/Legacy/AbstractBlockSniff.php index be4d2fad..6aeb67dd 100644 --- a/Magento2/Sniffs/Legacy/AbstractBlockSniff.php +++ b/Magento2/Sniffs/Legacy/AbstractBlockSniff.php @@ -68,6 +68,8 @@ public function process(File $phpcsFile, $stackPtr) } /** + * Get the quantity of parameters on a method + * * @param File $phpcsFile * @param int $methodHtmlPosition * @return int @@ -76,11 +78,11 @@ private function getParametersCount(File $phpcsFile, int $methodHtmlPosition): i { $closePosition = $phpcsFile->getTokens()[$methodHtmlPosition +1]['parenthesis_closer']; $getTokenAsContent = $phpcsFile->getTokensAsString( - $methodHtmlPosition + 2, + $methodHtmlPosition + 2, ($closePosition - $methodHtmlPosition) - 2 ); if ($getTokenAsContent) { - $parameters = explode(',' , $getTokenAsContent); + $parameters = explode(',', $getTokenAsContent); return count($parameters); } return 0; From 750260eb7136c0da6e6ada848f35c8479efcb04f Mon Sep 17 00:00:00 2001 From: Elisea Cornejo Date: Thu, 19 Aug 2021 11:16:37 +0200 Subject: [PATCH 107/630] AC-601: Create phpcs static check for AbstractBlockTest --- Magento2/Sniffs/Legacy/AbstractBlockSniff.php | 28 +++++++++++-------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/Magento2/Sniffs/Legacy/AbstractBlockSniff.php b/Magento2/Sniffs/Legacy/AbstractBlockSniff.php index 6aeb67dd..77cff626 100644 --- a/Magento2/Sniffs/Legacy/AbstractBlockSniff.php +++ b/Magento2/Sniffs/Legacy/AbstractBlockSniff.php @@ -10,8 +10,8 @@ class AbstractBlockSniff implements Sniff { - const CHILD_HTML_METHOD = 'getChildHtml'; - const CHILD_CHILD_HTML_METHOD = 'getChildChildHtml'; + private const CHILD_HTML_METHOD = 'getChildHtml'; + private const CHILD_CHILD_HTML_METHOD = 'getChildChildHtml'; /** * Warning violation code. @@ -38,18 +38,13 @@ public function process(File $phpcsFile, $stackPtr) if (!isset($phpcsFile->getTokens()[$stackPtr + 1]['content'])) { return; } + $content = $phpcsFile->getTokens()[$stackPtr + 1]['content']; - $isTheNextMethodGetChildSomething = in_array( - $content, - [ - self::CHILD_HTML_METHOD, - self::CHILD_CHILD_HTML_METHOD - ] - ); - if (!$isTheNextMethodGetChildSomething) { + + if (!$this->isApplicable($content)) { return; } - + $paramsCount = $this->getParametersCount($phpcsFile, $stackPtr + 1); if ($content === self::CHILD_HTML_METHOD && $paramsCount >= 3) { $phpcsFile->addError( @@ -67,6 +62,17 @@ public function process(File $phpcsFile, $stackPtr) } } + /** + * Return if it is applicable to do the check + * + * @param String $content + * @return bool + */ + private function isApplicable(String $content): bool + { + return in_array($content, [self::CHILD_HTML_METHOD, self::CHILD_CHILD_HTML_METHOD]); + } + /** * Get the quantity of parameters on a method * From 3479d07a006c7731932862d76d3068f0ed2f37cc Mon Sep 17 00:00:00 2001 From: Elisea Cornejo Date: Thu, 19 Aug 2021 12:44:05 +0200 Subject: [PATCH 108/630] AC-601: Create phpcs static check for AbstractBlockTest --- Magento2/Sniffs/Legacy/AbstractBlockSniff.php | 1 + 1 file changed, 1 insertion(+) diff --git a/Magento2/Sniffs/Legacy/AbstractBlockSniff.php b/Magento2/Sniffs/Legacy/AbstractBlockSniff.php index 77cff626..86041d13 100644 --- a/Magento2/Sniffs/Legacy/AbstractBlockSniff.php +++ b/Magento2/Sniffs/Legacy/AbstractBlockSniff.php @@ -1,4 +1,5 @@ Date: Thu, 19 Aug 2021 14:44:28 +0200 Subject: [PATCH 109/630] AC-601: Create phpcs static check for AbstractBlockTest --- Magento2/Sniffs/Legacy/AbstractBlockSniff.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Magento2/Sniffs/Legacy/AbstractBlockSniff.php b/Magento2/Sniffs/Legacy/AbstractBlockSniff.php index 86041d13..dd1575b2 100644 --- a/Magento2/Sniffs/Legacy/AbstractBlockSniff.php +++ b/Magento2/Sniffs/Legacy/AbstractBlockSniff.php @@ -1,9 +1,10 @@ Date: Thu, 19 Aug 2021 14:45:03 +0200 Subject: [PATCH 110/630] AC-601: Create phpcs static check for AbstractBlockTest --- Magento2/Sniffs/Legacy/AbstractBlockSniff.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Magento2/Sniffs/Legacy/AbstractBlockSniff.php b/Magento2/Sniffs/Legacy/AbstractBlockSniff.php index dd1575b2..41a7da00 100644 --- a/Magento2/Sniffs/Legacy/AbstractBlockSniff.php +++ b/Magento2/Sniffs/Legacy/AbstractBlockSniff.php @@ -16,7 +16,7 @@ class AbstractBlockSniff implements Sniff private const CHILD_CHILD_HTML_METHOD = 'getChildChildHtml'; /** - * Warning violation code. + * Error violation code. * * @var string */ From c9c072fdb244190c42abcfa36274aa3be9792300 Mon Sep 17 00:00:00 2001 From: Franciszek Wawrzak Date: Fri, 20 Aug 2021 12:44:19 +0200 Subject: [PATCH 111/630] Prevent ImportsFromTestNamespaceSniff from hanging when group use declaration has trailing coma. If a grouped use statement has a trailing coma like this: ``` use Magento\Something{ Foo, Bar, }; ``` `findNext` on line 59 was returning false and next call was starting to search again from line 1 (`$next + 1`) and this function was looping indefinitely through input tokens. --- .../Namespaces/ImportsFromTestNamespaceSniff.php | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/Magento2/Sniffs/Namespaces/ImportsFromTestNamespaceSniff.php b/Magento2/Sniffs/Namespaces/ImportsFromTestNamespaceSniff.php index 3e5dbce7..1266c0dc 100644 --- a/Magento2/Sniffs/Namespaces/ImportsFromTestNamespaceSniff.php +++ b/Magento2/Sniffs/Namespaces/ImportsFromTestNamespaceSniff.php @@ -57,11 +57,13 @@ public function process(File $phpcsFile, $stackPtr) $closingCurly = $phpcsFile->findNext(T_CLOSE_USE_GROUP, ($next + 1)); do { $next = $phpcsFile->findNext(Tokens::$emptyTokens, ($next + 1), $closingCurly, true); - $groupedAsContent = $baseUse. $tokens[$next]['content']; - $next = $phpcsFile->findNext(T_COMMA, ($next + 1), $closingCurly); - if (strpos($groupedAsContent, $this->prohibitNamespace) !== false) { - $phpcsFile->addWarning($this->warningMessage, $stackPtr, $this->warningCode); - return; + if ($next !== false) { + $groupedAsContent = $baseUse. $tokens[$next]['content']; + $next = $phpcsFile->findNext(T_COMMA, ($next + 1), $closingCurly); + if (strpos($groupedAsContent, $this->prohibitNamespace) !== false) { + $phpcsFile->addWarning($this->warningMessage, $stackPtr, $this->warningCode); + return; + } } } while ($next !== false); } From 02f1438219d66e5cf427b771941a1286ab2a5b91 Mon Sep 17 00:00:00 2001 From: Andrii Beziazychnyi Date: Fri, 20 Aug 2021 09:22:11 +0300 Subject: [PATCH 112/630] The `phpunit/phpunit` composer dependency has been updated to 9.5.8 --- .github/workflows/php.yml | 6 +- .../AbstractGraphQLSniffUnitTestCase.php | 2 +- .../Tests/Standards/AbstractSniffUnitTest.php | 461 ++++++++++ composer.json | 11 +- composer.lock | 862 +++++++++++++----- 5 files changed, 1100 insertions(+), 242 deletions(-) create mode 100644 PHP_CodeSniffer/Tests/Standards/AbstractSniffUnitTest.php diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index 5a7cb023..48a7089f 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -14,18 +14,14 @@ jobs: fail-fast: false matrix: php-version: - - "7.2" - "7.3" - "7.4" + - "8.0" dependencies: - "lowest" - "highest" experimental: - false - include: - - php-version: "8.0" - dependencies: "highest" - composer-options: "--ignore-platform-reqs" name: Tests with PHP ${{ matrix.php-version }} and ${{ matrix.dependencies }} dependencies steps: diff --git a/Magento2/Tests/GraphQL/AbstractGraphQLSniffUnitTestCase.php b/Magento2/Tests/GraphQL/AbstractGraphQLSniffUnitTestCase.php index dc921b17..c9451e88 100644 --- a/Magento2/Tests/GraphQL/AbstractGraphQLSniffUnitTestCase.php +++ b/Magento2/Tests/GraphQL/AbstractGraphQLSniffUnitTestCase.php @@ -16,7 +16,7 @@ abstract class AbstractGraphQLSniffUnitTestCase extends AbstractSniffUnitTest /** * @inheritDoc */ - protected function setUp() + protected function setUp(): void { //let parent do its job parent::setUp(); diff --git a/PHP_CodeSniffer/Tests/Standards/AbstractSniffUnitTest.php b/PHP_CodeSniffer/Tests/Standards/AbstractSniffUnitTest.php new file mode 100644 index 00000000..206cc374 --- /dev/null +++ b/PHP_CodeSniffer/Tests/Standards/AbstractSniffUnitTest.php @@ -0,0 +1,461 @@ + + * @copyright 2006-2015 Squiz Pty Ltd (ABN 77 084 670 600) + * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence + */ + +namespace PHP_CodeSniffer\Tests\Standards; + +use PHP_CodeSniffer\Config; +use PHP_CodeSniffer\Exceptions\RuntimeException; +use PHP_CodeSniffer\Ruleset; +use PHP_CodeSniffer\Files\LocalFile; +use PHP_CodeSniffer\Util\Common; +use PHPUnit\Framework\TestCase; + +abstract class AbstractSniffUnitTest extends TestCase +{ + + /** + * Enable or disable the backup and restoration of the $GLOBALS array. + * Overwrite this attribute in a child class of TestCase. + * Setting this attribute in setUp() has no effect! + * + * @var boolean + */ + protected $backupGlobals = false; + + /** + * The path to the standard's main directory. + * + * @var string + */ + public $standardsDir = null; + + /** + * The path to the standard's test directory. + * + * @var string + */ + public $testsDir = null; + + + /** + * Sets up this unit test. + * + * @return void + */ + protected function setUp(): void + { + $class = get_class($this); + $this->standardsDir = $GLOBALS['PHP_CODESNIFFER_STANDARD_DIRS'][$class]; + $this->testsDir = $GLOBALS['PHP_CODESNIFFER_TEST_DIRS'][$class]; + + }//end setUp() + + + /** + * Get a list of all test files to check. + * + * These will have the same base as the sniff name but different extensions. + * We ignore the .php file as it is the class. + * + * @param string $testFileBase The base path that the unit tests files will have. + * + * @return string[] + */ + protected function getTestFiles($testFileBase) + { + $testFiles = []; + + $dir = substr($testFileBase, 0, strrpos($testFileBase, DIRECTORY_SEPARATOR)); + $di = new \DirectoryIterator($dir); + + foreach ($di as $file) { + $path = $file->getPathname(); + if (substr($path, 0, strlen($testFileBase)) === $testFileBase) { + if ($path !== $testFileBase.'php' && substr($path, -5) !== 'fixed' && substr($path, -4) !== '.bak') { + $testFiles[] = $path; + } + } + } + + // Put them in order. + sort($testFiles); + + return $testFiles; + + }//end getTestFiles() + + + /** + * Should this test be skipped for some reason. + * + * @return boolean + */ + protected function shouldSkipTest() + { + return false; + + }//end shouldSkipTest() + + + /** + * Tests the extending classes Sniff class. + * + * @return void + * @throws \PHPUnit\Framework\Exception + */ + final public function testSniff() + { + // Skip this test if we can't run in this environment. + if ($this->shouldSkipTest() === true) { + $this->markTestSkipped(); + } + + $sniffCode = Common::getSniffCode(get_class($this)); + list($standardName, $categoryName, $sniffName) = explode('.', $sniffCode); + + $testFileBase = $this->testsDir.$categoryName.DIRECTORY_SEPARATOR.$sniffName.'UnitTest.'; + + // Get a list of all test files to check. + $testFiles = $this->getTestFiles($testFileBase); + $GLOBALS['PHP_CODESNIFFER_SNIFF_CASE_FILES'][] = $testFiles; + + if (isset($GLOBALS['PHP_CODESNIFFER_CONFIG']) === true) { + $config = $GLOBALS['PHP_CODESNIFFER_CONFIG']; + } else { + $config = new Config(); + $config->cache = false; + $GLOBALS['PHP_CODESNIFFER_CONFIG'] = $config; + } + + $config->standards = [$standardName]; + $config->sniffs = [$sniffCode]; + $config->ignored = []; + + if (isset($GLOBALS['PHP_CODESNIFFER_RULESETS']) === false) { + $GLOBALS['PHP_CODESNIFFER_RULESETS'] = []; + } + + if (isset($GLOBALS['PHP_CODESNIFFER_RULESETS'][$standardName]) === false) { + $ruleset = new Ruleset($config); + $GLOBALS['PHP_CODESNIFFER_RULESETS'][$standardName] = $ruleset; + } + + $ruleset = $GLOBALS['PHP_CODESNIFFER_RULESETS'][$standardName]; + + $sniffFile = $this->standardsDir.DIRECTORY_SEPARATOR.'Sniffs'.DIRECTORY_SEPARATOR.$categoryName.DIRECTORY_SEPARATOR.$sniffName.'Sniff.php'; + + $sniffClassName = substr(get_class($this), 0, -8).'Sniff'; + $sniffClassName = str_replace('\Tests\\', '\Sniffs\\', $sniffClassName); + $sniffClassName = Common::cleanSniffClass($sniffClassName); + + $restrictions = [strtolower($sniffClassName) => true]; + $ruleset->registerSniffs([$sniffFile], $restrictions, []); + $ruleset->populateTokenListeners(); + + $failureMessages = []; + foreach ($testFiles as $testFile) { + $filename = basename($testFile); + $oldConfig = $config->getSettings(); + + try { + $this->setCliValues($filename, $config); + $phpcsFile = new LocalFile($testFile, $ruleset, $config); + $phpcsFile->process(); + } catch (RuntimeException $e) { + $this->fail('An unexpected exception has been caught: '.$e->getMessage()); + } + + $failures = $this->generateFailureMessages($phpcsFile); + $failureMessages = array_merge($failureMessages, $failures); + + if ($phpcsFile->getFixableCount() > 0) { + // Attempt to fix the errors. + $phpcsFile->fixer->fixFile(); + $fixable = $phpcsFile->getFixableCount(); + if ($fixable > 0) { + $failureMessages[] = "Failed to fix $fixable fixable violations in $filename"; + } + + // Check for a .fixed file to check for accuracy of fixes. + $fixedFile = $testFile.'.fixed'; + if (file_exists($fixedFile) === true) { + $diff = $phpcsFile->fixer->generateDiff($fixedFile); + if (trim($diff) !== '') { + $filename = basename($testFile); + $fixedFilename = basename($fixedFile); + $failureMessages[] = "Fixed version of $filename does not match expected version in $fixedFilename; the diff is\n$diff"; + } + } + } + + // Restore the config. + $config->setSettings($oldConfig); + }//end foreach + + if (empty($failureMessages) === false) { + $this->fail(implode(PHP_EOL, $failureMessages)); + } + + }//end testSniff() + + + /** + * Generate a list of test failures for a given sniffed file. + * + * @param \PHP_CodeSniffer\Files\LocalFile $file The file being tested. + * + * @return array + * @throws \PHP_CodeSniffer\Exceptions\RuntimeException + */ + public function generateFailureMessages(LocalFile $file) + { + $testFile = $file->getFilename(); + + $foundErrors = $file->getErrors(); + $foundWarnings = $file->getWarnings(); + $expectedErrors = $this->getErrorList(basename($testFile)); + $expectedWarnings = $this->getWarningList(basename($testFile)); + + if (is_array($expectedErrors) === false) { + throw new RuntimeException('getErrorList() must return an array'); + } + + if (is_array($expectedWarnings) === false) { + throw new RuntimeException('getWarningList() must return an array'); + } + + /* + We merge errors and warnings together to make it easier + to iterate over them and produce the errors string. In this way, + we can report on errors and warnings in the same line even though + it's not really structured to allow that. + */ + + $allProblems = []; + $failureMessages = []; + + foreach ($foundErrors as $line => $lineErrors) { + foreach ($lineErrors as $column => $errors) { + if (isset($allProblems[$line]) === false) { + $allProblems[$line] = [ + 'expected_errors' => 0, + 'expected_warnings' => 0, + 'found_errors' => [], + 'found_warnings' => [], + ]; + } + + $foundErrorsTemp = []; + foreach ($allProblems[$line]['found_errors'] as $foundError) { + $foundErrorsTemp[] = $foundError; + } + + $errorsTemp = []; + foreach ($errors as $foundError) { + $errorsTemp[] = $foundError['message'].' ('.$foundError['source'].')'; + + $source = $foundError['source']; + if (in_array($source, $GLOBALS['PHP_CODESNIFFER_SNIFF_CODES'], true) === false) { + $GLOBALS['PHP_CODESNIFFER_SNIFF_CODES'][] = $source; + } + + if ($foundError['fixable'] === true + && in_array($source, $GLOBALS['PHP_CODESNIFFER_FIXABLE_CODES'], true) === false + ) { + $GLOBALS['PHP_CODESNIFFER_FIXABLE_CODES'][] = $source; + } + } + + $allProblems[$line]['found_errors'] = array_merge($foundErrorsTemp, $errorsTemp); + }//end foreach + + if (isset($expectedErrors[$line]) === true) { + $allProblems[$line]['expected_errors'] = $expectedErrors[$line]; + } else { + $allProblems[$line]['expected_errors'] = 0; + } + + unset($expectedErrors[$line]); + }//end foreach + + foreach ($expectedErrors as $line => $numErrors) { + if (isset($allProblems[$line]) === false) { + $allProblems[$line] = [ + 'expected_errors' => 0, + 'expected_warnings' => 0, + 'found_errors' => [], + 'found_warnings' => [], + ]; + } + + $allProblems[$line]['expected_errors'] = $numErrors; + } + + foreach ($foundWarnings as $line => $lineWarnings) { + foreach ($lineWarnings as $column => $warnings) { + if (isset($allProblems[$line]) === false) { + $allProblems[$line] = [ + 'expected_errors' => 0, + 'expected_warnings' => 0, + 'found_errors' => [], + 'found_warnings' => [], + ]; + } + + $foundWarningsTemp = []; + foreach ($allProblems[$line]['found_warnings'] as $foundWarning) { + $foundWarningsTemp[] = $foundWarning; + } + + $warningsTemp = []; + foreach ($warnings as $warning) { + $warningsTemp[] = $warning['message'].' ('.$warning['source'].')'; + + $source = $warning['source']; + if (in_array($source, $GLOBALS['PHP_CODESNIFFER_SNIFF_CODES'], true) === false) { + $GLOBALS['PHP_CODESNIFFER_SNIFF_CODES'][] = $source; + } + + if ($warning['fixable'] === true + && in_array($source, $GLOBALS['PHP_CODESNIFFER_FIXABLE_CODES'], true) === false + ) { + $GLOBALS['PHP_CODESNIFFER_FIXABLE_CODES'][] = $source; + } + } + + $allProblems[$line]['found_warnings'] = array_merge($foundWarningsTemp, $warningsTemp); + }//end foreach + + if (isset($expectedWarnings[$line]) === true) { + $allProblems[$line]['expected_warnings'] = $expectedWarnings[$line]; + } else { + $allProblems[$line]['expected_warnings'] = 0; + } + + unset($expectedWarnings[$line]); + }//end foreach + + foreach ($expectedWarnings as $line => $numWarnings) { + if (isset($allProblems[$line]) === false) { + $allProblems[$line] = [ + 'expected_errors' => 0, + 'expected_warnings' => 0, + 'found_errors' => [], + 'found_warnings' => [], + ]; + } + + $allProblems[$line]['expected_warnings'] = $numWarnings; + } + + // Order the messages by line number. + ksort($allProblems); + + foreach ($allProblems as $line => $problems) { + $numErrors = count($problems['found_errors']); + $numWarnings = count($problems['found_warnings']); + $expectedErrors = $problems['expected_errors']; + $expectedWarnings = $problems['expected_warnings']; + + $errors = ''; + $foundString = ''; + + if ($expectedErrors !== $numErrors || $expectedWarnings !== $numWarnings) { + $lineMessage = "[LINE $line]"; + $expectedMessage = 'Expected '; + $foundMessage = 'in '.basename($testFile).' but found '; + + if ($expectedErrors !== $numErrors) { + $expectedMessage .= "$expectedErrors error(s)"; + $foundMessage .= "$numErrors error(s)"; + if ($numErrors !== 0) { + $foundString .= 'error(s)'; + $errors .= implode(PHP_EOL.' -> ', $problems['found_errors']); + } + + if ($expectedWarnings !== $numWarnings) { + $expectedMessage .= ' and '; + $foundMessage .= ' and '; + if ($numWarnings !== 0) { + if ($foundString !== '') { + $foundString .= ' and '; + } + } + } + } + + if ($expectedWarnings !== $numWarnings) { + $expectedMessage .= "$expectedWarnings warning(s)"; + $foundMessage .= "$numWarnings warning(s)"; + if ($numWarnings !== 0) { + $foundString .= 'warning(s)'; + if (empty($errors) === false) { + $errors .= PHP_EOL.' -> '; + } + + $errors .= implode(PHP_EOL.' -> ', $problems['found_warnings']); + } + } + + $fullMessage = "$lineMessage $expectedMessage $foundMessage."; + if ($errors !== '') { + $fullMessage .= " The $foundString found were:".PHP_EOL." -> $errors"; + } + + $failureMessages[] = $fullMessage; + }//end if + }//end foreach + + return $failureMessages; + + }//end generateFailureMessages() + + + /** + * Get a list of CLI values to set before the file is tested. + * + * @param string $filename The name of the file being tested. + * @param \PHP_CodeSniffer\Config $config The config data for the run. + * + * @return void + */ + public function setCliValues($filename, $config) + { + return; + + }//end setCliValues() + + + /** + * Returns the lines where errors should occur. + * + * The key of the array should represent the line number and the value + * should represent the number of errors that should occur on that line. + * + * @return array + */ + abstract protected function getErrorList(); + + + /** + * Returns the lines where warnings should occur. + * + * The key of the array should represent the line number and the value + * should represent the number of warnings that should occur on that line. + * + * @return array + */ + abstract protected function getWarningList(); + + +}//end class diff --git a/composer.json b/composer.json index 89c193c8..fef78240 100644 --- a/composer.json +++ b/composer.json @@ -8,12 +8,12 @@ "type": "phpcodesniffer-standard", "version": "6", "require": { - "php": ">=7.2", - "squizlabs/php_codesniffer": "^3.5", + "php": ">=7.3", + "squizlabs/php_codesniffer": "^3.6", "webonyx/graphql-php": "^14.9" }, "require-dev": { - "phpunit/phpunit": "^7.0" + "phpunit/phpunit": "^9.5.8" }, "autoload": { "classmap": [ @@ -21,7 +21,10 @@ ], "psr-4": { "Magento2\\": "Magento2/" - } + }, + "files": [ + "PHP_CodeSniffer/Tests/Standards/AbstractSniffUnitTest.php" + ] }, "scripts": { "post-install-cmd": "vendor/bin/phpcs --config-set installed_paths ../../..", diff --git a/composer.lock b/composer.lock index 0bbf81ae..8a7ddd72 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": "ded4734336bc43d824498918b37b815c", + "content-hash": "9da12284ef127e6443c2207e471f5970", "packages": [ { "name": "squizlabs/php_codesniffer", @@ -257,30 +257,87 @@ ], "time": "2020-11-13T09:40:50+00:00" }, + { + "name": "nikic/php-parser", + "version": "v4.12.0", + "source": { + "type": "git", + "url": "https://github.com/nikic/PHP-Parser.git", + "reference": "6608f01670c3cc5079e18c1dab1104e002579143" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/6608f01670c3cc5079e18c1dab1104e002579143", + "reference": "6608f01670c3cc5079e18c1dab1104e002579143", + "shasum": "" + }, + "require": { + "ext-tokenizer": "*", + "php": ">=7.0" + }, + "require-dev": { + "ircmaxell/php-yacc": "^0.0.7", + "phpunit/phpunit": "^6.5 || ^7.0 || ^8.0 || ^9.0" + }, + "bin": [ + "bin/php-parse" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "4.9-dev" + } + }, + "autoload": { + "psr-4": { + "PhpParser\\": "lib/PhpParser" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Nikita Popov" + } + ], + "description": "A PHP parser written in PHP", + "keywords": [ + "parser", + "php" + ], + "support": { + "issues": "https://github.com/nikic/PHP-Parser/issues", + "source": "https://github.com/nikic/PHP-Parser/tree/v4.12.0" + }, + "time": "2021-07-21T10:44:31+00:00" + }, { "name": "phar-io/manifest", - "version": "1.0.3", + "version": "2.0.3", "source": { "type": "git", "url": "https://github.com/phar-io/manifest.git", - "reference": "7761fcacf03b4d4f16e7ccb606d4879ca431fcf4" + "reference": "97803eca37d319dfa7826cc2437fc020857acb53" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phar-io/manifest/zipball/7761fcacf03b4d4f16e7ccb606d4879ca431fcf4", - "reference": "7761fcacf03b4d4f16e7ccb606d4879ca431fcf4", + "url": "https://api.github.com/repos/phar-io/manifest/zipball/97803eca37d319dfa7826cc2437fc020857acb53", + "reference": "97803eca37d319dfa7826cc2437fc020857acb53", "shasum": "" }, "require": { "ext-dom": "*", "ext-phar": "*", - "phar-io/version": "^2.0", - "php": "^5.6 || ^7.0" + "ext-xmlwriter": "*", + "phar-io/version": "^3.0.1", + "php": "^7.2 || ^8.0" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "1.0.x-dev" + "dev-master": "2.0.x-dev" } }, "autoload": { @@ -312,26 +369,26 @@ "description": "Component for reading phar.io manifest information from a PHP Archive (PHAR)", "support": { "issues": "https://github.com/phar-io/manifest/issues", - "source": "https://github.com/phar-io/manifest/tree/master" + "source": "https://github.com/phar-io/manifest/tree/2.0.3" }, - "time": "2018-07-08T19:23:20+00:00" + "time": "2021-07-20T11:28:43+00:00" }, { "name": "phar-io/version", - "version": "2.0.1", + "version": "3.1.0", "source": { "type": "git", "url": "https://github.com/phar-io/version.git", - "reference": "45a2ec53a73c70ce41d55cedef9063630abaf1b6" + "reference": "bae7c545bef187884426f042434e561ab1ddb182" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phar-io/version/zipball/45a2ec53a73c70ce41d55cedef9063630abaf1b6", - "reference": "45a2ec53a73c70ce41d55cedef9063630abaf1b6", + "url": "https://api.github.com/repos/phar-io/version/zipball/bae7c545bef187884426f042434e561ab1ddb182", + "reference": "bae7c545bef187884426f042434e561ab1ddb182", "shasum": "" }, "require": { - "php": "^5.6 || ^7.0" + "php": "^7.2 || ^8.0" }, "type": "library", "autoload": { @@ -363,9 +420,9 @@ "description": "Library for handling version information and constraints", "support": { "issues": "https://github.com/phar-io/version/issues", - "source": "https://github.com/phar-io/version/tree/master" + "source": "https://github.com/phar-io/version/tree/3.1.0" }, - "time": "2018-07-08T19:19:57+00:00" + "time": "2021-02-23T14:00:09+00:00" }, { "name": "phpdocumentor/reflection-common", @@ -594,40 +651,44 @@ }, { "name": "phpunit/php-code-coverage", - "version": "6.1.4", + "version": "9.2.6", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-code-coverage.git", - "reference": "807e6013b00af69b6c5d9ceb4282d0393dbb9d8d" + "reference": "f6293e1b30a2354e8428e004689671b83871edde" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/807e6013b00af69b6c5d9ceb4282d0393dbb9d8d", - "reference": "807e6013b00af69b6c5d9ceb4282d0393dbb9d8d", + "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/f6293e1b30a2354e8428e004689671b83871edde", + "reference": "f6293e1b30a2354e8428e004689671b83871edde", "shasum": "" }, "require": { "ext-dom": "*", + "ext-libxml": "*", "ext-xmlwriter": "*", - "php": "^7.1", - "phpunit/php-file-iterator": "^2.0", - "phpunit/php-text-template": "^1.2.1", - "phpunit/php-token-stream": "^3.0", - "sebastian/code-unit-reverse-lookup": "^1.0.1", - "sebastian/environment": "^3.1 || ^4.0", - "sebastian/version": "^2.0.1", - "theseer/tokenizer": "^1.1" + "nikic/php-parser": "^4.10.2", + "php": ">=7.3", + "phpunit/php-file-iterator": "^3.0.3", + "phpunit/php-text-template": "^2.0.2", + "sebastian/code-unit-reverse-lookup": "^2.0.2", + "sebastian/complexity": "^2.0", + "sebastian/environment": "^5.1.2", + "sebastian/lines-of-code": "^1.0.3", + "sebastian/version": "^3.0.1", + "theseer/tokenizer": "^1.2.0" }, "require-dev": { - "phpunit/phpunit": "^7.0" + "phpunit/phpunit": "^9.3" }, "suggest": { - "ext-xdebug": "^2.6.0" + "ext-pcov": "*", + "ext-xdebug": "*" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "6.1-dev" + "dev-master": "9.2-dev" } }, "autoload": { @@ -655,34 +716,40 @@ ], "support": { "issues": "https://github.com/sebastianbergmann/php-code-coverage/issues", - "source": "https://github.com/sebastianbergmann/php-code-coverage/tree/master" + "source": "https://github.com/sebastianbergmann/php-code-coverage/tree/9.2.6" }, - "time": "2018-10-31T16:06:48+00:00" + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2021-03-28T07:26:59+00:00" }, { "name": "phpunit/php-file-iterator", - "version": "2.0.4", + "version": "3.0.5", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-file-iterator.git", - "reference": "28af674ff175d0768a5a978e6de83f697d4a7f05" + "reference": "aa4be8575f26070b100fccb67faabb28f21f66f8" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/28af674ff175d0768a5a978e6de83f697d4a7f05", - "reference": "28af674ff175d0768a5a978e6de83f697d4a7f05", + "url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/aa4be8575f26070b100fccb67faabb28f21f66f8", + "reference": "aa4be8575f26070b100fccb67faabb28f21f66f8", "shasum": "" }, "require": { - "php": ">=7.1" + "php": ">=7.3" }, "require-dev": { - "phpunit/phpunit": "^8.5" + "phpunit/phpunit": "^9.3" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "2.0.x-dev" + "dev-master": "3.0-dev" } }, "autoload": { @@ -709,7 +776,7 @@ ], "support": { "issues": "https://github.com/sebastianbergmann/php-file-iterator/issues", - "source": "https://github.com/sebastianbergmann/php-file-iterator/tree/2.0.4" + "source": "https://github.com/sebastianbergmann/php-file-iterator/tree/3.0.5" }, "funding": [ { @@ -717,26 +784,38 @@ "type": "github" } ], - "time": "2021-07-19T06:46:01+00:00" + "time": "2020-09-28T05:57:25+00:00" }, { - "name": "phpunit/php-text-template", - "version": "1.2.1", + "name": "phpunit/php-invoker", + "version": "3.1.1", "source": { "type": "git", - "url": "https://github.com/sebastianbergmann/php-text-template.git", - "reference": "31f8b717e51d9a2afca6c9f046f5d69fc27c8686" + "url": "https://github.com/sebastianbergmann/php-invoker.git", + "reference": "5a10147d0aaf65b58940a0b72f71c9ac0423cc67" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-text-template/zipball/31f8b717e51d9a2afca6c9f046f5d69fc27c8686", - "reference": "31f8b717e51d9a2afca6c9f046f5d69fc27c8686", + "url": "https://api.github.com/repos/sebastianbergmann/php-invoker/zipball/5a10147d0aaf65b58940a0b72f71c9ac0423cc67", + "reference": "5a10147d0aaf65b58940a0b72f71c9ac0423cc67", "shasum": "" }, "require": { - "php": ">=5.3.3" + "php": ">=7.3" + }, + "require-dev": { + "ext-pcntl": "*", + "phpunit/phpunit": "^9.3" + }, + "suggest": { + "ext-pcntl": "*" }, "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.1-dev" + } + }, "autoload": { "classmap": [ "src/" @@ -753,41 +832,47 @@ "role": "lead" } ], - "description": "Simple template engine.", - "homepage": "https://github.com/sebastianbergmann/php-text-template/", + "description": "Invoke callables with a timeout", + "homepage": "https://github.com/sebastianbergmann/php-invoker/", "keywords": [ - "template" + "process" ], "support": { - "issues": "https://github.com/sebastianbergmann/php-text-template/issues", - "source": "https://github.com/sebastianbergmann/php-text-template/tree/1.2.1" + "issues": "https://github.com/sebastianbergmann/php-invoker/issues", + "source": "https://github.com/sebastianbergmann/php-invoker/tree/3.1.1" }, - "time": "2015-06-21T13:50:34+00:00" + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2020-09-28T05:58:55+00:00" }, { - "name": "phpunit/php-timer", - "version": "2.1.3", + "name": "phpunit/php-text-template", + "version": "2.0.4", "source": { "type": "git", - "url": "https://github.com/sebastianbergmann/php-timer.git", - "reference": "2454ae1765516d20c4ffe103d85a58a9a3bd5662" + "url": "https://github.com/sebastianbergmann/php-text-template.git", + "reference": "5da5f67fc95621df9ff4c4e5a84d6a8a2acf7c28" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-timer/zipball/2454ae1765516d20c4ffe103d85a58a9a3bd5662", - "reference": "2454ae1765516d20c4ffe103d85a58a9a3bd5662", + "url": "https://api.github.com/repos/sebastianbergmann/php-text-template/zipball/5da5f67fc95621df9ff4c4e5a84d6a8a2acf7c28", + "reference": "5da5f67fc95621df9ff4c4e5a84d6a8a2acf7c28", "shasum": "" }, "require": { - "php": ">=7.1" + "php": ">=7.3" }, "require-dev": { - "phpunit/phpunit": "^8.5" + "phpunit/phpunit": "^9.3" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "2.1-dev" + "dev-master": "2.0-dev" } }, "autoload": { @@ -806,14 +891,14 @@ "role": "lead" } ], - "description": "Utility class for timing", - "homepage": "https://github.com/sebastianbergmann/php-timer/", + "description": "Simple template engine.", + "homepage": "https://github.com/sebastianbergmann/php-text-template/", "keywords": [ - "timer" + "template" ], "support": { - "issues": "https://github.com/sebastianbergmann/php-timer/issues", - "source": "https://github.com/sebastianbergmann/php-timer/tree/2.1.3" + "issues": "https://github.com/sebastianbergmann/php-text-template/issues", + "source": "https://github.com/sebastianbergmann/php-text-template/tree/2.0.4" }, "funding": [ { @@ -821,33 +906,32 @@ "type": "github" } ], - "time": "2020-11-30T08:20:02+00:00" + "time": "2020-10-26T05:33:50+00:00" }, { - "name": "phpunit/php-token-stream", - "version": "3.1.3", + "name": "phpunit/php-timer", + "version": "5.0.3", "source": { "type": "git", - "url": "https://github.com/sebastianbergmann/php-token-stream.git", - "reference": "9c1da83261628cb24b6a6df371b6e312b3954768" + "url": "https://github.com/sebastianbergmann/php-timer.git", + "reference": "5a63ce20ed1b5bf577850e2c4e87f4aa902afbd2" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-token-stream/zipball/9c1da83261628cb24b6a6df371b6e312b3954768", - "reference": "9c1da83261628cb24b6a6df371b6e312b3954768", + "url": "https://api.github.com/repos/sebastianbergmann/php-timer/zipball/5a63ce20ed1b5bf577850e2c4e87f4aa902afbd2", + "reference": "5a63ce20ed1b5bf577850e2c4e87f4aa902afbd2", "shasum": "" }, "require": { - "ext-tokenizer": "*", - "php": ">=7.1" + "php": ">=7.3" }, "require-dev": { - "phpunit/phpunit": "^7.0" + "phpunit/phpunit": "^9.3" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "3.1-dev" + "dev-master": "5.0-dev" } }, "autoload": { @@ -862,17 +946,18 @@ "authors": [ { "name": "Sebastian Bergmann", - "email": "sebastian@phpunit.de" + "email": "sebastian@phpunit.de", + "role": "lead" } ], - "description": "Wrapper around PHP's tokenizer extension.", - "homepage": "https://github.com/sebastianbergmann/php-token-stream/", + "description": "Utility class for timing", + "homepage": "https://github.com/sebastianbergmann/php-timer/", "keywords": [ - "tokenizer" + "timer" ], "support": { - "issues": "https://github.com/sebastianbergmann/php-token-stream/issues", - "source": "https://github.com/sebastianbergmann/php-token-stream/tree/3.1.3" + "issues": "https://github.com/sebastianbergmann/php-timer/issues", + "source": "https://github.com/sebastianbergmann/php-timer/tree/5.0.3" }, "funding": [ { @@ -880,58 +965,59 @@ "type": "github" } ], - "abandoned": true, - "time": "2021-07-26T12:15:06+00:00" + "time": "2020-10-26T13:16:10+00:00" }, { "name": "phpunit/phpunit", - "version": "7.5.20", + "version": "9.5.8", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "9467db479d1b0487c99733bb1e7944d32deded2c" + "reference": "191768ccd5c85513b4068bdbe99bb6390c7d54fb" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/9467db479d1b0487c99733bb1e7944d32deded2c", - "reference": "9467db479d1b0487c99733bb1e7944d32deded2c", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/191768ccd5c85513b4068bdbe99bb6390c7d54fb", + "reference": "191768ccd5c85513b4068bdbe99bb6390c7d54fb", "shasum": "" }, "require": { - "doctrine/instantiator": "^1.1", + "doctrine/instantiator": "^1.3.1", "ext-dom": "*", "ext-json": "*", "ext-libxml": "*", "ext-mbstring": "*", "ext-xml": "*", - "myclabs/deep-copy": "^1.7", - "phar-io/manifest": "^1.0.2", - "phar-io/version": "^2.0", - "php": "^7.1", - "phpspec/prophecy": "^1.7", - "phpunit/php-code-coverage": "^6.0.7", - "phpunit/php-file-iterator": "^2.0.1", - "phpunit/php-text-template": "^1.2.1", - "phpunit/php-timer": "^2.1", - "sebastian/comparator": "^3.0", - "sebastian/diff": "^3.0", - "sebastian/environment": "^4.0", - "sebastian/exporter": "^3.1", - "sebastian/global-state": "^2.0", - "sebastian/object-enumerator": "^3.0.3", - "sebastian/resource-operations": "^2.0", - "sebastian/version": "^2.0.1" - }, - "conflict": { - "phpunit/phpunit-mock-objects": "*" + "ext-xmlwriter": "*", + "myclabs/deep-copy": "^1.10.1", + "phar-io/manifest": "^2.0.3", + "phar-io/version": "^3.0.2", + "php": ">=7.3", + "phpspec/prophecy": "^1.12.1", + "phpunit/php-code-coverage": "^9.2.3", + "phpunit/php-file-iterator": "^3.0.5", + "phpunit/php-invoker": "^3.1.1", + "phpunit/php-text-template": "^2.0.3", + "phpunit/php-timer": "^5.0.2", + "sebastian/cli-parser": "^1.0.1", + "sebastian/code-unit": "^1.0.6", + "sebastian/comparator": "^4.0.5", + "sebastian/diff": "^4.0.3", + "sebastian/environment": "^5.1.3", + "sebastian/exporter": "^4.0.3", + "sebastian/global-state": "^5.0.1", + "sebastian/object-enumerator": "^4.0.3", + "sebastian/resource-operations": "^3.0.3", + "sebastian/type": "^2.3.4", + "sebastian/version": "^3.0.2" }, "require-dev": { - "ext-pdo": "*" + "ext-pdo": "*", + "phpspec/prophecy-phpunit": "^2.0.1" }, "suggest": { "ext-soap": "*", - "ext-xdebug": "*", - "phpunit/php-invoker": "^2.0" + "ext-xdebug": "*" }, "bin": [ "phpunit" @@ -939,12 +1025,15 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "7.5-dev" + "dev-master": "9.5-dev" } }, "autoload": { "classmap": [ "src/" + ], + "files": [ + "src/Framework/Assert/Functions.php" ] }, "notification-url": "https://packagist.org/downloads/", @@ -967,34 +1056,156 @@ ], "support": { "issues": "https://github.com/sebastianbergmann/phpunit/issues", - "source": "https://github.com/sebastianbergmann/phpunit/tree/7.5.20" + "source": "https://github.com/sebastianbergmann/phpunit/tree/9.5.8" }, - "time": "2020-01-08T08:45:45+00:00" + "funding": [ + { + "url": "https://phpunit.de/donate.html", + "type": "custom" + }, + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2021-07-31T15:17:34+00:00" + }, + { + "name": "sebastian/cli-parser", + "version": "1.0.1", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/cli-parser.git", + "reference": "442e7c7e687e42adc03470c7b668bc4b2402c0b2" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/cli-parser/zipball/442e7c7e687e42adc03470c7b668bc4b2402c0b2", + "reference": "442e7c7e687e42adc03470c7b668bc4b2402c0b2", + "shasum": "" + }, + "require": { + "php": ">=7.3" + }, + "require-dev": { + "phpunit/phpunit": "^9.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "Library for parsing CLI options", + "homepage": "https://github.com/sebastianbergmann/cli-parser", + "support": { + "issues": "https://github.com/sebastianbergmann/cli-parser/issues", + "source": "https://github.com/sebastianbergmann/cli-parser/tree/1.0.1" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2020-09-28T06:08:49+00:00" + }, + { + "name": "sebastian/code-unit", + "version": "1.0.8", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/code-unit.git", + "reference": "1fc9f64c0927627ef78ba436c9b17d967e68e120" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/code-unit/zipball/1fc9f64c0927627ef78ba436c9b17d967e68e120", + "reference": "1fc9f64c0927627ef78ba436c9b17d967e68e120", + "shasum": "" + }, + "require": { + "php": ">=7.3" + }, + "require-dev": { + "phpunit/phpunit": "^9.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "Collection of value objects that represent the PHP code units", + "homepage": "https://github.com/sebastianbergmann/code-unit", + "support": { + "issues": "https://github.com/sebastianbergmann/code-unit/issues", + "source": "https://github.com/sebastianbergmann/code-unit/tree/1.0.8" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2020-10-26T13:08:54+00:00" }, { "name": "sebastian/code-unit-reverse-lookup", - "version": "1.0.2", + "version": "2.0.3", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/code-unit-reverse-lookup.git", - "reference": "1de8cd5c010cb153fcd68b8d0f64606f523f7619" + "reference": "ac91f01ccec49fb77bdc6fd1e548bc70f7faa3e5" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/code-unit-reverse-lookup/zipball/1de8cd5c010cb153fcd68b8d0f64606f523f7619", - "reference": "1de8cd5c010cb153fcd68b8d0f64606f523f7619", + "url": "https://api.github.com/repos/sebastianbergmann/code-unit-reverse-lookup/zipball/ac91f01ccec49fb77bdc6fd1e548bc70f7faa3e5", + "reference": "ac91f01ccec49fb77bdc6fd1e548bc70f7faa3e5", "shasum": "" }, "require": { - "php": ">=5.6" + "php": ">=7.3" }, "require-dev": { - "phpunit/phpunit": "^8.5" + "phpunit/phpunit": "^9.3" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "1.0.x-dev" + "dev-master": "2.0-dev" } }, "autoload": { @@ -1016,7 +1227,7 @@ "homepage": "https://github.com/sebastianbergmann/code-unit-reverse-lookup/", "support": { "issues": "https://github.com/sebastianbergmann/code-unit-reverse-lookup/issues", - "source": "https://github.com/sebastianbergmann/code-unit-reverse-lookup/tree/1.0.2" + "source": "https://github.com/sebastianbergmann/code-unit-reverse-lookup/tree/2.0.3" }, "funding": [ { @@ -1024,34 +1235,34 @@ "type": "github" } ], - "time": "2020-11-30T08:15:22+00:00" + "time": "2020-09-28T05:30:19+00:00" }, { "name": "sebastian/comparator", - "version": "3.0.3", + "version": "4.0.6", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/comparator.git", - "reference": "1071dfcef776a57013124ff35e1fc41ccd294758" + "reference": "55f4261989e546dc112258c7a75935a81a7ce382" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/1071dfcef776a57013124ff35e1fc41ccd294758", - "reference": "1071dfcef776a57013124ff35e1fc41ccd294758", + "url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/55f4261989e546dc112258c7a75935a81a7ce382", + "reference": "55f4261989e546dc112258c7a75935a81a7ce382", "shasum": "" }, "require": { - "php": ">=7.1", - "sebastian/diff": "^3.0", - "sebastian/exporter": "^3.1" + "php": ">=7.3", + "sebastian/diff": "^4.0", + "sebastian/exporter": "^4.0" }, "require-dev": { - "phpunit/phpunit": "^8.5" + "phpunit/phpunit": "^9.3" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "3.0-dev" + "dev-master": "4.0-dev" } }, "autoload": { @@ -1090,7 +1301,7 @@ ], "support": { "issues": "https://github.com/sebastianbergmann/comparator/issues", - "source": "https://github.com/sebastianbergmann/comparator/tree/3.0.3" + "source": "https://github.com/sebastianbergmann/comparator/tree/4.0.6" }, "funding": [ { @@ -1098,33 +1309,90 @@ "type": "github" } ], - "time": "2020-11-30T08:04:30+00:00" + "time": "2020-10-26T15:49:45+00:00" + }, + { + "name": "sebastian/complexity", + "version": "2.0.2", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/complexity.git", + "reference": "739b35e53379900cc9ac327b2147867b8b6efd88" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/complexity/zipball/739b35e53379900cc9ac327b2147867b8b6efd88", + "reference": "739b35e53379900cc9ac327b2147867b8b6efd88", + "shasum": "" + }, + "require": { + "nikic/php-parser": "^4.7", + "php": ">=7.3" + }, + "require-dev": { + "phpunit/phpunit": "^9.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "Library for calculating the complexity of PHP code units", + "homepage": "https://github.com/sebastianbergmann/complexity", + "support": { + "issues": "https://github.com/sebastianbergmann/complexity/issues", + "source": "https://github.com/sebastianbergmann/complexity/tree/2.0.2" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2020-10-26T15:52:27+00:00" }, { "name": "sebastian/diff", - "version": "3.0.3", + "version": "4.0.4", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/diff.git", - "reference": "14f72dd46eaf2f2293cbe79c93cc0bc43161a211" + "reference": "3461e3fccc7cfdfc2720be910d3bd73c69be590d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/14f72dd46eaf2f2293cbe79c93cc0bc43161a211", - "reference": "14f72dd46eaf2f2293cbe79c93cc0bc43161a211", + "url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/3461e3fccc7cfdfc2720be910d3bd73c69be590d", + "reference": "3461e3fccc7cfdfc2720be910d3bd73c69be590d", "shasum": "" }, "require": { - "php": ">=7.1" + "php": ">=7.3" }, "require-dev": { - "phpunit/phpunit": "^7.5 || ^8.0", - "symfony/process": "^2 || ^3.3 || ^4" + "phpunit/phpunit": "^9.3", + "symfony/process": "^4.2 || ^5" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "3.0-dev" + "dev-master": "4.0-dev" } }, "autoload": { @@ -1156,7 +1424,7 @@ ], "support": { "issues": "https://github.com/sebastianbergmann/diff/issues", - "source": "https://github.com/sebastianbergmann/diff/tree/3.0.3" + "source": "https://github.com/sebastianbergmann/diff/tree/4.0.4" }, "funding": [ { @@ -1164,27 +1432,27 @@ "type": "github" } ], - "time": "2020-11-30T07:59:04+00:00" + "time": "2020-10-26T13:10:38+00:00" }, { "name": "sebastian/environment", - "version": "4.2.4", + "version": "5.1.3", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/environment.git", - "reference": "d47bbbad83711771f167c72d4e3f25f7fcc1f8b0" + "reference": "388b6ced16caa751030f6a69e588299fa09200ac" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/d47bbbad83711771f167c72d4e3f25f7fcc1f8b0", - "reference": "d47bbbad83711771f167c72d4e3f25f7fcc1f8b0", + "url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/388b6ced16caa751030f6a69e588299fa09200ac", + "reference": "388b6ced16caa751030f6a69e588299fa09200ac", "shasum": "" }, "require": { - "php": ">=7.1" + "php": ">=7.3" }, "require-dev": { - "phpunit/phpunit": "^7.5" + "phpunit/phpunit": "^9.3" }, "suggest": { "ext-posix": "*" @@ -1192,7 +1460,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "4.2-dev" + "dev-master": "5.1-dev" } }, "autoload": { @@ -1219,7 +1487,7 @@ ], "support": { "issues": "https://github.com/sebastianbergmann/environment/issues", - "source": "https://github.com/sebastianbergmann/environment/tree/4.2.4" + "source": "https://github.com/sebastianbergmann/environment/tree/5.1.3" }, "funding": [ { @@ -1227,34 +1495,34 @@ "type": "github" } ], - "time": "2020-11-30T07:53:42+00:00" + "time": "2020-09-28T05:52:38+00:00" }, { "name": "sebastian/exporter", - "version": "3.1.3", + "version": "4.0.3", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/exporter.git", - "reference": "6b853149eab67d4da22291d36f5b0631c0fd856e" + "reference": "d89cc98761b8cb5a1a235a6b703ae50d34080e65" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/6b853149eab67d4da22291d36f5b0631c0fd856e", - "reference": "6b853149eab67d4da22291d36f5b0631c0fd856e", + "url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/d89cc98761b8cb5a1a235a6b703ae50d34080e65", + "reference": "d89cc98761b8cb5a1a235a6b703ae50d34080e65", "shasum": "" }, "require": { - "php": ">=7.0", - "sebastian/recursion-context": "^3.0" + "php": ">=7.3", + "sebastian/recursion-context": "^4.0" }, "require-dev": { "ext-mbstring": "*", - "phpunit/phpunit": "^6.0" + "phpunit/phpunit": "^9.3" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "3.1.x-dev" + "dev-master": "4.0-dev" } }, "autoload": { @@ -1296,7 +1564,7 @@ ], "support": { "issues": "https://github.com/sebastianbergmann/exporter/issues", - "source": "https://github.com/sebastianbergmann/exporter/tree/3.1.3" + "source": "https://github.com/sebastianbergmann/exporter/tree/4.0.3" }, "funding": [ { @@ -1304,27 +1572,30 @@ "type": "github" } ], - "time": "2020-11-30T07:47:53+00:00" + "time": "2020-09-28T05:24:23+00:00" }, { "name": "sebastian/global-state", - "version": "2.0.0", + "version": "5.0.3", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/global-state.git", - "reference": "e8ba02eed7bbbb9e59e43dedd3dddeff4a56b0c4" + "reference": "23bd5951f7ff26f12d4e3242864df3e08dec4e49" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/global-state/zipball/e8ba02eed7bbbb9e59e43dedd3dddeff4a56b0c4", - "reference": "e8ba02eed7bbbb9e59e43dedd3dddeff4a56b0c4", + "url": "https://api.github.com/repos/sebastianbergmann/global-state/zipball/23bd5951f7ff26f12d4e3242864df3e08dec4e49", + "reference": "23bd5951f7ff26f12d4e3242864df3e08dec4e49", "shasum": "" }, "require": { - "php": "^7.0" + "php": ">=7.3", + "sebastian/object-reflector": "^2.0", + "sebastian/recursion-context": "^4.0" }, "require-dev": { - "phpunit/phpunit": "^6.0" + "ext-dom": "*", + "phpunit/phpunit": "^9.3" }, "suggest": { "ext-uopz": "*" @@ -1332,7 +1603,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "2.0-dev" + "dev-master": "5.0-dev" } }, "autoload": { @@ -1357,36 +1628,99 @@ ], "support": { "issues": "https://github.com/sebastianbergmann/global-state/issues", - "source": "https://github.com/sebastianbergmann/global-state/tree/2.0.0" + "source": "https://github.com/sebastianbergmann/global-state/tree/5.0.3" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2021-06-11T13:31:12+00:00" + }, + { + "name": "sebastian/lines-of-code", + "version": "1.0.3", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/lines-of-code.git", + "reference": "c1c2e997aa3146983ed888ad08b15470a2e22ecc" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/lines-of-code/zipball/c1c2e997aa3146983ed888ad08b15470a2e22ecc", + "reference": "c1c2e997aa3146983ed888ad08b15470a2e22ecc", + "shasum": "" + }, + "require": { + "nikic/php-parser": "^4.6", + "php": ">=7.3" + }, + "require-dev": { + "phpunit/phpunit": "^9.3" }, - "time": "2017-04-27T15:39:26+00:00" + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "Library for counting the lines of code in PHP source code", + "homepage": "https://github.com/sebastianbergmann/lines-of-code", + "support": { + "issues": "https://github.com/sebastianbergmann/lines-of-code/issues", + "source": "https://github.com/sebastianbergmann/lines-of-code/tree/1.0.3" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2020-11-28T06:42:11+00:00" }, { "name": "sebastian/object-enumerator", - "version": "3.0.4", + "version": "4.0.4", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/object-enumerator.git", - "reference": "e67f6d32ebd0c749cf9d1dbd9f226c727043cdf2" + "reference": "5c9eeac41b290a3712d88851518825ad78f45c71" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/object-enumerator/zipball/e67f6d32ebd0c749cf9d1dbd9f226c727043cdf2", - "reference": "e67f6d32ebd0c749cf9d1dbd9f226c727043cdf2", + "url": "https://api.github.com/repos/sebastianbergmann/object-enumerator/zipball/5c9eeac41b290a3712d88851518825ad78f45c71", + "reference": "5c9eeac41b290a3712d88851518825ad78f45c71", "shasum": "" }, "require": { - "php": ">=7.0", - "sebastian/object-reflector": "^1.1.1", - "sebastian/recursion-context": "^3.0" + "php": ">=7.3", + "sebastian/object-reflector": "^2.0", + "sebastian/recursion-context": "^4.0" }, "require-dev": { - "phpunit/phpunit": "^6.0" + "phpunit/phpunit": "^9.3" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "3.0.x-dev" + "dev-master": "4.0-dev" } }, "autoload": { @@ -1408,7 +1742,7 @@ "homepage": "https://github.com/sebastianbergmann/object-enumerator/", "support": { "issues": "https://github.com/sebastianbergmann/object-enumerator/issues", - "source": "https://github.com/sebastianbergmann/object-enumerator/tree/3.0.4" + "source": "https://github.com/sebastianbergmann/object-enumerator/tree/4.0.4" }, "funding": [ { @@ -1416,32 +1750,32 @@ "type": "github" } ], - "time": "2020-11-30T07:40:27+00:00" + "time": "2020-10-26T13:12:34+00:00" }, { "name": "sebastian/object-reflector", - "version": "1.1.2", + "version": "2.0.4", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/object-reflector.git", - "reference": "9b8772b9cbd456ab45d4a598d2dd1a1bced6363d" + "reference": "b4f479ebdbf63ac605d183ece17d8d7fe49c15c7" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/object-reflector/zipball/9b8772b9cbd456ab45d4a598d2dd1a1bced6363d", - "reference": "9b8772b9cbd456ab45d4a598d2dd1a1bced6363d", + "url": "https://api.github.com/repos/sebastianbergmann/object-reflector/zipball/b4f479ebdbf63ac605d183ece17d8d7fe49c15c7", + "reference": "b4f479ebdbf63ac605d183ece17d8d7fe49c15c7", "shasum": "" }, "require": { - "php": ">=7.0" + "php": ">=7.3" }, "require-dev": { - "phpunit/phpunit": "^6.0" + "phpunit/phpunit": "^9.3" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "1.1-dev" + "dev-master": "2.0-dev" } }, "autoload": { @@ -1463,7 +1797,7 @@ "homepage": "https://github.com/sebastianbergmann/object-reflector/", "support": { "issues": "https://github.com/sebastianbergmann/object-reflector/issues", - "source": "https://github.com/sebastianbergmann/object-reflector/tree/1.1.2" + "source": "https://github.com/sebastianbergmann/object-reflector/tree/2.0.4" }, "funding": [ { @@ -1471,32 +1805,32 @@ "type": "github" } ], - "time": "2020-11-30T07:37:18+00:00" + "time": "2020-10-26T13:14:26+00:00" }, { "name": "sebastian/recursion-context", - "version": "3.0.1", + "version": "4.0.4", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/recursion-context.git", - "reference": "367dcba38d6e1977be014dc4b22f47a484dac7fb" + "reference": "cd9d8cf3c5804de4341c283ed787f099f5506172" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/recursion-context/zipball/367dcba38d6e1977be014dc4b22f47a484dac7fb", - "reference": "367dcba38d6e1977be014dc4b22f47a484dac7fb", + "url": "https://api.github.com/repos/sebastianbergmann/recursion-context/zipball/cd9d8cf3c5804de4341c283ed787f099f5506172", + "reference": "cd9d8cf3c5804de4341c283ed787f099f5506172", "shasum": "" }, "require": { - "php": ">=7.0" + "php": ">=7.3" }, "require-dev": { - "phpunit/phpunit": "^6.0" + "phpunit/phpunit": "^9.3" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "3.0.x-dev" + "dev-master": "4.0-dev" } }, "autoload": { @@ -1526,7 +1860,7 @@ "homepage": "http://www.github.com/sebastianbergmann/recursion-context", "support": { "issues": "https://github.com/sebastianbergmann/recursion-context/issues", - "source": "https://github.com/sebastianbergmann/recursion-context/tree/3.0.1" + "source": "https://github.com/sebastianbergmann/recursion-context/tree/4.0.4" }, "funding": [ { @@ -1534,29 +1868,32 @@ "type": "github" } ], - "time": "2020-11-30T07:34:24+00:00" + "time": "2020-10-26T13:17:30+00:00" }, { "name": "sebastian/resource-operations", - "version": "2.0.2", + "version": "3.0.3", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/resource-operations.git", - "reference": "31d35ca87926450c44eae7e2611d45a7a65ea8b3" + "reference": "0f4443cb3a1d92ce809899753bc0d5d5a8dd19a8" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/resource-operations/zipball/31d35ca87926450c44eae7e2611d45a7a65ea8b3", - "reference": "31d35ca87926450c44eae7e2611d45a7a65ea8b3", + "url": "https://api.github.com/repos/sebastianbergmann/resource-operations/zipball/0f4443cb3a1d92ce809899753bc0d5d5a8dd19a8", + "reference": "0f4443cb3a1d92ce809899753bc0d5d5a8dd19a8", "shasum": "" }, "require": { - "php": ">=7.1" + "php": ">=7.3" + }, + "require-dev": { + "phpunit/phpunit": "^9.0" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "2.0-dev" + "dev-master": "3.0-dev" } }, "autoload": { @@ -1578,7 +1915,7 @@ "homepage": "https://www.github.com/sebastianbergmann/resource-operations", "support": { "issues": "https://github.com/sebastianbergmann/resource-operations/issues", - "source": "https://github.com/sebastianbergmann/resource-operations/tree/2.0.2" + "source": "https://github.com/sebastianbergmann/resource-operations/tree/3.0.3" }, "funding": [ { @@ -1586,30 +1923,85 @@ "type": "github" } ], - "abandoned": true, - "time": "2020-11-30T07:30:19+00:00" + "time": "2020-09-28T06:45:17+00:00" + }, + { + "name": "sebastian/type", + "version": "2.3.4", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/type.git", + "reference": "b8cd8a1c753c90bc1a0f5372170e3e489136f914" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/type/zipball/b8cd8a1c753c90bc1a0f5372170e3e489136f914", + "reference": "b8cd8a1c753c90bc1a0f5372170e3e489136f914", + "shasum": "" + }, + "require": { + "php": ">=7.3" + }, + "require-dev": { + "phpunit/phpunit": "^9.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.3-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "Collection of value objects that represent the types of the PHP type system", + "homepage": "https://github.com/sebastianbergmann/type", + "support": { + "issues": "https://github.com/sebastianbergmann/type/issues", + "source": "https://github.com/sebastianbergmann/type/tree/2.3.4" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2021-06-15T12:49:02+00:00" }, { "name": "sebastian/version", - "version": "2.0.1", + "version": "3.0.2", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/version.git", - "reference": "99732be0ddb3361e16ad77b68ba41efc8e979019" + "reference": "c6c1022351a901512170118436c764e473f6de8c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/version/zipball/99732be0ddb3361e16ad77b68ba41efc8e979019", - "reference": "99732be0ddb3361e16ad77b68ba41efc8e979019", + "url": "https://api.github.com/repos/sebastianbergmann/version/zipball/c6c1022351a901512170118436c764e473f6de8c", + "reference": "c6c1022351a901512170118436c764e473f6de8c", "shasum": "" }, "require": { - "php": ">=5.6" + "php": ">=7.3" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "2.0.x-dev" + "dev-master": "3.0-dev" } }, "autoload": { @@ -1632,9 +2024,15 @@ "homepage": "https://github.com/sebastianbergmann/version", "support": { "issues": "https://github.com/sebastianbergmann/version/issues", - "source": "https://github.com/sebastianbergmann/version/tree/master" + "source": "https://github.com/sebastianbergmann/version/tree/3.0.2" }, - "time": "2016-10-03T07:35:21+00:00" + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2020-09-28T06:39:44+00:00" }, { "name": "symfony/polyfill-ctype", @@ -1717,16 +2115,16 @@ }, { "name": "theseer/tokenizer", - "version": "1.2.0", + "version": "1.2.1", "source": { "type": "git", "url": "https://github.com/theseer/tokenizer.git", - "reference": "75a63c33a8577608444246075ea0af0d052e452a" + "reference": "34a41e998c2183e22995f158c581e7b5e755ab9e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/theseer/tokenizer/zipball/75a63c33a8577608444246075ea0af0d052e452a", - "reference": "75a63c33a8577608444246075ea0af0d052e452a", + "url": "https://api.github.com/repos/theseer/tokenizer/zipball/34a41e998c2183e22995f158c581e7b5e755ab9e", + "reference": "34a41e998c2183e22995f158c581e7b5e755ab9e", "shasum": "" }, "require": { @@ -1755,7 +2153,7 @@ "description": "A small library for converting tokenized PHP source code into XML and potentially other formats", "support": { "issues": "https://github.com/theseer/tokenizer/issues", - "source": "https://github.com/theseer/tokenizer/tree/master" + "source": "https://github.com/theseer/tokenizer/tree/1.2.1" }, "funding": [ { @@ -1763,7 +2161,7 @@ "type": "github" } ], - "time": "2020-07-12T23:59:07+00:00" + "time": "2021-07-28T10:34:58+00:00" }, { "name": "webmozart/assert", @@ -1830,8 +2228,8 @@ "prefer-stable": false, "prefer-lowest": false, "platform": { - "php": ">=7.2" + "php": ">=7.3" }, "platform-dev": [], - "plugin-api-version": "2.0.0" + "plugin-api-version": "2.1.0" } From 5507110b08e6d48cf10b5956819133523fc4f501 Mon Sep 17 00:00:00 2001 From: Sergii Ivashchenko Date: Fri, 20 Aug 2021 13:18:56 +0100 Subject: [PATCH 113/630] Version 7 --- composer.json | 2 +- composer.lock | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index fef78240..d6004a88 100644 --- a/composer.json +++ b/composer.json @@ -6,7 +6,7 @@ "AFL-3.0" ], "type": "phpcodesniffer-standard", - "version": "6", + "version": "7", "require": { "php": ">=7.3", "squizlabs/php_codesniffer": "^3.6", diff --git a/composer.lock b/composer.lock index 8a7ddd72..72a2ad6a 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": "9da12284ef127e6443c2207e471f5970", + "content-hash": "1ed3638000f0e172d4e01c45333fcfb6", "packages": [ { "name": "squizlabs/php_codesniffer", From 696c3aae04492499c249c4c0340bd0d64021d742 Mon Sep 17 00:00:00 2001 From: Franciszek Szczepan Wawrzak Date: Fri, 20 Aug 2021 14:26:06 +0200 Subject: [PATCH 114/630] add test case for #220 --- Magento2/Tests/Namespaces/ImportsFromTestNamespaceUnitTest.inc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Magento2/Tests/Namespaces/ImportsFromTestNamespaceUnitTest.inc b/Magento2/Tests/Namespaces/ImportsFromTestNamespaceUnitTest.inc index 50d339a1..b3ca9957 100644 --- a/Magento2/Tests/Namespaces/ImportsFromTestNamespaceUnitTest.inc +++ b/Magento2/Tests/Namespaces/ImportsFromTestNamespaceUnitTest.inc @@ -3,4 +3,5 @@ use Magento\Tests; use Magento\Foo\Tests as FakeTest; use Magento\Real\Classes; use \Magento\{Tests\String, Tests\Int}; -use \Magento\{Foo\string, Bar\float}; \ No newline at end of file +use \Magento\{Foo\string, Bar\float}; +use \Foo\{Trailing, Space,}; \ No newline at end of file From 146bfb099583f7ee26bbafec66fe6560eab4373a Mon Sep 17 00:00:00 2001 From: Shankar Konar Date: Sun, 22 Aug 2021 16:51:28 +0530 Subject: [PATCH 115/630] Resolved test failure --- .../Classes/DiscouragedDependenciesSniff.php | 6 --- .../ClassPropertyPHPDocFormattingSniff.php | 42 +++++++++++++++---- .../Methods/DeprecatedModelMethodSniff.php | 2 - Magento2/Sniffs/Security/XssTemplateSniff.php | 2 - 4 files changed, 34 insertions(+), 18 deletions(-) diff --git a/Magento2/Sniffs/Classes/DiscouragedDependenciesSniff.php b/Magento2/Sniffs/Classes/DiscouragedDependenciesSniff.php index ed106d4b..85c1f103 100644 --- a/Magento2/Sniffs/Classes/DiscouragedDependenciesSniff.php +++ b/Magento2/Sniffs/Classes/DiscouragedDependenciesSniff.php @@ -32,22 +32,16 @@ class DiscouragedDependenciesSniff implements Sniff protected $warningCode = 'ConstructorProxyInterceptor'; /** - * Aliases of proxies or plugins from use statements - * * @var string[] */ private $aliases = []; /** - * The current file - used for clearing USE aliases when file changes - * * @var null|string */ private $currentFile = null; /** - * Terms to search for in variables and namespaces - * * @var string[] */ public $incorrectClassNames = ['proxy','interceptor']; diff --git a/Magento2/Sniffs/Commenting/ClassPropertyPHPDocFormattingSniff.php b/Magento2/Sniffs/Commenting/ClassPropertyPHPDocFormattingSniff.php index cf006d56..268e4696 100644 --- a/Magento2/Sniffs/Commenting/ClassPropertyPHPDocFormattingSniff.php +++ b/Magento2/Sniffs/Commenting/ClassPropertyPHPDocFormattingSniff.php @@ -89,11 +89,24 @@ public function processMemberVar(File $phpcsFile, $stackPtr) } // Check if class has already have meaningful description after @var tag - $isShortDescriptionAfterVar = $phpcsFile->findNext(T_DOC_COMMENT_STRING, $foundVar + 4, $commentEnd, false, + $isShortDescriptionAfterVar = $phpcsFile->findNext( + T_DOC_COMMENT_STRING, + $foundVar + 4, + $commentEnd, + false, null, - false); - if ($this->PHPDocFormattingValidator->providesMeaning($isShortDescriptionAfterVar, $commentStart, $tokens) !== true) { - preg_match('`^((?:\|?(?:array\([^\)]*\)|[\\\\\[\]]+))*)( .*)?`i', $tokens[($foundVar + 2)]['content'], $varParts); + false + ); + if ($this->PHPDocFormattingValidator->providesMeaning( + $isShortDescriptionAfterVar, + $commentStart, + $tokens + ) !== true) { + preg_match( + '`^((?:\|?(?:array\([^\)]*\)|[\\\\\[\]]+))*)( .*)?`i', + $tokens[($foundVar + 2)]['content'], + $varParts + ); if ($varParts[1]) { return; } @@ -102,11 +115,24 @@ public function processMemberVar(File $phpcsFile, $stackPtr) return; } // Check if class has already have meaningful description before @var tag - $isShortDescriptionPreviousVar = $phpcsFile->findPrevious(T_DOC_COMMENT_STRING, $foundVar, $commentStart, false, + $isShortDescriptionPreviousVar = $phpcsFile->findPrevious( + T_DOC_COMMENT_STRING, + $foundVar, + $commentStart, + false, null, - false); - if ($this->PHPDocFormattingValidator->providesMeaning($isShortDescriptionPreviousVar, $commentStart, $tokens) !== true) { - preg_match('`^((?:\|?(?:array\([^\)]*\)|[\\\\\[\]]+))*)( .*)?`i', $tokens[($foundVar + 2)]['content'], $varParts); + false + ); + if ($this->PHPDocFormattingValidator->providesMeaning( + $isShortDescriptionPreviousVar, + $commentStart, + $tokens + ) !== true) { + preg_match( + '`^((?:\|?(?:array\([^\)]*\)|[\\\\\[\]]+))*)( .*)?`i', + $tokens[($foundVar + 2)]['content'], + $varParts + ); if ($varParts[1]) { return; } diff --git a/Magento2/Sniffs/Methods/DeprecatedModelMethodSniff.php b/Magento2/Sniffs/Methods/DeprecatedModelMethodSniff.php index 94bfc2d5..df8fba14 100644 --- a/Magento2/Sniffs/Methods/DeprecatedModelMethodSniff.php +++ b/Magento2/Sniffs/Methods/DeprecatedModelMethodSniff.php @@ -40,8 +40,6 @@ class DeprecatedModelMethodSniff implements Sniff 'delete' ]; - protected $severity = 0; - /** * @inheritdoc */ diff --git a/Magento2/Sniffs/Security/XssTemplateSniff.php b/Magento2/Sniffs/Security/XssTemplateSniff.php index aa2accbe..dc17f03b 100644 --- a/Magento2/Sniffs/Security/XssTemplateSniff.php +++ b/Magento2/Sniffs/Security/XssTemplateSniff.php @@ -50,8 +50,6 @@ class XssTemplateSniff implements Sniff ]; /** - * Allowed method name - {suffix}Html{postfix}() - * * @var string */ protected $methodNameContains = 'html'; From 83f7609a946596a6305c5122abe54740ba87fa56 Mon Sep 17 00:00:00 2001 From: Shankar Konar Date: Sun, 22 Aug 2021 17:13:05 +0530 Subject: [PATCH 116/630] Resolved test failure --- Magento2/Helpers/Tokenizer/AbstractTokenizer.php | 4 ---- Magento2/Helpers/Tokenizer/Variable.php | 2 -- .../ClassPropertyPHPDocFormattingSniff.php | 12 +++--------- Magento2/Sniffs/Less/AvoidIdSniff.php | 2 -- Magento2/Sniffs/Less/IndentationSniff.php | 3 +-- Magento2/Sniffs/Less/PropertiesSortingSniff.php | 4 ---- Magento2/Sniffs/Less/SemicolonSpacingSniff.php | 5 +---- Magento2/Sniffs/Less/TypeSelectorsSniff.php | 2 -- Magento2/Sniffs/Less/ZeroUnitsSniff.php | 2 -- 9 files changed, 5 insertions(+), 31 deletions(-) diff --git a/Magento2/Helpers/Tokenizer/AbstractTokenizer.php b/Magento2/Helpers/Tokenizer/AbstractTokenizer.php index f49c753f..1a3c4a63 100644 --- a/Magento2/Helpers/Tokenizer/AbstractTokenizer.php +++ b/Magento2/Helpers/Tokenizer/AbstractTokenizer.php @@ -11,15 +11,11 @@ abstract class AbstractTokenizer { /** - * Current index in string - * * @var int */ protected $_currentIndex; /** - * String for tokenize - * * @var string */ protected $_string; diff --git a/Magento2/Helpers/Tokenizer/Variable.php b/Magento2/Helpers/Tokenizer/Variable.php index 81c8b1d8..43938c03 100644 --- a/Magento2/Helpers/Tokenizer/Variable.php +++ b/Magento2/Helpers/Tokenizer/Variable.php @@ -12,8 +12,6 @@ class Variable extends AbstractTokenizer { /** - * Internal counter used to keep track of how deep in array parsing we are - * * @var int */ protected $arrayDepth = 0; diff --git a/Magento2/Sniffs/Commenting/ClassPropertyPHPDocFormattingSniff.php b/Magento2/Sniffs/Commenting/ClassPropertyPHPDocFormattingSniff.php index 268e4696..a402fbd8 100644 --- a/Magento2/Sniffs/Commenting/ClassPropertyPHPDocFormattingSniff.php +++ b/Magento2/Sniffs/Commenting/ClassPropertyPHPDocFormattingSniff.php @@ -46,9 +46,7 @@ public function __construct() } /** - * @param File $phpcsFile - * @param int $stackPtr - * @return int|void + * @inheritDoc */ public function processMemberVar(File $phpcsFile, $stackPtr) { @@ -143,9 +141,7 @@ public function processMemberVar(File $phpcsFile, $stackPtr) } /** - * @param File $phpcsFile - * @param int $stackPtr - * @return int|void + * @inheritDoc * phpcs:disable Magento2.CodeAnalysis.EmptyBlock */ protected function processVariable(File $phpcsFile, $stackPtr) @@ -153,9 +149,7 @@ protected function processVariable(File $phpcsFile, $stackPtr) } /** - * @param File $phpcsFile - * @param int $stackPtr - * @return int|void + * @inheritDoc * phpcs:disable Magento2.CodeAnalysis.EmptyBlock */ protected function processVariableInString(File $phpcsFile, $stackPtr) diff --git a/Magento2/Sniffs/Less/AvoidIdSniff.php b/Magento2/Sniffs/Less/AvoidIdSniff.php index d4e1b213..62346274 100644 --- a/Magento2/Sniffs/Less/AvoidIdSniff.php +++ b/Magento2/Sniffs/Less/AvoidIdSniff.php @@ -25,8 +25,6 @@ class AvoidIdSniff implements Sniff public $supportedTokenizers = [TokenizerSymbolsInterface::TOKENIZER_CSS]; /** - * Tokens that can appear in a selector - * * @var array */ private $selectorTokens = [ diff --git a/Magento2/Sniffs/Less/IndentationSniff.php b/Magento2/Sniffs/Less/IndentationSniff.php index 76a6fbcc..57947a07 100644 --- a/Magento2/Sniffs/Less/IndentationSniff.php +++ b/Magento2/Sniffs/Less/IndentationSniff.php @@ -39,8 +39,7 @@ class IndentationSniff implements Sniff */ public $maxIndentLevel = 3; - /** Skip codes that can be detected by sniffer incorrectly - * + /** * @var array */ private $styleCodesToSkip = [T_ASPERAND, T_COLON, T_OPEN_PARENTHESIS, T_CLOSE_PARENTHESIS]; diff --git a/Magento2/Sniffs/Less/PropertiesSortingSniff.php b/Magento2/Sniffs/Less/PropertiesSortingSniff.php index d1c7c387..2c5fe9e5 100644 --- a/Magento2/Sniffs/Less/PropertiesSortingSniff.php +++ b/Magento2/Sniffs/Less/PropertiesSortingSniff.php @@ -25,15 +25,11 @@ class PropertiesSortingSniff implements Sniff public $supportedTokenizers = [TokenizerSymbolsInterface::TOKENIZER_CSS]; /** - * List of properties that belong to class - * * @var array */ private $properties = []; /** - * Skip symbols that can be detected by sniffer incorrectly - * * @var array */ private $styleSymbolsToSkip = [ diff --git a/Magento2/Sniffs/Less/SemicolonSpacingSniff.php b/Magento2/Sniffs/Less/SemicolonSpacingSniff.php index cad13290..8db8d216 100644 --- a/Magento2/Sniffs/Less/SemicolonSpacingSniff.php +++ b/Magento2/Sniffs/Less/SemicolonSpacingSniff.php @@ -25,8 +25,6 @@ class SemicolonSpacingSniff implements Sniff public $supportedTokenizers = [TokenizerSymbolsInterface::TOKENIZER_CSS]; /** - * Skip symbols that can be detected by sniffer incorrectly - * * @var array */ private $styleSymbolsToSkip = [ @@ -36,8 +34,7 @@ class SemicolonSpacingSniff implements Sniff TokenizerSymbolsInterface::CLOSE_PARENTHESIS, ]; - /** Skip codes that can be detected by sniffer incorrectly - * + /** * @var array */ private $styleCodesToSkip = [T_ASPERAND, T_COLON, T_OPEN_PARENTHESIS, T_CLOSE_PARENTHESIS]; diff --git a/Magento2/Sniffs/Less/TypeSelectorsSniff.php b/Magento2/Sniffs/Less/TypeSelectorsSniff.php index 00c8b35c..4735c761 100644 --- a/Magento2/Sniffs/Less/TypeSelectorsSniff.php +++ b/Magento2/Sniffs/Less/TypeSelectorsSniff.php @@ -23,8 +23,6 @@ class TypeSelectorsSniff implements Sniff { /** - * Tags that are not allowed as type selector - * * @var array */ private $tags = [ diff --git a/Magento2/Sniffs/Less/ZeroUnitsSniff.php b/Magento2/Sniffs/Less/ZeroUnitsSniff.php index 51971c78..c62eaa52 100644 --- a/Magento2/Sniffs/Less/ZeroUnitsSniff.php +++ b/Magento2/Sniffs/Less/ZeroUnitsSniff.php @@ -24,8 +24,6 @@ class ZeroUnitsSniff implements Sniff const CSS_PROPERTY_UNIT_REM = 'rem'; /** - * List of available CSS Property units - * * @var array */ private $units = [ From 98edd6adbcd6e176ebda04959a72c75ce57b0219 Mon Sep 17 00:00:00 2001 From: Elisea Cornejo Date: Mon, 23 Aug 2021 15:35:25 +0200 Subject: [PATCH 117/630] AC-957: Create unit test for Magento2\Html\HtmlDirectiveSniff check --- Magento2/Sniffs/Html/HtmlDirectiveSniff.php | 8 +- ...itTest.1.inc => HtmlBindingUnitTest.1.inc} | 0 .../Tests/Html/HtmlDirectiveUnitTest.1.inc | 117 ++++++++++++++++++ .../Tests/Html/HtmlDirectiveUnitTest.2.inc | 12 ++ Magento2/Tests/Html/HtmlDirectiveUnitTest.php | 33 +++++ 5 files changed, 166 insertions(+), 4 deletions(-) rename Magento2/Tests/Html/{HtmlBindingSniffUnitTest.1.inc => HtmlBindingUnitTest.1.inc} (100%) create mode 100644 Magento2/Tests/Html/HtmlDirectiveUnitTest.1.inc create mode 100644 Magento2/Tests/Html/HtmlDirectiveUnitTest.2.inc create mode 100644 Magento2/Tests/Html/HtmlDirectiveUnitTest.php diff --git a/Magento2/Sniffs/Html/HtmlDirectiveSniff.php b/Magento2/Sniffs/Html/HtmlDirectiveSniff.php index 62267ec1..d140f96c 100644 --- a/Magento2/Sniffs/Html/HtmlDirectiveSniff.php +++ b/Magento2/Sniffs/Html/HtmlDirectiveSniff.php @@ -200,7 +200,7 @@ private function validateVariableUsage(File $phpcsFile, string $body): void 'Template directives may not invoke methods. Only scalar array access is allowed.' . PHP_EOL . 'Found "' . trim($body) . '"', null, - 'HtmlTemplates.DirectiveUsage.ProhibitedMethodCall' + 'HtmlTemplatesProhibitedMethodCall' ); } } @@ -224,7 +224,7 @@ private function validateDefinedVariables(File $phpcsFile, string $templateText) $phpcsFile->addError( 'Template @vars comment block contains invalid JSON.', null, - 'HtmlTemplates.DirectiveUsage.InvalidVarsJSON' + 'HtmlTemplatesInvalidVarsJSON' ); return; } @@ -235,7 +235,7 @@ private function validateDefinedVariables(File $phpcsFile, string $templateText) 'Template @vars comment block contains invalid label.' . PHP_EOL . 'Label for variable "' . $var . '" is empty.', null, - 'HtmlTemplates.DirectiveUsage.InvalidVariableLabel' + 'HtmlTemplatesInvalidVariableLabel' ); } } @@ -254,7 +254,7 @@ private function validateDefinedVariables(File $phpcsFile, string $templateText) 'Template @vars comment block is missing a variable used in the template.' . PHP_EOL . 'Missing variable: ' . $undefinedVariable, null, - 'HtmlTemplates.DirectiveUsage.UndefinedVariable' + 'HtmlTemplatesUndefinedVariable' ); } } diff --git a/Magento2/Tests/Html/HtmlBindingSniffUnitTest.1.inc b/Magento2/Tests/Html/HtmlBindingUnitTest.1.inc similarity index 100% rename from Magento2/Tests/Html/HtmlBindingSniffUnitTest.1.inc rename to Magento2/Tests/Html/HtmlBindingUnitTest.1.inc diff --git a/Magento2/Tests/Html/HtmlDirectiveUnitTest.1.inc b/Magento2/Tests/Html/HtmlDirectiveUnitTest.1.inc new file mode 100644 index 00000000..250b162f --- /dev/null +++ b/Magento2/Tests/Html/HtmlDirectiveUnitTest.1.inc @@ -0,0 +1,117 @@ + + + +
{{var foo.good}}
+
{{var foo.good|stillfine}}
+
{{var foo.bad()}}
+
{{var foo.bad()|alsobad}}
+
{{var foo.getGood()}}
+
{{var foo.foo.getGood()}}
+
{{var foo.getGood().fine}}
+
{{var foo.getGood().fine|alsofine}}
+
{{var foo.bad($bad.param())}}
+
{{var foo.bad.baz()}}
+
{{var foo.undeclared.baz}}
+
{{trans "foo %bar" bar=$foo.good.trans}}
+
{{trans "foo %bar" bar=$foo.bad.trans()}}
+
{{trans "foo %bar" bar="something"}}
+
{{trans "foo %bar" bar="something" bad="$bad.bad()" something=$undeclared.var.error}}
+
{{something " + foo %barblah + " bar="something" + }}
+
{{something " + foo %barblah + " bar="something" bad=$bad.multiline() + }}
+ +{{if foo.goodif}} +
{{var foo.goodif2}}
+{{/if}} + +{{if foo.goodif}} +
{{var foo.goodif2}}
+{{else}} +
{{var foo.goodif3}}
+{{/if}} + +{{if foo.badif().bad}} +
{{var foo.badif2()}}
+{{/if}} + +{{if foo.badif3()}} +
{{var foo.badif4()}}
+{{else}} +
{{var foo.badif5()}}
+{{/if}} + +{{depend foo.gooddepend}} +
{{var foo.gooddepend2}}
+{{/depend}} + +{{depend foo.badDepend().bad}} +
{{var foo.baddepend2()}}
+{{/depend}} + +{{for item in foo.goodFor}} +
{{var foo.goodFor}}
+
{{var foo.goodFor|stillfine}}
+
{{var foo.badFor()}}
+
{{var foo.badFor()|alsobad}}
+{{/for}} + +{{for item in foo.getGoodFor()}} +
loopy
+{{/for}} + +{{for item in foo.badForLoop()}} +
this loop has a bad variable
+{{/for}} + +{{depend iusefilterslater}} +{{var iusefilterslater|raw}} +{{/depend}} diff --git a/Magento2/Tests/Html/HtmlDirectiveUnitTest.2.inc b/Magento2/Tests/Html/HtmlDirectiveUnitTest.2.inc new file mode 100644 index 00000000..6a6b222c --- /dev/null +++ b/Magento2/Tests/Html/HtmlDirectiveUnitTest.2.inc @@ -0,0 +1,12 @@ + + + +Template content doesn't matter. The JSON is invalid. diff --git a/Magento2/Tests/Html/HtmlDirectiveUnitTest.php b/Magento2/Tests/Html/HtmlDirectiveUnitTest.php new file mode 100644 index 00000000..6d7a0034 --- /dev/null +++ b/Magento2/Tests/Html/HtmlDirectiveUnitTest.php @@ -0,0 +1,33 @@ + 20]; + } elseif ($testFile === 'HtmlDirectiveUnitTest.2.inc') { + return [1 => 1]; + } + + return []; + } + + /** + * @inheritdoc + */ + public function getWarningList() + { + return []; + } +} From 533dde2a8207587b4f2810e054a1e77112be1156 Mon Sep 17 00:00:00 2001 From: Elisea Cornejo Date: Mon, 23 Aug 2021 15:46:15 +0200 Subject: [PATCH 118/630] AC-958: create unit test for Magento2\Annotation checks --- .../MethodAnnotationStructureUnitTest.inc | 309 ++++++++++++++++++ .../MethodAnnotationStructureUnitTest.php | 51 +++ .../Annotation/MethodArgumentsUnitTest.inc | 24 ++ .../Annotation/MethodArgumentsUnitTest.php | 30 ++ 4 files changed, 414 insertions(+) create mode 100644 Magento2/Tests/Annotation/MethodAnnotationStructureUnitTest.inc create mode 100644 Magento2/Tests/Annotation/MethodAnnotationStructureUnitTest.php create mode 100644 Magento2/Tests/Annotation/MethodArgumentsUnitTest.inc create mode 100644 Magento2/Tests/Annotation/MethodArgumentsUnitTest.php diff --git a/Magento2/Tests/Annotation/MethodAnnotationStructureUnitTest.inc b/Magento2/Tests/Annotation/MethodAnnotationStructureUnitTest.inc new file mode 100644 index 00000000..8124bc75 --- /dev/null +++ b/Magento2/Tests/Annotation/MethodAnnotationStructureUnitTest.inc @@ -0,0 +1,309 @@ +productVisibility = $productVisibility; + } + + /** + * block description + * + * {@inheritdoc} + * + * @param \Magento\Catalog\Model\ResourceModel\Product\Collection $collection + * @return void + */ + public function construct(AbstractDb $collection) + { + /** @var */ + $collection->setVisibility($this->productVisibility->getVisibleInCatalogIds()); + } + + /** + * Move category + * + * + * @param int $parentId new parent category id + * + * @return $this + * @throws \Magento\Framework\Exception\LocalizedException|\Exception + */ + public function move($parentId) + { + /** + * Validate new parent category id. (category model is used for backward + * compatibility in event params) + */ + try { + $this->categoryRepository->get($parentId, $this->getStoreId()); + } + catch (NoSuchEntityException $e) { + throw new \Magento\Framework\Exception\LocalizedException( + __('Sorry, but we can\'t find the new parent category you selected.'), + $e + ); + } + return true; + } + + /** + * Block for short description + * + * This a long description {@inheritdoc} consists more lines as part of the long description + * on multi line. + * + * @param int $store + * + * + */ + public function getProductListDefaultSortBy26032($store) + { + return $store; + } + + /** + * + * + * + */ + public function getProductListDefaultSortBy2632() + { + } + + /** + * Block for short description + * + * This a long description {@inheritdoc} consists more lines as part of the long description + * on multi line. + * + * @param int $store + * + * + * + */ + public function getProductListDefaultSortBy2002($store) + { + return $store; + } + + /** + * + * block for short description + * + * @param int $store + * @return int + */ + public function getProductListDefaultSortBy3002($store) + { + return $store; + } + + /** + * Block for short description + * + * @see consists more lines as part of the long description + * on multi line. + * + * @param string $store + * @param string $foo + */ + public function getProductListDefaultSortBy12($store, $foo) + { + return $store === $foo; + } + + /** + * Block for short description + * + * {@inheritdoc} + * + * @param string $store + * @param string $foo + */ + public function getProductListDefaultSort2($store, $foo) + { + return $store === $foo; + } + + /** + * Block for short description + * + * a long description {@inheritdoc} consists more lines as part of the long description + * on multi line. + * + * @param string $store + * @param string $foo + */ + public function getProductListDefault($store, $foo) + { + return $store === $foo; + } + + /** + * Retrieve custom options + * + * @param ProductOptionInterface $productOption + * + * @return array + */ + protected function getCustomOptions(ProductOptionInterface $productOption) + { + if ($productOption + && $productOption->getExtensionAttributes() + && $productOption->getExtensionAttributes()->getCustomOptions() + ) { + return $productOption->getExtensionAttributes()->getCustomOptions(); + } + return []; + } + + /** + * This is the summary for a DocBlock. + * + * This is the description for a DocBlock. This text may contain + * multiple lines and even some _markdown_. + * * Markdown style lists function too + * * Just try this out once + * The section after the description contains the tags; which provide + * structured meta-data concerning the given element. + * + * @param int $example This is an example function/method parameter description. + * @param string $example2 This is a second example. + * + */ + public function getProductListDefaultSortBy2($example, $example2) + { + return $example === $example2; + } + + /** + * Returns the content of the tokens from the specified start position in + * the token stack for the specified length. + * + * @param int $start + * @param int $length + * + * @return string The token contents. + */ + public function getProductListDefaultSortBy($start, $length) + { + return $start === $length; + } + + /** + * Some text about this step/method returns the content of the tokens the token stack for the specified length + * + * @param string $name + * @param string $folder + * + * @see this file + * @When I create a file called :name in :folder + */ + public function getProductListDefaultSortBy222($name, $folder) + { + return $name === $folder; + } + + public function setExtensionAs(\Magento\Catalog\Api\Data\CategoryExtensionInterface $extensionAttributes) + { + return $this->_setExtensionAttributes($extensionAttributes); + } + + /** + * + * short description + * @param \Magento\Catalog\Api\Data\CategoryExtensionInterface $extensionAttributes + * @return mixed + */ + public function setEn(\Magento\Catalog\Api\Data\CategoryExtensionInterface $extensionAttributes) + { + return $this->_setExtensionAttributes($extensionAttributes); + } + + /** + * @param \Magento\Catalog\Api\Data\CategoryExtensionInterface $extensionAttributes + * @return mixed + */ + public function setExtenw(\Magento\Catalog\Api\Data\CategoryExtensionInterface $extensionAttributes) + { + return $this->_setExtensionAttributes($extensionAttributes); + } + + /** + * + * Short description + * @param \Magento\Catalog\Api\Data\CategoryExtensionInterface $extensionAttributes + * @return mixed + */ + public function setExff(\Magento\Catalog\Api\Data\CategoryExtensionInterface $extensionAttributes) + { + return $this->_setExtensionAttributes($extensionAttributes); + } + + /** + * {@inheritdoc} + * + * @param int $start + * @param int $length + * + * @return string The token contents. + */ + public function getProductSortBy($start, $length) + { + return $start === $length; + } +} diff --git a/Magento2/Tests/Annotation/MethodAnnotationStructureUnitTest.php b/Magento2/Tests/Annotation/MethodAnnotationStructureUnitTest.php new file mode 100644 index 00000000..8c2ac4a1 --- /dev/null +++ b/Magento2/Tests/Annotation/MethodAnnotationStructureUnitTest.php @@ -0,0 +1,51 @@ + 1, + 18 => 1, + 30 => 1, + 36 => 1, + 45 => 2, + 47 => 1, + 55 => 1, + 63 => 1, + 80 => 1, + 112 => 1, + 118 => 1, + 137 => 1, + 145 => 2, + 185 => 1, + 227 => 1, + 235 => 1, + 268 => 2, + 269 => 1, + 277 => 1, + 278 => 1, + 288 => 1, + 289 => 1, + 298 => 1 + ]; + } + + /** + * @inheritdoc + */ + public function getWarningList() + { + return []; + } +} diff --git a/Magento2/Tests/Annotation/MethodArgumentsUnitTest.inc b/Magento2/Tests/Annotation/MethodArgumentsUnitTest.inc new file mode 100644 index 00000000..f3cbbb54 --- /dev/null +++ b/Magento2/Tests/Annotation/MethodArgumentsUnitTest.inc @@ -0,0 +1,24 @@ +_setExtensionAttributes($extensionAttributes); +} diff --git a/Magento2/Tests/Annotation/MethodArgumentsUnitTest.php b/Magento2/Tests/Annotation/MethodArgumentsUnitTest.php new file mode 100644 index 00000000..623c7539 --- /dev/null +++ b/Magento2/Tests/Annotation/MethodArgumentsUnitTest.php @@ -0,0 +1,30 @@ + 1, + 21 => 1 + ]; + } + + /** + * @inheritdoc + */ + public function getWarningList() + { + return []; + } +} From cab2f92f973d0887fb78bd20d15354ceef588736 Mon Sep 17 00:00:00 2001 From: Sergio Vera Date: Mon, 23 Aug 2021 16:06:50 +0200 Subject: [PATCH 119/630] AC-659: Create phpcs static check for ModuleXMLTest --- Magento2/Sniffs/Legacy/ModuleXMLSniff.php | 57 +++++++++++++++++++++ Magento2/Tests/Legacy/ModuleXMLUnitTest.php | 29 +++++++++++ Magento2/Tests/Legacy/ModuleXMLUnitTest.xml | 10 ++++ Magento2/ruleset.xml | 7 +++ composer.json | 3 +- 5 files changed, 105 insertions(+), 1 deletion(-) create mode 100644 Magento2/Sniffs/Legacy/ModuleXMLSniff.php create mode 100644 Magento2/Tests/Legacy/ModuleXMLUnitTest.php create mode 100644 Magento2/Tests/Legacy/ModuleXMLUnitTest.xml diff --git a/Magento2/Sniffs/Legacy/ModuleXMLSniff.php b/Magento2/Sniffs/Legacy/ModuleXMLSniff.php new file mode 100644 index 00000000..087027e9 --- /dev/null +++ b/Magento2/Sniffs/Legacy/ModuleXMLSniff.php @@ -0,0 +1,57 @@ +getTokensAsString(0, 999999)); + + if ($xml->xpath('/config/module/@version') !== false) { + $phpcsFile->addWarning( + 'The "version" attribute is obsolete. Use "setup_version" instead.', + $stackPtr, + $this->warningCode + ); + } + + if ($xml->xpath('/config/module/@active') !== false) { + $phpcsFile->addWarning( + 'The "active" attribute is obsolete. The list of active modules is defined in deployment configuration.', + $stackPtr, + $this->warningCode + ); + } + } +} diff --git a/Magento2/Tests/Legacy/ModuleXMLUnitTest.php b/Magento2/Tests/Legacy/ModuleXMLUnitTest.php new file mode 100644 index 00000000..d5c4328f --- /dev/null +++ b/Magento2/Tests/Legacy/ModuleXMLUnitTest.php @@ -0,0 +1,29 @@ + 2 + ]; + } +} \ No newline at end of file diff --git a/Magento2/Tests/Legacy/ModuleXMLUnitTest.xml b/Magento2/Tests/Legacy/ModuleXMLUnitTest.xml new file mode 100644 index 00000000..e94daaf7 --- /dev/null +++ b/Magento2/Tests/Legacy/ModuleXMLUnitTest.xml @@ -0,0 +1,10 @@ + + + + + \ No newline at end of file diff --git a/Magento2/ruleset.xml b/Magento2/ruleset.xml index 3ea0c969..dcf3c608 100644 --- a/Magento2/ruleset.xml +++ b/Magento2/ruleset.xml @@ -223,6 +223,13 @@ 8 warning
+ + *\.php$ + module.xml + ModuleXMLUnitTest.xml + 8 + warning + diff --git a/composer.json b/composer.json index d6004a88..42cbd3be 100644 --- a/composer.json +++ b/composer.json @@ -10,7 +10,8 @@ "require": { "php": ">=7.3", "squizlabs/php_codesniffer": "^3.6", - "webonyx/graphql-php": "^14.9" + "webonyx/graphql-php": "^14.9", + "ext-simplexml": "*" }, "require-dev": { "phpunit/phpunit": "^9.5.8" From e935df801705227ed7743d5da691d64ed2bb1168 Mon Sep 17 00:00:00 2001 From: Sergio Vera Date: Mon, 23 Aug 2021 16:10:03 +0200 Subject: [PATCH 120/630] AC-659: Create phpcs static check for ModuleXMLTest --- Magento2/Tests/Legacy/ModuleXMLUnitTest.php | 2 +- Magento2/Tests/Legacy/ModuleXMLUnitTest.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Magento2/Tests/Legacy/ModuleXMLUnitTest.php b/Magento2/Tests/Legacy/ModuleXMLUnitTest.php index d5c4328f..718ebf9f 100644 --- a/Magento2/Tests/Legacy/ModuleXMLUnitTest.php +++ b/Magento2/Tests/Legacy/ModuleXMLUnitTest.php @@ -26,4 +26,4 @@ public function getWarningList() 1 => 2 ]; } -} \ No newline at end of file +} diff --git a/Magento2/Tests/Legacy/ModuleXMLUnitTest.xml b/Magento2/Tests/Legacy/ModuleXMLUnitTest.xml index e94daaf7..28c02b6f 100644 --- a/Magento2/Tests/Legacy/ModuleXMLUnitTest.xml +++ b/Magento2/Tests/Legacy/ModuleXMLUnitTest.xml @@ -7,4 +7,4 @@ --> - \ No newline at end of file + From aa530654413d585b77662e25ab21a9e711d9a28f Mon Sep 17 00:00:00 2001 From: Sergio Vera Date: Mon, 23 Aug 2021 16:12:14 +0200 Subject: [PATCH 121/630] AC-659: Create phpcs static check for ModuleXMLTest --- composer.lock | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/composer.lock b/composer.lock index 72a2ad6a..fc31a666 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": "1ed3638000f0e172d4e01c45333fcfb6", + "content-hash": "148dc78a64f9790450688c1d3310f3e7", "packages": [ { "name": "squizlabs/php_codesniffer", @@ -2228,7 +2228,8 @@ "prefer-stable": false, "prefer-lowest": false, "platform": { - "php": ">=7.3" + "php": ">=7.3", + "ext-simplexml": "*" }, "platform-dev": [], "plugin-api-version": "2.1.0" From 38f32af3f77a3af999e5258d6f4e6dcea92e7c27 Mon Sep 17 00:00:00 2001 From: Sergii Ivashchenko Date: Tue, 24 Aug 2021 12:55:40 +0100 Subject: [PATCH 122/630] AC-958: Corrected error reporting where fix is not provided --- .../Annotation/AnnotationFormatValidator.php | 26 +++++++++---------- .../Annotation/MethodArgumentsSniff.php | 24 ++++++++--------- 2 files changed, 25 insertions(+), 25 deletions(-) diff --git a/Magento2/Sniffs/Annotation/AnnotationFormatValidator.php b/Magento2/Sniffs/Annotation/AnnotationFormatValidator.php index 220d1a19..b69d2ad6 100644 --- a/Magento2/Sniffs/Annotation/AnnotationFormatValidator.php +++ b/Magento2/Sniffs/Annotation/AnnotationFormatValidator.php @@ -64,7 +64,7 @@ private function validateMultiLinesInShortDescription( && $tokens[$shortPtrEnd]['code'] !== T_DOC_COMMENT_TAG ) { $error = 'Short description should not be in multi lines'; - $phpcsFile->addFixableError($error, $shortPtrEnd + 1, 'MethodAnnotation'); + $phpcsFile->addError($error, $shortPtrEnd + 1, 'MethodAnnotation'); } } @@ -95,7 +95,7 @@ private function validateSpacingBetweenShortAndLongDescriptions( && $tokens[$shortPtrEnd]['code'] !== T_DOC_COMMENT_TAG ) { $error = 'There must be exactly one blank line between lines short and long descriptions'; - $phpcsFile->addFixableError($error, $shortPtrEnd + 1, 'MethodAnnotation'); + $phpcsFile->addError($error, $shortPtrEnd + 1, 'MethodAnnotation'); } if ($shortPtrEnd != $shortPtr) { $this->validateLongDescriptionFormat($phpcsFile, $shortPtrEnd, $commentEndPtr, $emptyTypeTokens); @@ -123,16 +123,16 @@ private function validateShortDescriptionFormat( $tokens = $phpcsFile->getTokens(); if ($tokens[$shortPtr]['line'] !== $tokens[$stackPtr]['line'] + 1) { $error = 'No blank lines are allowed before short description'; - $phpcsFile->addFixableError($error, $shortPtr, 'MethodAnnotation'); + $phpcsFile->addError($error, $shortPtr, 'MethodAnnotation'); } if (strtolower($tokens[$shortPtr]['content']) === '{@inheritdoc}') { $error = 'If the @inheritdoc not inline it shouldn’t have braces'; - $phpcsFile->addFixableError($error, $shortPtr, 'MethodAnnotation'); + $phpcsFile->addError($error, $shortPtr, 'MethodAnnotation'); } $shortPtrContent = $tokens[$shortPtr]['content']; if (preg_match('/^\p{Ll}/u', $shortPtrContent) === 1) { $error = 'Short description must start with a capital letter'; - $phpcsFile->addFixableError($error, $shortPtr, 'MethodAnnotation'); + $phpcsFile->addError($error, $shortPtr, 'MethodAnnotation'); } $this->validateNoExtraNewLineBeforeShortDescription( $phpcsFile, @@ -171,16 +171,16 @@ private function validateLongDescriptionFormat( $longPtr = $phpcsFile->findNext($emptyTypeTokens, $shortPtrEnd + 1, $commentEndPtr - 1, true); if (strtolower($tokens[$longPtr]['content']) === '@inheritdoc') { $error = '@inheritdoc imports only short description, annotation must have long description'; - $phpcsFile->addFixableError($error, $longPtr, 'MethodAnnotation'); + $phpcsFile->addError($error, $longPtr, 'MethodAnnotation'); } if ($longPtr !== false && $tokens[$longPtr]['code'] === T_DOC_COMMENT_STRING) { if ($tokens[$longPtr]['line'] !== $tokens[$shortPtrEnd]['line'] + 2) { $error = 'There must be exactly one blank line between descriptions'; - $phpcsFile->addFixableError($error, $longPtr, 'MethodAnnotation'); + $phpcsFile->addError($error, $longPtr, 'MethodAnnotation'); } if (preg_match('/^\p{Ll}/u', $tokens[$longPtr]['content']) === 1) { $error = 'Long description must start with a capital letter'; - $phpcsFile->addFixableError($error, $longPtr, 'MethodAnnotation'); + $phpcsFile->addError($error, $longPtr, 'MethodAnnotation'); } } } @@ -203,7 +203,7 @@ public function validateTagsSpacingFormat(File $phpcsFile, int $commentStartPtr, && strtolower($commentTagPtrContent) !== '@inheritdoc' ) { $error = 'There must be exactly one blank line before tags'; - $phpcsFile->addFixableError($error, $firstTagPtr, 'MethodAnnotation'); + $phpcsFile->addError($error, $firstTagPtr, 'MethodAnnotation'); } } } @@ -240,7 +240,7 @@ public function validateTagGroupingFormat(File $phpcsFile, int $commentStartPtr) if ($paramGroupId !== null && $paramGroupId !== $groupId) { $error = 'Parameter tags must be grouped together'; - $phpcsFile->addFixableError($error, $tag, 'MethodAnnotation'); + $phpcsFile->addError($error, $tag, 'MethodAnnotation'); } if ($paramGroupId === null) { $paramGroupId = $groupId; @@ -273,7 +273,7 @@ public function validateTagAligningFormat(File $phpcsFile, int $commentStartPtr) if (!$this->allTagsAligned($actualPositions) && !$this->noneTagsAligned($actualPositions, $noAlignmentPositions)) { - $phpcsFile->addFixableError( + $phpcsFile->addError( 'Tags visual alignment must be consistent', $stackPtr, 'MethodArguments' @@ -322,7 +322,7 @@ private function validateNoExtraNewLineBeforeShortDescription( $prevPtr = $phpcsFile->findPrevious($emptyTypeTokens, $commentEndPtr - 1, $commentStartPtr, true); if ($tokens[$prevPtr]['line'] < ($tokens[$commentEndPtr]['line'] - 1)) { $error = 'Additional blank lines found at end of the annotation block'; - $phpcsFile->addFixableError($error, $commentEndPtr, 'MethodAnnotation'); + $phpcsFile->addError($error, $commentEndPtr, 'MethodAnnotation'); } } @@ -351,7 +351,7 @@ public function validateDescriptionFormatStructure( && strtolower($commentTagPtrContent) !== '@inheritdoc' ) { $error = 'Missing short description'; - $phpcsFile->addFixableError($error, $commentStartPtr, 'MethodAnnotation'); + $phpcsFile->addError($error, $commentStartPtr, 'MethodAnnotation'); } else { $this->validateShortDescriptionFormat( $phpcsFile, diff --git a/Magento2/Sniffs/Annotation/MethodArgumentsSniff.php b/Magento2/Sniffs/Annotation/MethodArgumentsSniff.php index 2ebb12d4..655bd37c 100644 --- a/Magento2/Sniffs/Annotation/MethodArgumentsSniff.php +++ b/Magento2/Sniffs/Annotation/MethodArgumentsSniff.php @@ -225,7 +225,7 @@ private function validateParameterAnnotationForArgumentExists( $previousCommentClosePtr ); if ($inheritdocAnnotationWithBracesExists) { - $phpcsFile->addFixableError( + $phpcsFile->addError( '{@inheritdoc} does not import parameter annotation', $stackPtr, 'MethodArguments' @@ -233,7 +233,7 @@ private function validateParameterAnnotationForArgumentExists( } elseif ($this->validateCommentBlockExists($phpcsFile, $previousCommentClosePtr, $stackPtr) && !$inheritdocAnnotationWithoutBracesExists ) { - $phpcsFile->addFixableError( + $phpcsFile->addError( 'Missing @param for argument in method annotation', $stackPtr, 'MethodArguments' @@ -257,13 +257,13 @@ private function validateCommentBlockDoesnotHaveExtraParameterAnnotation( int $stackPtr ): void { if ($argumentsCount < $parametersCount && $argumentsCount > 0) { - $phpcsFile->addFixableError( + $phpcsFile->addError( 'Extra @param found in method annotation', $stackPtr, 'MethodArguments' ); } elseif ($argumentsCount > 0 && $argumentsCount != $parametersCount && $parametersCount != 0) { - $phpcsFile->addFixableError( + $phpcsFile->addError( '@param is not found for one or more params in method annotation', $stackPtr, 'MethodArguments' @@ -290,7 +290,7 @@ private function validateArgumentNameInParameterAnnotationExists( $parameterNames = $this->getMethodParameters($paramDefinitions); if (!in_array($methodArguments[$ptr], $parameterNames)) { $error = $methodArguments[$ptr] . ' parameter is missing in method annotation'; - $phpcsFile->addFixableError($error, $stackPtr, 'MethodArguments'); + $phpcsFile->addError($error, $stackPtr, 'MethodArguments'); } } @@ -311,7 +311,7 @@ private function validateParameterPresentInMethodSignature( array $paramPointers ): void { if (!in_array($paramDefinitionsArguments, $methodArguments)) { - $phpcsFile->addFixableError( + $phpcsFile->addError( $paramDefinitionsArguments . ' parameter is missing in method arguments signature', $paramPointers[$ptr], 'MethodArguments' @@ -340,7 +340,7 @@ private function validateParameterOrderIsCorrect( && in_array($methodArguments[$ptr], $parameterNames) ) { if ($methodArguments[$ptr] != $parameterNames[$ptr]) { - $phpcsFile->addFixableError( + $phpcsFile->addError( $methodArguments[$ptr] . ' parameter is not in order', $paramPointers[$ptr], 'MethodArguments' @@ -383,7 +383,7 @@ private function validateDuplicateAnnotationDoesnotExists( } } foreach ($duplicateParameters as $value) { - $phpcsFile->addFixableError( + $phpcsFile->addError( $value . ' duplicate found in method annotation', $stackPtr, 'MethodArguments' @@ -410,7 +410,7 @@ private function validateParameterAnnotationFormatIsCorrect( ): void { switch (count($paramDefinitions)) { case 0: - $phpcsFile->addFixableError( + $phpcsFile->addError( 'Missing both type and parameter', $paramPointers[$ptr], 'MethodArguments' @@ -427,7 +427,7 @@ private function validateParameterAnnotationFormatIsCorrect( break; case 2: if ($this->isInvalidType($paramDefinitions[0])) { - $phpcsFile->addFixableError( + $phpcsFile->addError( $paramDefinitions[0] . ' is not a valid PHP type', $paramPointers[$ptr], 'MethodArguments' @@ -449,7 +449,7 @@ private function validateParameterAnnotationFormatIsCorrect( 'MethodArguments' ); if ($this->isInvalidType($paramDefinitions[0])) { - $phpcsFile->addFixableError( + $phpcsFile->addError( $paramDefinitions[0] . ' is not a valid PHP type', $paramPointers[$ptr], 'MethodArguments' @@ -633,7 +633,7 @@ private function validateFormattingConsistency( } if (!$this->allParamsAligned($argumentPositions, $commentPositions) && !$this->noneParamsAligned($argumentPositions, $commentPositions, $paramDefinitions)) { - $phpcsFile->addFixableError( + $phpcsFile->addError( 'Method arguments visual alignment must be consistent', $paramPointers[0], 'MethodArguments' From 757171f8b74c841d2e2669fa731da7bc0e7b6490 Mon Sep 17 00:00:00 2001 From: Sergii Ivashchenko Date: Tue, 24 Aug 2021 13:06:50 +0100 Subject: [PATCH 123/630] Moved abstract unit test to autoload-dev --- composer.json | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/composer.json b/composer.json index d6004a88..cc1950eb 100644 --- a/composer.json +++ b/composer.json @@ -15,16 +15,18 @@ "require-dev": { "phpunit/phpunit": "^9.5.8" }, + "autoload-dev": { + "files": [ + "PHP_CodeSniffer/Tests/Standards/AbstractSniffUnitTest.php" + ] + }, "autoload": { "classmap": [ "PHP_CodeSniffer/Tokenizers/" ], "psr-4": { "Magento2\\": "Magento2/" - }, - "files": [ - "PHP_CodeSniffer/Tests/Standards/AbstractSniffUnitTest.php" - ] + } }, "scripts": { "post-install-cmd": "vendor/bin/phpcs --config-set installed_paths ../../..", From e6a43fe26035a8a402f822b861f88f3529131db0 Mon Sep 17 00:00:00 2001 From: Elisea Cornejo Date: Tue, 24 Aug 2021 14:40:57 +0200 Subject: [PATCH 124/630] AC-939: Create unit test for Magento2\Less\AvoidIdSniff check --- Magento2/Sniffs/Less/AvoidIdSniff.php | 1 + Magento2/Tests/Less/AvoidIdUnitTest.inc | 39 ++++++++++++++++++++ Magento2/Tests/Less/AvoidIdUnitTest.php | 48 +++++++++++++++++++++++++ Magento2/ruleset.xml | 6 ++-- 4 files changed, 92 insertions(+), 2 deletions(-) create mode 100644 Magento2/Tests/Less/AvoidIdUnitTest.inc create mode 100644 Magento2/Tests/Less/AvoidIdUnitTest.php diff --git a/Magento2/Sniffs/Less/AvoidIdSniff.php b/Magento2/Sniffs/Less/AvoidIdSniff.php index d4e1b213..387b5ed8 100644 --- a/Magento2/Sniffs/Less/AvoidIdSniff.php +++ b/Magento2/Sniffs/Less/AvoidIdSniff.php @@ -51,6 +51,7 @@ class AvoidIdSniff implements Sniff T_PLUS, T_NS_SEPARATOR, T_LNUMBER, + T_BITWISE_NOT ]; /** diff --git a/Magento2/Tests/Less/AvoidIdUnitTest.inc b/Magento2/Tests/Less/AvoidIdUnitTest.inc new file mode 100644 index 00000000..070c2eec --- /dev/null +++ b/Magento2/Tests/Less/AvoidIdUnitTest.inc @@ -0,0 +1,39 @@ +// /** +// * Copyright © Magento, Inc. All rights reserved. +// * See COPYING.txt for license details. +// */ + +#foo[bar], +#foo[bar=bash], +#foo[bar~=bash], +#foo[bar$=bash], +#foo[bar*=bash], +#foo[bar|=bash], +#foo[bar='bash'], +#foo:hover, +#foo:nth-last-of-type(n), +#foo::before, +#foo + div, +#foo > div, +#foo ~ div, +#foo\3Abar ~ div, +#foo\:bar ~ div, +#foo.bar .baz, +div#foo { +blah: 'abc'; +} + +.my #foo, +#foo .blah, +.my #foo .blah { +some: 'stuff'; +} +.blah { +#bar .baz(); +.foo #bar .baz(); +#bar .baz(); + +#bar .baz; +.foo #bar .baz; +#bar .baz; +} diff --git a/Magento2/Tests/Less/AvoidIdUnitTest.php b/Magento2/Tests/Less/AvoidIdUnitTest.php new file mode 100644 index 00000000..962af35f --- /dev/null +++ b/Magento2/Tests/Less/AvoidIdUnitTest.php @@ -0,0 +1,48 @@ + 1, + 7 => 1, + 8 => 1, + 9 => 1, + 10 => 1, + 11 => 1, + 12 => 1, + 13 => 1, + 14 => 1, + 15 => 1, + 16 => 1, + 17 => 1, + 18 => 1, + 19 => 1, + 20 => 1, + 21 => 3, + 22 => 1, + 26 => 1, + 27 => 1, + 28 => 1 + ]; + } + + /** + * @inheritdoc + */ + public function getWarningList() + { + return []; + } +} diff --git a/Magento2/ruleset.xml b/Magento2/ruleset.xml index 3ea0c969..daf54da8 100644 --- a/Magento2/ruleset.xml +++ b/Magento2/ruleset.xml @@ -3,7 +3,7 @@ Magento Coding Standard - + @@ -590,7 +590,9 @@ *Test.php - + + *\.less$ + 0 From 8d23aa4fc00f03f141a1013a95c475af5a1ccfd8 Mon Sep 17 00:00:00 2001 From: Sergio Vera Date: Tue, 24 Aug 2021 14:42:45 +0200 Subject: [PATCH 125/630] AC-659: Create phpcs static check for ModuleXMLTest --- Magento2/Sniffs/Legacy/ModuleXMLSniff.php | 57 ++++++++++++++++----- Magento2/Tests/Legacy/ModuleXMLUnitTest.php | 2 +- Magento2/ruleset.xml | 8 +-- composer.json | 3 +- 4 files changed, 51 insertions(+), 19 deletions(-) diff --git a/Magento2/Sniffs/Legacy/ModuleXMLSniff.php b/Magento2/Sniffs/Legacy/ModuleXMLSniff.php index 087027e9..a60c9fdb 100644 --- a/Magento2/Sniffs/Legacy/ModuleXMLSniff.php +++ b/Magento2/Sniffs/Legacy/ModuleXMLSniff.php @@ -8,6 +8,7 @@ use PHP_CodeSniffer\Files\File; use PHP_CodeSniffer\Sniffs\Sniff; +use SimpleXMLElement; /** * Test for obsolete nodes/attributes in the module.xml @@ -36,22 +37,52 @@ public function register(): array */ public function process(File $phpcsFile, $stackPtr) { - $xml = simplexml_load_string($phpcsFile->getTokensAsString(0, 999999)); + $line = $phpcsFile->getTokens()[$stackPtr]['content']; + if (strpos(trim($line), 'xpath('/config/module/@version') !== false) { - $phpcsFile->addWarning( - 'The "version" attribute is obsolete. Use "setup_version" instead.', - $stackPtr, - $this->warningCode - ); + $xml = simplexml_load_string($phpcsFile->getTokensAsString(0, 999999)); + + $foundElements = $xml->xpath('/config/module'); + if ($foundElements === false) { + return; } - if ($xml->xpath('/config/module/@active') !== false) { - $phpcsFile->addWarning( - 'The "active" attribute is obsolete. The list of active modules is defined in deployment configuration.', - $stackPtr, - $this->warningCode - ); + foreach ($foundElements as $element) { + if (!$this->elementIsCurrentlySniffedLine($element, $stackPtr)) { + continue; + } + + if (property_exists($element->attributes(), 'version')) { + $phpcsFile->addWarning( + 'The "version" attribute is obsolete. Use "setup_version" instead.', + $stackPtr, + $this->warningCode + ); + } + + if (property_exists($element->attributes(), 'active')) { + $phpcsFile->addWarning( + 'The "active" attribute is obsolete. The list of active modules is defined in deployment configuration.', + $stackPtr, + $this->warningCode + ); + } + } + } + + /** + * @param SimpleXMLElement $element + * @param int $stackPtr + * @return bool + */ + private function elementIsCurrentlySniffedLine(SimpleXMLElement $element, int $stackPtr): bool + { + $node = dom_import_simplexml($element); + if ($node->getLineNo() === $stackPtr+1) { + return true; } + return false; } } diff --git a/Magento2/Tests/Legacy/ModuleXMLUnitTest.php b/Magento2/Tests/Legacy/ModuleXMLUnitTest.php index 718ebf9f..0220b1d8 100644 --- a/Magento2/Tests/Legacy/ModuleXMLUnitTest.php +++ b/Magento2/Tests/Legacy/ModuleXMLUnitTest.php @@ -23,7 +23,7 @@ public function getErrorList() public function getWarningList() { return [ - 1 => 2 + 9 => 2 ]; } } diff --git a/Magento2/ruleset.xml b/Magento2/ruleset.xml index dcf3c608..bc9f4385 100644 --- a/Magento2/ruleset.xml +++ b/Magento2/ruleset.xml @@ -3,7 +3,7 @@ Magento Coding Standard - + @@ -224,9 +224,8 @@ warning - *\.php$ - module.xml - ModuleXMLUnitTest.xml + *\/module.xml$ + *\/ModuleXMLUnitTest.xml$ 8 warning @@ -265,6 +264,7 @@ warning + *\.xml$ 7 warning diff --git a/composer.json b/composer.json index 42cbd3be..f5037b17 100644 --- a/composer.json +++ b/composer.json @@ -11,7 +11,8 @@ "php": ">=7.3", "squizlabs/php_codesniffer": "^3.6", "webonyx/graphql-php": "^14.9", - "ext-simplexml": "*" + "ext-simplexml": "*", + "ext-dom": "*" }, "require-dev": { "phpunit/phpunit": "^9.5.8" From a9ef69fb91391df629b460adcd106dff70c511e6 Mon Sep 17 00:00:00 2001 From: Elisea Cornejo Date: Tue, 24 Aug 2021 14:45:19 +0200 Subject: [PATCH 126/630] AC-939: Create unit test for Magento2\Less\AvoidIdSniff check --- Magento2/Tests/Less/{AvoidIdUnitTest.inc => AvoidIdUnitTest.less} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename Magento2/Tests/Less/{AvoidIdUnitTest.inc => AvoidIdUnitTest.less} (100%) diff --git a/Magento2/Tests/Less/AvoidIdUnitTest.inc b/Magento2/Tests/Less/AvoidIdUnitTest.less similarity index 100% rename from Magento2/Tests/Less/AvoidIdUnitTest.inc rename to Magento2/Tests/Less/AvoidIdUnitTest.less From 135630e5804b0fd760f48c1651def302ee292276 Mon Sep 17 00:00:00 2001 From: Sergio Vera Date: Tue, 24 Aug 2021 14:48:33 +0200 Subject: [PATCH 127/630] AC-659: Create phpcs static check for ModuleXMLTest --- composer.lock | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/composer.lock b/composer.lock index fc31a666..04231d90 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": "148dc78a64f9790450688c1d3310f3e7", + "content-hash": "8c3c7509df274fdeaf09edfd7eac6cf5", "packages": [ { "name": "squizlabs/php_codesniffer", @@ -2229,7 +2229,8 @@ "prefer-lowest": false, "platform": { "php": ">=7.3", - "ext-simplexml": "*" + "ext-simplexml": "*", + "ext-dom": "*" }, "platform-dev": [], "plugin-api-version": "2.1.0" From 85de47c2a62f3b538dd4ee8bd80e179f395136a0 Mon Sep 17 00:00:00 2001 From: Sergio Vera Date: Tue, 24 Aug 2021 14:50:59 +0200 Subject: [PATCH 128/630] AC-659: Create phpcs static check for ModuleXMLTest --- Magento2/Sniffs/Legacy/ModuleXMLSniff.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Magento2/Sniffs/Legacy/ModuleXMLSniff.php b/Magento2/Sniffs/Legacy/ModuleXMLSniff.php index a60c9fdb..b7fe303b 100644 --- a/Magento2/Sniffs/Legacy/ModuleXMLSniff.php +++ b/Magento2/Sniffs/Legacy/ModuleXMLSniff.php @@ -64,7 +64,8 @@ public function process(File $phpcsFile, $stackPtr) if (property_exists($element->attributes(), 'active')) { $phpcsFile->addWarning( - 'The "active" attribute is obsolete. The list of active modules is defined in deployment configuration.', + 'The "active" attribute is obsolete. The list of active modules '. + 'is defined in deployment configuration.', $stackPtr, $this->warningCode ); @@ -73,6 +74,8 @@ public function process(File $phpcsFile, $stackPtr) } /** + * Check if the element passed is in the currently sniffed line + * * @param SimpleXMLElement $element * @param int $stackPtr * @return bool From 5f4d45f06d5217ae35c08b719f72d0e0cc945b12 Mon Sep 17 00:00:00 2001 From: Sergio Vera Date: Tue, 24 Aug 2021 15:00:09 +0200 Subject: [PATCH 129/630] AC-659: Create phpcs static check for ModuleXMLTest --- Magento2/Sniffs/Legacy/ModuleXMLSniff.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Magento2/Sniffs/Legacy/ModuleXMLSniff.php b/Magento2/Sniffs/Legacy/ModuleXMLSniff.php index b7fe303b..1cfa6ef9 100644 --- a/Magento2/Sniffs/Legacy/ModuleXMLSniff.php +++ b/Magento2/Sniffs/Legacy/ModuleXMLSniff.php @@ -65,7 +65,7 @@ public function process(File $phpcsFile, $stackPtr) if (property_exists($element->attributes(), 'active')) { $phpcsFile->addWarning( 'The "active" attribute is obsolete. The list of active modules '. - 'is defined in deployment configuration.', + 'is defined in deployment configuration.', $stackPtr, $this->warningCode ); @@ -75,7 +75,7 @@ public function process(File $phpcsFile, $stackPtr) /** * Check if the element passed is in the currently sniffed line - * + * * @param SimpleXMLElement $element * @param int $stackPtr * @return bool From 70636590ce96dc8be89df5e14ae877c9ff8f9968 Mon Sep 17 00:00:00 2001 From: Sergio Vera Date: Tue, 24 Aug 2021 15:27:37 +0200 Subject: [PATCH 130/630] AC-659: Create phpcs static check for ModuleXMLTest --- Magento2/Sniffs/Legacy/ModuleXMLSniff.php | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/Magento2/Sniffs/Legacy/ModuleXMLSniff.php b/Magento2/Sniffs/Legacy/ModuleXMLSniff.php index 1cfa6ef9..a3b9cbd9 100644 --- a/Magento2/Sniffs/Legacy/ModuleXMLSniff.php +++ b/Magento2/Sniffs/Legacy/ModuleXMLSniff.php @@ -17,10 +17,8 @@ class ModuleXMLSniff implements Sniff { /** * Error violation code. - * - * @var string */ - protected $warningCode = 'FoundObsoleteAttribute'; + const WARNING_CODE = 'FoundObsoleteAttribute'; /** * @inheritdoc @@ -43,6 +41,16 @@ public function process(File $phpcsFile, $stackPtr) } $xml = simplexml_load_string($phpcsFile->getTokensAsString(0, 999999)); + if ($xml === false) { + $phpcsFile->addError( + sprintf( + "Couldn't parse contents of '%s', check that they are in valid XML format", + basename($phpcsFile->getFilename()), + ), + $stackPtr, + self::WARNING_CODE + ); + } $foundElements = $xml->xpath('/config/module'); if ($foundElements === false) { @@ -58,7 +66,7 @@ public function process(File $phpcsFile, $stackPtr) $phpcsFile->addWarning( 'The "version" attribute is obsolete. Use "setup_version" instead.', $stackPtr, - $this->warningCode + self::WARNING_CODE ); } @@ -67,7 +75,7 @@ public function process(File $phpcsFile, $stackPtr) 'The "active" attribute is obsolete. The list of active modules '. 'is defined in deployment configuration.', $stackPtr, - $this->warningCode + self::WARNING_CODE ); } } From c2786fe1b7ac6c7867ae8e7837a425d378d1b060 Mon Sep 17 00:00:00 2001 From: Sergio Vera Date: Tue, 24 Aug 2021 15:32:29 +0200 Subject: [PATCH 131/630] AC-659: Create phpcs static check for ModuleXMLTest --- Magento2/Sniffs/Legacy/ModuleXMLSniff.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Magento2/Sniffs/Legacy/ModuleXMLSniff.php b/Magento2/Sniffs/Legacy/ModuleXMLSniff.php index a3b9cbd9..ca1b3084 100644 --- a/Magento2/Sniffs/Legacy/ModuleXMLSniff.php +++ b/Magento2/Sniffs/Legacy/ModuleXMLSniff.php @@ -45,7 +45,7 @@ public function process(File $phpcsFile, $stackPtr) $phpcsFile->addError( sprintf( "Couldn't parse contents of '%s', check that they are in valid XML format", - basename($phpcsFile->getFilename()), + $phpcsFile->getFilename(), ), $stackPtr, self::WARNING_CODE From aca6b41a8160ed603d856ba77dbaa79c025698f5 Mon Sep 17 00:00:00 2001 From: Sergio Vera Date: Tue, 24 Aug 2021 16:53:12 +0200 Subject: [PATCH 132/630] AC-659: Create phpcs static check for ModuleXMLTest --- Magento2/Sniffs/Legacy/ModuleXMLSniff.php | 27 +++++++++++++++------ Magento2/Tests/Legacy/ModuleXMLUnitTest.php | 3 ++- Magento2/Tests/Legacy/ModuleXMLUnitTest.xml | 5 ++++ 3 files changed, 26 insertions(+), 9 deletions(-) diff --git a/Magento2/Sniffs/Legacy/ModuleXMLSniff.php b/Magento2/Sniffs/Legacy/ModuleXMLSniff.php index ca1b3084..5a741156 100644 --- a/Magento2/Sniffs/Legacy/ModuleXMLSniff.php +++ b/Magento2/Sniffs/Legacy/ModuleXMLSniff.php @@ -6,6 +6,7 @@ namespace Magento2\Sniffs\Legacy; +use DOMDocument; use PHP_CodeSniffer\Files\File; use PHP_CodeSniffer\Sniffs\Sniff; use SimpleXMLElement; @@ -15,10 +16,8 @@ */ class ModuleXMLSniff implements Sniff { - /** - * Error violation code. - */ - const WARNING_CODE = 'FoundObsoleteAttribute'; + private const WARNING_CODE = 'FoundObsoleteAttribute'; + private const ERROR_CODE = 'WrongXML'; /** * @inheritdoc @@ -36,11 +35,11 @@ public function register(): array public function process(File $phpcsFile, $stackPtr) { $line = $phpcsFile->getTokens()[$stackPtr]['content']; - if (strpos(trim($line), 'getTokensAsString(0, 999999)); + + $xml = simplexml_load_string($this->getFormattedXML($phpcsFile)); if ($xml === false) { $phpcsFile->addError( sprintf( @@ -48,7 +47,7 @@ public function process(File $phpcsFile, $stackPtr) $phpcsFile->getFilename(), ), $stackPtr, - self::WARNING_CODE + self::ERROR_CODE ); } @@ -96,4 +95,16 @@ private function elementIsCurrentlySniffedLine(SimpleXMLElement $element, int $s } return false; } + + /** + * @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/ModuleXMLUnitTest.php b/Magento2/Tests/Legacy/ModuleXMLUnitTest.php index 0220b1d8..f75673d8 100644 --- a/Magento2/Tests/Legacy/ModuleXMLUnitTest.php +++ b/Magento2/Tests/Legacy/ModuleXMLUnitTest.php @@ -23,7 +23,8 @@ public function getErrorList() public function getWarningList() { return [ - 9 => 2 + 9 => 2, + 10 => 2 ]; } } diff --git a/Magento2/Tests/Legacy/ModuleXMLUnitTest.xml b/Magento2/Tests/Legacy/ModuleXMLUnitTest.xml index 28c02b6f..9d545a65 100644 --- a/Magento2/Tests/Legacy/ModuleXMLUnitTest.xml +++ b/Magento2/Tests/Legacy/ModuleXMLUnitTest.xml @@ -7,4 +7,9 @@ --> + From 754e84c471e3c5749c399788a49c3f9184bc8b5c Mon Sep 17 00:00:00 2001 From: Sergio Vera Date: Tue, 24 Aug 2021 17:01:47 +0200 Subject: [PATCH 133/630] AC-659: Create phpcs static check for ModuleXMLTest --- Magento2/Sniffs/Legacy/ModuleXMLSniff.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Magento2/Sniffs/Legacy/ModuleXMLSniff.php b/Magento2/Sniffs/Legacy/ModuleXMLSniff.php index 5a741156..efb903c1 100644 --- a/Magento2/Sniffs/Legacy/ModuleXMLSniff.php +++ b/Magento2/Sniffs/Legacy/ModuleXMLSniff.php @@ -97,6 +97,9 @@ private function elementIsCurrentlySniffedLine(SimpleXMLElement $element, int $s } /** + * We need to format the incoming XML to avoid tags split into several lines. In that case, PHP's DOMElement + * returns the position of the closing /> as the position of the tag. + * * @param File $phpcsFile * @return false|string */ From 75f43afb48f407472659ab64fe66054d6deef1a2 Mon Sep 17 00:00:00 2001 From: Sergio Vera Date: Tue, 24 Aug 2021 17:04:59 +0200 Subject: [PATCH 134/630] AC-659: Create phpcs static check for ModuleXMLTest --- Magento2/Sniffs/Legacy/ModuleXMLSniff.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Magento2/Sniffs/Legacy/ModuleXMLSniff.php b/Magento2/Sniffs/Legacy/ModuleXMLSniff.php index efb903c1..5f016d5e 100644 --- a/Magento2/Sniffs/Legacy/ModuleXMLSniff.php +++ b/Magento2/Sniffs/Legacy/ModuleXMLSniff.php @@ -39,6 +39,8 @@ public function process(File $phpcsFile, $stackPtr) return; } + // We need to format the incoming XML to avoid tags split into several lines. In that case, PHP's DOMElement + // returns the position of the closing /> as the position of the tag. $xml = simplexml_load_string($this->getFormattedXML($phpcsFile)); if ($xml === false) { $phpcsFile->addError( @@ -97,8 +99,7 @@ private function elementIsCurrentlySniffedLine(SimpleXMLElement $element, int $s } /** - * We need to format the incoming XML to avoid tags split into several lines. In that case, PHP's DOMElement - * returns the position of the closing /> as the position of the tag. + * Format the incoming XML to avoid tags split into several lines. * * @param File $phpcsFile * @return false|string From d0fe1500e648f4dbf1164582ab22b0a0300a3541 Mon Sep 17 00:00:00 2001 From: Sergio Vera Date: Tue, 24 Aug 2021 17:09:23 +0200 Subject: [PATCH 135/630] AC-659: Create phpcs static check for ModuleXMLTest --- Magento2/Sniffs/Legacy/ModuleXMLSniff.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Magento2/Sniffs/Legacy/ModuleXMLSniff.php b/Magento2/Sniffs/Legacy/ModuleXMLSniff.php index 5f016d5e..da25de0d 100644 --- a/Magento2/Sniffs/Legacy/ModuleXMLSniff.php +++ b/Magento2/Sniffs/Legacy/ModuleXMLSniff.php @@ -40,7 +40,8 @@ public function process(File $phpcsFile, $stackPtr) } // We need to format the incoming XML to avoid tags split into several lines. In that case, PHP's DOMElement - // returns the position of the closing /> as the position of the tag. + // returns the position of the closing /> as the position of the tag, and we need the position of getFormattedXML($phpcsFile)); if ($xml === false) { $phpcsFile->addError( From bd8c956301d22813945263770bf2572dc5dba361 Mon Sep 17 00:00:00 2001 From: Jose Orsini Date: Tue, 24 Aug 2021 16:58:07 -0500 Subject: [PATCH 136/630] Update list of functions to block --- Magento2/Sniffs/Security/InsecureFunctionSniff.php | 7 ------- 1 file changed, 7 deletions(-) diff --git a/Magento2/Sniffs/Security/InsecureFunctionSniff.php b/Magento2/Sniffs/Security/InsecureFunctionSniff.php index 66b6f5f0..a4df7a76 100644 --- a/Magento2/Sniffs/Security/InsecureFunctionSniff.php +++ b/Magento2/Sniffs/Security/InsecureFunctionSniff.php @@ -35,13 +35,6 @@ class InsecureFunctionSniff extends ForbiddenFunctionsSniff 'mt_rand' => 'random_int', // Custom Rules - MTS-2096 'eval' => null, - 'preg_replace' => null, - 'preg_replace_callback' => null, - 'preg_replace_callback_array' => null, - 'include' => null, - 'include_once' => null, - 'require' => null, - 'require_once' => null, 'proc_nice' => null, 'proc_open' => null, 'proc_close' => null, From e538e6f9fac9eaabba920c70c1ed4bfdbeadbbb4 Mon Sep 17 00:00:00 2001 From: Elisea Cornejo Date: Wed, 25 Aug 2021 12:39:03 +0200 Subject: [PATCH 137/630] AC-939: Create unit test for Magento2\Less\AvoidIdSniff check --- .../Less/AbstractLessSniffUnitTestCase.php | 33 +++++++++++++++++++ Magento2/Tests/Less/AvoidIdUnitTest.php | 6 ++-- Magento2/ruleset.xml | 2 +- 3 files changed, 36 insertions(+), 5 deletions(-) create mode 100644 Magento2/Tests/Less/AbstractLessSniffUnitTestCase.php diff --git a/Magento2/Tests/Less/AbstractLessSniffUnitTestCase.php b/Magento2/Tests/Less/AbstractLessSniffUnitTestCase.php new file mode 100644 index 00000000..71edcbee --- /dev/null +++ b/Magento2/Tests/Less/AbstractLessSniffUnitTestCase.php @@ -0,0 +1,33 @@ +extensions = array_merge( + $config->extensions, + [ + 'less' => 'CSS' + ] + ); + + $GLOBALS['PHP_CODESNIFFER_CONFIG'] = $config; + } +} diff --git a/Magento2/Tests/Less/AvoidIdUnitTest.php b/Magento2/Tests/Less/AvoidIdUnitTest.php index 962af35f..33012879 100644 --- a/Magento2/Tests/Less/AvoidIdUnitTest.php +++ b/Magento2/Tests/Less/AvoidIdUnitTest.php @@ -5,9 +5,7 @@ */ namespace Magento2\Tests\Less; -use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; - -class AvoidIdUnitTest extends AbstractSniffUnitTest +class AvoidIdUnitTest extends AbstractLessSniffUnitTestCase { /** * @inheritdoc @@ -30,7 +28,7 @@ public function getErrorList() 18 => 1, 19 => 1, 20 => 1, - 21 => 3, + 21 => 1, 22 => 1, 26 => 1, 27 => 1, diff --git a/Magento2/ruleset.xml b/Magento2/ruleset.xml index daf54da8..204946d0 100644 --- a/Magento2/ruleset.xml +++ b/Magento2/ruleset.xml @@ -3,7 +3,7 @@ Magento Coding Standard - + From b1c005c3f5ed687f149c9b0f285818c2123dd6de Mon Sep 17 00:00:00 2001 From: Sergii Ivashchenko Date: Wed, 25 Aug 2021 11:47:31 +0100 Subject: [PATCH 138/630] Version 8 --- composer.json | 2 +- composer.lock | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index cc1950eb..f30fd7fd 100644 --- a/composer.json +++ b/composer.json @@ -6,7 +6,7 @@ "AFL-3.0" ], "type": "phpcodesniffer-standard", - "version": "7", + "version": "8", "require": { "php": ">=7.3", "squizlabs/php_codesniffer": "^3.6", diff --git a/composer.lock b/composer.lock index 72a2ad6a..c26f9e74 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": "1ed3638000f0e172d4e01c45333fcfb6", + "content-hash": "93bec1b3a36cf67f2511aec0219bcc06", "packages": [ { "name": "squizlabs/php_codesniffer", From f0b61be7a03a002ac5dcf9ce8027fb64c1ed5ded Mon Sep 17 00:00:00 2001 From: Marc Ginesta Date: Wed, 25 Aug 2021 13:03:06 +0200 Subject: [PATCH 139/630] AC-660: Create phpcs static check for DiConfigTest - DiConfigTest: Test for obsolete nodes in di.xml --- Magento2/Sniffs/Legacy/DiConfigSniff.php | 80 ++++++++++++++++++++++ Magento2/Tests/Legacy/DiConfigUnitTest.php | 34 +++++++++ Magento2/Tests/Legacy/DiConfigUnitTest.xml | 19 +++++ Magento2/ruleset.xml | 5 ++ composer.json | 4 +- 5 files changed, 141 insertions(+), 1 deletion(-) create mode 100644 Magento2/Sniffs/Legacy/DiConfigSniff.php create mode 100644 Magento2/Tests/Legacy/DiConfigUnitTest.php create mode 100644 Magento2/Tests/Legacy/DiConfigUnitTest.xml diff --git a/Magento2/Sniffs/Legacy/DiConfigSniff.php b/Magento2/Sniffs/Legacy/DiConfigSniff.php new file mode 100644 index 00000000..680eb318 --- /dev/null +++ b/Magento2/Sniffs/Legacy/DiConfigSniff.php @@ -0,0 +1,80 @@ + 'The node is obsolete. Instead, use the ', + 'instance' => 'The node is obsolete. Instead, use the ', + 'array' => 'The node is obsolete. Instead, use the ', + 'item[@key]' => 'The node is obsolete. Instead, use the ', + 'value' => 'The node is obsolete. Instead, provide the actual value as a text literal.' + ]; + + public function register(): array + { + return [ + T_INLINE_HTML + ]; + } + + public function process(File $phpcsFile, $stackPtr): int + { + $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(), + ), + $stackPtr, + self::ERROR_CODE + ); + } + + foreach ($this->xpathObsoleteElems as $obsoleteElem) { + $found = $xml->xpath($obsoleteElem); + if ($found === true) { + $phpcsFile->addWarning( + $this->messages[$obsoleteElem], + $stackPtr, + self::WARNING_CODE + ); + } + } + } + + /** + * 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(); + } +} \ No newline at end of file diff --git a/Magento2/Tests/Legacy/DiConfigUnitTest.php b/Magento2/Tests/Legacy/DiConfigUnitTest.php new file mode 100644 index 00000000..8df8fa91 --- /dev/null +++ b/Magento2/Tests/Legacy/DiConfigUnitTest.php @@ -0,0 +1,34 @@ + 1, + 10 => 1, + 11 => 1, + 12 => 1, + 13 => 1, + 15 => 1 + ]; + } +} \ No newline at end of file diff --git a/Magento2/Tests/Legacy/DiConfigUnitTest.xml b/Magento2/Tests/Legacy/DiConfigUnitTest.xml new file mode 100644 index 00000000..83b29690 --- /dev/null +++ b/Magento2/Tests/Legacy/DiConfigUnitTest.xml @@ -0,0 +1,19 @@ + + + + + + + + scalar20 + + 50.00 + + + + \ No newline at end of file diff --git a/Magento2/ruleset.xml b/Magento2/ruleset.xml index 3ea0c969..0a0621f9 100644 --- a/Magento2/ruleset.xml +++ b/Magento2/ruleset.xml @@ -223,6 +223,11 @@ 8 warning + + 8 + warning + *\/DiConfigUnitTest.xml$ + diff --git a/composer.json b/composer.json index d6004a88..f5037b17 100644 --- a/composer.json +++ b/composer.json @@ -10,7 +10,9 @@ "require": { "php": ">=7.3", "squizlabs/php_codesniffer": "^3.6", - "webonyx/graphql-php": "^14.9" + "webonyx/graphql-php": "^14.9", + "ext-simplexml": "*", + "ext-dom": "*" }, "require-dev": { "phpunit/phpunit": "^9.5.8" From 7be675fbbf7c0126fac003faa4a7dcadf5be965d Mon Sep 17 00:00:00 2001 From: Marc Ginesta Date: Wed, 25 Aug 2021 14:49:10 +0200 Subject: [PATCH 140/630] AC-660: Create phpcs static check for DiConfigTest - Add missing composer.lock --- composer.lock | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/composer.lock b/composer.lock index 72a2ad6a..04231d90 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": "1ed3638000f0e172d4e01c45333fcfb6", + "content-hash": "8c3c7509df274fdeaf09edfd7eac6cf5", "packages": [ { "name": "squizlabs/php_codesniffer", @@ -2228,7 +2228,9 @@ "prefer-stable": false, "prefer-lowest": false, "platform": { - "php": ">=7.3" + "php": ">=7.3", + "ext-simplexml": "*", + "ext-dom": "*" }, "platform-dev": [], "plugin-api-version": "2.1.0" From d58d4b5d0dc9724acd5dfdd000d7b6974f9295ad Mon Sep 17 00:00:00 2001 From: Marc Ginesta Date: Wed, 25 Aug 2021 15:01:40 +0200 Subject: [PATCH 141/630] 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 74d59535..04731e74 100644 --- a/Magento2/ruleset.xml +++ b/Magento2/ruleset.xml @@ -226,7 +226,7 @@ 8 warning - *\/DiConfigUnitTest.xml$ + *\/di.xml$ From d0039ffc610630ce5bfc46e2c1aecc882f11fcc3 Mon Sep 17 00:00:00 2001 From: Marc Ginesta Date: Wed, 25 Aug 2021 15:05:04 +0200 Subject: [PATCH 142/630] AC-660: Create phpcs static check for DiConfigTest - Run composer update --lock --- composer.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.lock b/composer.lock index 04231d90..fa12108d 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": "8c3c7509df274fdeaf09edfd7eac6cf5", + "content-hash": "503b3dff10c4885d5f5b196d159c1fdd", "packages": [ { "name": "squizlabs/php_codesniffer", From d8d8cb78a516a9267ede95096d5134e22e39552c Mon Sep 17 00:00:00 2001 From: Marc Ginesta Date: Wed, 25 Aug 2021 15:40:10 +0200 Subject: [PATCH 143/630] AC-660: Create phpcs static check for DiConfigTest - Fix return type --- Magento2/Sniffs/Legacy/DiConfigSniff.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Magento2/Sniffs/Legacy/DiConfigSniff.php b/Magento2/Sniffs/Legacy/DiConfigSniff.php index 680eb318..164036f7 100644 --- a/Magento2/Sniffs/Legacy/DiConfigSniff.php +++ b/Magento2/Sniffs/Legacy/DiConfigSniff.php @@ -38,7 +38,7 @@ public function register(): array ]; } - public function process(File $phpcsFile, $stackPtr): int + public function process(File $phpcsFile, $stackPtr) { $xml = simplexml_load_string($this->getFormattedXML($phpcsFile)); if ($xml === false) { From 5e4b15b4f61331ea8f877a5fc412ac52b0086deb Mon Sep 17 00:00:00 2001 From: Marc Ginesta Date: Wed, 25 Aug 2021 18:08:42 +0200 Subject: [PATCH 144/630] AC-660: Create phpcs static check for DiConfigTest - Update XML files --- Magento2/Tests/Legacy/DiConfigUnitTest.xml | 24 +++++++++++++--------- Magento2/ruleset.xml | 6 ++++-- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/Magento2/Tests/Legacy/DiConfigUnitTest.xml b/Magento2/Tests/Legacy/DiConfigUnitTest.xml index 83b29690..a1328a22 100644 --- a/Magento2/Tests/Legacy/DiConfigUnitTest.xml +++ b/Magento2/Tests/Legacy/DiConfigUnitTest.xml @@ -5,15 +5,19 @@ * See COPYING.txt for license details. */ --> - + + + + + Magento\Catalog\Pricing\Price\RegularPrice + + + - - - - scalar20 - - 50.00 - - + + + scalar5 + + - \ No newline at end of file + \ No newline at end of file diff --git a/Magento2/ruleset.xml b/Magento2/ruleset.xml index 04731e74..7d2c9fc1 100644 --- a/Magento2/ruleset.xml +++ b/Magento2/ruleset.xml @@ -3,7 +3,7 @@ Magento Coding Standard - + @@ -224,9 +224,10 @@ warning + *\/di.xml$ + *\/DiConfigUnitTest.xml$ 8 warning - *\/di.xml$ @@ -263,6 +264,7 @@ warning + *\.xml$ 7 warning From d08c40f4cfcfc61db58f55b3791b3b3666b7b0c4 Mon Sep 17 00:00:00 2001 From: Marc Ginesta Date: Fri, 27 Aug 2021 16:26:24 +0200 Subject: [PATCH 145/630] AC-660: Create phpcs static check for DiConfigTest - Refactor: Simplify approach --- Magento2/Sniffs/Legacy/DiConfigSniff.php | 55 ++++------------------ Magento2/Tests/Legacy/DiConfigUnitTest.php | 11 ++--- Magento2/Tests/Legacy/DiConfigUnitTest.xml | 2 +- Magento2/ruleset.xml | 1 - composer.json | 4 +- composer.lock | 6 +-- 6 files changed, 19 insertions(+), 60 deletions(-) diff --git a/Magento2/Sniffs/Legacy/DiConfigSniff.php b/Magento2/Sniffs/Legacy/DiConfigSniff.php index 164036f7..98f072f0 100644 --- a/Magento2/Sniffs/Legacy/DiConfigSniff.php +++ b/Magento2/Sniffs/Legacy/DiConfigSniff.php @@ -6,29 +6,19 @@ namespace Magento2\Sniffs\Legacy; -use DOMDocument; use PHP_CodeSniffer\Files\File; use PHP_CodeSniffer\Sniffs\Sniff; class DiConfigSniff implements Sniff { private const WARNING_CODE = 'FoundObsoleteAttribute'; - private const ERROR_CODE = 'WrongXML'; private $xpathObsoleteElems = [ - 'param', - 'instance', - 'array', - 'item[@key]', - 'value' - ]; - - private $messages = [ - 'param' => 'The node is obsolete. Instead, use the ', - 'instance' => 'The node is obsolete. Instead, use the ', - 'array' => 'The node is obsolete. Instead, use the ', - 'item[@key]' => 'The node is obsolete. Instead, use the ', - 'value' => 'The node is obsolete. Instead, provide the actual value as a text literal.' + ' 'The node is obsolete. Instead, use the ', + ' 'The node is obsolete. Instead, use the ', + ' 'The node is obsolete. Instead, use the ', + ' node is obsolete. Instead, use the ', + ' 'The node is obsolete. Instead, provide the actual value as a text literal.' ]; public function register(): array @@ -40,41 +30,16 @@ public function register(): array 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(), - ), - $stackPtr, - self::ERROR_CODE - ); - } + $lineContent = $phpcsFile->getTokensAsString($stackPtr, 1); - foreach ($this->xpathObsoleteElems as $obsoleteElem) { - $found = $xml->xpath($obsoleteElem); - if ($found === true) { + foreach ($this->xpathObsoleteElems as $elem => $message ) { + if (strpos($lineContent, $elem) !== false) { $phpcsFile->addWarning( - $this->messages[$obsoleteElem], + $message, $stackPtr, self::WARNING_CODE ); } } } - - /** - * 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(); - } -} \ No newline at end of file +} diff --git a/Magento2/Tests/Legacy/DiConfigUnitTest.php b/Magento2/Tests/Legacy/DiConfigUnitTest.php index 8df8fa91..d5dad883 100644 --- a/Magento2/Tests/Legacy/DiConfigUnitTest.php +++ b/Magento2/Tests/Legacy/DiConfigUnitTest.php @@ -23,12 +23,11 @@ public function getErrorList(): array public function getWarningList(): array { return [ - 9 => 1, - 10 => 1, - 11 => 1, 12 => 1, - 13 => 1, - 15 => 1 + 16 => 1, + 17 => 1, + 18 => 1, + 19 => 1 ]; } -} \ No newline at end of file +} diff --git a/Magento2/Tests/Legacy/DiConfigUnitTest.xml b/Magento2/Tests/Legacy/DiConfigUnitTest.xml index a1328a22..048e31b4 100644 --- a/Magento2/Tests/Legacy/DiConfigUnitTest.xml +++ b/Magento2/Tests/Legacy/DiConfigUnitTest.xml @@ -20,4 +20,4 @@ - \ No newline at end of file + diff --git a/Magento2/ruleset.xml b/Magento2/ruleset.xml index 7d2c9fc1..7b1e78f7 100644 --- a/Magento2/ruleset.xml +++ b/Magento2/ruleset.xml @@ -225,7 +225,6 @@ *\/di.xml$ - *\/DiConfigUnitTest.xml$ 8 warning diff --git a/composer.json b/composer.json index 267fcaa3..f30fd7fd 100644 --- a/composer.json +++ b/composer.json @@ -10,9 +10,7 @@ "require": { "php": ">=7.3", "squizlabs/php_codesniffer": "^3.6", - "webonyx/graphql-php": "^14.9", - "ext-simplexml": "*", - "ext-dom": "*" + "webonyx/graphql-php": "^14.9" }, "require-dev": { "phpunit/phpunit": "^9.5.8" diff --git a/composer.lock b/composer.lock index fa12108d..c26f9e74 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": "503b3dff10c4885d5f5b196d159c1fdd", + "content-hash": "93bec1b3a36cf67f2511aec0219bcc06", "packages": [ { "name": "squizlabs/php_codesniffer", @@ -2228,9 +2228,7 @@ "prefer-stable": false, "prefer-lowest": false, "platform": { - "php": ">=7.3", - "ext-simplexml": "*", - "ext-dom": "*" + "php": ">=7.3" }, "platform-dev": [], "plugin-api-version": "2.1.0" From 6031c1e7e9e4fa570e125290cbef22bae4c4487d Mon Sep 17 00:00:00 2001 From: Marc Ginesta Date: Fri, 27 Aug 2021 16:29:48 +0200 Subject: [PATCH 146/630] AC-660: Create phpcs static check for DiConfigTest - Fix phpcs --- Magento2/Sniffs/Legacy/DiConfigSniff.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Magento2/Sniffs/Legacy/DiConfigSniff.php b/Magento2/Sniffs/Legacy/DiConfigSniff.php index 98f072f0..41dea6e7 100644 --- a/Magento2/Sniffs/Legacy/DiConfigSniff.php +++ b/Magento2/Sniffs/Legacy/DiConfigSniff.php @@ -21,6 +21,9 @@ class DiConfigSniff implements Sniff ' 'The node is obsolete. Instead, provide the actual value as a text literal.' ]; + /** + * @inheritDoc + */ public function register(): array { return [ @@ -28,11 +31,14 @@ public function register(): array ]; } + /** + * @inheritDoc + */ public function process(File $phpcsFile, $stackPtr) { $lineContent = $phpcsFile->getTokensAsString($stackPtr, 1); - foreach ($this->xpathObsoleteElems as $elem => $message ) { + foreach ($this->xpathObsoleteElems as $elem => $message) { if (strpos($lineContent, $elem) !== false) { $phpcsFile->addWarning( $message, From 8c600476101fb590a797b697810b4d7111d58aed Mon Sep 17 00:00:00 2001 From: Marc Ginesta Date: Sat, 28 Aug 2021 10:42:27 +0200 Subject: [PATCH 147/630] AC-660: Create phpcs static check for DiConfigTest - Refactor: Rename variables and add phpdoc --- Magento2/Sniffs/Legacy/DiConfigSniff.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Magento2/Sniffs/Legacy/DiConfigSniff.php b/Magento2/Sniffs/Legacy/DiConfigSniff.php index 41dea6e7..954c32e0 100644 --- a/Magento2/Sniffs/Legacy/DiConfigSniff.php +++ b/Magento2/Sniffs/Legacy/DiConfigSniff.php @@ -13,7 +13,10 @@ class DiConfigSniff implements Sniff { private const WARNING_CODE = 'FoundObsoleteAttribute'; - private $xpathObsoleteElems = [ + /** + * @var string[] Associative array containing the obsolete nodes and the message to display when they are found. + */ + private $obsoleteDiNodes = [ ' 'The node is obsolete. Instead, use the ', ' 'The node is obsolete. Instead, use the ', ' 'The node is obsolete. Instead, use the ', @@ -38,8 +41,8 @@ public function process(File $phpcsFile, $stackPtr) { $lineContent = $phpcsFile->getTokensAsString($stackPtr, 1); - foreach ($this->xpathObsoleteElems as $elem => $message) { - if (strpos($lineContent, $elem) !== false) { + foreach ($this->obsoleteDiNodes as $element => $message) { + if (strpos($lineContent, $element) !== false) { $phpcsFile->addWarning( $message, $stackPtr, From a4538fe599750ebb92b6174d75747d0da3505803 Mon Sep 17 00:00:00 2001 From: Sergio Vera Date: Mon, 30 Aug 2021 12:52:02 +0200 Subject: [PATCH 148/630] AC-940: Create unit test for Magento2\Less\BracesFormattingSniff check --- .../Tests/Less/BracesFormattingUnitTest.less | 16 +++++++++++ .../Tests/Less/BracesFormattingUnitTest.php | 28 +++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 Magento2/Tests/Less/BracesFormattingUnitTest.less create mode 100644 Magento2/Tests/Less/BracesFormattingUnitTest.php diff --git a/Magento2/Tests/Less/BracesFormattingUnitTest.less b/Magento2/Tests/Less/BracesFormattingUnitTest.less new file mode 100644 index 00000000..952237f4 --- /dev/null +++ b/Magento2/Tests/Less/BracesFormattingUnitTest.less @@ -0,0 +1,16 @@ +// /** +// * Copyright © Magento, Inc. All rights reserved. +// * See COPYING.txt for license details. +// */ + +.my{ + some: 'stuff'; +} +.foo { + anything: 'else'; +} + +.bar { + #bar .baz(); + +} diff --git a/Magento2/Tests/Less/BracesFormattingUnitTest.php b/Magento2/Tests/Less/BracesFormattingUnitTest.php new file mode 100644 index 00000000..ebbea8ee --- /dev/null +++ b/Magento2/Tests/Less/BracesFormattingUnitTest.php @@ -0,0 +1,28 @@ + 1, + 16 => 1, + ]; + } + + /** + * @inheritdoc + */ + public function getWarningList() + { + return []; + } +} From fad9a4472b0fba3d621685bd68bcd881a2dd9125 Mon Sep 17 00:00:00 2001 From: Sergio Vera Date: Mon, 30 Aug 2021 13:18:38 +0200 Subject: [PATCH 149/630] AC-942: Create unit test for Magento2\Less\ColonSpacingSniff check --- Magento2/Sniffs/Less/ColonSpacingSniff.php | 4 +-- Magento2/Tests/Less/ColonSpacingUnitTest.less | 26 +++++++++++++++++ Magento2/Tests/Less/ColonSpacingUnitTest.php | 29 +++++++++++++++++++ 3 files changed, 57 insertions(+), 2 deletions(-) create mode 100644 Magento2/Tests/Less/ColonSpacingUnitTest.less create mode 100644 Magento2/Tests/Less/ColonSpacingUnitTest.php diff --git a/Magento2/Sniffs/Less/ColonSpacingSniff.php b/Magento2/Sniffs/Less/ColonSpacingSniff.php index 6ada0fac..dd8fee7f 100644 --- a/Magento2/Sniffs/Less/ColonSpacingSniff.php +++ b/Magento2/Sniffs/Less/ColonSpacingSniff.php @@ -12,7 +12,7 @@ /** * Class ColonSpacingSniff * - * Ensure that single quotes are used + * Ensure that colon spacing is right * * @link https://devdocs.magento.com/guides/v2.4/coding-standards/code-standard-less.html#properties-colon-indents */ @@ -101,7 +101,7 @@ private function validateSpaces(File $phpcsFile, $stackPtr, array $tokens) if (false === strpos($content, $phpcsFile->eolChar)) { $length = strlen($content); if ($length !== 1) { - $error = 'Expected 1 space after colon in style definition; %s found'; + $error = sprintf('Expected 1 space after colon in style definition; %s found', $length); $phpcsFile->addError($error, $stackPtr, 'After'); } } else { diff --git a/Magento2/Tests/Less/ColonSpacingUnitTest.less b/Magento2/Tests/Less/ColonSpacingUnitTest.less new file mode 100644 index 00000000..d888af2e --- /dev/null +++ b/Magento2/Tests/Less/ColonSpacingUnitTest.less @@ -0,0 +1,26 @@ +// /** +// * Copyright © Magento, Inc. All rights reserved. +// * See COPYING.txt for license details. +// */ + + +div#foo { + blah:'abc'; +} + +.my #foo .blah { + some: 'stuff'; +} + +.blah { + foo :'xyz'; +} + +.foo { + bar: + 'xyz'; +} + +.right { + way: 'good' +} diff --git a/Magento2/Tests/Less/ColonSpacingUnitTest.php b/Magento2/Tests/Less/ColonSpacingUnitTest.php new file mode 100644 index 00000000..b50e47d0 --- /dev/null +++ b/Magento2/Tests/Less/ColonSpacingUnitTest.php @@ -0,0 +1,29 @@ + 1, + 12 => 1, + 16 => 2, + ]; + } + + /** + * @inheritdoc + */ + public function getWarningList() + { + return []; + } +} From 0b6fe4b2aaa000dc5b8d3bfba49e7ee11cf9583c Mon Sep 17 00:00:00 2001 From: Sergio Vera Date: Mon, 30 Aug 2021 13:55:52 +0200 Subject: [PATCH 150/630] AC-943: Create unit test for Magento2\Less\ColourDefinitionSniff check --- .../Sniffs/Less/ColourDefinitionSniff.php | 2 +- .../Tests/Less/ColourDefinitionUnitTest.less | 24 +++++++++++++++ .../Tests/Less/ColourDefinitionUnitTest.php | 29 +++++++++++++++++++ 3 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 Magento2/Tests/Less/ColourDefinitionUnitTest.less create mode 100644 Magento2/Tests/Less/ColourDefinitionUnitTest.php diff --git a/Magento2/Sniffs/Less/ColourDefinitionSniff.php b/Magento2/Sniffs/Less/ColourDefinitionSniff.php index 82568824..afebb9a9 100644 --- a/Magento2/Sniffs/Less/ColourDefinitionSniff.php +++ b/Magento2/Sniffs/Less/ColourDefinitionSniff.php @@ -42,7 +42,7 @@ public function process(File $phpcsFile, $stackPtr) $variablePtr = $phpcsFile->findPrevious(T_ASPERAND, $stackPtr); if ((false === $variablePtr) || ($tokens[$stackPtr]['line'] !== $tokens[$variablePtr]['line'])) { - $phpcsFile->addError('Hexadecimal value should be used for variable', $stackPtr, 'NotInVariable'); + $phpcsFile->addError('Hexadecimal value should be get from a variable', $stackPtr, 'NotInVariable'); } $expected = strtolower($colour); diff --git a/Magento2/Tests/Less/ColourDefinitionUnitTest.less b/Magento2/Tests/Less/ColourDefinitionUnitTest.less new file mode 100644 index 00000000..e32323f9 --- /dev/null +++ b/Magento2/Tests/Less/ColourDefinitionUnitTest.less @@ -0,0 +1,24 @@ +// /** +// * Copyright © Magento, Inc. All rights reserved. +// * See COPYING.txt for license details. +// */ + +@red: #aaaaaa; +@blue: #00F; +@green: #0f0; + +.my{ + color: @red; +} + +.foo { + color: #aaa; +} + +.baz { + color: @blue; +} + +.bar { + color: @green; +} diff --git a/Magento2/Tests/Less/ColourDefinitionUnitTest.php b/Magento2/Tests/Less/ColourDefinitionUnitTest.php new file mode 100644 index 00000000..34862ed2 --- /dev/null +++ b/Magento2/Tests/Less/ColourDefinitionUnitTest.php @@ -0,0 +1,29 @@ + 1, + 7 => 1, + 15 => 1, + ]; + } + + /** + * @inheritdoc + */ + public function getWarningList() + { + return []; + } +} From 1153ab2177f93520f507e8e766c837fb1ed39c5d Mon Sep 17 00:00:00 2001 From: Sergio Vera Date: Tue, 31 Aug 2021 12:07:41 +0200 Subject: [PATCH 151/630] AC-943: Create unit test for Magento2\Less\ColourDefinitionSniff check --- Magento2/Sniffs/Less/ColourDefinitionSniff.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Magento2/Sniffs/Less/ColourDefinitionSniff.php b/Magento2/Sniffs/Less/ColourDefinitionSniff.php index afebb9a9..945abffd 100644 --- a/Magento2/Sniffs/Less/ColourDefinitionSniff.php +++ b/Magento2/Sniffs/Less/ColourDefinitionSniff.php @@ -42,7 +42,7 @@ public function process(File $phpcsFile, $stackPtr) $variablePtr = $phpcsFile->findPrevious(T_ASPERAND, $stackPtr); if ((false === $variablePtr) || ($tokens[$stackPtr]['line'] !== $tokens[$variablePtr]['line'])) { - $phpcsFile->addError('Hexadecimal value should be get from a variable', $stackPtr, 'NotInVariable'); + $phpcsFile->addError('A variable should be used for a CSS colour', $stackPtr, 'NotInVariable'); } $expected = strtolower($colour); From ba918266ed9276316d8ff5d599f2f0acd3453178 Mon Sep 17 00:00:00 2001 From: Sergio Vera Date: Tue, 31 Aug 2021 15:15:57 +0200 Subject: [PATCH 152/630] AC-948: Create unit test for Magento2\Less\PropertiesLineBreakSniff check --- .../Less/PropertiesLineBreakUnitTest.less | 12 +++++++++ .../Less/PropertiesLineBreakUnitTest.php | 27 +++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 Magento2/Tests/Less/PropertiesLineBreakUnitTest.less create mode 100644 Magento2/Tests/Less/PropertiesLineBreakUnitTest.php diff --git a/Magento2/Tests/Less/PropertiesLineBreakUnitTest.less b/Magento2/Tests/Less/PropertiesLineBreakUnitTest.less new file mode 100644 index 00000000..885a2fa9 --- /dev/null +++ b/Magento2/Tests/Less/PropertiesLineBreakUnitTest.less @@ -0,0 +1,12 @@ +// /** +// * Copyright © Magento, Inc. All rights reserved. +// * See COPYING.txt for license details. +// */ + +.my{ + some: 'stuff'; anything: 'else'; +} + +.foo { + anything: 'else'; +} diff --git a/Magento2/Tests/Less/PropertiesLineBreakUnitTest.php b/Magento2/Tests/Less/PropertiesLineBreakUnitTest.php new file mode 100644 index 00000000..61477f03 --- /dev/null +++ b/Magento2/Tests/Less/PropertiesLineBreakUnitTest.php @@ -0,0 +1,27 @@ + 1, + ]; + } + + /** + * @inheritdoc + */ + public function getWarningList() + { + return []; + } +} From cf9c0dd7d21e0b283085d5ac99cf081c1fb3a348 Mon Sep 17 00:00:00 2001 From: Magento Community Engineering <31669971+magento-engcom-team@users.noreply.github.com> Date: Tue, 31 Aug 2021 10:01:55 -0500 Subject: [PATCH 153/630] [Imported] AC-945: Create unit test for Magento2\Less\CommentLevelsSniff check (#34) https://jira.corp.magento.com/browse/AC-945 --- .../Tests/Less/CommentLevelsUnitTest.less | 48 +++++++++++++++++++ Magento2/Tests/Less/CommentLevelsUnitTest.php | 32 +++++++++++++ 2 files changed, 80 insertions(+) create mode 100644 Magento2/Tests/Less/CommentLevelsUnitTest.less create mode 100644 Magento2/Tests/Less/CommentLevelsUnitTest.php diff --git a/Magento2/Tests/Less/CommentLevelsUnitTest.less b/Magento2/Tests/Less/CommentLevelsUnitTest.less new file mode 100644 index 00000000..77d3dbd7 --- /dev/null +++ b/Magento2/Tests/Less/CommentLevelsUnitTest.less @@ -0,0 +1,48 @@ +// /** +// * Copyright © Magento, Inc. All rights reserved. +// * See COPYING.txt for license details. +// */ + +// +// First level comment +// _____________________________________________ + +.first-level { + background-color: green; +} + +// +// Incorrect First level comment +// _____________________________________________ +.incorrect-first-level { + background-color: red; +} + +// +// Second level comment +// --------------------------------------------- + +.second-level { + background-color: green; +} + +// +// Incorrect Second level comment +// --------------------------------------------- + +.incorrect-second-level { + background-color: red; +} + +// third level comment +.third-level-nav { + // New line comment, considered third level too + background-color: green; // ToDo UI: todo inline comment + color: white; // inline comment +} + +//Incorrect third level comment +.incorrect-third-level { + // Incorrect new line comment + color: red; // incorrect inline comment +} diff --git a/Magento2/Tests/Less/CommentLevelsUnitTest.php b/Magento2/Tests/Less/CommentLevelsUnitTest.php new file mode 100644 index 00000000..9e5315d9 --- /dev/null +++ b/Magento2/Tests/Less/CommentLevelsUnitTest.php @@ -0,0 +1,32 @@ + 1, + 30 => 1, + 31 => 1, + 44 => 1, + 46 => 1, + 47 => 1 + ]; + } + + /** + * @inheritdoc + */ + public function getWarningList() + { + return []; + } +} From e71dbf8b46409c222ba9fa3811fcec47ba6b57f0 Mon Sep 17 00:00:00 2001 From: Magento Community Engineering <31669971+magento-engcom-team@users.noreply.github.com> Date: Tue, 31 Aug 2021 10:08:20 -0500 Subject: [PATCH 154/630] [Imported] AC-946: Create unit test for Magento2\Less\ImportantPropertySniff check (#35) https://jira.corp.magento.com/browse/AC-946 --- .../Tests/Less/ImportantPropertyUnitTest.less | 12 +++++++++ .../Tests/Less/ImportantPropertyUnitTest.php | 27 +++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 Magento2/Tests/Less/ImportantPropertyUnitTest.less create mode 100644 Magento2/Tests/Less/ImportantPropertyUnitTest.php diff --git a/Magento2/Tests/Less/ImportantPropertyUnitTest.less b/Magento2/Tests/Less/ImportantPropertyUnitTest.less new file mode 100644 index 00000000..0a0783ba --- /dev/null +++ b/Magento2/Tests/Less/ImportantPropertyUnitTest.less @@ -0,0 +1,12 @@ +// /** +// * Copyright © Magento, Inc. All rights reserved. +// * See COPYING.txt for license details. +// */ + +.correct-important-property { + background-color: green !important; +} + +.incorrect-important-property { + background-color: red!important; +} diff --git a/Magento2/Tests/Less/ImportantPropertyUnitTest.php b/Magento2/Tests/Less/ImportantPropertyUnitTest.php new file mode 100644 index 00000000..c3044415 --- /dev/null +++ b/Magento2/Tests/Less/ImportantPropertyUnitTest.php @@ -0,0 +1,27 @@ + 1 + ]; + } + + /** + * @inheritdoc + */ + public function getWarningList() + { + return []; + } +} From 4b2ca825d0fe1bb26804ad6c0d2c7d68dc2f7cbb Mon Sep 17 00:00:00 2001 From: Magento Community Engineering <31669971+magento-engcom-team@users.noreply.github.com> Date: Tue, 31 Aug 2021 10:11:04 -0500 Subject: [PATCH 155/630] [Imported] AC-947: Create unit test for Magento2\Less\IndentationSniff check (#36) https://jira.corp.magento.com/browse/AC-947 --- Magento2/Tests/Less/IndentationUnitTest.less | 21 +++++++++++++ Magento2/Tests/Less/IndentationUnitTest.php | 33 ++++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 Magento2/Tests/Less/IndentationUnitTest.less create mode 100644 Magento2/Tests/Less/IndentationUnitTest.php diff --git a/Magento2/Tests/Less/IndentationUnitTest.less b/Magento2/Tests/Less/IndentationUnitTest.less new file mode 100644 index 00000000..1ddbff6f --- /dev/null +++ b/Magento2/Tests/Less/IndentationUnitTest.less @@ -0,0 +1,21 @@ +// /** +// * Copyright © Magento, Inc. All rights reserved. +// * See COPYING.txt for license details. +// */ + +.nav { + background: green; + .nav-item { + background: green; + } +} + +.bar { + background: red; + .bar-item { + background: red; + .bar-item-child { + background: red; + } + } +} diff --git a/Magento2/Tests/Less/IndentationUnitTest.php b/Magento2/Tests/Less/IndentationUnitTest.php new file mode 100644 index 00000000..a7bf6502 --- /dev/null +++ b/Magento2/Tests/Less/IndentationUnitTest.php @@ -0,0 +1,33 @@ + 1, + 15 => 1, + 16 => 1, + 17 => 1, + 18 => 1, + 19 => 1, + 20 => 1 + ]; + } + + /** + * @inheritdoc + */ + public function getWarningList() + { + return []; + } +} From 0759da94ae2c489bf46077b43fe30bc83b89fb11 Mon Sep 17 00:00:00 2001 From: Magento Community Engineering <31669971+magento-engcom-team@users.noreply.github.com> Date: Tue, 31 Aug 2021 10:21:24 -0500 Subject: [PATCH 156/630] [Imported] AC-941: Create unit test for Magento2\Less\ClassNamingSniff check (#38) https://jira.corp.magento.com/browse/AC-941 --- Magento2/Sniffs/Less/ClassNamingSniff.php | 19 +++++++++--- Magento2/Tests/Less/ClassNamingUnitTest.less | 32 ++++++++++++++++++++ Magento2/Tests/Less/ClassNamingUnitTest.php | 30 ++++++++++++++++++ 3 files changed, 76 insertions(+), 5 deletions(-) create mode 100644 Magento2/Tests/Less/ClassNamingUnitTest.less create mode 100644 Magento2/Tests/Less/ClassNamingUnitTest.php diff --git a/Magento2/Sniffs/Less/ClassNamingSniff.php b/Magento2/Sniffs/Less/ClassNamingSniff.php index 90d44280..e684172b 100644 --- a/Magento2/Sniffs/Less/ClassNamingSniff.php +++ b/Magento2/Sniffs/Less/ClassNamingSniff.php @@ -21,10 +21,7 @@ */ class ClassNamingSniff implements Sniff { - - const STRING_HELPER_CLASSES_PREFIX = '_'; - - const STRING_ALLOWED_UNDERSCORES = '__'; + private const STRING_HELPER_CLASSES_PREFIX = '_'; /** * A list of tokenizers this sniff supports. @@ -62,7 +59,19 @@ public function process(File $phpcsFile, $stackPtr) $className = $tokens[$stackPtr + 1]['content']; if (preg_match_all('/[^a-z0-9\-_]/U', $className, $matches)) { - $phpcsFile->addError('Class name contains not allowed symbols', $stackPtr, 'NotAllowedSymbol', $matches); + $phpcsFile->addError( + 'CSS class name does not follow class naming requirements: %s', + $stackPtr, + 'NotAllowedSymbol', + [implode("", $matches[0])] + ); + } + if (strpos($className, self::STRING_HELPER_CLASSES_PREFIX, 2) !== false) { + $phpcsFile->addError( + 'CSS class names should be separated with "-" (dash) instead of "_" (underscore)', + $stackPtr, + 'NotAllowedSymbol' + ); } } } diff --git a/Magento2/Tests/Less/ClassNamingUnitTest.less b/Magento2/Tests/Less/ClassNamingUnitTest.less new file mode 100644 index 00000000..ba60c205 --- /dev/null +++ b/Magento2/Tests/Less/ClassNamingUnitTest.less @@ -0,0 +1,32 @@ +// /** +// * Copyright © Magento, Inc. All rights reserved. +// * See COPYING.txt for license details. +// */ + +.UPPERCASE { + background: red; +} + +.Capital { + background: red; +} + +.camelCase { + background: red; +} + +.snake_case { + background: red; +} + +._helper { + background: green; +} + +.__another-helper { + background: green; +} + +.category-title { + background: green; +} diff --git a/Magento2/Tests/Less/ClassNamingUnitTest.php b/Magento2/Tests/Less/ClassNamingUnitTest.php new file mode 100644 index 00000000..c50ff1bf --- /dev/null +++ b/Magento2/Tests/Less/ClassNamingUnitTest.php @@ -0,0 +1,30 @@ + 1, + 10 => 1, + 14 => 1, + 18 => 1 + ]; + } + + /** + * @inheritdoc + */ + public function getWarningList() + { + return []; + } +} From faddd308916a331a3157fbc88df5cc8c4358279d Mon Sep 17 00:00:00 2001 From: Magento Community Engineering <31669971+magento-engcom-team@users.noreply.github.com> Date: Tue, 31 Aug 2021 10:23:43 -0500 Subject: [PATCH 157/630] AC-949: Create unit test for Magento2\Less\PropertiesSortingSniff check (#37) https://jira.corp.magento.com/browse/AC-949 --- .../Tests/Less/PropertiesSortingUnitTest.less | 28 +++++++++++++++++++ .../Tests/Less/PropertiesSortingUnitTest.php | 28 +++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 Magento2/Tests/Less/PropertiesSortingUnitTest.less create mode 100644 Magento2/Tests/Less/PropertiesSortingUnitTest.php diff --git a/Magento2/Tests/Less/PropertiesSortingUnitTest.less b/Magento2/Tests/Less/PropertiesSortingUnitTest.less new file mode 100644 index 00000000..9e67fff8 --- /dev/null +++ b/Magento2/Tests/Less/PropertiesSortingUnitTest.less @@ -0,0 +1,28 @@ +// /** +// * Copyright © Magento, Inc. All rights reserved. +// * See COPYING.txt for license details. +// */ + +.menu { + color: white; + text-align: center; + background-color: red; + + .item { + background-color: green; + color: white; + text-align: center; + } +} + +.nav { + background-color: green; + color: white; + text-align: center; + + .item { + color: white; + text-align: center; + background-color: red; + } +} diff --git a/Magento2/Tests/Less/PropertiesSortingUnitTest.php b/Magento2/Tests/Less/PropertiesSortingUnitTest.php new file mode 100644 index 00000000..e32561e5 --- /dev/null +++ b/Magento2/Tests/Less/PropertiesSortingUnitTest.php @@ -0,0 +1,28 @@ + 1, + 26 => 1 + ]; + } + + /** + * @inheritdoc + */ + public function getWarningList() + { + return []; + } +} From d4dc9e2fd2881e4400444891012b2229e45de64a Mon Sep 17 00:00:00 2001 From: Magento Community Engineering <31669971+magento-engcom-team@users.noreply.github.com> Date: Tue, 31 Aug 2021 10:27:50 -0500 Subject: [PATCH 158/630] AC-951: Create unit test for Magento2\Less\SelectorDelimiterSniff check (#39) https://jira.corp.magento.com/browse/AC-951 --- .../Tests/Less/SelectorDelimiterUnitTest.less | 13 +++++++++ .../Tests/Less/SelectorDelimiterUnitTest.php | 27 +++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 Magento2/Tests/Less/SelectorDelimiterUnitTest.less create mode 100644 Magento2/Tests/Less/SelectorDelimiterUnitTest.php diff --git a/Magento2/Tests/Less/SelectorDelimiterUnitTest.less b/Magento2/Tests/Less/SelectorDelimiterUnitTest.less new file mode 100644 index 00000000..1ff936ea --- /dev/null +++ b/Magento2/Tests/Less/SelectorDelimiterUnitTest.less @@ -0,0 +1,13 @@ +// /** +// * Copyright © Magento, Inc. All rights reserved. +// * See COPYING.txt for license details. +// */ + +.nav, +.bar { + background: green; +} + +.nav, .bar { + background: red; +} diff --git a/Magento2/Tests/Less/SelectorDelimiterUnitTest.php b/Magento2/Tests/Less/SelectorDelimiterUnitTest.php new file mode 100644 index 00000000..9fced2eb --- /dev/null +++ b/Magento2/Tests/Less/SelectorDelimiterUnitTest.php @@ -0,0 +1,27 @@ + 1 + ]; + } + + /** + * @inheritdoc + */ + public function getWarningList() + { + return []; + } +} From fce7c6e231018ed09209c8014fa0b818ec3c1af6 Mon Sep 17 00:00:00 2001 From: Marc Ginesta Date: Tue, 31 Aug 2021 18:10:00 +0200 Subject: [PATCH 159/630] AC-952: Create unit test for Magento2\Less\SemicolonSpacingSniff check --- .../Tests/Less/SemicolonSpacingUnitTest.less | 13 +++++++++ .../Tests/Less/SemicolonSpacingUnitTest.php | 27 +++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 Magento2/Tests/Less/SemicolonSpacingUnitTest.less create mode 100644 Magento2/Tests/Less/SemicolonSpacingUnitTest.php diff --git a/Magento2/Tests/Less/SemicolonSpacingUnitTest.less b/Magento2/Tests/Less/SemicolonSpacingUnitTest.less new file mode 100644 index 00000000..b7721cde --- /dev/null +++ b/Magento2/Tests/Less/SemicolonSpacingUnitTest.less @@ -0,0 +1,13 @@ +// /** +// * Copyright © Magento, Inc. All rights reserved. +// * See COPYING.txt for license details. +// */ + +.nav { + background-color: green +} + +.bar { + background-color: red + color: white +} diff --git a/Magento2/Tests/Less/SemicolonSpacingUnitTest.php b/Magento2/Tests/Less/SemicolonSpacingUnitTest.php new file mode 100644 index 00000000..fe5d9d92 --- /dev/null +++ b/Magento2/Tests/Less/SemicolonSpacingUnitTest.php @@ -0,0 +1,27 @@ + 1 + ]; + } + + /** + * @inheritdoc + */ + public function getWarningList() + { + return []; + } +} From 6bf26ababffebaac3d98a75d54eef0773c0c0255 Mon Sep 17 00:00:00 2001 From: Marc Ginesta Date: Tue, 31 Aug 2021 18:32:27 +0200 Subject: [PATCH 160/630] AC-953: Create unit test for Magento2\Less\TypeSelectorConcatenationSniff check --- .../TypeSelectorConcatenationUnitTest.less | 25 +++++++++++++++++ .../TypeSelectorConcatenationUnitTest.php | 28 +++++++++++++++++++ 2 files changed, 53 insertions(+) create mode 100644 Magento2/Tests/Less/TypeSelectorConcatenationUnitTest.less create mode 100644 Magento2/Tests/Less/TypeSelectorConcatenationUnitTest.php diff --git a/Magento2/Tests/Less/TypeSelectorConcatenationUnitTest.less b/Magento2/Tests/Less/TypeSelectorConcatenationUnitTest.less new file mode 100644 index 00000000..74216d54 --- /dev/null +++ b/Magento2/Tests/Less/TypeSelectorConcatenationUnitTest.less @@ -0,0 +1,25 @@ +// /** +// * Copyright © Magento, Inc. All rights reserved. +// * See COPYING.txt for license details. +// */ + +.product-list-item { + background: green; +} + +.product-image { + background: green; +} + +.product { + random: 'stuff '; + &-list { + background: red; + &-item { + background: red; + } + } + &-image { + background: red; + } +} diff --git a/Magento2/Tests/Less/TypeSelectorConcatenationUnitTest.php b/Magento2/Tests/Less/TypeSelectorConcatenationUnitTest.php new file mode 100644 index 00000000..1fbe3227 --- /dev/null +++ b/Magento2/Tests/Less/TypeSelectorConcatenationUnitTest.php @@ -0,0 +1,28 @@ + 1, + 22 => 1 + ]; + } + + /** + * @inheritdoc + */ + public function getWarningList() + { + return []; + } +} From 4bc13c9f42ff9ec947fc9b235ddfc31c6f2de16a Mon Sep 17 00:00:00 2001 From: Marc Ginesta Date: Tue, 31 Aug 2021 18:35:01 +0200 Subject: [PATCH 161/630] AC-953: Create unit test for Magento2\Less\TypeSelectorConcatenationSniff check - Amend typo --- Magento2/Tests/Less/TypeSelectorConcatenationUnitTest.less | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Magento2/Tests/Less/TypeSelectorConcatenationUnitTest.less b/Magento2/Tests/Less/TypeSelectorConcatenationUnitTest.less index 74216d54..241af673 100644 --- a/Magento2/Tests/Less/TypeSelectorConcatenationUnitTest.less +++ b/Magento2/Tests/Less/TypeSelectorConcatenationUnitTest.less @@ -12,7 +12,7 @@ } .product { - random: 'stuff '; + random: 'stuff'; &-list { background: red; &-item { From 446372ac1623435627d84c385ad3fddc95f12404 Mon Sep 17 00:00:00 2001 From: Marc Ginesta Date: Wed, 1 Sep 2021 09:43:06 +0200 Subject: [PATCH 162/630] AC-952: Create unit test for Magento2\Less\SemicolonSpacingSniff check - Refactor: Fix indentation --- Magento2/Tests/Less/SemicolonSpacingUnitTest.less | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Magento2/Tests/Less/SemicolonSpacingUnitTest.less b/Magento2/Tests/Less/SemicolonSpacingUnitTest.less index b7721cde..bf68b499 100644 --- a/Magento2/Tests/Less/SemicolonSpacingUnitTest.less +++ b/Magento2/Tests/Less/SemicolonSpacingUnitTest.less @@ -4,10 +4,10 @@ // */ .nav { - background-color: green + background-color: green } -.bar { - background-color: red - color: white +.nav-list { + background-color: red + color: white } From 14ad98a4af6dda6f50387b3e180bd7c867467c5b Mon Sep 17 00:00:00 2001 From: Sergio Vera Date: Wed, 1 Sep 2021 11:23:46 +0200 Subject: [PATCH 163/630] AC-950: Create unit test for Magento2\Less\QuotesSniff check --- Magento2/Tests/Less/QuotesSniffUnitTest.less | 12 +++++++++ Magento2/Tests/Less/QuotesSniffUnitTest.php | 27 ++++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 Magento2/Tests/Less/QuotesSniffUnitTest.less create mode 100644 Magento2/Tests/Less/QuotesSniffUnitTest.php diff --git a/Magento2/Tests/Less/QuotesSniffUnitTest.less b/Magento2/Tests/Less/QuotesSniffUnitTest.less new file mode 100644 index 00000000..1b300703 --- /dev/null +++ b/Magento2/Tests/Less/QuotesSniffUnitTest.less @@ -0,0 +1,12 @@ +// /** +// * Copyright © Magento, Inc. All rights reserved. +// * See COPYING.txt for license details. +// */ + +.my{ + some: "stuff"; +} + +.foo { + anything: 'else'; +} diff --git a/Magento2/Tests/Less/QuotesSniffUnitTest.php b/Magento2/Tests/Less/QuotesSniffUnitTest.php new file mode 100644 index 00000000..eb0fa5cb --- /dev/null +++ b/Magento2/Tests/Less/QuotesSniffUnitTest.php @@ -0,0 +1,27 @@ + 1, + ]; + } + + /** + * @inheritdoc + */ + public function getWarningList() + { + return []; + } +} From e619db357ee8490f9882934a50f40f037128a805 Mon Sep 17 00:00:00 2001 From: Sergio Vera Date: Wed, 1 Sep 2021 11:48:52 +0200 Subject: [PATCH 164/630] AC-950: Create unit test for Magento2\Less\QuotesSniff check --- .../Tests/Less/{QuotesSniffUnitTest.less => QuotesUnitTest.less} | 0 .../Tests/Less/{QuotesSniffUnitTest.php => QuotesUnitTest.php} | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename Magento2/Tests/Less/{QuotesSniffUnitTest.less => QuotesUnitTest.less} (100%) rename Magento2/Tests/Less/{QuotesSniffUnitTest.php => QuotesUnitTest.php} (100%) diff --git a/Magento2/Tests/Less/QuotesSniffUnitTest.less b/Magento2/Tests/Less/QuotesUnitTest.less similarity index 100% rename from Magento2/Tests/Less/QuotesSniffUnitTest.less rename to Magento2/Tests/Less/QuotesUnitTest.less diff --git a/Magento2/Tests/Less/QuotesSniffUnitTest.php b/Magento2/Tests/Less/QuotesUnitTest.php similarity index 100% rename from Magento2/Tests/Less/QuotesSniffUnitTest.php rename to Magento2/Tests/Less/QuotesUnitTest.php From a9a1a467335cf4253e9e4092fac3668dcee9d467 Mon Sep 17 00:00:00 2001 From: Sergio Vera Date: Wed, 1 Sep 2021 12:23:06 +0200 Subject: [PATCH 165/630] AC-944: Create unit test for Magento2\Less\CombinatorIndentationSniff check --- .../Less/CombinatorIndentationUnitTest.less | 20 +++++++++++++ .../Less/CombinatorIndentationUnitTest.php | 29 +++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 Magento2/Tests/Less/CombinatorIndentationUnitTest.less create mode 100644 Magento2/Tests/Less/CombinatorIndentationUnitTest.php diff --git a/Magento2/Tests/Less/CombinatorIndentationUnitTest.less b/Magento2/Tests/Less/CombinatorIndentationUnitTest.less new file mode 100644 index 00000000..0d8a4932 --- /dev/null +++ b/Magento2/Tests/Less/CombinatorIndentationUnitTest.less @@ -0,0 +1,20 @@ +// /** +// * Copyright © Magento, Inc. All rights reserved. +// * See COPYING.txt for license details. +// */ + +.nav+.bar { + color: @bar__color; +} + +.nav +.foo { + color: @bar__color; +} + +.nav+ .baz { + color: @bar__color; +} + +.nav + .qux { + color: @bar__color; +} \ No newline at end of file diff --git a/Magento2/Tests/Less/CombinatorIndentationUnitTest.php b/Magento2/Tests/Less/CombinatorIndentationUnitTest.php new file mode 100644 index 00000000..d3e5c882 --- /dev/null +++ b/Magento2/Tests/Less/CombinatorIndentationUnitTest.php @@ -0,0 +1,29 @@ + 1, + 10 => 1, + 14 => 1, + ]; + } + + /** + * @inheritdoc + */ + public function getWarningList() + { + return []; + } +} From a728d6efac41799642123894147e9cebe0a67f20 Mon Sep 17 00:00:00 2001 From: Sergio Vera Date: Wed, 1 Sep 2021 12:23:59 +0200 Subject: [PATCH 166/630] AC-944: Create unit test for Magento2\Less\CombinatorIndentationSniff check --- Magento2/Tests/Less/CombinatorIndentationUnitTest.less | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Magento2/Tests/Less/CombinatorIndentationUnitTest.less b/Magento2/Tests/Less/CombinatorIndentationUnitTest.less index 0d8a4932..fb66cd1d 100644 --- a/Magento2/Tests/Less/CombinatorIndentationUnitTest.less +++ b/Magento2/Tests/Less/CombinatorIndentationUnitTest.less @@ -17,4 +17,4 @@ .nav + .qux { color: @bar__color; -} \ No newline at end of file +} From 7b565c5817d0b75a4e089b2e12e302291e0725ef Mon Sep 17 00:00:00 2001 From: Sergio Vera Date: Wed, 1 Sep 2021 12:39:35 +0200 Subject: [PATCH 167/630] AC-954: Create unit test for Magento2\Less\TypeSelectorsSniff check --- .../Tests/Less/TypeSelectorsUnitTest.less | 23 ++++++++++++++++ Magento2/Tests/Less/TypeSelectorsUnitTest.php | 27 +++++++++++++++++++ 2 files changed, 50 insertions(+) create mode 100644 Magento2/Tests/Less/TypeSelectorsUnitTest.less create mode 100644 Magento2/Tests/Less/TypeSelectorsUnitTest.php diff --git a/Magento2/Tests/Less/TypeSelectorsUnitTest.less b/Magento2/Tests/Less/TypeSelectorsUnitTest.less new file mode 100644 index 00000000..1894d7b6 --- /dev/null +++ b/Magento2/Tests/Less/TypeSelectorsUnitTest.less @@ -0,0 +1,23 @@ +// /** +// * Copyright © Magento, Inc. All rights reserved. +// * See COPYING.txt for license details. +// */ + +.error { + some: 'stuff'; +} + +/** + * Should throw an error, Will be implemented in MAGETWO-49778 + */ +div.error { + anything: 'else'; +} + +.nav > LI { + #bar .baz(); +} + +.nav > ul { + foo: 'bar'; +} diff --git a/Magento2/Tests/Less/TypeSelectorsUnitTest.php b/Magento2/Tests/Less/TypeSelectorsUnitTest.php new file mode 100644 index 00000000..1c6ab265 --- /dev/null +++ b/Magento2/Tests/Less/TypeSelectorsUnitTest.php @@ -0,0 +1,27 @@ + 1, + ]; + } + + /** + * @inheritdoc + */ + public function getWarningList() + { + return []; + } +} From a16e77e80849a42e7cec98610e8a39897b0e4789 Mon Sep 17 00:00:00 2001 From: Sergio Vera Date: Wed, 1 Sep 2021 12:54:15 +0200 Subject: [PATCH 168/630] AC-956: Create unit test for Magento2\Less\ZeroUnitsSniff check --- Magento2/Sniffs/Less/ZeroUnitsSniff.php | 2 +- Magento2/Tests/Less/ZeroUnitsUnitTest.less | 14 +++++++++++ Magento2/Tests/Less/ZeroUnitsUnitTest.php | 28 ++++++++++++++++++++++ 3 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 Magento2/Tests/Less/ZeroUnitsUnitTest.less create mode 100644 Magento2/Tests/Less/ZeroUnitsUnitTest.php diff --git a/Magento2/Sniffs/Less/ZeroUnitsSniff.php b/Magento2/Sniffs/Less/ZeroUnitsSniff.php index 51971c78..05b26327 100644 --- a/Magento2/Sniffs/Less/ZeroUnitsSniff.php +++ b/Magento2/Sniffs/Less/ZeroUnitsSniff.php @@ -14,7 +14,7 @@ * Ensure that units for 0 is not specified * Omit leading "0"s in values, use dot instead * - * @link https://devdocs.magento.com/guides/v2.4/coding-standards/code-standard-less.html#and-units + * @link https://devdocs.magento.com/guides/v2.4/coding-standards/code-standard-less.html#0-and-units * @link https://devdocs.magento.com/guides/v2.4/coding-standards/code-standard-less.html#floating-values */ class ZeroUnitsSniff implements Sniff diff --git a/Magento2/Tests/Less/ZeroUnitsUnitTest.less b/Magento2/Tests/Less/ZeroUnitsUnitTest.less new file mode 100644 index 00000000..dcb794ad --- /dev/null +++ b/Magento2/Tests/Less/ZeroUnitsUnitTest.less @@ -0,0 +1,14 @@ +// /** +// * Copyright © Magento, Inc. All rights reserved. +// * See COPYING.txt for license details. +// */ + +.my{ + border-width: 0px; + margin-left: 0.5rem; +} + +.foo { + border-width: 0; + margin-left: .5rem; +} diff --git a/Magento2/Tests/Less/ZeroUnitsUnitTest.php b/Magento2/Tests/Less/ZeroUnitsUnitTest.php new file mode 100644 index 00000000..96c0d028 --- /dev/null +++ b/Magento2/Tests/Less/ZeroUnitsUnitTest.php @@ -0,0 +1,28 @@ + 1, + 8 => 1, + ]; + } + + /** + * @inheritdoc + */ + public function getWarningList() + { + return []; + } +} From 61187535256341cb77eb45347e3b19300186c14d Mon Sep 17 00:00:00 2001 From: Marc Ginesta Date: Wed, 1 Sep 2021 13:13:00 +0200 Subject: [PATCH 169/630] AC-955: Create unit test for Magento2\Less\VariablesSniff check --- Magento2/Tests/Less/VariablesUnitTest.less | 17 +++++++++++++ Magento2/Tests/Less/VariablesUnitTest.php | 28 ++++++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 Magento2/Tests/Less/VariablesUnitTest.less create mode 100644 Magento2/Tests/Less/VariablesUnitTest.php diff --git a/Magento2/Tests/Less/VariablesUnitTest.less b/Magento2/Tests/Less/VariablesUnitTest.less new file mode 100644 index 00000000..91590d20 --- /dev/null +++ b/Magento2/Tests/Less/VariablesUnitTest.less @@ -0,0 +1,17 @@ +// /** +// * Copyright © Magento, Inc. All rights reserved. +// * See COPYING.txt for license details. +// */ + +.nav { + random: 'stuff'; +} + +@INCORRECT-PROPERTY__color: red; + +// +// Variables not correctly located +// _____________________________________________ + +// Colors +@btn__color: red; diff --git a/Magento2/Tests/Less/VariablesUnitTest.php b/Magento2/Tests/Less/VariablesUnitTest.php new file mode 100644 index 00000000..c6a49ec7 --- /dev/null +++ b/Magento2/Tests/Less/VariablesUnitTest.php @@ -0,0 +1,28 @@ + 2, + 17 => 1 + ]; + } + + /** + * @inheritdoc + */ + public function getWarningList() + { + return []; + } +} From 33d319696542441162c71fab1925bcb3357d90c5 Mon Sep 17 00:00:00 2001 From: Sergio Vera Date: Wed, 1 Sep 2021 17:00:18 +0200 Subject: [PATCH 170/630] AC-943: Create unit test for Magento2\Less\ColourDefinitionSniff check --- Magento2/Tests/Less/ColourDefinitionUnitTest.less | 1 + Magento2/Tests/Less/ColourDefinitionUnitTest.php | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Magento2/Tests/Less/ColourDefinitionUnitTest.less b/Magento2/Tests/Less/ColourDefinitionUnitTest.less index e32323f9..49af23a9 100644 --- a/Magento2/Tests/Less/ColourDefinitionUnitTest.less +++ b/Magento2/Tests/Less/ColourDefinitionUnitTest.less @@ -6,6 +6,7 @@ @red: #aaaaaa; @blue: #00F; @green: #0f0; +@purple: #abcdef; .my{ color: @red; diff --git a/Magento2/Tests/Less/ColourDefinitionUnitTest.php b/Magento2/Tests/Less/ColourDefinitionUnitTest.php index 34862ed2..890a39ca 100644 --- a/Magento2/Tests/Less/ColourDefinitionUnitTest.php +++ b/Magento2/Tests/Less/ColourDefinitionUnitTest.php @@ -15,7 +15,7 @@ public function getErrorList() return [ 6 => 1, 7 => 1, - 15 => 1, + 16 => 1, ]; } From 1dd90d0caded5c604733e17afd78c5f76ee17596 Mon Sep 17 00:00:00 2001 From: Marc Ginesta Date: Wed, 1 Sep 2021 17:27:17 +0200 Subject: [PATCH 171/630] AC-952: Create unit test for Magento2\Less\SemicolonSpacingSniff check - Refactor: Fix wrong index and adapt tests accordingly --- Magento2/Sniffs/Less/SemicolonSpacingSniff.php | 2 +- Magento2/Tests/Less/SemicolonSpacingUnitTest.less | 6 +++--- Magento2/Tests/Less/SemicolonSpacingUnitTest.php | 3 ++- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/Magento2/Sniffs/Less/SemicolonSpacingSniff.php b/Magento2/Sniffs/Less/SemicolonSpacingSniff.php index cad13290..5acc7d2e 100644 --- a/Magento2/Sniffs/Less/SemicolonSpacingSniff.php +++ b/Magento2/Sniffs/Less/SemicolonSpacingSniff.php @@ -83,7 +83,7 @@ private function validateSemicolon(File $phpcsFile, $stackPtr, array $tokens, $s { if ((false === $semicolonPtr || $tokens[$semicolonPtr]['line'] !== $tokens[$stackPtr]['line']) && (isset($tokens[$stackPtr - 1]) && !in_array($tokens[$stackPtr - 1]['code'], $this->styleCodesToSkip)) - && (T_COLON !== $tokens[$stackPtr + 1]['code']) + && (T_COLON !== $tokens[$stackPtr]['code']) ) { $error = 'Style definitions must end with a semicolon'; $phpcsFile->addError($error, $stackPtr, 'NotAtEnd'); diff --git a/Magento2/Tests/Less/SemicolonSpacingUnitTest.less b/Magento2/Tests/Less/SemicolonSpacingUnitTest.less index bf68b499..4c621871 100644 --- a/Magento2/Tests/Less/SemicolonSpacingUnitTest.less +++ b/Magento2/Tests/Less/SemicolonSpacingUnitTest.less @@ -4,10 +4,10 @@ // */ .nav { - background-color: green + background-color: green; } .nav-list { - background-color: red - color: white + background-color: red ; + color: red } diff --git a/Magento2/Tests/Less/SemicolonSpacingUnitTest.php b/Magento2/Tests/Less/SemicolonSpacingUnitTest.php index fe5d9d92..e25e8d6d 100644 --- a/Magento2/Tests/Less/SemicolonSpacingUnitTest.php +++ b/Magento2/Tests/Less/SemicolonSpacingUnitTest.php @@ -13,7 +13,8 @@ class SemicolonSpacingUnitTest extends AbstractLessSniffUnitTestCase public function getErrorList() { return [ - 11 => 1 + 11 => 1, + 12 => 1 ]; } From 53e9d751141a1649caf53a8457de03cc2adc55a7 Mon Sep 17 00:00:00 2001 From: Sergio Vera Date: Thu, 2 Sep 2021 11:54:29 +0200 Subject: [PATCH 172/630] AC-659: Create phpcs static check for ModuleXMLTest --- Magento2/Tests/Legacy/ModuleXMLUnitTest.1.xml | 10 ++++++++++ ...eXMLUnitTest.xml => ModuleXMLUnitTest.2.xml} | 1 - Magento2/Tests/Legacy/ModuleXMLUnitTest.php | 17 ++++++++++++----- 3 files changed, 22 insertions(+), 6 deletions(-) create mode 100644 Magento2/Tests/Legacy/ModuleXMLUnitTest.1.xml rename Magento2/Tests/Legacy/{ModuleXMLUnitTest.xml => ModuleXMLUnitTest.2.xml} (85%) diff --git a/Magento2/Tests/Legacy/ModuleXMLUnitTest.1.xml b/Magento2/Tests/Legacy/ModuleXMLUnitTest.1.xml new file mode 100644 index 00000000..28c02b6f --- /dev/null +++ b/Magento2/Tests/Legacy/ModuleXMLUnitTest.1.xml @@ -0,0 +1,10 @@ + + + + + diff --git a/Magento2/Tests/Legacy/ModuleXMLUnitTest.xml b/Magento2/Tests/Legacy/ModuleXMLUnitTest.2.xml similarity index 85% rename from Magento2/Tests/Legacy/ModuleXMLUnitTest.xml rename to Magento2/Tests/Legacy/ModuleXMLUnitTest.2.xml index 9d545a65..13fbd752 100644 --- a/Magento2/Tests/Legacy/ModuleXMLUnitTest.xml +++ b/Magento2/Tests/Legacy/ModuleXMLUnitTest.2.xml @@ -6,7 +6,6 @@ */ --> - 2, - 10 => 2 - ]; + if ($testFile === 'ModuleXMLUnitTest.1.xml') { + return [ + 9 => 2, + ]; + } + if ($testFile === 'ModuleXMLUnitTest.2.xml') { + return [ + 9 => 2, + ]; + } + return []; } } From 47a0536fe81a5d0a999542ada2773df59d9baa4a Mon Sep 17 00:00:00 2001 From: Sergio Vera Date: Thu, 2 Sep 2021 12:03:27 +0200 Subject: [PATCH 173/630] AC-659: Create phpcs static check for ModuleXMLTest --- Magento2/Tests/Legacy/ModuleXMLUnitTest.3.xml | 10 ++++++++++ Magento2/Tests/Legacy/ModuleXMLUnitTest.php | 3 +++ 2 files changed, 13 insertions(+) create mode 100644 Magento2/Tests/Legacy/ModuleXMLUnitTest.3.xml diff --git a/Magento2/Tests/Legacy/ModuleXMLUnitTest.3.xml b/Magento2/Tests/Legacy/ModuleXMLUnitTest.3.xml new file mode 100644 index 00000000..93312a82 --- /dev/null +++ b/Magento2/Tests/Legacy/ModuleXMLUnitTest.3.xml @@ -0,0 +1,10 @@ + + + + + diff --git a/Magento2/Tests/Legacy/ModuleXMLUnitTest.php b/Magento2/Tests/Legacy/ModuleXMLUnitTest.php index 62300103..eab099a4 100644 --- a/Magento2/Tests/Legacy/ModuleXMLUnitTest.php +++ b/Magento2/Tests/Legacy/ModuleXMLUnitTest.php @@ -32,6 +32,9 @@ public function getWarningList($testFile = '') 9 => 2, ]; } + if ($testFile === 'ModuleXMLUnitTest.3.xml') { + return []; + } return []; } } From 1b1eae2e464513f8df4b8a797732d605c1169baf Mon Sep 17 00:00:00 2001 From: Elisea Cornejo Date: Thu, 2 Sep 2021 16:06:07 +0200 Subject: [PATCH 174/630] AC-1128: Add severity and type (warning or error) for annotation, html and less checks --- Magento2/ruleset.xml | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/Magento2/ruleset.xml b/Magento2/ruleset.xml index eb7460f8..f31b105d 100644 --- a/Magento2/ruleset.xml +++ b/Magento2/ruleset.xml @@ -144,6 +144,10 @@ 9 warning + + 9 + warning + @@ -233,6 +237,10 @@ 8 warning + + 8 + warning + @@ -565,6 +573,15 @@ 6 warning + + 6 + warning + + + 6 + warning + *\.less$ + 0 @@ -596,16 +613,13 @@ warning
+ 5 + warning */_files/* */Test/* *Test.php - - - *\.less$ - 0 - From 31b1699de75f701fefdadc47361c42f4444ab0f3 Mon Sep 17 00:00:00 2001 From: Dan Wallis Date: Thu, 2 Sep 2021 15:06:27 +0100 Subject: [PATCH 175/630] Ignore PHPUnit results cache file --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index ba13e90d..6591b97d 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,5 @@ .project/ .settings/ .vscode/ + +.phpunit.result.cache From 3fd461e60b2cb60bf3f7e4326ab10e1da8a8d3e2 Mon Sep 17 00:00:00 2001 From: Dan Wallis Date: Thu, 2 Sep 2021 15:07:58 +0100 Subject: [PATCH 176/630] Fix PHP Fatal error when docblock is invalid PHP Fatal error: Uncaught TypeError: strpos(): Argument #2 ($needle) must be of type string, null given in /srv/www/vendor/magento/magento-coding-standard/Magento2/Sniffs/Annotation/MethodArgumentsSniff.php:629 Stack trace: #0 /srv/www/vendor/magento/magento-coding-standard/Magento2/Sniffs/Annotation/MethodArgumentsSniff.php(629): strpos('\\VendorName\\Mod...', NULL) #1 /srv/www/vendor/magento/magento-coding-standard/Magento2/Sniffs/Annotation/MethodArgumentsSniff.php(515): Magento2\Sniffs\Annotation\MethodArgumentsSniff->validateFormattingConsistency(Array, Array, Object(PHP_CodeSniffer\Files\LocalFile), Array) #2 /srv/www/vendor/magento/magento-coding-standard/Magento2/Sniffs/Annotation/MethodArgumentsSniff.php(600): Magento2\Sniffs\Annotation\MethodArgumentsSniff->validateMethodParameterAnnotations(385, Array, Array, Object(PHP_CodeSniffer\Files\LocalFile), Array, 356, 380) #3 /srv/www/vendor/squizlabs/php_codesniffer/src/Files/File.php(498): Magento2\Sniffs\Annotation\MethodArgumentsSniff->process(Object(PHP_CodeSniffer\Files\LocalFile), 385) #4 /srv/www/vendor/squizlabs/php_codesniffer/src/Files/LocalFile.php(92): PHP_CodeSniffer\Files\File->process() #5 /srv/www/vendor/squizlabs/php_codesniffer/src/Runner.php(630): PHP_CodeSniffer\Files\LocalFile->process() #6 /srv/www/vendor/squizlabs/php_codesniffer/src/Runner.php(434): PHP_CodeSniffer\Runner->processFile(Object(PHP_CodeSniffer\Files\LocalFile)) #7 /srv/www/vendor/squizlabs/php_codesniffer/src/Runner.php(114): PHP_CodeSniffer\Runner->run() #8 /srv/www/vendor/squizlabs/php_codesniffer/bin/phpcs(18): PHP_CodeSniffer\Runner->runPHPCS() #9 {main} thrown in /srv/www/vendor/magento/magento-coding-standard/Magento2/Sniffs/Annotation/MethodArgumentsSniff.php on line 629 --- Magento2/Sniffs/Annotation/MethodArgumentsSniff.php | 6 +++--- Magento2/Tests/Annotation/MethodArgumentsUnitTest.inc | 11 +++++++++++ Magento2/Tests/Annotation/MethodArgumentsUnitTest.php | 5 +++-- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/Magento2/Sniffs/Annotation/MethodArgumentsSniff.php b/Magento2/Sniffs/Annotation/MethodArgumentsSniff.php index 655bd37c..09c8208b 100644 --- a/Magento2/Sniffs/Annotation/MethodArgumentsSniff.php +++ b/Magento2/Sniffs/Annotation/MethodArgumentsSniff.php @@ -609,8 +609,6 @@ public function process(File $phpcsFile, $stackPtr) * @param File $phpcsFile * @param array $paramPointers * - * @SuppressWarnings(PHPMD.UnusedLocalVariable) - * * @see https://devdocs.magento.com/guides/v2.4/coding-standards/docblock-standard-general.html#format-consistency */ private function validateFormattingConsistency( @@ -626,7 +624,9 @@ private function validateFormattingConsistency( if (isset($paramPointers[$ptr])) { $paramContent = $tokens[$paramPointers[$ptr] + 2]['content']; $paramDefinition = $paramDefinitions[$ptr]; - $argumentPositions[] = strpos($paramContent, $paramDefinition['paramName']); + if (isset($paramDefinition['paramName'])) { + $argumentPositions[] = strpos($paramContent, $paramDefinition['paramName']); + } $commentPositions[] = $paramDefinition['comment'] ? strrpos($paramContent, $paramDefinition['comment']) : null; } diff --git a/Magento2/Tests/Annotation/MethodArgumentsUnitTest.inc b/Magento2/Tests/Annotation/MethodArgumentsUnitTest.inc index f3cbbb54..7add3ae9 100644 --- a/Magento2/Tests/Annotation/MethodArgumentsUnitTest.inc +++ b/Magento2/Tests/Annotation/MethodArgumentsUnitTest.inc @@ -22,3 +22,14 @@ public function setExtensionAs(\Magento\Catalog\Api\Data\CategoryExtensionInterf { return $this->_setExtensionAttributes($extensionAttributes); } + +/** + * Short description of method + * + * @param int + * @return int + */ +public function invalidDocBlockShouldNotCauseFatalErrorInSniff(int $number): int +{ + return $number; +} diff --git a/Magento2/Tests/Annotation/MethodArgumentsUnitTest.php b/Magento2/Tests/Annotation/MethodArgumentsUnitTest.php index 623c7539..86854e83 100644 --- a/Magento2/Tests/Annotation/MethodArgumentsUnitTest.php +++ b/Magento2/Tests/Annotation/MethodArgumentsUnitTest.php @@ -16,10 +16,11 @@ public function getErrorList() { return [ 12 => 1, - 21 => 1 + 21 => 1, + 32 => 1, ]; } - + /** * @inheritdoc */ From 142ef3bdc365327ab7a7c6cfae0b006cd8c62930 Mon Sep 17 00:00:00 2001 From: Sergio Vera Date: Fri, 3 Sep 2021 09:28:25 +0200 Subject: [PATCH 177/630] AC-1100: Catch badly put newlines in LESS files --- Magento2/Sniffs/Less/ColonSpacingSniff.php | 18 ++++++++---------- Magento2/Tests/Less/ColonSpacingUnitTest.less | 2 +- Magento2/Tests/Less/ColonSpacingUnitTest.php | 1 + 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/Magento2/Sniffs/Less/ColonSpacingSniff.php b/Magento2/Sniffs/Less/ColonSpacingSniff.php index dd8fee7f..2868db29 100644 --- a/Magento2/Sniffs/Less/ColonSpacingSniff.php +++ b/Magento2/Sniffs/Less/ColonSpacingSniff.php @@ -40,6 +40,12 @@ public function process(File $phpcsFile, $stackPtr) { $tokens = $phpcsFile->getTokens(); + $nextSemicolon = $phpcsFile->findNext(T_SEMICOLON, $stackPtr); + if (false !== $nextSemicolon && ($tokens[$nextSemicolon]['line'] !== $tokens[$stackPtr]['line'])) { + $error = 'Expected 1 space after colon in style definition; newline found'; + $phpcsFile->addError($error, $stackPtr, 'AfterNewline'); + } + if ($this->needValidateSpaces($phpcsFile, $stackPtr, $tokens)) { $this->validateSpaces($phpcsFile, $stackPtr, $tokens); } @@ -56,12 +62,7 @@ public function process(File $phpcsFile, $stackPtr) */ private function needValidateSpaces(File $phpcsFile, $stackPtr, $tokens) { - $nextSemicolon = $phpcsFile->findNext(T_SEMICOLON, $stackPtr); - - if (false === $nextSemicolon - || ($tokens[$nextSemicolon]['line'] !== $tokens[$stackPtr]['line']) - || TokenizerSymbolsInterface::BITWISE_AND === $tokens[$stackPtr - 1]['content'] - ) { + if (TokenizerSymbolsInterface::BITWISE_AND === $tokens[$stackPtr - 1]['content']) { return false; } @@ -98,15 +99,12 @@ private function validateSpaces(File $phpcsFile, $stackPtr, array $tokens) $phpcsFile->addError('Expected 1 space after colon in style definition; 0 found', $stackPtr, 'NoneAfter'); } else { $content = $tokens[($stackPtr + 1)]['content']; - if (false === strpos($content, $phpcsFile->eolChar)) { + if (false !== strpos($content, ' ')) { $length = strlen($content); if ($length !== 1) { $error = sprintf('Expected 1 space after colon in style definition; %s found', $length); $phpcsFile->addError($error, $stackPtr, 'After'); } - } else { - $error = 'Expected 1 space after colon in style definition; newline found'; - $phpcsFile->addError($error, $stackPtr, 'AfterNewline'); } } } diff --git a/Magento2/Tests/Less/ColonSpacingUnitTest.less b/Magento2/Tests/Less/ColonSpacingUnitTest.less index d888af2e..37de49e4 100644 --- a/Magento2/Tests/Less/ColonSpacingUnitTest.less +++ b/Magento2/Tests/Less/ColonSpacingUnitTest.less @@ -13,7 +13,7 @@ div#foo { } .blah { - foo :'xyz'; + foo :'jkl'; } .foo { diff --git a/Magento2/Tests/Less/ColonSpacingUnitTest.php b/Magento2/Tests/Less/ColonSpacingUnitTest.php index b50e47d0..81b596e5 100644 --- a/Magento2/Tests/Less/ColonSpacingUnitTest.php +++ b/Magento2/Tests/Less/ColonSpacingUnitTest.php @@ -16,6 +16,7 @@ public function getErrorList() 8 => 1, 12 => 1, 16 => 2, + 20 => 1, ]; } From 2fc6815b671b033a7891d44aa3bc0e0e4651e100 Mon Sep 17 00:00:00 2001 From: Sergio Vera Date: Fri, 3 Sep 2021 09:29:54 +0200 Subject: [PATCH 178/630] AC-1100: Catch badly put newlines in LESS files --- Magento2/Sniffs/Less/ColonSpacingSniff.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Magento2/Sniffs/Less/ColonSpacingSniff.php b/Magento2/Sniffs/Less/ColonSpacingSniff.php index 2868db29..d623ab3e 100644 --- a/Magento2/Sniffs/Less/ColonSpacingSniff.php +++ b/Magento2/Sniffs/Less/ColonSpacingSniff.php @@ -39,12 +39,6 @@ public function register() public function process(File $phpcsFile, $stackPtr) { $tokens = $phpcsFile->getTokens(); - - $nextSemicolon = $phpcsFile->findNext(T_SEMICOLON, $stackPtr); - if (false !== $nextSemicolon && ($tokens[$nextSemicolon]['line'] !== $tokens[$stackPtr]['line'])) { - $error = 'Expected 1 space after colon in style definition; newline found'; - $phpcsFile->addError($error, $stackPtr, 'AfterNewline'); - } if ($this->needValidateSpaces($phpcsFile, $stackPtr, $tokens)) { $this->validateSpaces($phpcsFile, $stackPtr, $tokens); @@ -95,6 +89,12 @@ private function validateSpaces(File $phpcsFile, $stackPtr, array $tokens) $phpcsFile->addError('There must be no space before a colon in a style definition', $stackPtr, 'Before'); } + $nextSemicolon = $phpcsFile->findNext(T_SEMICOLON, $stackPtr); + if (false !== $nextSemicolon && ($tokens[$nextSemicolon]['line'] !== $tokens[$stackPtr]['line'])) { + $error = 'Expected 1 space after colon in style definition; newline found'; + $phpcsFile->addError($error, $stackPtr, 'AfterNewline'); + } + if (T_WHITESPACE !== $tokens[($stackPtr + 1)]['code']) { $phpcsFile->addError('Expected 1 space after colon in style definition; 0 found', $stackPtr, 'NoneAfter'); } else { From e2aa287eb60ed7afed1cdce1f9d5225e2b3f309d Mon Sep 17 00:00:00 2001 From: Sergio Vera Date: Fri, 3 Sep 2021 13:26:55 +0200 Subject: [PATCH 179/630] AC-1100: Catch badly put newlines in LESS files --- Magento2/Sniffs/Less/ColonSpacingSniff.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Magento2/Sniffs/Less/ColonSpacingSniff.php b/Magento2/Sniffs/Less/ColonSpacingSniff.php index d623ab3e..505c44fd 100644 --- a/Magento2/Sniffs/Less/ColonSpacingSniff.php +++ b/Magento2/Sniffs/Less/ColonSpacingSniff.php @@ -39,7 +39,7 @@ public function register() public function process(File $phpcsFile, $stackPtr) { $tokens = $phpcsFile->getTokens(); - + if ($this->needValidateSpaces($phpcsFile, $stackPtr, $tokens)) { $this->validateSpaces($phpcsFile, $stackPtr, $tokens); } @@ -75,7 +75,10 @@ private function needValidateSpaces(File $phpcsFile, $stackPtr, $tokens) } /** - * Validate Colon Spacing according to requirements + * Validate Colon Spacing according to requirements: + * - No spaces before colon + * - Exactly 1 space after colon + * - No property definition scattered among several lines * * @param File $phpcsFile * @param int $stackPtr From 56e2de84fd8b46185fcd32082bbc0dca070e9e94 Mon Sep 17 00:00:00 2001 From: Sergio Vera Date: Mon, 6 Sep 2021 13:40:14 +0200 Subject: [PATCH 180/630] AC-663: Create phpcs static check for ClassesTest::testPhpCode --- Magento2/Sniffs/Legacy/ClassesPHPSniff.php | 93 ++++++++++++++++++++ Magento2/Tests/Legacy/ClassesPHPUnitTest.inc | 10 +++ Magento2/Tests/Legacy/ClassesPHPUnitTest.php | 30 +++++++ 3 files changed, 133 insertions(+) create mode 100644 Magento2/Sniffs/Legacy/ClassesPHPSniff.php create mode 100644 Magento2/Tests/Legacy/ClassesPHPUnitTest.inc create mode 100644 Magento2/Tests/Legacy/ClassesPHPUnitTest.php diff --git a/Magento2/Sniffs/Legacy/ClassesPHPSniff.php b/Magento2/Sniffs/Legacy/ClassesPHPSniff.php new file mode 100644 index 00000000..6849b46d --- /dev/null +++ b/Magento2/Sniffs/Legacy/ClassesPHPSniff.php @@ -0,0 +1,93 @@ +getTokens(); + $methodNameStackPtr = $phpcsFile->findNext(T_STRING, $stackPtr + 1, null, false, null, true); + if ($methodNameStackPtr === false) { + return; + } + $name = $tokens[$methodNameStackPtr]['content']; + if (in_array($name, $this->methodsThatReceiveClassNameAsFirstArgument)) { + $firstArgumentStackPtr = $phpcsFile->findNext( + [T_CONSTANT_ENCAPSED_STRING], + $methodNameStackPtr + 1, + null, + false, + null, + true + ); + if ($firstArgumentStackPtr === false) { + return; + } + $name = $tokens[$firstArgumentStackPtr]['content']; + if (!$this->isAValidNonFactoryName($name)) { + $phpcsFile->addError( + self::errorMessage, + $methodNameStackPtr + 1, + self::errorCode, + ); + } + } + } + + /** + * Check whether specified classes or module names correspond to a file according PSR-1 Standard. + * + * @param string $name + * @return bool + */ + private function isAValidNonFactoryName(string $name): bool + { + if (strpos($name, 'Magento') === false) { + return true; + } + + if (false === strpos($name, '\\')) { + return false; + } + + if (preg_match('/^([A-Z\\\\][A-Za-z\d\\\\]+)+$/', $name) !== 1) { + return false; + } + + return true; + } +} diff --git a/Magento2/Tests/Legacy/ClassesPHPUnitTest.inc b/Magento2/Tests/Legacy/ClassesPHPUnitTest.inc new file mode 100644 index 00000000..5482d3fe --- /dev/null +++ b/Magento2/Tests/Legacy/ClassesPHPUnitTest.inc @@ -0,0 +1,10 @@ + 1, + 9 => 1, + ]; + } + + /** + * @inheritdoc + */ + public function getWarningList() + { + return []; + } +} From c9703a6f40e8596285447000309182179a98a823 Mon Sep 17 00:00:00 2001 From: Sergio Vera Date: Mon, 6 Sep 2021 15:31:47 +0200 Subject: [PATCH 181/630] AC-663: Create phpcs static check for ClassesTest::testPhpCode --- Magento2/Sniffs/Legacy/ClassesPHPSniff.php | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/Magento2/Sniffs/Legacy/ClassesPHPSniff.php b/Magento2/Sniffs/Legacy/ClassesPHPSniff.php index 6849b46d..866afefc 100644 --- a/Magento2/Sniffs/Legacy/ClassesPHPSniff.php +++ b/Magento2/Sniffs/Legacy/ClassesPHPSniff.php @@ -11,9 +11,9 @@ class ClassesPHPSniff implements Sniff { - private const errorMessage = 'Obsolete factory name(s) detected'; + private const ERROR_MESSAGE = 'Obsolete factory name(s) detected'; - private const errorCode = 'ObsoleteFactoryName'; + private const ERROR_CODE = 'ObsoleteFactoryName'; private $methodsThatReceiveClassNameAsFirstArgument = [ 'getModel', 'getSingleton', 'getResourceModel', 'getResourceSingleton', @@ -32,7 +32,6 @@ public function register(): array T_DOUBLE_COLON, ]; } - /** * @inheritdoc @@ -60,9 +59,9 @@ public function process(File $phpcsFile, $stackPtr) $name = $tokens[$firstArgumentStackPtr]['content']; if (!$this->isAValidNonFactoryName($name)) { $phpcsFile->addError( - self::errorMessage, + self::ERROR_MESSAGE, $methodNameStackPtr + 1, - self::errorCode, + self::ERROR_CODE, ); } } 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 182/630] 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 183/630] 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 184/630] 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 185/630] 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 4f341fe3147bac1113fa8d18627125bcbb001f97 Mon Sep 17 00:00:00 2001 From: Sergii Ivashchenko Date: Tue, 7 Sep 2021 17:38:17 +0100 Subject: [PATCH 186/630] Version 9 --- composer.json | 2 +- composer.lock | 15 ++++++++------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/composer.json b/composer.json index 267fcaa3..c06ab6c7 100644 --- a/composer.json +++ b/composer.json @@ -6,7 +6,7 @@ "AFL-3.0" ], "type": "phpcodesniffer-standard", - "version": "8", + "version": "9", "require": { "php": ">=7.3", "squizlabs/php_codesniffer": "^3.6", diff --git a/composer.lock b/composer.lock index fa12108d..025e27ee 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": "503b3dff10c4885d5f5b196d159c1fdd", + "content-hash": "9f04a53a3b02845918c714a149ab00b2", "packages": [ { "name": "squizlabs/php_codesniffer", @@ -969,16 +969,16 @@ }, { "name": "phpunit/phpunit", - "version": "9.5.8", + "version": "9.5.9", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "191768ccd5c85513b4068bdbe99bb6390c7d54fb" + "reference": "ea8c2dfb1065eb35a79b3681eee6e6fb0a6f273b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/191768ccd5c85513b4068bdbe99bb6390c7d54fb", - "reference": "191768ccd5c85513b4068bdbe99bb6390c7d54fb", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/ea8c2dfb1065eb35a79b3681eee6e6fb0a6f273b", + "reference": "ea8c2dfb1065eb35a79b3681eee6e6fb0a6f273b", "shasum": "" }, "require": { @@ -1056,7 +1056,7 @@ ], "support": { "issues": "https://github.com/sebastianbergmann/phpunit/issues", - "source": "https://github.com/sebastianbergmann/phpunit/tree/9.5.8" + "source": "https://github.com/sebastianbergmann/phpunit/tree/9.5.9" }, "funding": [ { @@ -1068,7 +1068,7 @@ "type": "github" } ], - "time": "2021-07-31T15:17:34+00:00" + "time": "2021-08-31T06:47:40+00:00" }, { "name": "sebastian/cli-parser", @@ -1923,6 +1923,7 @@ "type": "github" } ], + "abandoned": true, "time": "2020-09-28T06:45:17+00:00" }, { 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 187/630] 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 188/630] 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 189/630] 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 190/630] 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 191/630] 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 5a83385431d2b0628f341c757b761ab663c9039e Mon Sep 17 00:00:00 2001 From: Sergio Vera Date: Thu, 9 Sep 2021 11:45:49 +0200 Subject: [PATCH 192/630] AC-663: Create phpcs static check for ClassesTest::testPhpCode --- ...niff.php => ObsoleteMethodsUsageSniff.php} | 46 ++++--------------- ...t.inc => ObsoleteMethodsUsageUnitTest.inc} | 6 +-- ...t.php => ObsoleteMethodsUsageUnitTest.php} | 7 +-- 3 files changed, 15 insertions(+), 44 deletions(-) rename Magento2/Sniffs/Legacy/{ClassesPHPSniff.php => ObsoleteMethodsUsageSniff.php} (53%) rename Magento2/Tests/Legacy/{ClassesPHPUnitTest.inc => ObsoleteMethodsUsageUnitTest.inc} (64%) rename Magento2/Tests/Legacy/{ClassesPHPUnitTest.php => ObsoleteMethodsUsageUnitTest.php} (76%) diff --git a/Magento2/Sniffs/Legacy/ClassesPHPSniff.php b/Magento2/Sniffs/Legacy/ObsoleteMethodsUsageSniff.php similarity index 53% rename from Magento2/Sniffs/Legacy/ClassesPHPSniff.php rename to Magento2/Sniffs/Legacy/ObsoleteMethodsUsageSniff.php index 866afefc..44ae964b 100644 --- a/Magento2/Sniffs/Legacy/ClassesPHPSniff.php +++ b/Magento2/Sniffs/Legacy/ObsoleteMethodsUsageSniff.php @@ -8,14 +8,13 @@ use PHP_CodeSniffer\Sniffs\Sniff; use PHP_CodeSniffer\Files\File; -class ClassesPHPSniff implements Sniff +class ObsoleteMethodsUsageSniff implements Sniff { - - private const ERROR_MESSAGE = 'Obsolete factory name(s) detected'; + private const ERROR_MESSAGE = 'Obsolete methods usage detected'; - private const ERROR_CODE = 'ObsoleteFactoryName'; + private const ERROR_CODE = 'ObsoleteMethodsUsage'; - private $methodsThatReceiveClassNameAsFirstArgument = [ + private $obsoleteStaticMethods = [ 'getModel', 'getSingleton', 'getResourceModel', 'getResourceSingleton', 'addBlock', 'createBlock', 'getBlockSingleton', 'initReport', 'setEntityModelClass', 'setAttributeModel', 'setBackendModel', 'setFrontendModel', @@ -28,7 +27,6 @@ class ClassesPHPSniff implements Sniff public function register(): array { return [ - T_OBJECT, T_DOUBLE_COLON, ]; } @@ -44,20 +42,19 @@ public function process(File $phpcsFile, $stackPtr) return; } $name = $tokens[$methodNameStackPtr]['content']; - if (in_array($name, $this->methodsThatReceiveClassNameAsFirstArgument)) { - $firstArgumentStackPtr = $phpcsFile->findNext( - [T_CONSTANT_ENCAPSED_STRING], - $methodNameStackPtr + 1, + if (in_array($name, $this->obsoleteStaticMethods)) { + $classNameStackPtr = $phpcsFile->findPrevious( + [T_STRING], + $methodNameStackPtr - 1, null, false, null, true ); - if ($firstArgumentStackPtr === false) { + if ($classNameStackPtr === false) { return; } - $name = $tokens[$firstArgumentStackPtr]['content']; - if (!$this->isAValidNonFactoryName($name)) { + if ($tokens[$classNameStackPtr]['content'] === 'Mage') { $phpcsFile->addError( self::ERROR_MESSAGE, $methodNameStackPtr + 1, @@ -66,27 +63,4 @@ public function process(File $phpcsFile, $stackPtr) } } } - - /** - * Check whether specified classes or module names correspond to a file according PSR-1 Standard. - * - * @param string $name - * @return bool - */ - private function isAValidNonFactoryName(string $name): bool - { - if (strpos($name, 'Magento') === false) { - return true; - } - - if (false === strpos($name, '\\')) { - return false; - } - - if (preg_match('/^([A-Z\\\\][A-Za-z\d\\\\]+)+$/', $name) !== 1) { - return false; - } - - return true; - } } diff --git a/Magento2/Tests/Legacy/ClassesPHPUnitTest.inc b/Magento2/Tests/Legacy/ObsoleteMethodsUsageUnitTest.inc similarity index 64% rename from Magento2/Tests/Legacy/ClassesPHPUnitTest.inc rename to Magento2/Tests/Legacy/ObsoleteMethodsUsageUnitTest.inc index 5482d3fe..91583ae7 100644 --- a/Magento2/Tests/Legacy/ClassesPHPUnitTest.inc +++ b/Magento2/Tests/Legacy/ObsoleteMethodsUsageUnitTest.inc @@ -1,10 +1,6 @@ 1, - 9 => 1, + 3 => 1, + 5 => 1, + 6 => 1, ]; } From 5b407128bb6de41fb2348c0bcfc55dc163f7e7fa Mon Sep 17 00:00:00 2001 From: Sergio Vera Date: Thu, 9 Sep 2021 11:51:44 +0200 Subject: [PATCH 193/630] AC-663: Create phpcs static check for ClassesTest::testPhpCode --- Magento2/Sniffs/Legacy/ObsoleteMethodsUsageSniff.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Magento2/Sniffs/Legacy/ObsoleteMethodsUsageSniff.php b/Magento2/Sniffs/Legacy/ObsoleteMethodsUsageSniff.php index 44ae964b..d12c9fa6 100644 --- a/Magento2/Sniffs/Legacy/ObsoleteMethodsUsageSniff.php +++ b/Magento2/Sniffs/Legacy/ObsoleteMethodsUsageSniff.php @@ -14,6 +14,9 @@ class ObsoleteMethodsUsageSniff implements Sniff private const ERROR_CODE = 'ObsoleteMethodsUsage'; + /** + * @var string[] + */ private $obsoleteStaticMethods = [ 'getModel', 'getSingleton', 'getResourceModel', 'getResourceSingleton', 'addBlock', 'createBlock', 'getBlockSingleton', From e2c2d07c09f8bc6d9538cc92fa6732d35da88601 Mon Sep 17 00:00:00 2001 From: Elisea Cornejo Date: Thu, 9 Sep 2021 12:08:35 +0200 Subject: [PATCH 194/630] 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 195/630] 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 196/630] 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 197/630] 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 198/630] 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 199/630] 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 200/630] 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 201/630] 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 94acecdc682280709ddef4e367ca495feab31320 Mon Sep 17 00:00:00 2001 From: Maksym Aposov Date: Thu, 9 Sep 2021 16:22:19 -0500 Subject: [PATCH 202/630] AC-1102: Static test to verify self-closing tags for non-void html elements --- .../Sniffs/Html/HtmlSelfClosingTagsSniff.php | 84 +++++++++++++++++++ Magento2/ruleset.xml | 7 ++ 2 files changed, 91 insertions(+) create mode 100644 Magento2/Sniffs/Html/HtmlSelfClosingTagsSniff.php diff --git a/Magento2/Sniffs/Html/HtmlSelfClosingTagsSniff.php b/Magento2/Sniffs/Html/HtmlSelfClosingTagsSniff.php new file mode 100644 index 00000000..cd215313 --- /dev/null +++ b/Magento2/Sniffs/Html/HtmlSelfClosingTagsSniff.php @@ -0,0 +1,84 @@ +getTokensAsString($stackPtr, count($phpcsFile->getTokens())); + + if (empty($html)) { + return; + } + + if (preg_match_all('$<(\w{2,})\s?[^<]*\/>$', $html, $matches, PREG_SET_ORDER)) { + foreach ($matches as $match) { + if (!in_array($match[1], $this->voidElements)) { + $phpcsFile->addError( + 'Avoid using self-closing tag with non-void html element' + . ' - "' . $match[0] . PHP_EOL, + null, + 'HtmlTemplates.Tag.SelfClosing' + ); + } + } + } + } +} diff --git a/Magento2/ruleset.xml b/Magento2/ruleset.xml index 1e247a2f..13bbef09 100644 --- a/Magento2/ruleset.xml +++ b/Magento2/ruleset.xml @@ -116,6 +116,11 @@ error
+ + 10 + error + *\.xml$ + 9 @@ -153,6 +158,7 @@ 9 warning + *\.xml$ @@ -246,6 +252,7 @@ 8 warning + *\.xml$ From a2864d222ff6c1afb86ae37b8672a1e5f0d07b4e Mon Sep 17 00:00:00 2001 From: Elisea Cornejo Date: Mon, 13 Sep 2021 09:29:07 +0200 Subject: [PATCH 203/630] 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 204/630] 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 205/630] 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 206/630] 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 207/630] 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 208/630] 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 209/630] 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 210/630] 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 211/630] 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 212/630] 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 213/630] 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 214/630] 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 215/630] 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 216/630] 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 217/630] 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 218/630] 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 219/630] 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 220/630] 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 221/630] 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 222/630] 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", From 80e07de67f87f84c6b57251afede86de908f21ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Cuerdo=20=C3=81lvarez?= Date: Tue, 14 Sep 2021 16:14:26 +0200 Subject: [PATCH 223/630] AC-662: Create phpcs static check for AutogeneratedClassNotInConstructorTest --- ...utogeneratedClassNotInConstructorSniff.php | 210 ++++++++++++++++++ ...tedClassNotInConstructorUnitTest.1.php.inc | 28 +++ ...tedClassNotInConstructorUnitTest.2.php.inc | 16 ++ ...generatedClassNotInConstructorUnitTest.php | 33 +++ 4 files changed, 287 insertions(+) create mode 100644 Magento2/Sniffs/PHP/AutogeneratedClassNotInConstructorSniff.php create mode 100644 Magento2/Tests/PHP/AutogeneratedClassNotInConstructorUnitTest.1.php.inc create mode 100644 Magento2/Tests/PHP/AutogeneratedClassNotInConstructorUnitTest.2.php.inc create mode 100644 Magento2/Tests/PHP/AutogeneratedClassNotInConstructorUnitTest.php diff --git a/Magento2/Sniffs/PHP/AutogeneratedClassNotInConstructorSniff.php b/Magento2/Sniffs/PHP/AutogeneratedClassNotInConstructorSniff.php new file mode 100644 index 00000000..b7343896 --- /dev/null +++ b/Magento2/Sniffs/PHP/AutogeneratedClassNotInConstructorSniff.php @@ -0,0 +1,210 @@ +getTokens()[$stackPtr]['type'] === 'T_USE') { + $this->registerUses($phpcsFile, $stackPtr); + } + if ($phpcsFile->getTokens()[$stackPtr]['type'] === 'T_FUNCTION') { + $this->registerConstructorParameters($phpcsFile, $stackPtr); + } + if ($phpcsFile->getTokens()[$stackPtr]['type'] === 'T_DOUBLE_COLON') { + if (!$this->isInsideConstruct($stackPtr)) { + return; + } + if (!$this->isObjectManagerGetInstance($phpcsFile, $stackPtr)) { + return; + } + + $statementStart = $phpcsFile->findStartOfStatement($stackPtr); + $statementEnd = $phpcsFile->findEndOfStatement($stackPtr); + $equalsPtr = $phpcsFile->findNext(T_EQUAL, $statementStart, $statementEnd); + + if (!$equalsPtr) { + return; + } + + $variableInParameters = false; + if ($variable = $phpcsFile->findNext(T_VARIABLE, $equalsPtr, $statementEnd)) { + $variableName = $phpcsFile->getTokens()[$variable]['content']; + foreach ($this->constructorParameters as $parameter) { + $parameterName = $parameter['name']; + if ($parameterName === $variableName) { + $variableInParameters = true; + } + } + } + + if (!$variableInParameters) { + $next = $stackPtr; + while ($next = $phpcsFile->findNext(T_DOUBLE_COLON, $next + 1, $statementEnd)) { + if ($this->getNext($phpcsFile, $next, $statementEnd, T_STRING)['content'] === 'class') { + $className = $this->getPrevious($phpcsFile, $next, T_STRING)['content']; + } + } + + $className = $this->getClassNamespace($className); + + $phpcsFile->addError( + sprintf("Class %s needs to be requested in constructor, " . + "otherwise compiler will not be able to find and generate these classes", $className), + $stackPtr, + self::ERROR_CODE + ); + } + } + } + + /** + * Check if it is a ObjectManager::getInstance + * + * @param File $phpcsFile + * @param int $stackPtr + * @return bool + */ + private function isObjectManagerGetInstance(File $phpcsFile, int $stackPtr): bool + { + $prev = $phpcsFile->findPrevious(T_STRING, $stackPtr - 1); + $next = $phpcsFile->findNext(T_STRING, $stackPtr + 1); + if ($prev && + $next && + $phpcsFile->getTokens()[$prev]['content'] === 'ObjectManager' && + $phpcsFile->getTokens()[$next]['content'] === 'getInstance') { + return true; + } + return false; + } + + /** + * Checks if the code is inside __construct + * + * @param int $stackPtr + * @return bool + */ + private function isInsideConstruct(int $stackPtr): bool + { + return $stackPtr > $this->constructorScopeOpener && $stackPtr < $this->constructorScopeCloser; + } + + /** + * Get the complete class namespace from the use's + * + * @param string $className + * @return string + */ + private function getClassNamespace(string $className): string + { + foreach ($this->uses as $use) { + if (end($use) === $className) { + $className = implode('/', $use); + } + } + return $className; + } + + /** + * Register php uses + * + * @param File $phpcsFile + * @param int $stackPtr + */ + private function registerUses(File $phpcsFile, int $stackPtr): void + { + $useEnd = $phpcsFile->findEndOfStatement($stackPtr); + $use = []; + $usePosition = $stackPtr; + while ($usePosition = $phpcsFile->findNext(T_STRING, $usePosition + 1, $useEnd)) { + $use[] = $phpcsFile->getTokens()[$usePosition]['content']; + } + $this->uses [] = $use; + } + + /** + * Register php constructor parameters + * + * @param File $phpcsFile + * @param int $stackPtr + */ + private function registerConstructorParameters(File $phpcsFile, int $stackPtr): void + { + $functionName = $phpcsFile->getDeclarationName($stackPtr); + if ($functionName == '__construct') { + $this->constructorParameters = $phpcsFile->getMethodParameters($stackPtr); + $this->constructorScopeOpener = $phpcsFile->getTokens()[$stackPtr]['scope_opener']; + $this->constructorScopeCloser = $phpcsFile->getTokens()[$stackPtr]['scope_closer']; + + } + } + + /** + * Get next token + * + * @param File $phpcsFile + * @param int $nextDoubleColumn + * @param int $statementEnd + * @param int|string|array $types + * @return mixed + */ + private function getNext(File $phpcsFile, int $nextDoubleColumn, int $statementEnd, $types) + { + return $phpcsFile->getTokens()[$phpcsFile->findNext($types, $nextDoubleColumn + 1, $statementEnd)]; + } + + /** + * Get previous token + * + * @param File $phpcsFile + * @param int $nextDoubleColumn + * @param int|string|array $types + * @return mixed + */ + private function getPrevious(File $phpcsFile, int $nextDoubleColumn, $types) + { + return $phpcsFile->getTokens()[$phpcsFile->findPrevious($types, $nextDoubleColumn - 1)]; + } +} diff --git a/Magento2/Tests/PHP/AutogeneratedClassNotInConstructorUnitTest.1.php.inc b/Magento2/Tests/PHP/AutogeneratedClassNotInConstructorUnitTest.1.php.inc new file mode 100644 index 00000000..e490e6c0 --- /dev/null +++ b/Magento2/Tests/PHP/AutogeneratedClassNotInConstructorUnitTest.1.php.inc @@ -0,0 +1,28 @@ +model = $model ?? ObjectManager::getInstance()->get(Model::class); + } + + /** + * @return Model + */ + public function otherMethodThatCallsGetInstance(): void + { + $model = ObjectManager::getInstance()->get(Model::class); + $model->something(); + } +} diff --git a/Magento2/Tests/PHP/AutogeneratedClassNotInConstructorUnitTest.2.php.inc b/Magento2/Tests/PHP/AutogeneratedClassNotInConstructorUnitTest.2.php.inc new file mode 100644 index 00000000..5b6271ca --- /dev/null +++ b/Magento2/Tests/PHP/AutogeneratedClassNotInConstructorUnitTest.2.php.inc @@ -0,0 +1,16 @@ +model = ObjectManager::getInstance()->get(Model::class); + } +} + diff --git a/Magento2/Tests/PHP/AutogeneratedClassNotInConstructorUnitTest.php b/Magento2/Tests/PHP/AutogeneratedClassNotInConstructorUnitTest.php new file mode 100644 index 00000000..4ecab492 --- /dev/null +++ b/Magento2/Tests/PHP/AutogeneratedClassNotInConstructorUnitTest.php @@ -0,0 +1,33 @@ + 1 + ]; + } + return []; + } + + /** + * @inheritdoc + */ + public function getWarningList() + { + return []; + } +} From a6d2530c8eb5300ee7d79f2d0bc3f05ac6d7b902 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Cuerdo=20=C3=81lvarez?= Date: Tue, 14 Sep 2021 16:20:45 +0200 Subject: [PATCH 224/630] AC-662: Create phpcs static check for AutogeneratedClassNotInConstructorTest --- .../Sniffs/PHP/AutogeneratedClassNotInConstructorSniff.php | 3 ++- .../PHP/AutogeneratedClassNotInConstructorUnitTest.1.php.inc | 3 ++- .../PHP/AutogeneratedClassNotInConstructorUnitTest.2.php.inc | 3 ++- .../Tests/PHP/AutogeneratedClassNotInConstructorUnitTest.php | 5 +++-- 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/Magento2/Sniffs/PHP/AutogeneratedClassNotInConstructorSniff.php b/Magento2/Sniffs/PHP/AutogeneratedClassNotInConstructorSniff.php index b7343896..91fdc265 100644 --- a/Magento2/Sniffs/PHP/AutogeneratedClassNotInConstructorSniff.php +++ b/Magento2/Sniffs/PHP/AutogeneratedClassNotInConstructorSniff.php @@ -1,8 +1,9 @@ 1 + 14 => 1 ]; } return []; From 592dcfc82508ec3196c2aca46b4d14293ef230bf Mon Sep 17 00:00:00 2001 From: Maksym Aposov Date: Tue, 14 Sep 2021 14:26:10 -0500 Subject: [PATCH 225/630] AC-1102: Static test to verify self-closing tags for non-void html elements - add unit test for new sniff --- .../Sniffs/Html/HtmlSelfClosingTagsSniff.php | 2 +- .../Html/HtmlSelfClosingTagsUnitTest.1.inc | 45 +++++++++++++++++++ .../Html/HtmlSelfClosingTagsUnitTest.php | 27 +++++++++++ 3 files changed, 73 insertions(+), 1 deletion(-) create mode 100644 Magento2/Tests/Html/HtmlSelfClosingTagsUnitTest.1.inc create mode 100644 Magento2/Tests/Html/HtmlSelfClosingTagsUnitTest.php diff --git a/Magento2/Sniffs/Html/HtmlSelfClosingTagsSniff.php b/Magento2/Sniffs/Html/HtmlSelfClosingTagsSniff.php index cd215313..ecbdca44 100644 --- a/Magento2/Sniffs/Html/HtmlSelfClosingTagsSniff.php +++ b/Magento2/Sniffs/Html/HtmlSelfClosingTagsSniff.php @@ -75,7 +75,7 @@ public function process(File $phpcsFile, $stackPtr) 'Avoid using self-closing tag with non-void html element' . ' - "' . $match[0] . PHP_EOL, null, - 'HtmlTemplates.Tag.SelfClosing' + 'HtmlSelfClosingNonVoidTag' ); } } diff --git a/Magento2/Tests/Html/HtmlSelfClosingTagsUnitTest.1.inc b/Magento2/Tests/Html/HtmlSelfClosingTagsUnitTest.1.inc new file mode 100644 index 00000000..3fadb203 --- /dev/null +++ b/Magento2/Tests/Html/HtmlSelfClosingTagsUnitTest.1.inc @@ -0,0 +1,45 @@ + + + + + + + + + +
+ + + + +
+ +
+ + + + + + + + + +