Skip to content

Commit 6f2a22d

Browse files
committed
Fixed bug #3165 : Squiz.PHP.DisallowComparisonAssignment false positive when comparison inside closure
1 parent 8421eeb commit 6f2a22d

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

package.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
6363
-- Thanks to Michael S for the patch
6464
- Fixed bug #2913 : Generic.WhiteSpace.ScopeIndent false positive when opening and closing tag on same line inside conditional
6565
- Fixed bug #3157 : PSR2.ControlStructures.SwitchDeclaration.BreakIndent false positive when case keyword is not indented
66+
- Fixed bug #3165 : Squiz.PHP.DisallowComparisonAssignment false positive when comparison inside closure
6667
</notes>
6768
<contents>
6869
<dir name="/">

src/Standards/Squiz/Sniffs/PHP/DisallowComparisonAssignmentSniff.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,9 @@ public function process(File $phpcsFile, $stackPtr)
7676
];
7777

7878
$next = $phpcsFile->findNext($ignore, ($stackPtr + 1), null, true);
79-
if ($tokens[$next]['code'] === T_OPEN_PARENTHESIS
80-
&& $tokens[($next - 1)]['code'] === T_STRING
79+
if ($tokens[$next]['code'] === T_CLOSURE
80+
|| ($tokens[$next]['code'] === T_OPEN_PARENTHESIS
81+
&& $tokens[($next - 1)]['code'] === T_STRING)
8182
) {
8283
// Code will look like: $var = myFunction(
8384
// and will be ignored.

src/Standards/Squiz/Tests/PHP/DisallowComparisonAssignmentUnitTest.inc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,9 @@ $a = [
6565

6666
$var = $foo->something(!$var);
6767
$var = $foo?->something(!$var);
68+
69+
$callback = function ($value) {
70+
if ($value > 10) {
71+
return false;
72+
}
73+
};

0 commit comments

Comments
 (0)