Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NoSuperfluousPhpdocTagsFixer - fix for reference and splat operator #6241

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Fixer/Phpdoc/NoSuperfluousPhpdocTagsFixer.php
Expand Up @@ -416,7 +416,7 @@ private function parseTypeHint(Tokens $tokens, int $index): array
private function annotationIsSuperfluous(Annotation $annotation, array $info, array $symbolShortNames): bool
{
if ('param' === $annotation->getTag()->getName()) {
$regex = '/@param\s+(?:\S|\s(?!\$))++\s\$\S+\s+\S/';
$regex = '/@param\s+[^\$]+\s(?:\&\s*)?(?:\.{3}\s*)?\$\S+\s+\S/';
} elseif ('var' === $annotation->getTag()->getName()) {
$regex = '/@var\s+\S+(\s+\$\S+)?(\s+)(?!\*+\/)([^$\s]+)/';
} else {
Expand Down
98 changes: 98 additions & 0 deletions tests/Fixer/Phpdoc/NoSuperfluousPhpdocTagsFixerTest.php
Expand Up @@ -1496,6 +1496,104 @@ final class Bar{}
*/
class Foo {
}', ],
'remove when used with reference' => [
'<?php class Foo {
/**
*/
function f1(string &$x) {}
/**
*/
function f2(string &$x) {}
/**
*/
function f3(string &$x) {}
}',
'<?php class Foo {
/**
* @param string $x
*/
function f1(string &$x) {}
/**
* @param string &$x
*/
function f2(string &$x) {}
/**
* @param string $y Description
*/
function f3(string &$x) {}
}',
],
'dont remove when used with reference' => [
'<?php class Foo {
/**
* @param string ...$x Description
*/
function f(string ...$x) {}
}',
],
'remove when used with splat operator' => [
'<?php class Foo {
/**
*/
function f1(string ...$x) {}
/**
*/
function f2(string ...$x) {}
}',
'<?php class Foo {
/**
* @param string ...$x
*/
function f1(string ...$x) {}
/**
* @param string ...$y Description
*/
function f2(string ...$x) {}
}',
],
'dont remove when used with splat operator' => [
'<?php class Foo {
/**
* @param string ...$x Description
*/
function f(string ...$x) {}
}',
],
'remove when used with reference and splat operator' => [
'<?php class Foo {
/**
*/
function f1(string &...$x) {}
/**
*/
function f2(string &...$x) {}
/**
*/
function f3(string &...$x) {}
}',
'<?php class Foo {
/**
* @param string ...$x
*/
function f1(string &...$x) {}
/**
* @param string &...$x
*/
function f2(string &...$x) {}
/**
* @param string ...$y Description
*/
function f3(string &...$x) {}
}',
],
'dont remove when used with reference and splat operator' => [
'<?php class Foo {
/**
* @param string &...$x Description
*/
function f(string &...$x) {}
}',
],
];
}

Expand Down