Skip to content

Commit 0cf921c

Browse files
authored
PhpdocNoSuperfluousParamFixer - do not remove callable types (#1055)
1 parent e65a069 commit 0cf921c

File tree

5 files changed

+19
-18
lines changed

5 files changed

+19
-18
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# CHANGELOG for PHP CS Fixer: custom fixers
22

3+
## v3.30.0
4+
- Update minimum PHP CS Fixer version to 3.82.0
5+
36
## v3.29.0
47
- Update minimum PHP CS Fixer version to 3.77.0
58

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
[![Latest stable version](https://img.shields.io/packagist/v/kubawerlos/php-cs-fixer-custom-fixers.svg?label=current%20version)](https://packagist.org/packages/kubawerlos/php-cs-fixer-custom-fixers)
66
[![PHP version](https://img.shields.io/packagist/php-v/kubawerlos/php-cs-fixer-custom-fixers.svg)](https://php.net)
77
[![License](https://img.shields.io/github/license/kubawerlos/php-cs-fixer-custom-fixers.svg)](LICENSE)
8-
![Tests](https://img.shields.io/badge/tests-3800-brightgreen.svg)
8+
![Tests](https://img.shields.io/badge/tests-3801-brightgreen.svg)
99
[![Downloads](https://img.shields.io/packagist/dt/kubawerlos/php-cs-fixer-custom-fixers.svg)](https://packagist.org/packages/kubawerlos/php-cs-fixer-custom-fixers)
1010

1111
[![CI status](https://github.com/kubawerlos/php-cs-fixer-custom-fixers/actions/workflows/ci.yaml/badge.svg)](https://github.com/kubawerlos/php-cs-fixer-custom-fixers/actions/workflows/ci.yaml)

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"php": "^7.4 || ^8.0",
1414
"ext-filter": "*",
1515
"ext-tokenizer": "*",
16-
"friendsofphp/php-cs-fixer": "^3.77"
16+
"friendsofphp/php-cs-fixer": "^3.82"
1717
},
1818
"require-dev": {
1919
"phpunit/phpunit": "^9.6.22 || 10.5.45 || ^11.5.7"

src/Fixer/PhpdocNoSuperfluousParamFixer.php

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
use PhpCsFixer\FixerDefinition\CodeSample;
1616
use PhpCsFixer\FixerDefinition\FixerDefinition;
1717
use PhpCsFixer\FixerDefinition\FixerDefinitionInterface;
18-
use PhpCsFixer\Preg;
1918
use PhpCsFixer\Tokenizer\Token;
2019
use PhpCsFixer\Tokenizer\Tokens;
2120

@@ -122,7 +121,7 @@ private static function getFilteredDocComment(string $comment, array $paramNames
122121

123122
$foundParamNames = [];
124123
foreach ($doc->getAnnotationsOfType('param') as $annotation) {
125-
$paramName = self::getParamName($annotation->getContent());
124+
$paramName = $annotation->getVariableName();
126125

127126
if (\in_array($paramName, $paramNames, true) && !\in_array($paramName, $foundParamNames, true)) {
128127
$foundParamNames[] = $paramName;
@@ -134,18 +133,4 @@ private static function getFilteredDocComment(string $comment, array $paramNames
134133

135134
return $doc->getContent();
136135
}
137-
138-
private static function getParamName(string $annotation): ?string
139-
{
140-
Preg::match('/@param\\s+(?:[^\\$]+)?\\s*(\\$[a-zA-Z_\\x80-\\xff][a-zA-Z0-9_\\x80-\\xff]*)\\b/', $annotation, $matches);
141-
142-
if (!\array_key_exists(1, $matches)) {
143-
return null;
144-
}
145-
146-
// @phpstan-ignore function.alreadyNarrowedType
147-
\assert(\is_string($matches[1]));
148-
149-
return $matches[1];
150-
}
151136
}

tests/Fixer/PhpdocNoSuperfluousParamFixerTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,5 +299,18 @@ function foo($x) {}
299299
function foo($x) {}
300300
PHP,
301301
];
302+
303+
yield [
304+
<<<'PHP'
305+
<?php
306+
class Foo
307+
{
308+
/**
309+
* @param callable(Type $type, callable(Type): Type $traverse): Type $callback
310+
*/
311+
public function __construct(mixed $callback) {}
312+
}
313+
PHP,
314+
];
302315
}
303316
}

0 commit comments

Comments
 (0)