Skip to content

Commit 71c8de2

Browse files
committed
Squiz/DisallowComparisonAssignment: fix sniff to work with the PHP 8 identifier tokens
Includes extra unit tests covering the change in so far it wasn't already covered. Note: this was previously a false positive for this sniff!
1 parent 6e33f43 commit 71c8de2

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

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

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -68,18 +68,16 @@ public function process(File $phpcsFile, $stackPtr)
6868
}
6969

7070
// Ignore function calls.
71-
$ignore = [
72-
T_NULLSAFE_OBJECT_OPERATOR,
73-
T_OBJECT_OPERATOR,
74-
T_STRING,
75-
T_VARIABLE,
76-
T_WHITESPACE,
77-
];
71+
$ignore = Tokens::$nameTokens;
72+
$ignore[] = T_NULLSAFE_OBJECT_OPERATOR;
73+
$ignore[] = T_OBJECT_OPERATOR;
74+
$ignore[] = T_VARIABLE;
75+
$ignore[] = T_WHITESPACE;
7876

7977
$next = $phpcsFile->findNext($ignore, ($stackPtr + 1), null, true);
8078
if ($tokens[$next]['code'] === T_CLOSURE
8179
|| ($tokens[$next]['code'] === T_OPEN_PARENTHESIS
82-
&& $tokens[($next - 1)]['code'] === T_STRING)
80+
&& isset(Tokens::$nameTokens[$tokens[($next - 1)]['code']]) === true)
8381
) {
8482
// Code will look like: $var = myFunction(
8583
// and will be ignored.

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,3 +81,7 @@ function issue3616() {
8181
$food === 'cake' => 'This food is a cake',
8282
};
8383
}
84+
85+
$var = \Fully\qualified(!$var);
86+
$var = Partially\qualified(!$var);
87+
$var = namespace\relative(!$var);

0 commit comments

Comments
 (0)