Skip to content

Commit 315bb13

Browse files
Simplify
1 parent f65ca58 commit 315bb13

File tree

2 files changed

+31
-60
lines changed

2 files changed

+31
-60
lines changed

src/Rules/Operators/InvalidAssignVarRule.php

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -66,42 +66,13 @@ public function processNode(Node $node, Scope $scope): array
6666
];
6767
}
6868

69-
if ($this->containsThisVariable($node->var)) {
70-
return [
71-
RuleErrorBuilder::message('Cannot re-assign $this.')
72-
->identifier('assign.this')
73-
->nonIgnorable()
74-
->build(),
75-
];
76-
}
77-
7869
return [];
7970
}
8071

81-
private function containsThisVariable(Expr $expr): bool
82-
{
83-
if ($expr instanceof Expr\Variable && $expr->name === 'this') {
84-
return true;
85-
}
86-
87-
if ($expr instanceof Expr\List_) {
88-
foreach ($expr->items as $item) {
89-
if ($item === null) {
90-
continue;
91-
}
92-
if ($this->containsThisVariable($item->value)) {
93-
return true;
94-
}
95-
}
96-
}
97-
98-
return false;
99-
}
100-
10172
private function containsNonAssignableExpression(Expr $expr): bool
10273
{
10374
if ($expr instanceof Expr\Variable) {
104-
return false;
75+
return $expr->name !== 'this';
10576
}
10677

10778
if ($expr instanceof Expr\PropertyFetch) {

tests/PHPStan/Rules/Operators/InvalidAssignVarRuleTest.php

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -17,36 +17,6 @@ protected function getRule(): Rule
1717
return new InvalidAssignVarRule(new NullsafeCheck());
1818
}
1919

20-
public function testBug3585(): void
21-
{
22-
$this->analyse([__DIR__ . '/data/bug-3585.php'], [
23-
[
24-
'Cannot re-assign $this.',
25-
9,
26-
],
27-
[
28-
'Cannot re-assign $this.',
29-
10,
30-
],
31-
[
32-
'Cannot re-assign $this.',
33-
11,
34-
],
35-
[
36-
'Cannot re-assign $this.',
37-
12,
38-
],
39-
[
40-
'Cannot re-assign $this.',
41-
17,
42-
],
43-
[
44-
'Cannot re-assign $this.',
45-
23,
46-
],
47-
]);
48-
}
49-
5020
public function testRule(): void
5121
{
5222
$this->analyse([__DIR__ . '/data/invalid-assign-var.php'], [
@@ -89,4 +59,34 @@ public function testRule(): void
8959
]);
9060
}
9161

62+
public function testBug3585(): void
63+
{
64+
$this->analyse([__DIR__ . '/data/bug-3585.php'], [
65+
[
66+
'Expression on left side of assignment is not assignable.',
67+
9,
68+
],
69+
[
70+
'Expression on left side of assignment is not assignable.',
71+
10,
72+
],
73+
[
74+
'Expression on left side of assignment is not assignable.',
75+
11,
76+
],
77+
[
78+
'Expression on left side of assignment is not assignable.',
79+
12,
80+
],
81+
[
82+
'Expression on left side of assignment is not assignable.',
83+
17,
84+
],
85+
[
86+
'Expression on left side of assignment is not assignable.',
87+
23,
88+
],
89+
]);
90+
}
91+
9292
}

0 commit comments

Comments
 (0)