Skip to content

Commit

Permalink
fix: no_superfluous_phpdoc_tags must honor multiline docs (#7697)
Browse files Browse the repository at this point in the history
  • Loading branch information
mvorisek committed Jan 8, 2024
1 parent 12c42b7 commit 6cc4ebd
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/Fixer/Phpdoc/NoSuperfluousPhpdocTagsFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -514,11 +514,11 @@ private function annotationIsSuperfluous(
array $symbolShortNames
): bool {
if ('param' === $annotation->getTag()->getName()) {
$regex = '{\*\h*@param(?:\h+'.TypeExpression::REGEX_TYPES.')?(?!\S)(?:\h+(?:\&\h*)?(?:\.{3}\h*)?\$\S+)?(?:\h+(?<description>(?!\*+\/)\S+))?}s';
$regex = '{\*\h*@param(?:\h+'.TypeExpression::REGEX_TYPES.')?(?!\S)(?:\h+(?:\&\h*)?(?:\.{3}\h*)?\$\S+)?(?:\s+(?<description>(?!\*+\/)\S+))?}s';
} elseif ('var' === $annotation->getTag()->getName()) {
$regex = '{\*\h*@var(?:\h+'.TypeExpression::REGEX_TYPES.')?(?!\S)(?:\h+\$\S+)?(?:\h+(?<description>(?!\*\/)\S+))?}s';
$regex = '{\*\h*@var(?:\h+'.TypeExpression::REGEX_TYPES.')?(?!\S)(?:\h+\$\S+)?(?:\s+(?<description>(?!\*\/)\S+))?}s';
} else {
$regex = '{\*\h*@return(?:\h+'.TypeExpression::REGEX_TYPES.')?(?!\S)(?:\h+(?<description>(?!\*\/)\S+))?}s';
$regex = '{\*\h*@return(?:\h+'.TypeExpression::REGEX_TYPES.')?(?!\S)(?:\s+(?<description>(?!\*\/)\S+))?}s';
}

if (!Preg::match($regex, $annotation->getContent(), $matches)) {
Expand Down
38 changes: 38 additions & 0 deletions tests/Fixer/Phpdoc/NoSuperfluousPhpdocTagsFixerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2528,6 +2528,44 @@ static function ($foo): int { return 1; };',
/** @return int */
static fn ($foo): int => 1;',
];

yield 'multiline @param must be kept even if there is no description on the phpdoc tag line' => [
<<<'EOD'
<?php
/**
* @param string $arg
* - foo
* - foo2
*/
function foo(string $arg) {}
EOD,
];

yield 'multiline @return must be kept even if there is no description on the phpdoc tag line' => [
<<<'EOD'
<?php
/**
* @return string
* - foo
* - foo2
*/
function foo(string $arg): string {}
EOD,
];

yield 'multiline @var must be kept even if there is no description on the phpdoc tag line' => [
<<<'EOD'
<?php
class Cl {
/**
* @var string
* - foo
* - foo2
*/
public string $prop;
}
EOD,
];
}

/**
Expand Down

0 comments on commit 6cc4ebd

Please sign in to comment.