Skip to content

Commit 37cd2ac

Browse files
committed
UselessParenthesesSniff: Fixed false positive
1 parent bd06327 commit 37cd2ac

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

SlevomatCodingStandard/Sniffs/PHP/UselessParenthesesSniff.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,8 @@ private function checkParenthesesAroundVariableOrFunctionCall(File $phpcsFile, i
155155
return;
156156
}
157157

158-
$ternaryOperatorPointer = TokenHelper::findNextEffective($phpcsFile, $tokens[$parenthesisOpenerPointer]['parenthesis_closer'] + 1);
159-
if ($tokens[$ternaryOperatorPointer]['code'] === T_INLINE_THEN) {
158+
$pointerAfterParenthesisCloser = TokenHelper::findNextEffective($phpcsFile, $tokens[$parenthesisOpenerPointer]['parenthesis_closer'] + 1);
159+
if (in_array($tokens[$pointerAfterParenthesisCloser]['code'], [T_INLINE_THEN, T_OPEN_PARENTHESIS], true)) {
160160
return;
161161
}
162162

tests/Sniffs/PHP/data/uselessParenthesesNoErrors.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,17 @@ function doSomething($parameter) {
6363
switch (true) {
6464
case !($boo !== null):
6565
}
66+
67+
class ClassWithClosure
68+
{
69+
private $closure;
70+
71+
public function __construct()
72+
{
73+
$this->closure = function () {
74+
echo 123;
75+
};
76+
77+
($this->closure)();
78+
}
79+
}

0 commit comments

Comments
 (0)