diff --git a/.travis.yml b/.travis.yml index 32f5042b..4b87566c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,4 +6,4 @@ php: install: composer install --no-interaction --prefer-source script: - bin/phpunit - - bin/phpcs --standard=PSR2 Magento/ --extensions=php + - bin/phpcs --standard=Magento Magento/ --extensions=php diff --git a/Magento/Sniffs/Annotation/ClassAnnotationStructureSniff.php b/Magento/Sniffs/Annotation/ClassAnnotationStructureSniff.php index 9e82bc91..548de767 100644 --- a/Magento/Sniffs/Annotation/ClassAnnotationStructureSniff.php +++ b/Magento/Sniffs/Annotation/ClassAnnotationStructureSniff.php @@ -33,6 +33,7 @@ public function register() */ public function __construct() { + // phpcs:ignore Magento.Classes.ObjectInstantiation.FoundDirectInstantiation $this->annotationFormatValidator = new AnnotationFormatValidator(); } diff --git a/Magento/Sniffs/Annotation/MethodAnnotationStructureSniff.php b/Magento/Sniffs/Annotation/MethodAnnotationStructureSniff.php index b4c51f63..73356005 100644 --- a/Magento/Sniffs/Annotation/MethodAnnotationStructureSniff.php +++ b/Magento/Sniffs/Annotation/MethodAnnotationStructureSniff.php @@ -23,6 +23,7 @@ class MethodAnnotationStructureSniff implements Sniff */ public function __construct() { + // phpcs:ignore Magento.Classes.ObjectInstantiation.FoundDirectInstantiation $this->annotationFormatValidator = new AnnotationFormatValidator(); } diff --git a/Magento/Sniffs/Annotation/MethodArgumentsSniff.php b/Magento/Sniffs/Annotation/MethodArgumentsSniff.php index b0b03a38..ac450c23 100644 --- a/Magento/Sniffs/Annotation/MethodArgumentsSniff.php +++ b/Magento/Sniffs/Annotation/MethodArgumentsSniff.php @@ -121,7 +121,8 @@ private function getMethodArguments(File $phpcsFile, $openParenthesisPtr, $close private function getMethodParameters(array $paramDefinitions) { $paramName = []; - for ($i = 0; $i < count($paramDefinitions); $i++) { + $countParams = count($paramDefinitions); + for ($i = 0; $i < $countParams; $i++) { if (isset($paramDefinitions[$i]['paramName'])) { $paramName[] = $paramDefinitions[$i]['paramName']; } @@ -368,10 +369,11 @@ private function validateDuplicateAnnotationDoesnotExists( $parametersCount = count($paramPointers); if ($argumentsCount <= $parametersCount && $argumentsCount > 0) { $duplicateParameters = []; - for ($i = 0; $i < sizeof($paramDefinitions); $i++) { + $countParams = count($paramDefinitions); + for ($i = 0; $i < $countParams; $i++) { if (isset($paramDefinitions[$i]['paramName'])) { $parameterContent = $paramDefinitions[$i]['paramName']; - for ($j = $i + 1; $j < count($paramDefinitions); $j++) { + for ($j = $i + 1; $j < $countParams; $j++) { if (isset($paramDefinitions[$j]['paramName']) && $parameterContent === $paramDefinitions[$j]['paramName'] ) { @@ -507,7 +509,8 @@ private function validateMethodParameterAnnotations( $phpcsFile, $paramPointers ); - for ($ptr = 0; $ptr < count($methodArguments); $ptr++) { + $countArguments = count($methodArguments); + for ($ptr = 0; $ptr < $countArguments; $ptr++) { $tokens = $phpcsFile->getTokens(); if (isset($paramPointers[$ptr])) { $this->validateArgumentNameInParameterAnnotationExists( diff --git a/Magento/Sniffs/Classes/ObjectInstantiationSniff.php b/Magento/Sniffs/Classes/ObjectInstantiationSniff.php index 3bdc6654..fbdb4993 100644 --- a/Magento/Sniffs/Classes/ObjectInstantiationSniff.php +++ b/Magento/Sniffs/Classes/ObjectInstantiationSniff.php @@ -18,7 +18,8 @@ class ObjectInstantiationSniff implements Sniff * * @var string */ - protected $warningMessage = 'Direct object instantiation (object of %s) is discouraged in Magento 2.'; + // phpcs:ignore Magento.Files.LineLength.MaxExceeded + protected $warningMessage = 'Direct %s object instantiation is discouraged in Magento. Use dependency injection or factories instead.'; /** * Warning violation code. diff --git a/Magento/Sniffs/Classes/ObjectManagerSniff.php b/Magento/Sniffs/Classes/ObjectManagerSniff.php index e2c41ae6..f68052e4 100644 --- a/Magento/Sniffs/Classes/ObjectManagerSniff.php +++ b/Magento/Sniffs/Classes/ObjectManagerSniff.php @@ -9,8 +9,7 @@ use PHP_CodeSniffer\Files\File; /** - * Class ObjectManagerSniff - * Detects direct ObjectManager usage. + * Class ObjectManagerSniff detects direct ObjectManager usage. */ class ObjectManagerSniff implements Sniff { @@ -19,7 +18,7 @@ class ObjectManagerSniff implements Sniff * * @var string */ - // phpcs:ignore Generic.Files.LineLength.TooLong + // phpcs:ignore Magento.Files.LineLength.MaxExceeded protected $warningMessage = 'The direct use of ObjectManager is discouraged. Inject necessary dependencies via constructor.'; /** diff --git a/Magento/Sniffs/PHP/DateTimeSniff.php b/Magento/Sniffs/PHP/DateTimeSniff.php index 4884cce0..0292f91f 100644 --- a/Magento/Sniffs/PHP/DateTimeSniff.php +++ b/Magento/Sniffs/PHP/DateTimeSniff.php @@ -18,7 +18,7 @@ class DateTimeSniff implements Sniff * * @var string */ - // phpcs:ignore Generic.Files.LineLength.TooLong + // phpcs:ignore Magento.Files.LineLength.MaxExceeded protected $warningMessage = 'Overcomplicated Date/Time handling. Use \Magento\Framework\Stdlib\DateTime\TimezoneInterface instead.'; /** diff --git a/Magento/Sniffs/PHP/FinalImplementationSniff.php b/Magento/Sniffs/PHP/FinalImplementationSniff.php index 5db2828b..07759570 100644 --- a/Magento/Sniffs/PHP/FinalImplementationSniff.php +++ b/Magento/Sniffs/PHP/FinalImplementationSniff.php @@ -27,7 +27,7 @@ public function register() public function process(File $phpcsFile, $stackPtr) { $phpcsFile->addError( - // phpcs:ignore Generic.Files.LineLength.TooLong + // phpcs:ignore Magento.Files.LineLength.MaxExceeded 'Final keyword is prohibited in Magento. It decreases extensibility and is not compatible with plugins and proxies.', $stackPtr, 'FoundFinal' diff --git a/Magento/Sniffs/PHP/LiteralNamespacesSniff.php b/Magento/Sniffs/PHP/LiteralNamespacesSniff.php index c1e83b96..7ac38cf7 100644 --- a/Magento/Sniffs/PHP/LiteralNamespacesSniff.php +++ b/Magento/Sniffs/PHP/LiteralNamespacesSniff.php @@ -62,6 +62,10 @@ public function process(File $sourceFile, $stackPtr) } /** + * Checks if class or interface exists. + * + * ToDo: get rig of this check https://github.com/magento/magento-coding-standard/issues/9 + * * @param string $className * @return bool */ diff --git a/Magento/Sniffs/Performance/EmptyCheckSniff.php b/Magento/Sniffs/Performance/EmptyCheckSniff.php index 5afd2abd..13a635be 100644 --- a/Magento/Sniffs/Performance/EmptyCheckSniff.php +++ b/Magento/Sniffs/Performance/EmptyCheckSniff.php @@ -20,12 +20,12 @@ class EmptyCheckSniff implements Sniff */ protected $map = [ 'count' => [ - // phpcs:ignore Generic.Files.LineLength.TooLong + // phpcs:ignore Magento.Files.LineLength.MaxExceeded 'message' => 'count(...) function should not be used to check if array is empty. Use empty(...) language construct instead', 'code' => 'FoundCount' ], 'strlen' => [ - // phpcs:ignore Generic.Files.LineLength.TooLong + // phpcs:ignore Magento.Files.LineLength.MaxExceeded 'message' => 'strlen(...) function should not be used to check if string is empty. Consider replace with (... === "") or (... !== "")', 'code' => 'FoundStrlen' ], @@ -114,7 +114,7 @@ public function process(File $phpcsFile, $stackPtr) $phpcsFile->addWarning($message, $stackPtr, $code); } } else { - // phpcs:ignore Generic.Files.LineLength.TooLong + // phpcs:ignore Magento.Files.LineLength.MaxExceeded if ($phpcsFile->findNext($this->otherComparisonOperators, $functionPosition, $endOfStatementPosition) === false) { $phpcsFile->addWarning($message, $stackPtr, $code); } @@ -130,7 +130,7 @@ public function process(File $phpcsFile, $stackPtr) */ private function findFunctionPosition($index) { - // phpcs:ignore Generic.Files.LineLength.TooLong + // phpcs:ignore Magento.Files.LineLength.MaxExceeded for ($i = $this->tokens[$index]['parenthesis_opener'] + 1; $i < $this->tokens[$index]['parenthesis_closer']; $i++) { if (array_key_exists($this->tokens[$i]['content'], $this->map)) { return $i; diff --git a/Magento/Sniffs/Security/IncludeFileSniff.php b/Magento/Sniffs/Security/IncludeFileSniff.php index 9aac21e2..28b768ea 100644 --- a/Magento/Sniffs/Security/IncludeFileSniff.php +++ b/Magento/Sniffs/Security/IncludeFileSniff.php @@ -38,9 +38,11 @@ public function register() /** * @inheritdoc + * phpcs:disable Generic.Metrics.CyclomaticComplexity.TooHigh */ public function process(File $phpcsFile, $stackPtr) { + // phpcs:enable $tokens = $phpcsFile->getTokens(); $firstToken = $phpcsFile->findNext(Tokens::$emptyTokens, $stackPtr + 1, null, true); $message = '"%s" statement detected. File manipulations are discouraged.'; diff --git a/Magento/Sniffs/Security/LanguageConstructSniff.php b/Magento/Sniffs/Security/LanguageConstructSniff.php index 78a71f5a..ddadce96 100644 --- a/Magento/Sniffs/Security/LanguageConstructSniff.php +++ b/Magento/Sniffs/Security/LanguageConstructSniff.php @@ -25,7 +25,7 @@ class LanguageConstructSniff implements Sniff * * @var string */ - // phpcs:ignore Generic.Files.LineLength.TooLong + // phpcs:ignore Magento.Files.LineLength.MaxExceeded protected $errorMessageBacktick = 'Incorrect usage of back quote string constant. Back quotes should be always inside strings.'; /** diff --git a/Magento/Sniffs/Security/XssTemplateSniff.php b/Magento/Sniffs/Security/XssTemplateSniff.php index 1ee8bf84..b737206d 100644 --- a/Magento/Sniffs/Security/XssTemplateSniff.php +++ b/Magento/Sniffs/Security/XssTemplateSniff.php @@ -161,9 +161,12 @@ private function findSpecialAnnotation($stackPtr) * * @param array $statement * @return void + * + * phpcs:disable Generic.Metrics.CyclomaticComplexity.TooHigh */ private function detectUnescapedString($statement) { + // phpcs:enable $posOfFirstElement = $this->file->findNext( [T_WHITESPACE, T_COMMENT], $statement['start'], diff --git a/Magento/Sniffs/Strings/ExecutableRegExSniff.php b/Magento/Sniffs/Strings/ExecutableRegExSniff.php index de29c789..5df0e8f2 100644 --- a/Magento/Sniffs/Strings/ExecutableRegExSniff.php +++ b/Magento/Sniffs/Strings/ExecutableRegExSniff.php @@ -19,7 +19,7 @@ class ExecutableRegExSniff implements Sniff * * @var string */ - // phpcs:ignore Generic.Files.LineLength.TooLong + // phpcs:ignore Magento.Files.LineLength.MaxExceeded protected $errorMessage = "Possible executable regular expression in %s. Make sure that the pattern doesn't contain 'e' modifier"; /** diff --git a/Magento/ruleset.xml b/Magento/ruleset.xml index 3e80c1cb..ce101e33 100644 --- a/Magento/ruleset.xml +++ b/Magento/ruleset.xml @@ -30,13 +30,6 @@ 6 - - 6 - warning - - - 6 - 10 @@ -84,6 +77,7 @@ + warning 6