Skip to content

Commit 6f45c01

Browse files
committed
UselessParenthesesSniff: Fixed false positive
1 parent 757efc8 commit 6f45c01

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

SlevomatCodingStandard/Sniffs/PHP/UselessParenthesesSniff.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,10 @@ public function process(File $phpcsFile, $parenthesisOpenerPointer): void
160160
return;
161161
}
162162

163+
if (TokenHelper::findNext($phpcsFile, T_EQUAL, $parenthesisOpenerPointer + 1, $tokens[$parenthesisOpenerPointer]['parenthesis_closer']) !== null) {
164+
return;
165+
}
166+
163167
$pointerAfterParenthesisCloser = TokenHelper::findNextEffective($phpcsFile, $tokens[$parenthesisOpenerPointer]['parenthesis_closer'] + 1);
164168
if ($pointerAfterParenthesisCloser !== null && $tokens[$pointerAfterParenthesisCloser]['code'] === T_OPEN_PARENTHESIS) {
165169
return;

tests/Sniffs/PHP/data/uselessParenthesesNoErrors.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ function doSomething($parameter) {
4949
$z = ($a ? '0' : '1') ? '2' : '3';
5050
$zzz = !($a) ? true : false;
5151
$zzzz = null !== ($a = 'a') ? true : false;
52+
$zzzzz = null !== ($a === 'a') ? true : false;
5253

5354
exit($a);
5455
die($a);
@@ -157,6 +158,8 @@ function ($value) {
157158

158159
$output = (($a and $b) ? 'yes' : 'nope');
159160

161+
$whatever = (null !== $a = $b->call());
162+
160163
// Must be last
161164
return true
162165
? 100

0 commit comments

Comments
 (0)