Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# CHANGELOG for PHP CS Fixer: custom fixers

## v3.30.0
- Update minimum PHP CS Fixer version to 3.82.0

## v3.29.0
- Update minimum PHP CS Fixer version to 3.77.0

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
[![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)
[![PHP version](https://img.shields.io/packagist/php-v/kubawerlos/php-cs-fixer-custom-fixers.svg)](https://php.net)
[![License](https://img.shields.io/github/license/kubawerlos/php-cs-fixer-custom-fixers.svg)](LICENSE)
![Tests](https://img.shields.io/badge/tests-3800-brightgreen.svg)
![Tests](https://img.shields.io/badge/tests-3801-brightgreen.svg)
[![Downloads](https://img.shields.io/packagist/dt/kubawerlos/php-cs-fixer-custom-fixers.svg)](https://packagist.org/packages/kubawerlos/php-cs-fixer-custom-fixers)

[![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)
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"php": "^7.4 || ^8.0",
"ext-filter": "*",
"ext-tokenizer": "*",
"friendsofphp/php-cs-fixer": "^3.77"
"friendsofphp/php-cs-fixer": "^3.82"
},
"require-dev": {
"phpunit/phpunit": "^9.6.22 || 10.5.45 || ^11.5.7"
Expand Down
17 changes: 1 addition & 16 deletions src/Fixer/PhpdocNoSuperfluousParamFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
use PhpCsFixer\FixerDefinition\CodeSample;
use PhpCsFixer\FixerDefinition\FixerDefinition;
use PhpCsFixer\FixerDefinition\FixerDefinitionInterface;
use PhpCsFixer\Preg;
use PhpCsFixer\Tokenizer\Token;
use PhpCsFixer\Tokenizer\Tokens;

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

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

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

return $doc->getContent();
}

private static function getParamName(string $annotation): ?string
{
Preg::match('/@param\\s+(?:[^\\$]+)?\\s*(\\$[a-zA-Z_\\x80-\\xff][a-zA-Z0-9_\\x80-\\xff]*)\\b/', $annotation, $matches);

if (!\array_key_exists(1, $matches)) {
return null;
}

// @phpstan-ignore function.alreadyNarrowedType
\assert(\is_string($matches[1]));

return $matches[1];
}
}
13 changes: 13 additions & 0 deletions tests/Fixer/PhpdocNoSuperfluousParamFixerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -299,5 +299,18 @@ function foo($x) {}
function foo($x) {}
PHP,
];

yield [
<<<'PHP'
<?php
class Foo
{
/**
* @param callable(Type $type, callable(Type): Type $traverse): Type $callback
*/
public function __construct(mixed $callback) {}
}
PHP,
];
}
}