From 30572ce2d6b3473195b3472b21878bffb91116ef Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Wed, 10 Jun 2026 00:05:29 +0100 Subject: [PATCH 1/2] split ParamReturnAndVarTagMalformsFixer into particular rules, each handling single job --- README.md | 136 +++++++++++++----- config/sets/docblock.php | 37 +++++ config/symplify.php | 5 +- .../Commenting/AbstractDocBlockFixer.php | 114 +++++++++++++++ .../Commenting/AddMissingParamNameFixer.php} | 24 +++- .../Commenting/AddMissingVarNameFixer.php} | 19 ++- .../DoubleAsteriskInlineVarFixer.php | 46 ++++++ .../Commenting/FixParamNameTypoFixer.php} | 24 +++- .../ParamReturnAndVarTagMalformsFixer.php | 136 +++--------------- src/Fixer/Commenting/RemoveDeadParamFixer.php | 51 +++++++ .../RemoveParamNameReferenceFixer.php | 41 ++++++ .../RemoveSuperfluousReturnNameFixer.php} | 19 ++- .../RemoveSuperfluousVarNameFixer.php} | 19 ++- .../SingleLineInlineVarDocBlockFixer.php} | 21 ++- .../Commenting/SwitchedTypeAndNameFixer.php} | 19 ++- .../DocBlock/MalformWorkerInterface.php | 16 --- .../MalformWorker/DeadParamMalformWorker.php | 41 ------ .../MalformWorker/InlineVarMalformWorker.php | 33 ----- .../ParamNameReferenceMalformWorker.php | 30 ---- .../AddMissingParamNameFixerTest.php} | 4 +- .../Fixture/wrong6.php.inc | 0 .../config/configured_rule.php | 10 ++ .../AddMissingVarNameFixerTest.php | 28 ++++ .../Fixture/inlined_var_above.php.inc | 0 .../inlined_var_above_many_types.php.inc | 0 .../config/configured_rule.php | 10 ++ .../DoubleAsteriskInlineVarFixerTest.php | 28 ++++ .../Fixture/single_asterisk.php.inc | 13 ++ .../config/configured_rule.php | 10 ++ .../FixParamNameTypoFixerTest.php | 28 ++++ .../Fixture/param_name_wrong.php.inc | 0 .../Fixture/wrong11.php.inc | 0 .../Fixture/wrong12.php.inc | 0 .../config/configured_rule.php | 10 ++ .../Source/Schedule.php | 9 -- .../config/configured_rule.php | 10 -- .../Fixture/dead_param.php.inc | 0 .../Fixture/dead_param_only.php.inc | 0 .../RemoveDeadParamFixerTest.php | 28 ++++ .../config/configured_rule.php | 10 ++ .../Fixture/param_reference.php.inc | 0 .../RemoveParamNameReferenceFixerTest.php | 28 ++++ .../config/configured_rule.php | 10 ++ .../Fixture/wrong10.php.inc | 0 .../Fixture/wrong7.php.inc | 0 .../RemoveSuperfluousReturnNameFixerTest.php | 28 ++++ .../config/configured_rule.php | 10 ++ .../Fixture/wrong8.php.inc | 0 .../RemoveSuperfluousVarNameFixerTest.php | 28 ++++ .../config/configured_rule.php | 10 ++ .../Fixture/multiline_var.php.inc | 21 +++ .../SingleLineInlineVarDocBlockFixerTest.php | 28 ++++ .../config/configured_rule.php | 10 ++ .../Fixture/wrong3.php.inc | 0 .../SwitchedTypeAndNameFixerTest.php | 28 ++++ .../config/configured_rule.php | 10 ++ tests/Set/DocblockSet/DocblockSetTest.php | 31 ++++ .../DocblockSet}/Fixture/correct.php.inc | 0 .../DocblockSet}/Fixture/correct2.php.inc | 0 .../Fixture/iterator_flip.php.inc | 0 .../Fixture/param_variable_mallforms.php.inc | 0 ...has_same_param_previous_definition.php.inc | 0 .../Fixture/skip_callable_param.php.inc | 2 +- .../Fixture/skip_curly_newline.php.inc | 0 .../skip_edge_case_with_assert.php.inc | 2 +- .../Fixture/skip_inlined_var_in_doc.php.inc | 0 .../Fixture/skip_nested_multiline.php.inc | 0 .../Fixture/skip_union_array.php.inc | 0 .../DocblockSet}/Fixture/wrong4.php.inc | 0 .../DocblockSet}/Fixture/wrong5.php.inc | 0 .../DocblockSet}/Fixture/wrong9.php.inc | 0 tests/Set/DocblockSet/Source/Schedule.php | 9 ++ 72 files changed, 958 insertions(+), 326 deletions(-) create mode 100644 config/sets/docblock.php create mode 100644 src/Fixer/Commenting/AbstractDocBlockFixer.php rename src/{TokenRunner/DocBlock/MalformWorker/MissingParamNameMalformWorker.php => Fixer/Commenting/AddMissingParamNameFixer.php} (82%) rename src/{TokenRunner/DocBlock/MalformWorker/MissingVarNameMalformWorker.php => Fixer/Commenting/AddMissingVarNameFixer.php} (69%) create mode 100644 src/Fixer/Commenting/DoubleAsteriskInlineVarFixer.php rename src/{TokenRunner/DocBlock/MalformWorker/ParamNameTypoMalformWorker.php => Fixer/Commenting/FixParamNameTypoFixer.php} (81%) create mode 100644 src/Fixer/Commenting/RemoveDeadParamFixer.php create mode 100644 src/Fixer/Commenting/RemoveParamNameReferenceFixer.php rename src/{TokenRunner/DocBlock/MalformWorker/SuperfluousReturnNameMalformWorker.php => Fixer/Commenting/RemoveSuperfluousReturnNameFixer.php} (74%) rename src/{TokenRunner/DocBlock/MalformWorker/SuperfluousVarNameMalformWorker.php => Fixer/Commenting/RemoveSuperfluousVarNameFixer.php} (76%) rename src/{TokenRunner/DocBlock/MalformWorker/InlineVariableDocBlockMalformWorker.php => Fixer/Commenting/SingleLineInlineVarDocBlockFixer.php} (71%) rename src/{TokenRunner/DocBlock/MalformWorker/SwitchedTypeAndNameMalformWorker.php => Fixer/Commenting/SwitchedTypeAndNameFixer.php} (65%) delete mode 100644 src/TokenRunner/Contract/DocBlock/MalformWorkerInterface.php delete mode 100644 src/TokenRunner/DocBlock/MalformWorker/DeadParamMalformWorker.php delete mode 100644 src/TokenRunner/DocBlock/MalformWorker/InlineVarMalformWorker.php delete mode 100644 src/TokenRunner/DocBlock/MalformWorker/ParamNameReferenceMalformWorker.php rename tests/Fixer/Commenting/{ParamReturnAndVarTagMalformsFixer/ParamReturnAndVarTagMalformsFixerTest.php => AddMissingParamNameFixer/AddMissingParamNameFixerTest.php} (75%) rename tests/Fixer/Commenting/{ParamReturnAndVarTagMalformsFixer => AddMissingParamNameFixer}/Fixture/wrong6.php.inc (100%) create mode 100644 tests/Fixer/Commenting/AddMissingParamNameFixer/config/configured_rule.php create mode 100644 tests/Fixer/Commenting/AddMissingVarNameFixer/AddMissingVarNameFixerTest.php rename tests/Fixer/Commenting/{ParamReturnAndVarTagMalformsFixer => AddMissingVarNameFixer}/Fixture/inlined_var_above.php.inc (100%) rename tests/Fixer/Commenting/{ParamReturnAndVarTagMalformsFixer => AddMissingVarNameFixer}/Fixture/inlined_var_above_many_types.php.inc (100%) create mode 100644 tests/Fixer/Commenting/AddMissingVarNameFixer/config/configured_rule.php create mode 100644 tests/Fixer/Commenting/DoubleAsteriskInlineVarFixer/DoubleAsteriskInlineVarFixerTest.php create mode 100644 tests/Fixer/Commenting/DoubleAsteriskInlineVarFixer/Fixture/single_asterisk.php.inc create mode 100644 tests/Fixer/Commenting/DoubleAsteriskInlineVarFixer/config/configured_rule.php create mode 100644 tests/Fixer/Commenting/FixParamNameTypoFixer/FixParamNameTypoFixerTest.php rename tests/Fixer/Commenting/{ParamReturnAndVarTagMalformsFixer => FixParamNameTypoFixer}/Fixture/param_name_wrong.php.inc (100%) rename tests/Fixer/Commenting/{ParamReturnAndVarTagMalformsFixer => FixParamNameTypoFixer}/Fixture/wrong11.php.inc (100%) rename tests/Fixer/Commenting/{ParamReturnAndVarTagMalformsFixer => FixParamNameTypoFixer}/Fixture/wrong12.php.inc (100%) create mode 100644 tests/Fixer/Commenting/FixParamNameTypoFixer/config/configured_rule.php delete mode 100644 tests/Fixer/Commenting/ParamReturnAndVarTagMalformsFixer/Source/Schedule.php delete mode 100644 tests/Fixer/Commenting/ParamReturnAndVarTagMalformsFixer/config/configured_rule.php rename tests/Fixer/Commenting/{ParamReturnAndVarTagMalformsFixer => RemoveDeadParamFixer}/Fixture/dead_param.php.inc (100%) rename tests/Fixer/Commenting/{ParamReturnAndVarTagMalformsFixer => RemoveDeadParamFixer}/Fixture/dead_param_only.php.inc (100%) create mode 100644 tests/Fixer/Commenting/RemoveDeadParamFixer/RemoveDeadParamFixerTest.php create mode 100644 tests/Fixer/Commenting/RemoveDeadParamFixer/config/configured_rule.php rename tests/Fixer/Commenting/{ParamReturnAndVarTagMalformsFixer => RemoveParamNameReferenceFixer}/Fixture/param_reference.php.inc (100%) create mode 100644 tests/Fixer/Commenting/RemoveParamNameReferenceFixer/RemoveParamNameReferenceFixerTest.php create mode 100644 tests/Fixer/Commenting/RemoveParamNameReferenceFixer/config/configured_rule.php rename tests/Fixer/Commenting/{ParamReturnAndVarTagMalformsFixer => RemoveSuperfluousReturnNameFixer}/Fixture/wrong10.php.inc (100%) rename tests/Fixer/Commenting/{ParamReturnAndVarTagMalformsFixer => RemoveSuperfluousReturnNameFixer}/Fixture/wrong7.php.inc (100%) create mode 100644 tests/Fixer/Commenting/RemoveSuperfluousReturnNameFixer/RemoveSuperfluousReturnNameFixerTest.php create mode 100644 tests/Fixer/Commenting/RemoveSuperfluousReturnNameFixer/config/configured_rule.php rename tests/Fixer/Commenting/{ParamReturnAndVarTagMalformsFixer => RemoveSuperfluousVarNameFixer}/Fixture/wrong8.php.inc (100%) create mode 100644 tests/Fixer/Commenting/RemoveSuperfluousVarNameFixer/RemoveSuperfluousVarNameFixerTest.php create mode 100644 tests/Fixer/Commenting/RemoveSuperfluousVarNameFixer/config/configured_rule.php create mode 100644 tests/Fixer/Commenting/SingleLineInlineVarDocBlockFixer/Fixture/multiline_var.php.inc create mode 100644 tests/Fixer/Commenting/SingleLineInlineVarDocBlockFixer/SingleLineInlineVarDocBlockFixerTest.php create mode 100644 tests/Fixer/Commenting/SingleLineInlineVarDocBlockFixer/config/configured_rule.php rename tests/Fixer/Commenting/{ParamReturnAndVarTagMalformsFixer => SwitchedTypeAndNameFixer}/Fixture/wrong3.php.inc (100%) create mode 100644 tests/Fixer/Commenting/SwitchedTypeAndNameFixer/SwitchedTypeAndNameFixerTest.php create mode 100644 tests/Fixer/Commenting/SwitchedTypeAndNameFixer/config/configured_rule.php create mode 100644 tests/Set/DocblockSet/DocblockSetTest.php rename tests/{Fixer/Commenting/ParamReturnAndVarTagMalformsFixer => Set/DocblockSet}/Fixture/correct.php.inc (100%) rename tests/{Fixer/Commenting/ParamReturnAndVarTagMalformsFixer => Set/DocblockSet}/Fixture/correct2.php.inc (100%) rename tests/{Fixer/Commenting/ParamReturnAndVarTagMalformsFixer => Set/DocblockSet}/Fixture/iterator_flip.php.inc (100%) rename tests/{Fixer/Commenting/ParamReturnAndVarTagMalformsFixer => Set/DocblockSet}/Fixture/param_variable_mallforms.php.inc (100%) rename tests/{Fixer/Commenting/ParamReturnAndVarTagMalformsFixer => Set/DocblockSet}/Fixture/skip_callable_has_same_param_previous_definition.php.inc (100%) rename tests/{Fixer/Commenting/ParamReturnAndVarTagMalformsFixer => Set/DocblockSet}/Fixture/skip_callable_param.php.inc (69%) rename tests/{Fixer/Commenting/ParamReturnAndVarTagMalformsFixer => Set/DocblockSet}/Fixture/skip_curly_newline.php.inc (100%) rename tests/{Fixer/Commenting/ParamReturnAndVarTagMalformsFixer => Set/DocblockSet}/Fixture/skip_edge_case_with_assert.php.inc (72%) rename tests/{Fixer/Commenting/ParamReturnAndVarTagMalformsFixer => Set/DocblockSet}/Fixture/skip_inlined_var_in_doc.php.inc (100%) rename tests/{Fixer/Commenting/ParamReturnAndVarTagMalformsFixer => Set/DocblockSet}/Fixture/skip_nested_multiline.php.inc (100%) rename tests/{Fixer/Commenting/ParamReturnAndVarTagMalformsFixer => Set/DocblockSet}/Fixture/skip_union_array.php.inc (100%) rename tests/{Fixer/Commenting/ParamReturnAndVarTagMalformsFixer => Set/DocblockSet}/Fixture/wrong4.php.inc (100%) rename tests/{Fixer/Commenting/ParamReturnAndVarTagMalformsFixer => Set/DocblockSet}/Fixture/wrong5.php.inc (100%) rename tests/{Fixer/Commenting/ParamReturnAndVarTagMalformsFixer => Set/DocblockSet}/Fixture/wrong9.php.inc (100%) create mode 100644 tests/Set/DocblockSet/Source/Schedule.php diff --git a/README.md b/README.md index 02bd31cb0..08918f3d0 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,7 @@ vendor/bin/ecs --fix
-# 14 Rules to Keep Your Code Clean +# 23 Rules to Keep Your Code Clean ## ArrayListItemNewlineFixer @@ -125,13 +125,19 @@ Each chain method call must be on own line
-## ParamReturnAndVarTagMalformsFixer +## Doc block malform rules -Fixes `@param`, `@return`, `@var` and inline `@var` annotations broken formats. This single rule covers a wide range of docblock malforms: +The previous all-in-one `ParamReturnAndVarTagMalformsFixer` is now **split into single-task rules**, each fixing one kind of `@param`/`@return`/`@var` malform. They are registered together in the [`docblock` set](../config/sets/docblock.php) and all handle the `@phpstan-` and `@psalm-` prefixed variants of these tags. -- class: [`Symplify\CodingStandard\Fixer\Commenting\ParamReturnAndVarTagMalformsFixer`](../src/Fixer/Commenting/ParamReturnAndVarTagMalformsFixer.php) +`ParamReturnAndVarTagMalformsFixer` is kept as a deprecated, empty rule that points to its successors. -**Add a missing `@param` variable name** +
+ +## AddMissingParamNameFixer + +Add a missing variable name to a `@param` annotation + +- class: [`Symplify\CodingStandard\Fixer\Commenting\AddMissingParamNameFixer`](../src/Fixer/Commenting/AddMissingParamNameFixer.php) ```diff /** @@ -143,21 +149,60 @@ Fixes `@param`, `@return`, `@var` and inline `@var` annotations broken formats. } ``` -**Reorder switched type and variable name** +
+ +## AddMissingVarNameFixer + +Add a missing variable name to an inline `@var` annotation + +- class: [`Symplify\CodingStandard\Fixer\Commenting\AddMissingVarNameFixer`](../src/Fixer/Commenting/AddMissingVarNameFixer.php) + +```diff +-/** @var int */ ++/** @var int $value */ + $value = 1000; +``` + +
+ +## DoubleAsteriskInlineVarFixer + +Use a double asterisk `/**` doc block for an inline `@var` comment + +- class: [`Symplify\CodingStandard\Fixer\Commenting\DoubleAsteriskInlineVarFixer`](../src/Fixer/Commenting/DoubleAsteriskInlineVarFixer.php) + +```diff +-/* @var int $variable */ ++/** @var int $variable */ + $variable = 5; +``` + +
+ +## FixParamNameTypoFixer + +Fix a typo in the `@param` variable name to match the real argument + +- class: [`Symplify\CodingStandard\Fixer\Commenting\FixParamNameTypoFixer`](../src/Fixer/Commenting/FixParamNameTypoFixer.php) ```diff /** -- * @param $a string -- * @param $b string|null -+ * @param string $a -+ * @param string|null $b + * @param string $one +- * @param string $twoTypo ++ * @param string $two */ - function test($a, string $b = null): string + function anotherFunction(string $one, string $two) { } ``` -**Remove a dead `@param` line that has only a name and no type** +
+ +## RemoveDeadParamFixer + +Remove a dead `@param` line that has only a name and no type + +- class: [`Symplify\CodingStandard\Fixer\Commenting\RemoveDeadParamFixer`](../src/Fixer/Commenting/RemoveDeadParamFixer.php) ```diff /** @@ -169,20 +214,13 @@ Fixes `@param`, `@return`, `@var` and inline `@var` annotations broken formats. } ``` -**Fix a typo in the `@param` variable name to match the real argument** +
-```diff - /** - * @param string $one -- * @param string $twoTypo -+ * @param string $two - */ - function anotherFunction(string $one, string $two) - { - } -``` +## RemoveParamNameReferenceFixer + +Remove the reference `&` from a `@param` variable name -**Remove the reference `&` from a `@param` name** +- class: [`Symplify\CodingStandard\Fixer\Commenting\RemoveParamNameReferenceFixer`](../src/Fixer/Commenting/RemoveParamNameReferenceFixer.php) ```diff /** @@ -194,7 +232,13 @@ Fixes `@param`, `@return`, `@var` and inline `@var` annotations broken formats. } ``` -**Remove a superfluous variable name from `@return`** +
+ +## RemoveSuperfluousReturnNameFixer + +Remove a superfluous variable name from a `@return` annotation + +- class: [`Symplify\CodingStandard\Fixer\Commenting\RemoveSuperfluousReturnNameFixer`](../src/Fixer/Commenting/RemoveSuperfluousReturnNameFixer.php) ```diff /** @@ -206,7 +250,13 @@ Fixes `@param`, `@return`, `@var` and inline `@var` annotations broken formats. } ``` -**Remove a superfluous variable name from a property `@var`** +
+ +## RemoveSuperfluousVarNameFixer + +Remove a superfluous variable name from a property `@var` annotation + +- class: [`Symplify\CodingStandard\Fixer\Commenting\RemoveSuperfluousVarNameFixer`](../src/Fixer/Commenting/RemoveSuperfluousVarNameFixer.php) ```diff /** @@ -216,24 +266,42 @@ Fixes `@param`, `@return`, `@var` and inline `@var` annotations broken formats. private $property; ``` -**Add a missing variable name to an inline `@var`** +
+ +## SingleLineInlineVarDocBlockFixer + +Collapse a multi-line inline `@var` doc block into a single line + +- class: [`Symplify\CodingStandard\Fixer\Commenting\SingleLineInlineVarDocBlockFixer`](../src/Fixer/Commenting/SingleLineInlineVarDocBlockFixer.php) ```diff --/** @var int */ +-/** +- * @var int $value +- */ +/** @var int $value */ $value = 1000; ``` -**Normalize a malformed inline `@var` (single asterisk, switched name/type)** +
+ +## SwitchedTypeAndNameFixer + +Reorder switched type and variable name in `@param`/`@var` annotation + +- class: [`Symplify\CodingStandard\Fixer\Commenting\SwitchedTypeAndNameFixer`](../src/Fixer/Commenting/SwitchedTypeAndNameFixer.php) ```diff --/* @var $variable int */ -+/** @var int $variable */ - $variable = 5; + /** +- * @param $a string +- * @param $b string|null ++ * @param string $a ++ * @param string|null $b + */ + function test($a, string $b = null): string + { + } ``` -It also handles the `@phpstan-` and `@psalm-` prefixed variants of these tags. -
## RemovePropertyVariableNameDescriptionFixer diff --git a/config/sets/docblock.php b/config/sets/docblock.php new file mode 100644 index 000000000..33b1d74c2 --- /dev/null +++ b/config/sets/docblock.php @@ -0,0 +1,37 @@ +rules([ + // inline @var + DoubleAsteriskInlineVarFixer::class, + SingleLineInlineVarDocBlockFixer::class, + AddMissingVarNameFixer::class, + + // @param + AddMissingParamNameFixer::class, + FixParamNameTypoFixer::class, + RemoveParamNameReferenceFixer::class, + RemoveDeadParamFixer::class, + + // superfluous names + RemoveSuperfluousReturnNameFixer::class, + RemoveSuperfluousVarNameFixer::class, + + // switched type/name order + SwitchedTypeAndNameFixer::class, + ]); +}; diff --git a/config/symplify.php b/config/symplify.php index b9922804d..103222e18 100644 --- a/config/symplify.php +++ b/config/symplify.php @@ -9,7 +9,6 @@ use Symplify\CodingStandard\Fixer\ArrayNotation\ArrayListItemNewlineFixer; use Symplify\CodingStandard\Fixer\ArrayNotation\ArrayOpenerAndCloserNewlineFixer; use Symplify\CodingStandard\Fixer\ArrayNotation\StandaloneLineInMultilineArrayFixer; -use Symplify\CodingStandard\Fixer\Commenting\ParamReturnAndVarTagMalformsFixer; use Symplify\CodingStandard\Fixer\Commenting\RemoveUselessDefaultCommentFixer; use Symplify\CodingStandard\Fixer\LineLength\LineLengthFixer; use Symplify\CodingStandard\Fixer\Spacing\MethodChainingNewlineFixer; @@ -20,10 +19,12 @@ use Symplify\EasyCodingStandard\Config\ECSConfig; return static function (ECSConfig $ecsConfig): void { + // split @param/@return/@var malform rules + $ecsConfig->sets([__DIR__ . '/sets/docblock.php']); + $ecsConfig->rules([ // docblocks and comments RemovePHPStormAnnotationFixer::class, - ParamReturnAndVarTagMalformsFixer::class, RemoveUselessDefaultCommentFixer::class, RemoveMethodNameDuplicateDescriptionFixer::class, RemovePropertyVariableNameDescriptionFixer::class, diff --git a/src/Fixer/Commenting/AbstractDocBlockFixer.php b/src/Fixer/Commenting/AbstractDocBlockFixer.php new file mode 100644 index 000000000..a91215e32 --- /dev/null +++ b/src/Fixer/Commenting/AbstractDocBlockFixer.php @@ -0,0 +1,114 @@ + $tokens + */ + public function isCandidate(Tokens $tokens): bool + { + if (! $tokens->isAnyTokenKindsFound([T_DOC_COMMENT, T_COMMENT])) { + return false; + } + + $reversedTokens = $this->tokenReverser->reverse($tokens); + + foreach ($reversedTokens as $index => $token) { + if (! $token->isGivenKind([T_CALLABLE])) { + continue; + } + + if (! (isset($tokens[$index + 3]) && $tokens[$index + 3]->getContent() === ')')) { + continue; + } + + return false; + } + + return $tokens->isAnyTokenKindsFound([T_FUNCTION, T_VARIABLE]); + } + + /** + * @param Tokens $tokens + */ + public function fix(SplFileInfo $fileInfo, Tokens $tokens): void + { + $reversedTokens = $this->tokenReverser->reverse($tokens); + + foreach ($reversedTokens as $index => $token) { + if (! $token->isGivenKind([T_DOC_COMMENT, T_COMMENT])) { + continue; + } + + $docContent = $token->getContent(); + if (! Regex::match($docContent, self::TYPE_ANNOTATION_REGEX)) { + continue; + } + + $newDocContent = $this->processDocContent($docContent, $tokens, $index); + if ($newDocContent === $docContent) { + continue; + } + + // doc block became empty after removing dead lines → remove it completely, + // including the whitespace that followed it, to avoid leaving a blank line + if ($this->isEmptyDocBlock($newDocContent)) { + $tokens->clearAt($index); + if (isset($tokens[$index + 1]) && $tokens[$index + 1]->isWhitespace()) { + $tokens->clearAt($index + 1); + } + + continue; + } + + $tokens[$index] = new Token([T_DOC_COMMENT, $newDocContent]); + } + } + + /** + * Must run before + * + * @see \PhpCsFixer\Fixer\Phpdoc\PhpdocAlignFixer::getPriority() + */ + #[Override] + public function getPriority(): int + { + return -37; + } + + /** + * @param Tokens $tokens + */ + abstract protected function processDocContent(string $docContent, Tokens $tokens, int $position): string; + + private function isEmptyDocBlock(string $docContent): bool + { + return Regex::replace($docContent, '#/\*\*|\*/|\*|\s#', '') === ''; + } +} diff --git a/src/TokenRunner/DocBlock/MalformWorker/MissingParamNameMalformWorker.php b/src/Fixer/Commenting/AddMissingParamNameFixer.php similarity index 82% rename from src/TokenRunner/DocBlock/MalformWorker/MissingParamNameMalformWorker.php rename to src/Fixer/Commenting/AddMissingParamNameFixer.php index 446bb2cf9..73b537cba 100644 --- a/src/TokenRunner/DocBlock/MalformWorker/MissingParamNameMalformWorker.php +++ b/src/Fixer/Commenting/AddMissingParamNameFixer.php @@ -2,18 +2,25 @@ declare(strict_types=1); -namespace Symplify\CodingStandard\TokenRunner\DocBlock\MalformWorker; +namespace Symplify\CodingStandard\Fixer\Commenting; use PhpCsFixer\DocBlock\DocBlock; use PhpCsFixer\DocBlock\Line; +use PhpCsFixer\FixerDefinition\FixerDefinition; +use PhpCsFixer\FixerDefinition\FixerDefinitionInterface; use PhpCsFixer\Tokenizer\Token; use PhpCsFixer\Tokenizer\Tokens; use Symplify\CodingStandard\TokenAnalyzer\DocblockRelatedParamNamesResolver; -use Symplify\CodingStandard\TokenRunner\Contract\DocBlock\MalformWorkerInterface; +use Symplify\CodingStandard\TokenRunner\Traverser\TokenReverser; use Symplify\CodingStandard\Utils\Regex; -final readonly class MissingParamNameMalformWorker implements MalformWorkerInterface +/** + * @see \Symplify\CodingStandard\Tests\Fixer\Commenting\AddMissingParamNameFixer\AddMissingParamNameFixerTest + */ +final class AddMissingParamNameFixer extends AbstractDocBlockFixer { + private const string ERROR_MESSAGE = 'Add a missing variable name to a @param annotation'; + /** * @see https://regex101.com/r/QtWnWv/6 */ @@ -30,14 +37,21 @@ private const string PARAM_WITH_NAME_REGEX = '#@param(.*?)\$[\w]+(.*?)\n#'; public function __construct( - private DocblockRelatedParamNamesResolver $docblockRelatedParamNamesResolver + TokenReverser $tokenReverser, + private readonly DocblockRelatedParamNamesResolver $docblockRelatedParamNamesResolver ) { + parent::__construct($tokenReverser); + } + + public function getDefinition(): FixerDefinitionInterface + { + return new FixerDefinition(self::ERROR_MESSAGE, []); } /** * @param Tokens $tokens */ - public function work(string $docContent, Tokens $tokens, int $position): string + protected function processDocContent(string $docContent, Tokens $tokens, int $position): string { $argumentNames = $this->docblockRelatedParamNamesResolver->resolve($tokens, $position); if ($argumentNames === []) { diff --git a/src/TokenRunner/DocBlock/MalformWorker/MissingVarNameMalformWorker.php b/src/Fixer/Commenting/AddMissingVarNameFixer.php similarity index 69% rename from src/TokenRunner/DocBlock/MalformWorker/MissingVarNameMalformWorker.php rename to src/Fixer/Commenting/AddMissingVarNameFixer.php index 49e2d4802..84e23df9b 100644 --- a/src/TokenRunner/DocBlock/MalformWorker/MissingVarNameMalformWorker.php +++ b/src/Fixer/Commenting/AddMissingVarNameFixer.php @@ -2,24 +2,35 @@ declare(strict_types=1); -namespace Symplify\CodingStandard\TokenRunner\DocBlock\MalformWorker; +namespace Symplify\CodingStandard\Fixer\Commenting; +use PhpCsFixer\FixerDefinition\FixerDefinition; +use PhpCsFixer\FixerDefinition\FixerDefinitionInterface; use PhpCsFixer\Tokenizer\Token; use PhpCsFixer\Tokenizer\Tokens; -use Symplify\CodingStandard\TokenRunner\Contract\DocBlock\MalformWorkerInterface; use Symplify\CodingStandard\Utils\Regex; -final class MissingVarNameMalformWorker implements MalformWorkerInterface +/** + * @see \Symplify\CodingStandard\Tests\Fixer\Commenting\AddMissingVarNameFixer\AddMissingVarNameFixerTest + */ +final class AddMissingVarNameFixer extends AbstractDocBlockFixer { + private const string ERROR_MESSAGE = 'Add a missing variable name to an inline @var annotation'; + /** * @see https://regex101.com/r/s1UkZs/1 */ private const string VAR_WITHOUT_NAME_REGEX = '#^(?\/\*\* @(?:psalm-|phpstan-)?var )(?[\\\\\w\|-|]+)(?\s+\*\/)$#'; + public function getDefinition(): FixerDefinitionInterface + { + return new FixerDefinition(self::ERROR_MESSAGE, []); + } + /** * @param Tokens $tokens */ - public function work(string $docContent, Tokens $tokens, int $position): string + protected function processDocContent(string $docContent, Tokens $tokens, int $position): string { if (! Regex::match($docContent, self::VAR_WITHOUT_NAME_REGEX)) { return $docContent; diff --git a/src/Fixer/Commenting/DoubleAsteriskInlineVarFixer.php b/src/Fixer/Commenting/DoubleAsteriskInlineVarFixer.php new file mode 100644 index 000000000..27897c27e --- /dev/null +++ b/src/Fixer/Commenting/DoubleAsteriskInlineVarFixer.php @@ -0,0 +1,46 @@ + $tokens + */ + protected function processDocContent(string $docContent, Tokens $tokens, int $position): string + { + /** @var Token $token */ + $token = $tokens[$position]; + + if (! $token->isGivenKind(T_COMMENT)) { + return $docContent; + } + + return Regex::replace($docContent, self::SINGLE_ASTERISK_START_REGEX, '/**$1'); + } +} diff --git a/src/TokenRunner/DocBlock/MalformWorker/ParamNameTypoMalformWorker.php b/src/Fixer/Commenting/FixParamNameTypoFixer.php similarity index 81% rename from src/TokenRunner/DocBlock/MalformWorker/ParamNameTypoMalformWorker.php rename to src/Fixer/Commenting/FixParamNameTypoFixer.php index b17f8fb53..45ff067f7 100644 --- a/src/TokenRunner/DocBlock/MalformWorker/ParamNameTypoMalformWorker.php +++ b/src/Fixer/Commenting/FixParamNameTypoFixer.php @@ -2,32 +2,46 @@ declare(strict_types=1); -namespace Symplify\CodingStandard\TokenRunner\DocBlock\MalformWorker; +namespace Symplify\CodingStandard\Fixer\Commenting; use PhpCsFixer\DocBlock\Annotation; use PhpCsFixer\DocBlock\DocBlock; +use PhpCsFixer\FixerDefinition\FixerDefinition; +use PhpCsFixer\FixerDefinition\FixerDefinitionInterface; use PhpCsFixer\Tokenizer\Token; use PhpCsFixer\Tokenizer\Tokens; use Symplify\CodingStandard\TokenAnalyzer\DocblockRelatedParamNamesResolver; -use Symplify\CodingStandard\TokenRunner\Contract\DocBlock\MalformWorkerInterface; +use Symplify\CodingStandard\TokenRunner\Traverser\TokenReverser; use Symplify\CodingStandard\Utils\Regex; -final readonly class ParamNameTypoMalformWorker implements MalformWorkerInterface +/** + * @see \Symplify\CodingStandard\Tests\Fixer\Commenting\FixParamNameTypoFixer\FixParamNameTypoFixerTest + */ +final class FixParamNameTypoFixer extends AbstractDocBlockFixer { + private const string ERROR_MESSAGE = 'Fix a typo in the @param variable name to match the real argument'; + /** * @see https://regex101.com/r/5szHlw/1 */ private const string PARAM_NAME_REGEX = '#@param(\s+)(?callable)?(.*?)(?\$\w+)#'; public function __construct( - private DocblockRelatedParamNamesResolver $docblockRelatedParamNamesResolver + TokenReverser $tokenReverser, + private readonly DocblockRelatedParamNamesResolver $docblockRelatedParamNamesResolver ) { + parent::__construct($tokenReverser); + } + + public function getDefinition(): FixerDefinitionInterface + { + return new FixerDefinition(self::ERROR_MESSAGE, []); } /** * @param Tokens $tokens */ - public function work(string $docContent, Tokens $tokens, int $position): string + protected function processDocContent(string $docContent, Tokens $tokens, int $position): string { $argumentNames = $this->docblockRelatedParamNamesResolver->resolve($tokens, $position); if ($argumentNames === []) { diff --git a/src/Fixer/Commenting/ParamReturnAndVarTagMalformsFixer.php b/src/Fixer/Commenting/ParamReturnAndVarTagMalformsFixer.php index fd11ef7cf..8d2157ba7 100644 --- a/src/Fixer/Commenting/ParamReturnAndVarTagMalformsFixer.php +++ b/src/Fixer/Commenting/ParamReturnAndVarTagMalformsFixer.php @@ -4,71 +4,22 @@ namespace Symplify\CodingStandard\Fixer\Commenting; -use Override; +use PhpCsFixer\Fixer\DeprecatedFixerInterface; use PhpCsFixer\FixerDefinition\FixerDefinition; use PhpCsFixer\FixerDefinition\FixerDefinitionInterface; use PhpCsFixer\Tokenizer\Token; use PhpCsFixer\Tokenizer\Tokens; use SplFileInfo; use Symplify\CodingStandard\Fixer\AbstractSymplifyFixer; -use Symplify\CodingStandard\TokenRunner\Contract\DocBlock\MalformWorkerInterface; -use Symplify\CodingStandard\TokenRunner\DocBlock\MalformWorker\DeadParamMalformWorker; -use Symplify\CodingStandard\TokenRunner\DocBlock\MalformWorker\InlineVariableDocBlockMalformWorker; -use Symplify\CodingStandard\TokenRunner\DocBlock\MalformWorker\InlineVarMalformWorker; -use Symplify\CodingStandard\TokenRunner\DocBlock\MalformWorker\MissingParamNameMalformWorker; -use Symplify\CodingStandard\TokenRunner\DocBlock\MalformWorker\MissingVarNameMalformWorker; -use Symplify\CodingStandard\TokenRunner\DocBlock\MalformWorker\ParamNameReferenceMalformWorker; -use Symplify\CodingStandard\TokenRunner\DocBlock\MalformWorker\ParamNameTypoMalformWorker; -use Symplify\CodingStandard\TokenRunner\DocBlock\MalformWorker\SuperfluousReturnNameMalformWorker; -use Symplify\CodingStandard\TokenRunner\DocBlock\MalformWorker\SuperfluousVarNameMalformWorker; -use Symplify\CodingStandard\TokenRunner\DocBlock\MalformWorker\SwitchedTypeAndNameMalformWorker; -use Symplify\CodingStandard\TokenRunner\Traverser\TokenReverser; -use Symplify\CodingStandard\Utils\Regex; /** - * @see \Symplify\CodingStandard\Tests\Fixer\Commenting\ParamReturnAndVarTagMalformsFixer\ParamReturnAndVarTagMalformsFixerTest + * @deprecated This rule was split into single-task rules registered in config/sets/docblock.php. + * Use the docblock set or the dedicated rules instead. */ -final class ParamReturnAndVarTagMalformsFixer extends AbstractSymplifyFixer +final class ParamReturnAndVarTagMalformsFixer extends AbstractSymplifyFixer implements DeprecatedFixerInterface { private const string ERROR_MESSAGE = 'Fixes @param, @return, @var and inline @var annotations broken formats'; - /** - * @see https://regex101.com/r/Nlxkd9/1 - */ - private const string TYPE_ANNOTATION_REGEX = '#@(psalm-|phpstan-)?(param|return|var)#'; - - /** - * @var MalformWorkerInterface[] - */ - private array $malformWorkers = []; - - public function __construct( - InlineVariableDocBlockMalformWorker $inlineVariableDocBlockMalformWorker, - InlineVarMalformWorker $inlineVarMalformWorker, - MissingParamNameMalformWorker $missingParamNameMalformWorker, - MissingVarNameMalformWorker $missingVarNameMalformWorker, - ParamNameReferenceMalformWorker $paramNameReferenceMalformWorker, - ParamNameTypoMalformWorker $paramNameTypoMalformWorker, - SuperfluousReturnNameMalformWorker $superfluousReturnNameMalformWorker, - SuperfluousVarNameMalformWorker $superfluousVarNameMalformWorker, - SwitchedTypeAndNameMalformWorker $switchedTypeAndNameMalformWorker, - DeadParamMalformWorker $deadParamMalformWorker, - private readonly TokenReverser $tokenReverser - ) { - $this->malformWorkers = [ - $inlineVariableDocBlockMalformWorker, - $inlineVarMalformWorker, - $missingParamNameMalformWorker, - $missingVarNameMalformWorker, - $paramNameReferenceMalformWorker, - $paramNameTypoMalformWorker, - $superfluousReturnNameMalformWorker, - $superfluousVarNameMalformWorker, - $switchedTypeAndNameMalformWorker, - $deadParamMalformWorker, - ]; - } - public function getDefinition(): FixerDefinitionInterface { return new FixerDefinition(self::ERROR_MESSAGE, []); @@ -79,25 +30,7 @@ public function getDefinition(): FixerDefinitionInterface */ public function isCandidate(Tokens $tokens): bool { - if (! $tokens->isAnyTokenKindsFound([T_DOC_COMMENT, T_COMMENT])) { - return false; - } - - $reversedTokens = $this->tokenReverser->reverse($tokens); - - foreach ($reversedTokens as $index => $token) { - if (! $token->isGivenKind([T_CALLABLE])) { - continue; - } - - if (! (isset($tokens[$index + 3]) && $tokens[$index + 3]->getContent() === ')')) { - continue; - } - - return false; - } - - return $tokens->isAnyTokenKindsFound([T_FUNCTION, T_VARIABLE]); + return false; } /** @@ -105,55 +38,24 @@ public function isCandidate(Tokens $tokens): bool */ public function fix(SplFileInfo $fileInfo, Tokens $tokens): void { - $reversedTokens = $this->tokenReverser->reverse($tokens); - - foreach ($reversedTokens as $index => $token) { - if (! $token->isGivenKind([T_DOC_COMMENT, T_COMMENT])) { - continue; - } - - $docContent = $token->getContent(); - if (! Regex::match($docContent, self::TYPE_ANNOTATION_REGEX)) { - continue; - } - - $originalDocContent = $docContent; - foreach ($this->malformWorkers as $malformWorker) { - $docContent = $malformWorker->work($docContent, $tokens, $index); - } - - if ($docContent === $originalDocContent) { - continue; - } - - // doc block became empty after removing dead lines → remove it completely, - // including the whitespace that followed it, to avoid leaving a blank line - if ($this->isEmptyDocBlock($docContent)) { - $tokens->clearAt($index); - if (isset($tokens[$index + 1]) && $tokens[$index + 1]->isWhitespace()) { - $tokens->clearAt($index + 1); - } - - continue; - } - - $tokens[$index] = new Token([T_DOC_COMMENT, $docContent]); - } } /** - * Must run before - * - * @see \PhpCsFixer\Fixer\Phpdoc\PhpdocAlignFixer::getPriority() + * @return list */ - #[Override] - public function getPriority(): int - { - return -37; - } - - private function isEmptyDocBlock(string $docContent): bool + public function getSuccessorsNames(): array { - return Regex::replace($docContent, '#/\*\*|\*/|\*|\s#', '') === ''; + return [ + DoubleAsteriskInlineVarFixer::class, + SingleLineInlineVarDocBlockFixer::class, + AddMissingParamNameFixer::class, + AddMissingVarNameFixer::class, + RemoveParamNameReferenceFixer::class, + FixParamNameTypoFixer::class, + RemoveSuperfluousReturnNameFixer::class, + RemoveSuperfluousVarNameFixer::class, + SwitchedTypeAndNameFixer::class, + RemoveDeadParamFixer::class, + ]; } } diff --git a/src/Fixer/Commenting/RemoveDeadParamFixer.php b/src/Fixer/Commenting/RemoveDeadParamFixer.php new file mode 100644 index 000000000..16f88f286 --- /dev/null +++ b/src/Fixer/Commenting/RemoveDeadParamFixer.php @@ -0,0 +1,51 @@ + $tokens + */ + protected function processDocContent(string $docContent, Tokens $tokens, int $position): string + { + $docBlock = new DocBlock($docContent); + + foreach ($docBlock->getLines() as $line) { + if (! Regex::match($line->getContent(), self::PARAM_WITHOUT_TYPE_REGEX)) { + continue; + } + + $line->remove(); + } + + return $docBlock->getContent(); + } +} diff --git a/src/Fixer/Commenting/RemoveParamNameReferenceFixer.php b/src/Fixer/Commenting/RemoveParamNameReferenceFixer.php new file mode 100644 index 000000000..b911f89ac --- /dev/null +++ b/src/Fixer/Commenting/RemoveParamNameReferenceFixer.php @@ -0,0 +1,41 @@ +@param(.*?))&(?\$\w+)#'; + + public function getDefinition(): FixerDefinitionInterface + { + return new FixerDefinition(self::ERROR_MESSAGE, []); + } + + /** + * @param Tokens $tokens + */ + protected function processDocContent(string $docContent, Tokens $tokens, int $position): string + { + return Regex::replace( + $docContent, + self::PARAM_NAME_REGEX, + static fn ($match): string => $match['param'] . $match['paramName'] + ); + } +} diff --git a/src/TokenRunner/DocBlock/MalformWorker/SuperfluousReturnNameMalformWorker.php b/src/Fixer/Commenting/RemoveSuperfluousReturnNameFixer.php similarity index 74% rename from src/TokenRunner/DocBlock/MalformWorker/SuperfluousReturnNameMalformWorker.php rename to src/Fixer/Commenting/RemoveSuperfluousReturnNameFixer.php index 386099ef6..99b1c55ab 100644 --- a/src/TokenRunner/DocBlock/MalformWorker/SuperfluousReturnNameMalformWorker.php +++ b/src/Fixer/Commenting/RemoveSuperfluousReturnNameFixer.php @@ -2,16 +2,22 @@ declare(strict_types=1); -namespace Symplify\CodingStandard\TokenRunner\DocBlock\MalformWorker; +namespace Symplify\CodingStandard\Fixer\Commenting; use PhpCsFixer\DocBlock\DocBlock; +use PhpCsFixer\FixerDefinition\FixerDefinition; +use PhpCsFixer\FixerDefinition\FixerDefinitionInterface; use PhpCsFixer\Tokenizer\Token; use PhpCsFixer\Tokenizer\Tokens; -use Symplify\CodingStandard\TokenRunner\Contract\DocBlock\MalformWorkerInterface; use Symplify\CodingStandard\Utils\Regex; -final class SuperfluousReturnNameMalformWorker implements MalformWorkerInterface +/** + * @see \Symplify\CodingStandard\Tests\Fixer\Commenting\RemoveSuperfluousReturnNameFixer\RemoveSuperfluousReturnNameFixerTest + */ +final class RemoveSuperfluousReturnNameFixer extends AbstractDocBlockFixer { + private const string ERROR_MESSAGE = 'Remove a superfluous variable name from a @return annotation'; + /** * @see https://regex101.com/r/4qyd2j/1 */ @@ -29,10 +35,15 @@ final class SuperfluousReturnNameMalformWorker implements MalformWorkerInterface private const string VARIABLE_NAME_PART = 'variableName'; + public function getDefinition(): FixerDefinitionInterface + { + return new FixerDefinition(self::ERROR_MESSAGE, []); + } + /** * @param Tokens $tokens */ - public function work(string $docContent, Tokens $tokens, int $position): string + protected function processDocContent(string $docContent, Tokens $tokens, int $position): string { $docBlock = new DocBlock($docContent); diff --git a/src/TokenRunner/DocBlock/MalformWorker/SuperfluousVarNameMalformWorker.php b/src/Fixer/Commenting/RemoveSuperfluousVarNameFixer.php similarity index 76% rename from src/TokenRunner/DocBlock/MalformWorker/SuperfluousVarNameMalformWorker.php rename to src/Fixer/Commenting/RemoveSuperfluousVarNameFixer.php index e26b7cb41..aa8cf4385 100644 --- a/src/TokenRunner/DocBlock/MalformWorker/SuperfluousVarNameMalformWorker.php +++ b/src/Fixer/Commenting/RemoveSuperfluousVarNameFixer.php @@ -2,16 +2,22 @@ declare(strict_types=1); -namespace Symplify\CodingStandard\TokenRunner\DocBlock\MalformWorker; +namespace Symplify\CodingStandard\Fixer\Commenting; use PhpCsFixer\DocBlock\DocBlock; +use PhpCsFixer\FixerDefinition\FixerDefinition; +use PhpCsFixer\FixerDefinition\FixerDefinitionInterface; use PhpCsFixer\Tokenizer\Token; use PhpCsFixer\Tokenizer\Tokens; -use Symplify\CodingStandard\TokenRunner\Contract\DocBlock\MalformWorkerInterface; use Symplify\CodingStandard\Utils\Regex; -final class SuperfluousVarNameMalformWorker implements MalformWorkerInterface +/** + * @see \Symplify\CodingStandard\Tests\Fixer\Commenting\RemoveSuperfluousVarNameFixer\RemoveSuperfluousVarNameFixerTest + */ +final class RemoveSuperfluousVarNameFixer extends AbstractDocBlockFixer { + private const string ERROR_MESSAGE = 'Remove a superfluous variable name from a property @var annotation'; + /** * @see https://regex101.com/r/euhrn8/1 */ @@ -22,10 +28,15 @@ final class SuperfluousVarNameMalformWorker implements MalformWorkerInterface */ private const string VAR_VARIABLE_NAME_REGEX = '#(?@(?:psalm-|phpstan-)?var)(?\s+[|\\\\\w]+)?(\s+)(?\$[\w]+)#'; + public function getDefinition(): FixerDefinitionInterface + { + return new FixerDefinition(self::ERROR_MESSAGE, []); + } + /** * @param Tokens $tokens */ - public function work(string $docContent, Tokens $tokens, int $position): string + protected function processDocContent(string $docContent, Tokens $tokens, int $position): string { if ($this->shouldSkip($tokens, $position)) { return $docContent; diff --git a/src/TokenRunner/DocBlock/MalformWorker/InlineVariableDocBlockMalformWorker.php b/src/Fixer/Commenting/SingleLineInlineVarDocBlockFixer.php similarity index 71% rename from src/TokenRunner/DocBlock/MalformWorker/InlineVariableDocBlockMalformWorker.php rename to src/Fixer/Commenting/SingleLineInlineVarDocBlockFixer.php index 294bef0ef..43befccab 100644 --- a/src/TokenRunner/DocBlock/MalformWorker/InlineVariableDocBlockMalformWorker.php +++ b/src/Fixer/Commenting/SingleLineInlineVarDocBlockFixer.php @@ -2,14 +2,20 @@ declare(strict_types=1); -namespace Symplify\CodingStandard\TokenRunner\DocBlock\MalformWorker; +namespace Symplify\CodingStandard\Fixer\Commenting; +use PhpCsFixer\FixerDefinition\FixerDefinition; +use PhpCsFixer\FixerDefinition\FixerDefinitionInterface; use PhpCsFixer\Tokenizer\Token; use PhpCsFixer\Tokenizer\Tokens; -use Symplify\CodingStandard\TokenRunner\Contract\DocBlock\MalformWorkerInterface; use Symplify\CodingStandard\Utils\Regex; -final class InlineVariableDocBlockMalformWorker implements MalformWorkerInterface +/** + * Collapses a multi-line @var doc block placed above an inline variable into a single line. + * + * @see \Symplify\CodingStandard\Tests\Fixer\Commenting\SingleLineInlineVarDocBlockFixer\SingleLineInlineVarDocBlockFixerTest + */ +final class SingleLineInlineVarDocBlockFixer extends AbstractDocBlockFixer { /** * @see https://regex101.com/r/GkyV1C/1 @@ -26,10 +32,17 @@ final class InlineVariableDocBlockMalformWorker implements MalformWorkerInterfac */ private const string ASTERISK_LEFTOVERS_REGEX = '#(\*\*)(\s+\*)#'; + private const string ERROR_MESSAGE = 'Collapse a multi-line inline @var doc block into a single line'; + + public function getDefinition(): FixerDefinitionInterface + { + return new FixerDefinition(self::ERROR_MESSAGE, []); + } + /** * @param Tokens $tokens */ - public function work(string $docContent, Tokens $tokens, int $position): string + protected function processDocContent(string $docContent, Tokens $tokens, int $position): string { if (! $this->isVariableComment($tokens, $position)) { return $docContent; diff --git a/src/TokenRunner/DocBlock/MalformWorker/SwitchedTypeAndNameMalformWorker.php b/src/Fixer/Commenting/SwitchedTypeAndNameFixer.php similarity index 65% rename from src/TokenRunner/DocBlock/MalformWorker/SwitchedTypeAndNameMalformWorker.php rename to src/Fixer/Commenting/SwitchedTypeAndNameFixer.php index ac6d9db78..4cb2131ff 100644 --- a/src/TokenRunner/DocBlock/MalformWorker/SwitchedTypeAndNameMalformWorker.php +++ b/src/Fixer/Commenting/SwitchedTypeAndNameFixer.php @@ -2,25 +2,36 @@ declare(strict_types=1); -namespace Symplify\CodingStandard\TokenRunner\DocBlock\MalformWorker; +namespace Symplify\CodingStandard\Fixer\Commenting; use PhpCsFixer\DocBlock\DocBlock; +use PhpCsFixer\FixerDefinition\FixerDefinition; +use PhpCsFixer\FixerDefinition\FixerDefinitionInterface; use PhpCsFixer\Tokenizer\Token; use PhpCsFixer\Tokenizer\Tokens; -use Symplify\CodingStandard\TokenRunner\Contract\DocBlock\MalformWorkerInterface; use Symplify\CodingStandard\Utils\Regex; -final class SwitchedTypeAndNameMalformWorker implements MalformWorkerInterface +/** + * @see \Symplify\CodingStandard\Tests\Fixer\Commenting\SwitchedTypeAndNameFixer\SwitchedTypeAndNameFixerTest + */ +final class SwitchedTypeAndNameFixer extends AbstractDocBlockFixer { + private const string ERROR_MESSAGE = 'Reorder switched type and variable name in @param/@var annotation'; + /** * @see https://regex101.com/r/4us32A/1 */ private const string NAME_THEN_TYPE_REGEX = '#@((?:psalm-|phpstan-)?(?:param|var))(\s+)(?\$\w+)(\s+)(?[|\\\\\w\[\]\<\>]+)#'; + public function getDefinition(): FixerDefinitionInterface + { + return new FixerDefinition(self::ERROR_MESSAGE, []); + } + /** * @param Tokens $tokens */ - public function work(string $docContent, Tokens $tokens, int $position): string + protected function processDocContent(string $docContent, Tokens $tokens, int $position): string { $docBlock = new DocBlock($docContent); diff --git a/src/TokenRunner/Contract/DocBlock/MalformWorkerInterface.php b/src/TokenRunner/Contract/DocBlock/MalformWorkerInterface.php deleted file mode 100644 index 480027d6e..000000000 --- a/src/TokenRunner/Contract/DocBlock/MalformWorkerInterface.php +++ /dev/null @@ -1,16 +0,0 @@ - $tokens - */ - public function work(string $docContent, Tokens $tokens, int $position): string; -} diff --git a/src/TokenRunner/DocBlock/MalformWorker/DeadParamMalformWorker.php b/src/TokenRunner/DocBlock/MalformWorker/DeadParamMalformWorker.php deleted file mode 100644 index f3d872ab6..000000000 --- a/src/TokenRunner/DocBlock/MalformWorker/DeadParamMalformWorker.php +++ /dev/null @@ -1,41 +0,0 @@ - $tokens - */ - public function work(string $docContent, Tokens $tokens, int $position): string - { - $docBlock = new DocBlock($docContent); - - foreach ($docBlock->getLines() as $line) { - if (! Regex::match($line->getContent(), self::PARAM_WITHOUT_TYPE_REGEX)) { - continue; - } - - $line->remove(); - } - - return $docBlock->getContent(); - } -} diff --git a/src/TokenRunner/DocBlock/MalformWorker/InlineVarMalformWorker.php b/src/TokenRunner/DocBlock/MalformWorker/InlineVarMalformWorker.php deleted file mode 100644 index 290190150..000000000 --- a/src/TokenRunner/DocBlock/MalformWorker/InlineVarMalformWorker.php +++ /dev/null @@ -1,33 +0,0 @@ - $tokens - */ - public function work(string $docContent, Tokens $tokens, int $position): string - { - /** @var Token $token */ - $token = $tokens[$position]; - - if (! $token->isGivenKind(T_COMMENT)) { - return $docContent; - } - - return Regex::replace($docContent, self::SINGLE_ASTERISK_START_REGEX, '/**$1'); - } -} diff --git a/src/TokenRunner/DocBlock/MalformWorker/ParamNameReferenceMalformWorker.php b/src/TokenRunner/DocBlock/MalformWorker/ParamNameReferenceMalformWorker.php deleted file mode 100644 index 26c669094..000000000 --- a/src/TokenRunner/DocBlock/MalformWorker/ParamNameReferenceMalformWorker.php +++ /dev/null @@ -1,30 +0,0 @@ -@param(.*?))&(?\$\w+)#'; - - /** - * @param Tokens $tokens - */ - public function work(string $docContent, Tokens $tokens, int $position): string - { - return Regex::replace( - $docContent, - self::PARAM_NAME_REGEX, - static fn ($match): string => $match['param'] . $match['paramName'] - ); - } -} diff --git a/tests/Fixer/Commenting/ParamReturnAndVarTagMalformsFixer/ParamReturnAndVarTagMalformsFixerTest.php b/tests/Fixer/Commenting/AddMissingParamNameFixer/AddMissingParamNameFixerTest.php similarity index 75% rename from tests/Fixer/Commenting/ParamReturnAndVarTagMalformsFixer/ParamReturnAndVarTagMalformsFixerTest.php rename to tests/Fixer/Commenting/AddMissingParamNameFixer/AddMissingParamNameFixerTest.php index 393d45318..5078648d8 100644 --- a/tests/Fixer/Commenting/ParamReturnAndVarTagMalformsFixer/ParamReturnAndVarTagMalformsFixerTest.php +++ b/tests/Fixer/Commenting/AddMissingParamNameFixer/AddMissingParamNameFixerTest.php @@ -2,13 +2,13 @@ declare(strict_types=1); -namespace Symplify\CodingStandard\Tests\Fixer\Commenting\ParamReturnAndVarTagMalformsFixer; +namespace Symplify\CodingStandard\Tests\Fixer\Commenting\AddMissingParamNameFixer; use Iterator; use PHPUnit\Framework\Attributes\DataProvider; use Symplify\EasyCodingStandard\Testing\PHPUnit\AbstractCheckerTestCase; -final class ParamReturnAndVarTagMalformsFixerTest extends AbstractCheckerTestCase +final class AddMissingParamNameFixerTest extends AbstractCheckerTestCase { #[DataProvider('provideData')] public function test(string $filePath): void diff --git a/tests/Fixer/Commenting/ParamReturnAndVarTagMalformsFixer/Fixture/wrong6.php.inc b/tests/Fixer/Commenting/AddMissingParamNameFixer/Fixture/wrong6.php.inc similarity index 100% rename from tests/Fixer/Commenting/ParamReturnAndVarTagMalformsFixer/Fixture/wrong6.php.inc rename to tests/Fixer/Commenting/AddMissingParamNameFixer/Fixture/wrong6.php.inc diff --git a/tests/Fixer/Commenting/AddMissingParamNameFixer/config/configured_rule.php b/tests/Fixer/Commenting/AddMissingParamNameFixer/config/configured_rule.php new file mode 100644 index 000000000..a3d9374c2 --- /dev/null +++ b/tests/Fixer/Commenting/AddMissingParamNameFixer/config/configured_rule.php @@ -0,0 +1,10 @@ +rule(AddMissingParamNameFixer::class); +}; diff --git a/tests/Fixer/Commenting/AddMissingVarNameFixer/AddMissingVarNameFixerTest.php b/tests/Fixer/Commenting/AddMissingVarNameFixer/AddMissingVarNameFixerTest.php new file mode 100644 index 000000000..ba44722bc --- /dev/null +++ b/tests/Fixer/Commenting/AddMissingVarNameFixer/AddMissingVarNameFixerTest.php @@ -0,0 +1,28 @@ +doTestFile($filePath); + } + + public static function provideData(): Iterator + { + return self::yieldFiles(__DIR__ . '/Fixture'); + } + + public function provideConfig(): string + { + return __DIR__ . '/config/configured_rule.php'; + } +} diff --git a/tests/Fixer/Commenting/ParamReturnAndVarTagMalformsFixer/Fixture/inlined_var_above.php.inc b/tests/Fixer/Commenting/AddMissingVarNameFixer/Fixture/inlined_var_above.php.inc similarity index 100% rename from tests/Fixer/Commenting/ParamReturnAndVarTagMalformsFixer/Fixture/inlined_var_above.php.inc rename to tests/Fixer/Commenting/AddMissingVarNameFixer/Fixture/inlined_var_above.php.inc diff --git a/tests/Fixer/Commenting/ParamReturnAndVarTagMalformsFixer/Fixture/inlined_var_above_many_types.php.inc b/tests/Fixer/Commenting/AddMissingVarNameFixer/Fixture/inlined_var_above_many_types.php.inc similarity index 100% rename from tests/Fixer/Commenting/ParamReturnAndVarTagMalformsFixer/Fixture/inlined_var_above_many_types.php.inc rename to tests/Fixer/Commenting/AddMissingVarNameFixer/Fixture/inlined_var_above_many_types.php.inc diff --git a/tests/Fixer/Commenting/AddMissingVarNameFixer/config/configured_rule.php b/tests/Fixer/Commenting/AddMissingVarNameFixer/config/configured_rule.php new file mode 100644 index 000000000..6bc21e044 --- /dev/null +++ b/tests/Fixer/Commenting/AddMissingVarNameFixer/config/configured_rule.php @@ -0,0 +1,10 @@ +rule(AddMissingVarNameFixer::class); +}; diff --git a/tests/Fixer/Commenting/DoubleAsteriskInlineVarFixer/DoubleAsteriskInlineVarFixerTest.php b/tests/Fixer/Commenting/DoubleAsteriskInlineVarFixer/DoubleAsteriskInlineVarFixerTest.php new file mode 100644 index 000000000..b46ce6487 --- /dev/null +++ b/tests/Fixer/Commenting/DoubleAsteriskInlineVarFixer/DoubleAsteriskInlineVarFixerTest.php @@ -0,0 +1,28 @@ +doTestFile($filePath); + } + + public static function provideData(): Iterator + { + return self::yieldFiles(__DIR__ . '/Fixture'); + } + + public function provideConfig(): string + { + return __DIR__ . '/config/configured_rule.php'; + } +} diff --git a/tests/Fixer/Commenting/DoubleAsteriskInlineVarFixer/Fixture/single_asterisk.php.inc b/tests/Fixer/Commenting/DoubleAsteriskInlineVarFixer/Fixture/single_asterisk.php.inc new file mode 100644 index 000000000..087371c3c --- /dev/null +++ b/tests/Fixer/Commenting/DoubleAsteriskInlineVarFixer/Fixture/single_asterisk.php.inc @@ -0,0 +1,13 @@ + +----- + diff --git a/tests/Fixer/Commenting/DoubleAsteriskInlineVarFixer/config/configured_rule.php b/tests/Fixer/Commenting/DoubleAsteriskInlineVarFixer/config/configured_rule.php new file mode 100644 index 000000000..c932db414 --- /dev/null +++ b/tests/Fixer/Commenting/DoubleAsteriskInlineVarFixer/config/configured_rule.php @@ -0,0 +1,10 @@ +rule(DoubleAsteriskInlineVarFixer::class); +}; diff --git a/tests/Fixer/Commenting/FixParamNameTypoFixer/FixParamNameTypoFixerTest.php b/tests/Fixer/Commenting/FixParamNameTypoFixer/FixParamNameTypoFixerTest.php new file mode 100644 index 000000000..6efc289e1 --- /dev/null +++ b/tests/Fixer/Commenting/FixParamNameTypoFixer/FixParamNameTypoFixerTest.php @@ -0,0 +1,28 @@ +doTestFile($filePath); + } + + public static function provideData(): Iterator + { + return self::yieldFiles(__DIR__ . '/Fixture'); + } + + public function provideConfig(): string + { + return __DIR__ . '/config/configured_rule.php'; + } +} diff --git a/tests/Fixer/Commenting/ParamReturnAndVarTagMalformsFixer/Fixture/param_name_wrong.php.inc b/tests/Fixer/Commenting/FixParamNameTypoFixer/Fixture/param_name_wrong.php.inc similarity index 100% rename from tests/Fixer/Commenting/ParamReturnAndVarTagMalformsFixer/Fixture/param_name_wrong.php.inc rename to tests/Fixer/Commenting/FixParamNameTypoFixer/Fixture/param_name_wrong.php.inc diff --git a/tests/Fixer/Commenting/ParamReturnAndVarTagMalformsFixer/Fixture/wrong11.php.inc b/tests/Fixer/Commenting/FixParamNameTypoFixer/Fixture/wrong11.php.inc similarity index 100% rename from tests/Fixer/Commenting/ParamReturnAndVarTagMalformsFixer/Fixture/wrong11.php.inc rename to tests/Fixer/Commenting/FixParamNameTypoFixer/Fixture/wrong11.php.inc diff --git a/tests/Fixer/Commenting/ParamReturnAndVarTagMalformsFixer/Fixture/wrong12.php.inc b/tests/Fixer/Commenting/FixParamNameTypoFixer/Fixture/wrong12.php.inc similarity index 100% rename from tests/Fixer/Commenting/ParamReturnAndVarTagMalformsFixer/Fixture/wrong12.php.inc rename to tests/Fixer/Commenting/FixParamNameTypoFixer/Fixture/wrong12.php.inc diff --git a/tests/Fixer/Commenting/FixParamNameTypoFixer/config/configured_rule.php b/tests/Fixer/Commenting/FixParamNameTypoFixer/config/configured_rule.php new file mode 100644 index 000000000..ddc7f4a5d --- /dev/null +++ b/tests/Fixer/Commenting/FixParamNameTypoFixer/config/configured_rule.php @@ -0,0 +1,10 @@ +rule(FixParamNameTypoFixer::class); +}; diff --git a/tests/Fixer/Commenting/ParamReturnAndVarTagMalformsFixer/Source/Schedule.php b/tests/Fixer/Commenting/ParamReturnAndVarTagMalformsFixer/Source/Schedule.php deleted file mode 100644 index e97c232dd..000000000 --- a/tests/Fixer/Commenting/ParamReturnAndVarTagMalformsFixer/Source/Schedule.php +++ /dev/null @@ -1,9 +0,0 @@ -rule(ParamReturnAndVarTagMalformsFixer::class); -}; diff --git a/tests/Fixer/Commenting/ParamReturnAndVarTagMalformsFixer/Fixture/dead_param.php.inc b/tests/Fixer/Commenting/RemoveDeadParamFixer/Fixture/dead_param.php.inc similarity index 100% rename from tests/Fixer/Commenting/ParamReturnAndVarTagMalformsFixer/Fixture/dead_param.php.inc rename to tests/Fixer/Commenting/RemoveDeadParamFixer/Fixture/dead_param.php.inc diff --git a/tests/Fixer/Commenting/ParamReturnAndVarTagMalformsFixer/Fixture/dead_param_only.php.inc b/tests/Fixer/Commenting/RemoveDeadParamFixer/Fixture/dead_param_only.php.inc similarity index 100% rename from tests/Fixer/Commenting/ParamReturnAndVarTagMalformsFixer/Fixture/dead_param_only.php.inc rename to tests/Fixer/Commenting/RemoveDeadParamFixer/Fixture/dead_param_only.php.inc diff --git a/tests/Fixer/Commenting/RemoveDeadParamFixer/RemoveDeadParamFixerTest.php b/tests/Fixer/Commenting/RemoveDeadParamFixer/RemoveDeadParamFixerTest.php new file mode 100644 index 000000000..23c530940 --- /dev/null +++ b/tests/Fixer/Commenting/RemoveDeadParamFixer/RemoveDeadParamFixerTest.php @@ -0,0 +1,28 @@ +doTestFile($filePath); + } + + public static function provideData(): Iterator + { + return self::yieldFiles(__DIR__ . '/Fixture'); + } + + public function provideConfig(): string + { + return __DIR__ . '/config/configured_rule.php'; + } +} diff --git a/tests/Fixer/Commenting/RemoveDeadParamFixer/config/configured_rule.php b/tests/Fixer/Commenting/RemoveDeadParamFixer/config/configured_rule.php new file mode 100644 index 000000000..cdf8fae59 --- /dev/null +++ b/tests/Fixer/Commenting/RemoveDeadParamFixer/config/configured_rule.php @@ -0,0 +1,10 @@ +rule(RemoveDeadParamFixer::class); +}; diff --git a/tests/Fixer/Commenting/ParamReturnAndVarTagMalformsFixer/Fixture/param_reference.php.inc b/tests/Fixer/Commenting/RemoveParamNameReferenceFixer/Fixture/param_reference.php.inc similarity index 100% rename from tests/Fixer/Commenting/ParamReturnAndVarTagMalformsFixer/Fixture/param_reference.php.inc rename to tests/Fixer/Commenting/RemoveParamNameReferenceFixer/Fixture/param_reference.php.inc diff --git a/tests/Fixer/Commenting/RemoveParamNameReferenceFixer/RemoveParamNameReferenceFixerTest.php b/tests/Fixer/Commenting/RemoveParamNameReferenceFixer/RemoveParamNameReferenceFixerTest.php new file mode 100644 index 000000000..d5de0019e --- /dev/null +++ b/tests/Fixer/Commenting/RemoveParamNameReferenceFixer/RemoveParamNameReferenceFixerTest.php @@ -0,0 +1,28 @@ +doTestFile($filePath); + } + + public static function provideData(): Iterator + { + return self::yieldFiles(__DIR__ . '/Fixture'); + } + + public function provideConfig(): string + { + return __DIR__ . '/config/configured_rule.php'; + } +} diff --git a/tests/Fixer/Commenting/RemoveParamNameReferenceFixer/config/configured_rule.php b/tests/Fixer/Commenting/RemoveParamNameReferenceFixer/config/configured_rule.php new file mode 100644 index 000000000..77ffa97de --- /dev/null +++ b/tests/Fixer/Commenting/RemoveParamNameReferenceFixer/config/configured_rule.php @@ -0,0 +1,10 @@ +rule(RemoveParamNameReferenceFixer::class); +}; diff --git a/tests/Fixer/Commenting/ParamReturnAndVarTagMalformsFixer/Fixture/wrong10.php.inc b/tests/Fixer/Commenting/RemoveSuperfluousReturnNameFixer/Fixture/wrong10.php.inc similarity index 100% rename from tests/Fixer/Commenting/ParamReturnAndVarTagMalformsFixer/Fixture/wrong10.php.inc rename to tests/Fixer/Commenting/RemoveSuperfluousReturnNameFixer/Fixture/wrong10.php.inc diff --git a/tests/Fixer/Commenting/ParamReturnAndVarTagMalformsFixer/Fixture/wrong7.php.inc b/tests/Fixer/Commenting/RemoveSuperfluousReturnNameFixer/Fixture/wrong7.php.inc similarity index 100% rename from tests/Fixer/Commenting/ParamReturnAndVarTagMalformsFixer/Fixture/wrong7.php.inc rename to tests/Fixer/Commenting/RemoveSuperfluousReturnNameFixer/Fixture/wrong7.php.inc diff --git a/tests/Fixer/Commenting/RemoveSuperfluousReturnNameFixer/RemoveSuperfluousReturnNameFixerTest.php b/tests/Fixer/Commenting/RemoveSuperfluousReturnNameFixer/RemoveSuperfluousReturnNameFixerTest.php new file mode 100644 index 000000000..af45d7e07 --- /dev/null +++ b/tests/Fixer/Commenting/RemoveSuperfluousReturnNameFixer/RemoveSuperfluousReturnNameFixerTest.php @@ -0,0 +1,28 @@ +doTestFile($filePath); + } + + public static function provideData(): Iterator + { + return self::yieldFiles(__DIR__ . '/Fixture'); + } + + public function provideConfig(): string + { + return __DIR__ . '/config/configured_rule.php'; + } +} diff --git a/tests/Fixer/Commenting/RemoveSuperfluousReturnNameFixer/config/configured_rule.php b/tests/Fixer/Commenting/RemoveSuperfluousReturnNameFixer/config/configured_rule.php new file mode 100644 index 000000000..8d2928daf --- /dev/null +++ b/tests/Fixer/Commenting/RemoveSuperfluousReturnNameFixer/config/configured_rule.php @@ -0,0 +1,10 @@ +rule(RemoveSuperfluousReturnNameFixer::class); +}; diff --git a/tests/Fixer/Commenting/ParamReturnAndVarTagMalformsFixer/Fixture/wrong8.php.inc b/tests/Fixer/Commenting/RemoveSuperfluousVarNameFixer/Fixture/wrong8.php.inc similarity index 100% rename from tests/Fixer/Commenting/ParamReturnAndVarTagMalformsFixer/Fixture/wrong8.php.inc rename to tests/Fixer/Commenting/RemoveSuperfluousVarNameFixer/Fixture/wrong8.php.inc diff --git a/tests/Fixer/Commenting/RemoveSuperfluousVarNameFixer/RemoveSuperfluousVarNameFixerTest.php b/tests/Fixer/Commenting/RemoveSuperfluousVarNameFixer/RemoveSuperfluousVarNameFixerTest.php new file mode 100644 index 000000000..a660b8861 --- /dev/null +++ b/tests/Fixer/Commenting/RemoveSuperfluousVarNameFixer/RemoveSuperfluousVarNameFixerTest.php @@ -0,0 +1,28 @@ +doTestFile($filePath); + } + + public static function provideData(): Iterator + { + return self::yieldFiles(__DIR__ . '/Fixture'); + } + + public function provideConfig(): string + { + return __DIR__ . '/config/configured_rule.php'; + } +} diff --git a/tests/Fixer/Commenting/RemoveSuperfluousVarNameFixer/config/configured_rule.php b/tests/Fixer/Commenting/RemoveSuperfluousVarNameFixer/config/configured_rule.php new file mode 100644 index 000000000..29a3fcb5d --- /dev/null +++ b/tests/Fixer/Commenting/RemoveSuperfluousVarNameFixer/config/configured_rule.php @@ -0,0 +1,10 @@ +rule(RemoveSuperfluousVarNameFixer::class); +}; diff --git a/tests/Fixer/Commenting/SingleLineInlineVarDocBlockFixer/Fixture/multiline_var.php.inc b/tests/Fixer/Commenting/SingleLineInlineVarDocBlockFixer/Fixture/multiline_var.php.inc new file mode 100644 index 000000000..e967b6fa7 --- /dev/null +++ b/tests/Fixer/Commenting/SingleLineInlineVarDocBlockFixer/Fixture/multiline_var.php.inc @@ -0,0 +1,21 @@ + +----- + diff --git a/tests/Fixer/Commenting/SingleLineInlineVarDocBlockFixer/SingleLineInlineVarDocBlockFixerTest.php b/tests/Fixer/Commenting/SingleLineInlineVarDocBlockFixer/SingleLineInlineVarDocBlockFixerTest.php new file mode 100644 index 000000000..0d4fe2dd4 --- /dev/null +++ b/tests/Fixer/Commenting/SingleLineInlineVarDocBlockFixer/SingleLineInlineVarDocBlockFixerTest.php @@ -0,0 +1,28 @@ +doTestFile($filePath); + } + + public static function provideData(): Iterator + { + return self::yieldFiles(__DIR__ . '/Fixture'); + } + + public function provideConfig(): string + { + return __DIR__ . '/config/configured_rule.php'; + } +} diff --git a/tests/Fixer/Commenting/SingleLineInlineVarDocBlockFixer/config/configured_rule.php b/tests/Fixer/Commenting/SingleLineInlineVarDocBlockFixer/config/configured_rule.php new file mode 100644 index 000000000..25ea6027c --- /dev/null +++ b/tests/Fixer/Commenting/SingleLineInlineVarDocBlockFixer/config/configured_rule.php @@ -0,0 +1,10 @@ +rule(SingleLineInlineVarDocBlockFixer::class); +}; diff --git a/tests/Fixer/Commenting/ParamReturnAndVarTagMalformsFixer/Fixture/wrong3.php.inc b/tests/Fixer/Commenting/SwitchedTypeAndNameFixer/Fixture/wrong3.php.inc similarity index 100% rename from tests/Fixer/Commenting/ParamReturnAndVarTagMalformsFixer/Fixture/wrong3.php.inc rename to tests/Fixer/Commenting/SwitchedTypeAndNameFixer/Fixture/wrong3.php.inc diff --git a/tests/Fixer/Commenting/SwitchedTypeAndNameFixer/SwitchedTypeAndNameFixerTest.php b/tests/Fixer/Commenting/SwitchedTypeAndNameFixer/SwitchedTypeAndNameFixerTest.php new file mode 100644 index 000000000..63064c95b --- /dev/null +++ b/tests/Fixer/Commenting/SwitchedTypeAndNameFixer/SwitchedTypeAndNameFixerTest.php @@ -0,0 +1,28 @@ +doTestFile($filePath); + } + + public static function provideData(): Iterator + { + return self::yieldFiles(__DIR__ . '/Fixture'); + } + + public function provideConfig(): string + { + return __DIR__ . '/config/configured_rule.php'; + } +} diff --git a/tests/Fixer/Commenting/SwitchedTypeAndNameFixer/config/configured_rule.php b/tests/Fixer/Commenting/SwitchedTypeAndNameFixer/config/configured_rule.php new file mode 100644 index 000000000..4f7d27350 --- /dev/null +++ b/tests/Fixer/Commenting/SwitchedTypeAndNameFixer/config/configured_rule.php @@ -0,0 +1,10 @@ +rule(SwitchedTypeAndNameFixer::class); +}; diff --git a/tests/Set/DocblockSet/DocblockSetTest.php b/tests/Set/DocblockSet/DocblockSetTest.php new file mode 100644 index 000000000..f52273802 --- /dev/null +++ b/tests/Set/DocblockSet/DocblockSetTest.php @@ -0,0 +1,31 @@ +doTestFile($filePath); + } + + public static function provideData(): Iterator + { + return self::yieldFiles(__DIR__ . '/Fixture'); + } + + public function provideConfig(): string + { + return __DIR__ . '/../../../config/sets/docblock.php'; + } +} diff --git a/tests/Fixer/Commenting/ParamReturnAndVarTagMalformsFixer/Fixture/correct.php.inc b/tests/Set/DocblockSet/Fixture/correct.php.inc similarity index 100% rename from tests/Fixer/Commenting/ParamReturnAndVarTagMalformsFixer/Fixture/correct.php.inc rename to tests/Set/DocblockSet/Fixture/correct.php.inc diff --git a/tests/Fixer/Commenting/ParamReturnAndVarTagMalformsFixer/Fixture/correct2.php.inc b/tests/Set/DocblockSet/Fixture/correct2.php.inc similarity index 100% rename from tests/Fixer/Commenting/ParamReturnAndVarTagMalformsFixer/Fixture/correct2.php.inc rename to tests/Set/DocblockSet/Fixture/correct2.php.inc diff --git a/tests/Fixer/Commenting/ParamReturnAndVarTagMalformsFixer/Fixture/iterator_flip.php.inc b/tests/Set/DocblockSet/Fixture/iterator_flip.php.inc similarity index 100% rename from tests/Fixer/Commenting/ParamReturnAndVarTagMalformsFixer/Fixture/iterator_flip.php.inc rename to tests/Set/DocblockSet/Fixture/iterator_flip.php.inc diff --git a/tests/Fixer/Commenting/ParamReturnAndVarTagMalformsFixer/Fixture/param_variable_mallforms.php.inc b/tests/Set/DocblockSet/Fixture/param_variable_mallforms.php.inc similarity index 100% rename from tests/Fixer/Commenting/ParamReturnAndVarTagMalformsFixer/Fixture/param_variable_mallforms.php.inc rename to tests/Set/DocblockSet/Fixture/param_variable_mallforms.php.inc diff --git a/tests/Fixer/Commenting/ParamReturnAndVarTagMalformsFixer/Fixture/skip_callable_has_same_param_previous_definition.php.inc b/tests/Set/DocblockSet/Fixture/skip_callable_has_same_param_previous_definition.php.inc similarity index 100% rename from tests/Fixer/Commenting/ParamReturnAndVarTagMalformsFixer/Fixture/skip_callable_has_same_param_previous_definition.php.inc rename to tests/Set/DocblockSet/Fixture/skip_callable_has_same_param_previous_definition.php.inc diff --git a/tests/Fixer/Commenting/ParamReturnAndVarTagMalformsFixer/Fixture/skip_callable_param.php.inc b/tests/Set/DocblockSet/Fixture/skip_callable_param.php.inc similarity index 69% rename from tests/Fixer/Commenting/ParamReturnAndVarTagMalformsFixer/Fixture/skip_callable_param.php.inc rename to tests/Set/DocblockSet/Fixture/skip_callable_param.php.inc index d9f4b1f82..af480314e 100644 --- a/tests/Fixer/Commenting/ParamReturnAndVarTagMalformsFixer/Fixture/skip_callable_param.php.inc +++ b/tests/Set/DocblockSet/Fixture/skip_callable_param.php.inc @@ -1,6 +1,6 @@ Date: Wed, 10 Jun 2026 00:08:37 +0100 Subject: [PATCH 2/2] README: drop deprecated rule mention from doc block section --- README.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/README.md b/README.md index 08918f3d0..e3a834904 100644 --- a/README.md +++ b/README.md @@ -127,9 +127,7 @@ Each chain method call must be on own line ## Doc block malform rules -The previous all-in-one `ParamReturnAndVarTagMalformsFixer` is now **split into single-task rules**, each fixing one kind of `@param`/`@return`/`@var` malform. They are registered together in the [`docblock` set](../config/sets/docblock.php) and all handle the `@phpstan-` and `@psalm-` prefixed variants of these tags. - -`ParamReturnAndVarTagMalformsFixer` is kept as a deprecated, empty rule that points to its successors. +Single-task rules that each fix one kind of `@param`/`@return`/`@var` malform. They are registered together in the [`docblock` set](../config/sets/docblock.php) and all handle the `@phpstan-` and `@psalm-` prefixed variants of these tags.