Skip to content

Commit 44e13a9

Browse files
authored
PhpdocNoSuperfluousParamFixer - bug with typed param (#130)
1 parent e83abd5 commit 44e13a9

File tree

3 files changed

+21
-6
lines changed

3 files changed

+21
-6
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
[![Build status](https://img.shields.io/travis/kubawerlos/php-cs-fixer-custom-fixers/master.svg)](https://travis-ci.org/kubawerlos/php-cs-fixer-custom-fixers)
1010
[![Code coverage](https://img.shields.io/coveralls/github/kubawerlos/php-cs-fixer-custom-fixers/master.svg)](https://coveralls.io/github/kubawerlos/php-cs-fixer-custom-fixers?branch=master)
11-
![Tests](https://img.shields.io/badge/tests-1076-brightgreen.svg)
11+
![Tests](https://img.shields.io/badge/tests-1077-brightgreen.svg)
1212
[![Mutation testing badge](https://badge.stryker-mutator.io/github.com/kubawerlos/php-cs-fixer-custom-fixers/master)](https://stryker-mutator.github.io)
1313

1414
A set of custom fixers for [PHP CS Fixer](https://github.com/FriendsOfPHP/PHP-CS-Fixer).

src/Fixer/PhpdocNoSuperfluousParamFixer.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,18 +95,19 @@ private function getParamNames(Tokens $tokens, int $functionIndex): array
9595

9696
private function getFilteredDocComment(string $comment, array $paramNames): string
9797
{
98+
$regexParamNamesPattern = \implode('|', \array_map(static function (string $paramName): string {
99+
return \preg_quote($paramName, '/');
100+
}, $paramNames));
101+
98102
$doc = new DocBlock($comment);
99103
$foundParamNames = [];
100104

101105
foreach ($doc->getAnnotationsOfType('param') as $annotation) {
102-
$regexParamNamesPattern = \implode('|', \array_map(static function (string $paramName): string {
103-
return \preg_quote($paramName, '/');
104-
}, $paramNames));
105-
106-
if (Preg::match(\sprintf('/@param\s+(?:[^\$](?:[^<\s]|<[^>]*>)*\s+)?(?:&|\.\.\.)?\s*(%s)\b/', $regexParamNamesPattern), $annotation->getContent(), $matches) === 1 && !isset($foundParamNames[$matches[1]])) {
106+
if (Preg::match(\sprintf('/@param\s+(?:[^\$](?:[^<\s]|<[^>]*>)*\s+)?(?:&|\.\.\.)?\s*(?=\$)(%s)\b/', $regexParamNamesPattern), $annotation->getContent(), $matches) === 1 && !isset($foundParamNames[$matches[1]])) {
107107
$foundParamNames[$matches[1]] = true;
108108
continue;
109109
}
110+
110111
$annotation->remove();
111112
}
112113

tests/Fixer/PhpdocNoSuperfluousParamFixerTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,20 @@ function foo($x) {}
9999
yield [
100100
'<?php
101101
/**
102+
*/
103+
function foo() {}
104+
',
105+
'<?php
106+
/**
107+
* @param int $x
108+
*/
109+
function foo() {}
110+
',
111+
];
112+
113+
yield [
114+
'<?php
115+
/**
102116
* @param $x
103117
*/
104118
/* private */ function foo($x) {}

0 commit comments

Comments
 (0)