From 7329d6a8d2ce591c83bdc64fc07dd347ddf02b71 Mon Sep 17 00:00:00 2001 From: Dariusz Ruminski Date: Wed, 28 Apr 2021 15:04:42 +0200 Subject: [PATCH] DX: code grooming --- dev-tools/composer.json | 8 ++++---- phpstan.neon | 10 ---------- src/Console/Application.php | 2 +- .../NoTrailingWhitespaceInStringFixer.php | 2 +- src/Tokenizer/Token.php | 1 + src/Tokenizer/Tokens.php | 2 +- tests/RuleSet/RuleSetsTest.php | 14 +++++++++++++- 7 files changed, 21 insertions(+), 18 deletions(-) diff --git a/dev-tools/composer.json b/dev-tools/composer.json index 59101667c5b..0786b63da7c 100644 --- a/dev-tools/composer.json +++ b/dev-tools/composer.json @@ -3,14 +3,14 @@ "php": "^7.1" }, "require-dev": { - "ergebnis/composer-normalize": "^2.11", + "ergebnis/composer-normalize": "^2.13", "humbug/box": "^3.8", "jangregor/phpstan-prophecy": "^0.6", "maglnet/composer-require-checker": "2.0.0", "mi-schi/phpmd-extension": "^4.3", - "phpmd/phpmd": "^2.9", - "phpstan/phpstan": "0.12.19", - "phpstan/phpstan-phpunit": "^0.12.8" + "phpmd/phpmd": "^2.10", + "phpstan/phpstan": "0.12.25", + "phpstan/phpstan-phpunit": "0.12.11" }, "config": { "optimize-autoloader": true, diff --git a/phpstan.neon b/phpstan.neon index aeb7ee9429c..ad9b782f184 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -21,9 +21,6 @@ parameters: - message: '/^Else branch is unreachable because previous condition is always true\.$/' path: src/Event/Event.php - - - message: '/^Strict comparison using !== between ''@git-commit@'' and ''@git-commit@'' will always evaluate to false\.$/' - path: src/Console/Application.php - message: '/^Result of && is always false\.$/' path: src/Config.php @@ -34,18 +31,11 @@ parameters: message: '/^Else branch is unreachable because ternary operator condition is always true\.$/' paths: - src/Config.php - - src/Tokenizer/Token.php - message: '/^Parameter #1 \$function of function register_shutdown_function expects callable\(\): void, array\(\$this\(PhpCsFixer\\FileRemoval\), ''clean''\) given\.$/' path: src/FileRemoval.php - - # https://github.com/phpstan/phpstan/issues/1215 - message: '/^Strict comparison using === between false and string will always evaluate to false\.$/' - path: src/Fixer/StringNotation/NoTrailingWhitespaceInStringFixer.php - message: '/^Constant T_ATTRIBUTE not found\.$/' path: src/Tokenizer/Transformer/AttributeTransformer.php - - - message: '/^\$this\(PhpCsFixer\\Tokenizer\\Tokens\) does not accept PhpCsFixer\\Tokenizer\\Token\|null\.$/' - path: src/Tokenizer/Tokens.php tipsOfTheDay: false diff --git a/src/Console/Application.php b/src/Console/Application.php index 7ab084bf3bf..10f940ff061 100644 --- a/src/Console/Application.php +++ b/src/Console/Application.php @@ -103,7 +103,7 @@ public function getLongVersion() $commit = '@git-commit@'; - if ('@'.'git-commit@' !== $commit) { + if ('@'.'git-commit@' !== $commit) { // @phpstan-ignore-line as `$commit` is replaced during phar building $version .= ' ('.substr($commit, 0, 7).')'; } diff --git a/src/Fixer/StringNotation/NoTrailingWhitespaceInStringFixer.php b/src/Fixer/StringNotation/NoTrailingWhitespaceInStringFixer.php index 98196019edd..da7c2316539 100644 --- a/src/Fixer/StringNotation/NoTrailingWhitespaceInStringFixer.php +++ b/src/Fixer/StringNotation/NoTrailingWhitespaceInStringFixer.php @@ -89,7 +89,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens) if ($tokens[$prev]->equals([T_CLOSE_TAG, '?>']) && Preg::match('/^\R/', $content, $match)) { $tokens[$prev] = new Token([T_CLOSE_TAG, $tokens[$prev]->getContent().$match[0]]); $content = substr($content, \strlen($match[0])); - $content = false === $content ? '' : $content; + $content = false === $content ? '' : $content; // @phpstan-ignore-line due to https://github.com/phpstan/phpstan/issues/1215 , awaiting PHP8 as min requirement of Fixer } $this->updateContent($tokens, $index, $content); diff --git a/src/Tokenizer/Token.php b/src/Tokenizer/Token.php index 9eff12479a9..c81b08cdd23 100644 --- a/src/Tokenizer/Token.php +++ b/src/Tokenizer/Token.php @@ -87,6 +87,7 @@ public function __construct($token) } else { throw new \InvalidArgumentException(sprintf( 'Cannot recognize input value as valid Token prototype, got "%s".', + // @phpstan-ignore-next-line due to lack of strong typing of method parameter \is_object($token) ? \get_class($token) : \gettype($token) )); } diff --git a/src/Tokenizer/Tokens.php b/src/Tokenizer/Tokens.php index 8eb762373c7..654bd47015f 100644 --- a/src/Tokenizer/Tokens.php +++ b/src/Tokenizer/Tokens.php @@ -386,7 +386,7 @@ public function clearEmptyTokens() for ($count = $index; $index < $limit; ++$index) { if (!$this->isEmptyAt($index)) { - $this[$count++] = $this[$index]; + $this[$count++] = $this[$index]; // @phpstan-ignore-line as we know that index exists } } diff --git a/tests/RuleSet/RuleSetsTest.php b/tests/RuleSet/RuleSetsTest.php index a82d4a26037..0f31b521eae 100644 --- a/tests/RuleSet/RuleSetsTest.php +++ b/tests/RuleSet/RuleSetsTest.php @@ -323,6 +323,18 @@ private static function getFixerByName($name) $factory->registerBuiltInFixers(); $factory->useRuleSet(new RuleSet([$name => true])); - return current($factory->getFixers()); + $fixers = $factory->getFixers(); + + if (empty($fixers)) { + throw new \RuntimeException('FixerFactory unexpectedly returned empty array.'); + } + + $fixer = current($fixers); + + if (!$fixer instanceof AbstractFixer) { + throw new \RuntimeException(sprintf('Fixer class for "%s" rule does not extend "%s".', $name, AbstractFixer::class)); + } + + return $fixer; } }