diff --git a/Makefile b/Makefile index 776b1082bb3..97eb28b4673 100644 --- a/Makefile +++ b/Makefile @@ -126,6 +126,7 @@ lint: --exclude tests/PHPStan/Rules/Properties/data/property-override-attr-missing.php \ --exclude tests/PHPStan/Rules/Properties/data/override-attr-on-property.php \ --exclude tests/PHPStan/Rules/Properties/data/property-override-attr.php \ + --exclude tests/PHPStan/Rules/Operators/data/bug-3585.php \ src tests install-paratest: diff --git a/src/Rules/Operators/InvalidAssignVarRule.php b/src/Rules/Operators/InvalidAssignVarRule.php index fd56b641077..fecb60794aa 100644 --- a/src/Rules/Operators/InvalidAssignVarRule.php +++ b/src/Rules/Operators/InvalidAssignVarRule.php @@ -72,7 +72,7 @@ public function processNode(Node $node, Scope $scope): array private function containsNonAssignableExpression(Expr $expr): bool { if ($expr instanceof Expr\Variable) { - return false; + return $expr->name === 'this'; } if ($expr instanceof Expr\PropertyFetch) { diff --git a/tests/PHPStan/Rules/Operators/InvalidAssignVarRuleTest.php b/tests/PHPStan/Rules/Operators/InvalidAssignVarRuleTest.php index 8dfd60fc26b..df4638e5576 100644 --- a/tests/PHPStan/Rules/Operators/InvalidAssignVarRuleTest.php +++ b/tests/PHPStan/Rules/Operators/InvalidAssignVarRuleTest.php @@ -59,4 +59,34 @@ public function testRule(): void ]); } + public function testBug3585(): void + { + $this->analyse([__DIR__ . '/data/bug-3585.php'], [ + [ + 'Expression on left side of assignment is not assignable.', + 9, + ], + [ + 'Expression on left side of assignment is not assignable.', + 10, + ], + [ + 'Expression on left side of assignment is not assignable.', + 11, + ], + [ + 'Expression on left side of assignment is not assignable.', + 12, + ], + [ + 'Expression on left side of assignment is not assignable.', + 17, + ], + [ + 'Expression on left side of assignment is not assignable.', + 23, + ], + ]); + } + } diff --git a/tests/PHPStan/Rules/Operators/data/bug-3585.php b/tests/PHPStan/Rules/Operators/data/bug-3585.php new file mode 100644 index 00000000000..dd7383f713c --- /dev/null +++ b/tests/PHPStan/Rules/Operators/data/bug-3585.php @@ -0,0 +1,24 @@ +