diff --git a/.github/workflows/code_analysis.yaml b/.github/workflows/code_analysis.yaml index 616aada81..2faa71380 100644 --- a/.github/workflows/code_analysis.yaml +++ b/.github/workflows/code_analysis.yaml @@ -36,10 +36,6 @@ jobs: name: 'Tests' run: vendor/bin/phpunit - - - name: 'PHP Linter' - run: vendor/bin/parallel-lint src tests - - name: 'Check Commented Code' run: vendor/bin/easy-ci check-commented-code src tests --ansi diff --git a/composer.json b/composer.json index ecb8d865e..461825e9a 100644 --- a/composer.json +++ b/composer.json @@ -5,23 +5,23 @@ "require": { "php": ">=8.1", "nette/utils": "^3.2", - "friendsofphp/php-cs-fixer": "^3.18", + "friendsofphp/php-cs-fixer": "^3.40", "symplify/rule-doc-generator-contracts": "^11.1" }, "require-dev": { - "symplify/easy-coding-standard": "^12.0.1", + "symplify/easy-coding-standard": "^12.0.8", "squizlabs/php_codesniffer": "^3.7.2", "phpunit/phpunit": "^10.2", "symplify/rule-doc-generator": "^12.0", - "php-parallel-lint/php-parallel-lint": "^1.3", "phpstan/extension-installer": "^1.3", "phpstan/phpstan": "^1.10.26", "rector/rector": "^0.17.7", "symplify/easy-ci": "^11.3", "symplify/phpstan-extensions": "^11.2", - "tomasvotruba/unused-public": "^0.2", + "tomasvotruba/unused-public": "^0.3", "tomasvotruba/type-coverage": "^0.2", - "tomasvotruba/class-leak": "^0.1" + "tomasvotruba/class-leak": "^0.2", + "tracy/tracy": "^2.10" }, "autoload": { "psr-4": { diff --git a/src/DocBlock/UselessDocBlockCleaner.php b/src/DocBlock/UselessDocBlockCleaner.php index 38c71fe71..70689e813 100644 --- a/src/DocBlock/UselessDocBlockCleaner.php +++ b/src/DocBlock/UselessDocBlockCleaner.php @@ -17,7 +17,6 @@ final class UselessDocBlockCleaner self::TODO_IMPLEMENT_METHOD_COMMENT_BY_PHPSTORM_REGEX, self::COMMENT_CLASS_REGEX, self::COMMENT_CONSTRUCTOR_CLASS_REGEX, - self::COMMENT_METHOD_CLASS_REGEX, ]; /** @@ -32,24 +31,6 @@ final class UselessDocBlockCleaner */ private const TODO_COMMENT_BY_PHPSTORM_REGEX = '#\/\/ TODO: Change the autogenerated stub$#'; - /** - * @see https://regex101.com/r/QeAiRV/1 - * @var string - */ - private const SPACE_STAR_SLASH_REGEX = '#[\s\*\/]#'; - - /** - * @see https://regex101.com/r/S1wAAh/2 - * @var string - */ - private const COMMENT_METHOD_CLASS_REGEX = '#^\s{0,}(\/\*{2}\s+?)?(\*|\/\/)\s+([Gg]et|[Ss]et)\s+[^\s]*\.?(\s+\*\/)?$#'; - - /** - * @see https://regex101.com/r/eBux3I/1 - * @var string - */ - private const COMMENT_ANY_METHOD_CLASS_REGEX = '#^\s{0,}(\/\*{2}\s+?)?(\*|\/\/)\s+(?([Gg]et|[Ss]et)\s+(.*))(\s+\*\/)?$#'; - /** * @see https://regex101.com/r/RzTdFH/4 * @var string @@ -65,63 +46,14 @@ final class UselessDocBlockCleaner /** * @param Token[] $tokens */ - public function clearDocTokenContent(array $tokens, int $position, string $docContent): string + public function clearDocTokenContent(array $tokens, int $position, Token $currentToken): string { + $docContent = $currentToken->getContent(); + foreach (self::CLEANING_REGEXES as $cleaningRegex) { $docContent = Strings::replace($docContent, $cleaningRegex, ''); } - return $this->cleanClassMethodCommentMimicMethodName($tokens, $position, $docContent); - } - - /** - * @param Token[] $reversedTokens - */ - private function cleanClassMethodCommentMimicMethodName( - array $reversedTokens, - int $index, - string $docContent - ): string { - $matchMethodClass = Strings::match($docContent, self::COMMENT_METHOD_CLASS_REGEX); - if ($matchMethodClass) { - return $docContent; - } - - if (! $this->isNextFunction($reversedTokens, $index)) { - return $docContent; - } - - $matchAnyMethodClass = Strings::match($docContent, self::COMMENT_ANY_METHOD_CLASS_REGEX); - if (! $matchAnyMethodClass) { - return $docContent; - } - - $obviousMethodComment = $matchAnyMethodClass['obvious_method_comment']; - $obviousMethodComment = $this->removeSpaces($obviousMethodComment); - - $methodNameContent = $reversedTokens[$index + 6]->getContent(); - - if (strtolower($obviousMethodComment) !== strtolower($methodNameContent)) { - return $docContent; - } - - return Strings::replace($docContent, self::COMMENT_ANY_METHOD_CLASS_REGEX, ''); - } - - /** - * @param Token[] $reversedTokens - */ - private function isNextFunction(array $reversedTokens, int $index): bool - { - if (! isset($reversedTokens[$index + 4])) { - return false; - } - - return $reversedTokens[$index + 4]->getContent() === 'function'; - } - - private function removeSpaces(string $content): string - { - return Strings::replace($content, self::SPACE_STAR_SLASH_REGEX, ''); + return $docContent; } } diff --git a/src/Fixer/Commenting/RemoveUselessDefaultCommentFixer.php b/src/Fixer/Commenting/RemoveUselessDefaultCommentFixer.php index fc5937f7d..ac3aa1c85 100644 --- a/src/Fixer/Commenting/RemoveUselessDefaultCommentFixer.php +++ b/src/Fixer/Commenting/RemoveUselessDefaultCommentFixer.php @@ -60,8 +60,9 @@ public function fix(SplFileInfo $fileInfo, Tokens $tokens): void $cleanedDocContent = $this->uselessDocBlockCleaner->clearDocTokenContent( $reversedTokens, $index, - $token->getContent() + $token ); + if ($cleanedDocContent !== '') { continue; } diff --git a/tests/Fixer/Commenting/RemoveUselessDefaultCommentFixer/Fixture/skip_inline_set.php.inc b/tests/Fixer/Commenting/RemoveUselessDefaultCommentFixer/Fixture/skip_inline_set.php.inc new file mode 100644 index 000000000..7add06940 --- /dev/null +++ b/tests/Fixer/Commenting/RemoveUselessDefaultCommentFixer/Fixture/skip_inline_set.php.inc @@ -0,0 +1,12 @@ + ------ - diff --git a/tests/Fixer/Commenting/RemoveUselessDefaultCommentFixer/Fixture/useless_extra_space_class_comment.php.inc b/tests/Fixer/Commenting/RemoveUselessDefaultCommentFixer/Fixture/useless_extra_space_class_comment.php.inc deleted file mode 100644 index 24b0dc35f..000000000 --- a/tests/Fixer/Commenting/RemoveUselessDefaultCommentFixer/Fixture/useless_extra_space_class_comment.php.inc +++ /dev/null @@ -1,43 +0,0 @@ - ------ - diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 79d35f8a9..855f0f8d5 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -28,3 +28,8 @@ // initialize custom T_* token constants used by PHP_CodeSniffer parser new Tokens(); } + + +// prefer local coding-standard over old, vendor one +exec('rm -rf vendor/symplify/easy-coding-standard/vendor/symplify/coding-standard/src'); +exec('ln -s $PWD/src vendor/symplify/easy-coding-standard/vendor/symplify/coding-standard/');