Skip to content

Commit 9117a15

Browse files
committed
SlevomatCodingStandard.PHP.OptimizedFunctionsWithoutUnpacking: Fixed false positive with first class callable
1 parent 59b7809 commit 9117a15

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

SlevomatCodingStandard/Sniffs/PHP/OptimizedFunctionsWithoutUnpackingSniff.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,11 @@ public function process(File $phpcsFile, $pointer): void
9999
return;
100100
}
101101

102+
if (TokenHelper::findNextEffective($phpcsFile, $nextTokenAfterSeparatorPointer + 1) === $closeBracketPointer) {
103+
// First class callables
104+
return;
105+
}
106+
102107
$phpcsFile->addError(
103108
sprintf('Function %s is specialized by PHP and should not use argument unpacking.', $invokedName),
104109
$nextTokenAfterSeparatorPointer,

tests/Sniffs/PHP/data/optimizedFunctionsWithoutUnpackingNamespacedNoErrors.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
<?php
1+
<?php // lint >= 8.1
22

33
namespace Test;
44

5+
use function array_map;
56
use function func_get_args;
67
use function is_double as is_funny;
78
use function strlen;
@@ -29,3 +30,5 @@
2930
new Foo(...bar());
3031

3132
$foo->strlen(...$foo);
33+
34+
array_map(\intval(...), ['123', '23']);

tests/Sniffs/PHP/data/optimizedFunctionsWithoutUnpackingNotNamespacedNoErrors.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?php
1+
<?php // lint >= 8.1
22

33
if (0) {
44
function strlen(...$foo)
@@ -9,3 +9,5 @@ function strlen(...$foo)
99
strlen($foo);
1010
new Foo(...$foo);
1111
(function (...$foo) {})(...$foo);
12+
13+
array_map(intval(...), ['123', '23']);

0 commit comments

Comments
 (0)