Skip to content

Commit 4201fd8

Browse files
committed
Fixed Squiz.PHP.DisallowComparisonAssignment false positive for methods called on an object (ref #3089)
1 parent 9cce685 commit 4201fd8

File tree

3 files changed

+7
-1
lines changed

3 files changed

+7
-1
lines changed

package.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
3737
- PSR12.Functions.NullableTypeDeclaration now supports the PHP8 static return type
3838
-- Thanks to Juliette Reinders Folmer for the patch
3939
- Fixed Squiz.Formatting.OperatorBracket false positive when exiting with a negative number
40+
- Fixed Squiz.PHP.DisallowComparisonAssignment false positive for methods called on an object
4041
- Fixed bug #2882 : Generic.Arrays.ArrayIndent can request close brace indent to be less than the statement indent level
4142
- Fixed bug #2883 : Generic.WhiteSpace.ScopeIndent.Incorrect issue after NOWDOC
4243
- Fixed bug #2975 : Undefined offset in PSR12.Functions.ReturnTypeDeclaration when checking function return type inside ternary

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,11 @@ public function process(File $phpcsFile, $stackPtr)
6868

6969
// Ignore function calls.
7070
$ignore = [
71+
T_NULLSAFE_OBJECT_OPERATOR,
72+
T_OBJECT_OPERATOR,
7173
T_STRING,
74+
T_VARIABLE,
7275
T_WHITESPACE,
73-
T_OBJECT_OPERATOR,
7476
];
7577

7678
$next = $phpcsFile->findNext($ignore, ($stackPtr + 1), null, true);

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,6 @@ $a = [
6262
$a = [
6363
'a' => ($foo) ? fn() => return 1 : fn() => return 2,
6464
];
65+
66+
$var = $foo->something(!$var);
67+
$var = $foo?->something(!$var);

0 commit comments

Comments
 (0)