diff --git a/packages/coding-standard/src/Fixer/Commenting/TypeToVarTagFixer.php b/packages/coding-standard/src/Fixer/Commenting/TypeToVarTagFixer.php index a6ed9e4e16..5b6cf3ddbe 100644 --- a/packages/coding-standard/src/Fixer/Commenting/TypeToVarTagFixer.php +++ b/packages/coding-standard/src/Fixer/Commenting/TypeToVarTagFixer.php @@ -21,9 +21,9 @@ final class TypeToVarTagFixer extends AbstractSymplifyFixer { /** - * @see https://regex101.com/r/8tFqJp/1 + * Matches only "@type" at the start of a doc line, not inside a description */ - private const string TYPE_TAG_REGEX = '#@type\b#'; + private const string TYPE_TAG_REGEX = '#^(\s*(?:/\*{1,2}|\*)?\s*)@type\b#m'; /** * @see https://regex101.com/r/cj95e6/1 @@ -67,7 +67,7 @@ public function fix(SplFileInfo $fileInfo, Tokens $tokens): void continue; } - $newDocContent = Regex::replace($docContent, self::TYPE_TAG_REGEX, '@var'); + $newDocContent = Regex::replace($docContent, self::TYPE_TAG_REGEX, '$1@var'); $newDocContent = Regex::replace($newDocContent, self::SINGLE_ASTERISK_START_REGEX, '/**$1'); $tokens[$index] = new Token([T_DOC_COMMENT, $newDocContent]); diff --git a/packages/coding-standard/tests/Fixer/Commenting/TypeToVarTagFixer/Fixture/skip_type_in_description.php.inc b/packages/coding-standard/tests/Fixer/Commenting/TypeToVarTagFixer/Fixture/skip_type_in_description.php.inc new file mode 100644 index 0000000000..c076a14cf6 --- /dev/null +++ b/packages/coding-standard/tests/Fixer/Commenting/TypeToVarTagFixer/Fixture/skip_type_in_description.php.inc @@ -0,0 +1,13 @@ +