Skip to content

Commit

Permalink
feat: no_superfluous_phpdoc_tags - support for arrow function (PHP-CS…
Browse files Browse the repository at this point in the history
…-Fixer#7666)

Co-authored-by: Julien Falque <[email protected]>
  • Loading branch information
keradus and julienfalque authored Jan 5, 2024
1 parent 4f76f0d commit bf9ddb6
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Fixer/Phpdoc/NoSuperfluousPhpdocTagsFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ private function findDocumentedElement(Tokens $tokens, int $docCommentIndex): ?a
return $element;
}

if ($tokens[$index]->isGivenKind(T_FUNCTION)) {
if ($tokens[$index]->isGivenKind([T_FUNCTION, T_FN])) {
$element['index'] = $index;
$element['type'] = 'function';

Expand Down
72 changes: 72 additions & 0 deletions tests/Fixer/Phpdoc/NoSuperfluousPhpdocTagsFixerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2456,6 +2456,78 @@ class Foo {
public function doFoo($bar): Baz {}
}',
];

yield 'superfluous parameter type for anonymous function' => [
'<?php
/** */
function (int $foo) { return 1; };',
'<?php
/** @param int $foo */
function (int $foo) { return 1; };',
];

yield 'superfluous return type for anonymous function' => [
'<?php
/** */
function ($foo): int { return 1; };',
'<?php
/** @return int */
function ($foo): int { return 1; };',
];

yield 'superfluous parameter type for static anonymous function' => [
'<?php
/** */
static function (int $foo) { return 1; };',
'<?php
/** @param int $foo */
static function (int $foo) { return 1; };',
];

yield 'superfluous return type for static anonymous function' => [
'<?php
/** */
static function ($foo): int { return 1; };',
'<?php
/** @return int */
static function ($foo): int { return 1; };',
];

yield 'superfluous parameter type for arrow function' => [
'<?php
/** */
fn (int $foo) => 1;',
'<?php
/** @param int $foo */
fn (int $foo) => 1;',
];

yield 'superfluous return type for arrow function' => [
'<?php
/** */
fn ($foo): int => 1;',
'<?php
/** @return int */
fn ($foo): int => 1;',
];

yield 'superfluous parameter type for static arrow function' => [
'<?php
/** */
static fn (int $foo) => 1;',
'<?php
/** @param int $foo */
static fn (int $foo) => 1;',
];

yield 'superfluous return type for static arrow function' => [
'<?php
/** */
static fn ($foo): int => 1;',
'<?php
/** @return int */
static fn ($foo): int => 1;',
];
}

/**
Expand Down

0 comments on commit bf9ddb6

Please sign in to comment.