Skip to content

Commit ef438f8

Browse files
committed
UselessParenthesesSniff: Fixed false positive
1 parent e905dcf commit ef438f8

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

SlevomatCodingStandard/Sniffs/PHP/UselessParenthesesSniff.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use SlevomatCodingStandard\Helpers\TokenHelper;
99
use const T_ANON_CLASS;
1010
use const T_BOOLEAN_NOT;
11+
use const T_CLOSE_PARENTHESIS;
1112
use const T_CLOSURE;
1213
use const T_DOLLAR;
1314
use const T_EMPTY;
@@ -55,7 +56,7 @@ public function process(File $phpcsFile, $parenthesisOpenerPointer): void
5556

5657
/** @var int $pointerBeforeParenthesisOpener */
5758
$pointerBeforeParenthesisOpener = TokenHelper::findPreviousEffective($phpcsFile, $parenthesisOpenerPointer - 1);
58-
if (in_array($tokens[$pointerBeforeParenthesisOpener]['code'], [T_VARIABLE, T_STRING, T_ISSET, T_UNSET, T_EMPTY, T_CLOSURE, T_USE, T_ANON_CLASS, T_SELF, T_STATIC, T_EXIT], true)) {
59+
if (in_array($tokens[$pointerBeforeParenthesisOpener]['code'], [T_VARIABLE, T_STRING, T_ISSET, T_UNSET, T_EMPTY, T_CLOSURE, T_USE, T_ANON_CLASS, T_SELF, T_STATIC, T_EXIT, T_CLOSE_PARENTHESIS], true)) {
5960
return;
6061
}
6162

tests/Sniffs/PHP/data/uselessParenthesesNoErrors.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,7 @@ function doSomething($parameter) {
5050

5151
exit($a);
5252
die($a);
53+
54+
(function ($b): void {
55+
// Do something
56+
})($b);

0 commit comments

Comments
 (0)