From 4201fd8931e2363afdcec8ef438c4efb04f6a017 Mon Sep 17 00:00:00 2001 From: Greg Sherwood Date: Mon, 21 Sep 2020 08:19:31 +1000 Subject: [PATCH] Fixed Squiz.PHP.DisallowComparisonAssignment false positive for methods called on an object (ref #3089) --- package.xml | 1 + .../Squiz/Sniffs/PHP/DisallowComparisonAssignmentSniff.php | 4 +++- .../Squiz/Tests/PHP/DisallowComparisonAssignmentUnitTest.inc | 3 +++ 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/package.xml b/package.xml index d9c856491e..40b971631b 100644 --- a/package.xml +++ b/package.xml @@ -37,6 +37,7 @@ http://pear.php.net/dtd/package-2.0.xsd"> - PSR12.Functions.NullableTypeDeclaration now supports the PHP8 static return type -- Thanks to Juliette Reinders Folmer for the patch - Fixed Squiz.Formatting.OperatorBracket false positive when exiting with a negative number + - Fixed Squiz.PHP.DisallowComparisonAssignment false positive for methods called on an object - Fixed bug #2882 : Generic.Arrays.ArrayIndent can request close brace indent to be less than the statement indent level - Fixed bug #2883 : Generic.WhiteSpace.ScopeIndent.Incorrect issue after NOWDOC - Fixed bug #2975 : Undefined offset in PSR12.Functions.ReturnTypeDeclaration when checking function return type inside ternary diff --git a/src/Standards/Squiz/Sniffs/PHP/DisallowComparisonAssignmentSniff.php b/src/Standards/Squiz/Sniffs/PHP/DisallowComparisonAssignmentSniff.php index aaed48d22a..7ad2b6f6ac 100644 --- a/src/Standards/Squiz/Sniffs/PHP/DisallowComparisonAssignmentSniff.php +++ b/src/Standards/Squiz/Sniffs/PHP/DisallowComparisonAssignmentSniff.php @@ -68,9 +68,11 @@ public function process(File $phpcsFile, $stackPtr) // Ignore function calls. $ignore = [ + T_NULLSAFE_OBJECT_OPERATOR, + T_OBJECT_OPERATOR, T_STRING, + T_VARIABLE, T_WHITESPACE, - T_OBJECT_OPERATOR, ]; $next = $phpcsFile->findNext($ignore, ($stackPtr + 1), null, true); diff --git a/src/Standards/Squiz/Tests/PHP/DisallowComparisonAssignmentUnitTest.inc b/src/Standards/Squiz/Tests/PHP/DisallowComparisonAssignmentUnitTest.inc index d4fce10f4d..3a629ff855 100644 --- a/src/Standards/Squiz/Tests/PHP/DisallowComparisonAssignmentUnitTest.inc +++ b/src/Standards/Squiz/Tests/PHP/DisallowComparisonAssignmentUnitTest.inc @@ -62,3 +62,6 @@ $a = [ $a = [ 'a' => ($foo) ? fn() => return 1 : fn() => return 2, ]; + +$var = $foo->something(!$var); +$var = $foo?->something(!$var);