diff --git a/Magento2/Sniffs/Performance/EmptyCheckSniff.php b/Magento2/Sniffs/Performance/EmptyCheckSniff.php deleted file mode 100644 index 9f7143e7..00000000 --- a/Magento2/Sniffs/Performance/EmptyCheckSniff.php +++ /dev/null @@ -1,141 +0,0 @@ - [ - // phpcs:ignore Magento2.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 Magento2.Files.LineLength.MaxExceeded - 'message' => 'strlen(...) function should not be used to check if string is empty. Consider replace with (... === "") or (... !== "")', - 'code' => 'FoundStrlen' - ], - ]; - - /** - * All tokens from current file. - * - * @var array - */ - private $tokens; - - /** - * List of comparison operators that are used to check if statement is empty. - * - * @var array - */ - protected $comparisonOperators = [ - T_GREATER_THAN, - T_IS_NOT_IDENTICAL, - T_IS_NOT_EQUAL - ]; - - /** - * List of all other comparison operators that can follow the statement. - * - * @var array - */ - protected $otherComparisonOperators = [ - T_IS_GREATER_OR_EQUAL, - T_LESS_THAN, - T_IS_SMALLER_OR_EQUAL, - T_IS_IDENTICAL, - T_IS_EQUAL - ]; - - /** - * List of logic operators that show an end of condition. - * - * @var array - */ - protected $logicOperators = [ - T_BOOLEAN_AND, - T_BOOLEAN_OR, - T_LOGICAL_AND, - T_LOGICAL_OR - ]; - - /** - * @inheritdoc - */ - public function register() - { - return [T_IF, T_ELSEIF]; - } - - /** - * @inheritdoc - */ - public function process(File $phpcsFile, $stackPtr) - { - $this->tokens = $phpcsFile->getTokens(); - $functionPosition = $this->findFunctionPosition($stackPtr); - if ($functionPosition !== false - && array_key_exists('nested_parenthesis', $this->tokens[$functionPosition]) - ) { - $openParenthesisPosition = key($this->tokens[$functionPosition]['nested_parenthesis']); - $endOfStatementPosition = $this->tokens[$openParenthesisPosition]['parenthesis_closer']; - $nextOperatorPosition = $phpcsFile->findNext( - $this->logicOperators, - $functionPosition, - $endOfStatementPosition - ); - if ($nextOperatorPosition !== false) { - $endOfStatementPosition = $nextOperatorPosition; - } - $operatorPosition = $phpcsFile->findNext( - $this->comparisonOperators, - $functionPosition, - $endOfStatementPosition - ); - $code = $this->map[$this->tokens[$functionPosition]['content']]['code']; - $message = $this->map[$this->tokens[$functionPosition]['content']]['message']; - if ($operatorPosition !== false) { - if ($phpcsFile->findNext(T_LNUMBER, $operatorPosition, $endOfStatementPosition, false, '0') !== false) { - $phpcsFile->addWarning($message, $stackPtr, $code); - } - } else { - // phpcs:ignore Magento2.Files.LineLength.MaxExceeded - if ($phpcsFile->findNext($this->otherComparisonOperators, $functionPosition, $endOfStatementPosition) === false) { - $phpcsFile->addWarning($message, $stackPtr, $code); - } - } - } - } - - /** - * Find the position of discouraged function between parenthesis. - * - * @param int $index - * @return mixed - */ - private function findFunctionPosition($index) - { - // phpcs:ignore Magento2.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; - } - } - return false; - } -} diff --git a/Magento2/Tests/Performance/EmptyCheckUnitTest.inc b/Magento2/Tests/Performance/EmptyCheckUnitTest.inc deleted file mode 100644 index be2d1bd1..00000000 --- a/Magento2/Tests/Performance/EmptyCheckUnitTest.inc +++ /dev/null @@ -1,105 +0,0 @@ - 0) { - // -} - -if ((anotherFunc($array) !== 0) && count($array) > 0) { - // -} - -if ((count($array) !== 0) && (((anotherFunc($array))))) { - // -} - -if (((count($array)))) { - // -} - -if (count($array) && (anotherFunc($array) !== 0)) { - // -} - -if ($findme === 'a' && (count($array) || $findme !== 'b') && $mystring !== false) { - // -} - -if ($findme === 'a' && (count($array) != 0 || $findme !== 'b') && $mystring !== false) { - // -} - -if ($findme === 'a' && (count($array) > 10 || $findme !== 'b') && $mystring !== false) { - // -} - -if (($column->getId() === 'store_id' || count($array) > 0 || $column->getId() === 'status') && $column->getFilter()->getValue()) { - // -} - -$length = count($array); - -if ('count' != $foo && count($bar)) { - // -} - -if ($findme === 'a' and (count($array) != 0 or $findme !== 'b') and $mystring !== false) { - // -} - -if (strlen($string) > 0) { - // -} - -if ((anotherFunc($string) !== 0) && strlen($string) > 0) { - // -} - -if ((strlen($string) !== 0) && (((anotherFunc($string))))) { - // -} - -if (((strlen($string)))) { - // -} - -if (strlen($string) && (anotherFunc($string) !== 0)) { - // -} - -if ($findme === 'a' && (strlen($string) || $findme !== 'b') && $mystring !== false) { - // -} - -if ($findme === 'a' && (strlen($string) != 0 || $findme !== 'b') && $mystring !== false) { - // -} - -if ($findme === 'a' && (strlen($string) > 10 || $findme !== 'b') && $mystring !== false) { - // -} - -if (($column->getId() === 'store_id' || strlen($string) > 0 || $column->getId() === 'status') && $column->getFilter()->getValue()) { - // -} - -if (strlen($string . implode(',', $array)) && (anotherFunc($string) !== 0)) { - // -} - -if (strlen($string . implode(',', $array)) > 10 && (anotherFunc($string) !== 0)) { - // -} - -$length = strlen($string); - -if ($findme === 'a' and (strlen($string) > 0 or $findme !== 'b') and $mystring !== false) { - // -} - -if (strlen($string) < $limit) { - // -} - -if (strlen($string) >= getLimit()) { - // -} diff --git a/Magento2/Tests/Performance/EmptyCheckUnitTest.php b/Magento2/Tests/Performance/EmptyCheckUnitTest.php deleted file mode 100644 index cf749980..00000000 --- a/Magento2/Tests/Performance/EmptyCheckUnitTest.php +++ /dev/null @@ -1,51 +0,0 @@ - 1, - 7 => 1, - 11 => 1, - 15 => 1, - 19 => 1, - 23 => 1, - 27 => 1, - 35 => 1, - 41 => 1, - 45 => 1, - 49 => 1, - 53 => 1, - 57 => 1, - 61 => 1, - 65 => 1, - 69 => 1, - 73 => 1, - 81 => 1, - 85 => 1, - 95 => 1, - ]; - } -} diff --git a/Magento2/ruleset.xml b/Magento2/ruleset.xml index 8da1d608..8c344985 100644 --- a/Magento2/ruleset.xml +++ b/Magento2/ruleset.xml @@ -120,6 +120,7 @@ 8 warning + */Test/* 8 @@ -213,10 +214,6 @@ 7 warning - - 7 - warning - 7 warning @@ -302,6 +299,7 @@ 6 warning + */Test/* 6 @@ -449,10 +447,6 @@ 0 - - 5 - warning - diff --git a/composer.json b/composer.json index 54577d2d..ee9cacbe 100644 --- a/composer.json +++ b/composer.json @@ -6,7 +6,7 @@ "AFL-3.0" ], "type": "phpcodesniffer-standard", - "version": "1.0.0", + "version": "1.0.1", "require": { "php": ">=5.6.0", "squizlabs/php_codesniffer": "~3.3.0" diff --git a/composer.lock b/composer.lock index 572544cd..7d72b455 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": "8b83af353c6a189e7b284afaa88eed78", + "content-hash": "1fad2c46da06bbde9b4fa1b8b09ae46e", "packages": [ { "name": "squizlabs/php_codesniffer",