Skip to content

Commit

Permalink
bug #6241 NoSuperfluousPhpdocTagsFixer - fix for reference and splat …
Browse files Browse the repository at this point in the history
…operator (kubawerlos)

This PR was squashed before being merged into the master branch (closes #6241).

Discussion
----------

NoSuperfluousPhpdocTagsFixer - fix for reference and splat operator

Fixes #6240

Commits
-------

0083ce7 NoSuperfluousPhpdocTagsFixer - fix for reference and splat operator
  • Loading branch information
SpacePossum committed Jan 20, 2022
2 parents ed38f3f + 0083ce7 commit 5a463a5
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 1 deletion.
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

0 comments on commit 5a463a5

Please sign in to comment.