Skip to content

Commit 87ab640

Browse files
committed
Squiz/DisallowMultipleAssignments: fix false positive
There was a bug in the code used to check if a equal sign is used to set a default value for a parameter that caused a false positive when the function was missing the closing parenthesis (which can happen during live coding). This commit fixes this false positive.
1 parent 0b8002b commit 87ab640

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public function process(File $phpcsFile, $stackPtr)
4747
if ($function !== false) {
4848
$opener = $tokens[$function]['parenthesis_opener'];
4949
$closer = $tokens[$function]['parenthesis_closer'];
50-
if ($opener < $stackPtr && $closer > $stackPtr) {
50+
if ($closer === null || ($opener < $stackPtr && $closer > $stackPtr)) {
5151
return;
5252
}
5353
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
// Intentional parse error (missing closing parenthesis).
4+
// This should be the only test in this file.
5+
// Testing that the sniff is *not* triggered.
6+
7+
function missingClosingParenthesis($a =

0 commit comments

Comments
 (0)