Skip to content

Commit aa238e2

Browse files
committed
fix
1 parent ca308ab commit aa238e2

File tree

2 files changed

+4
-18
lines changed

2 files changed

+4
-18
lines changed

src/Rules/Variables/UnsetRule.php

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -75,20 +75,6 @@ private function canBeUnset(Node $node, Scope $scope): ?IdentifierRuleError
7575
) {
7676
$type = $scope->getType($node->var);
7777
foreach ($type->getObjectClassReflections() as $classReflection) {
78-
if ($classReflection->isReadOnly() || $classReflection->isImmutable()) {
79-
return RuleErrorBuilder::message(
80-
sprintf(
81-
'Cannot unset property %s of %s class %s.',
82-
$node->name->name,
83-
$classReflection->isReadOnly() ? 'readonly' : 'immutable',
84-
$type->describe(VerbosityLevel::value()),
85-
),
86-
)
87-
->line($node->getStartLine())
88-
->identifier('unset.readonlyClass')
89-
->build();
90-
}
91-
9278
if (!$classReflection->hasNativeProperty($node->name->name)) {
9379
continue;
9480
}
@@ -104,7 +90,7 @@ private function canBeUnset(Node $node, Scope $scope): ?IdentifierRuleError
10490
),
10591
)
10692
->line($node->getStartLine())
107-
->identifier('unset.readonlyProperty')
93+
->identifier($propertyReflection->isReadOnly() ? 'unset.readOnlyProperty' : 'unset.readOnlyPropertyByPhpDoc')
10894
->build();
10995
}
11096
}

tests/PHPStan/Rules/Variables/UnsetRuleTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,23 +95,23 @@ public function testBug12421(): void
9595
{
9696
$this->analyse([__DIR__ . '/data/bug-12421.php'], [
9797
[
98-
'Cannot unset property y of readonly class Bug12421\NativeReadonlyClass.',
98+
'Cannot unset readonly property y of Bug12421\NativeReadonlyClass.',
9999
11,
100100
],
101101
[
102102
'Cannot unset readonly property y of Bug12421\NativeReadonlyProperty.',
103103
15,
104104
],
105105
[
106-
'Cannot unset property y of immutable class Bug12421\PhpdocReadonlyClass.',
106+
'Cannot unset @readonly property y of Bug12421\PhpdocReadonlyClass.',
107107
19,
108108
],
109109
[
110110
'Cannot unset @readonly property y of Bug12421\PhpdocReadonlyProperty.',
111111
23,
112112
],
113113
[
114-
'Cannot unset property y of immutable class Bug12421\PhpdocImmutableClass.',
114+
'Cannot unset @readonly property y of Bug12421\PhpdocImmutableClass.',
115115
27,
116116
],
117117
[

0 commit comments

Comments
 (0)