Skip to content

Commit 7cdc4fc

Browse files
committed
fix
1 parent 57d5143 commit 7cdc4fc

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

src/Rules/Variables/UnsetRule.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public function processNode(Node $node, Scope $scope): array
4848
return $errors;
4949
}
5050

51-
private function canBeUnset(Node $node, Scope $scope, bool $inArrayDimFetch = false): ?IdentifierRuleError
51+
private function canBeUnset(Node $node, Scope $scope): ?IdentifierRuleError
5252
{
5353
if ($node instanceof Node\Expr\Variable && is_string($node->name)) {
5454
$hasVariable = $scope->hasVariableType($node->name);
@@ -77,7 +77,9 @@ private function canBeUnset(Node $node, Scope $scope, bool $inArrayDimFetch = fa
7777
->build();
7878
}
7979

80-
return $this->canBeUnset($node->var, $scope, true);
80+
if (!$node->var instanceof Node\Expr\PropertyFetch) {
81+
return $this->canBeUnset($node->var, $scope);
82+
}
8183
} elseif (
8284
$node instanceof Node\Expr\PropertyFetch
8385
&& $node->name instanceof Node\Identifier
@@ -117,7 +119,7 @@ private function canBeUnset(Node $node, Scope $scope, bool $inArrayDimFetch = fa
117119
->line($node->getStartLine())
118120
->identifier('unset.hookedProperty')
119121
->build();
120-
} elseif ($this->phpVersion->supportsPropertyHooks() && !$inArrayDimFetch) {
122+
} elseif ($this->phpVersion->supportsPropertyHooks()) {
121123
if (
122124
!$propertyReflection->isPrivate()
123125
&& !$propertyReflection->isFinal()->yes()

tests/PHPStan/Rules/Variables/data/unset-hooked-property.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,3 +137,14 @@ public function render(): array
137137
return parent::render();
138138
}
139139
}
140+
141+
class UnsetReadonly
142+
{
143+
/** @var int[][] */
144+
public readonly array $a;
145+
146+
public function doFoo(): void
147+
{
148+
unset($this->a[5]);
149+
}
150+
}

0 commit comments

Comments
 (0)