Skip to content

Commit 2c0ecbc

Browse files
committed
UselessParenthesesSniff: Fixed false positive
1 parent 6b43d5a commit 2c0ecbc

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

SlevomatCodingStandard/Sniffs/PHP/UselessParenthesesSniff.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
use const T_USE;
5858
use const T_VARIABLE;
5959
use const T_WHITESPACE;
60+
use const T_YIELD_FROM;
6061

6162
class UselessParenthesesSniff implements Sniff
6263
{
@@ -123,7 +124,7 @@ public function process(File $phpcsFile, $parenthesisOpenerPointer): void
123124

124125
/** @var int $pointerAfterParenthesisOpener */
125126
$pointerAfterParenthesisOpener = TokenHelper::findNextEffective($phpcsFile, $parenthesisOpenerPointer + 1);
126-
if (in_array($tokens[$pointerAfterParenthesisOpener]['code'], [T_NEW, T_CLONE], true)) {
127+
if (in_array($tokens[$pointerAfterParenthesisOpener]['code'], [T_NEW, T_CLONE, T_YIELD_FROM], true)) {
127128
return;
128129
}
129130

tests/Sniffs/PHP/data/uselessParenthesesNoErrors.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,8 @@ function () {
119119
'a',
120120
] + $defaults('b'));
121121

122+
$y = (yield from whatever()) ?? $y;
123+
122124
// Must be last
123125
return true
124126
? 100

0 commit comments

Comments
 (0)