Skip to content

Commit c9b031e

Browse files
staabmondrejmirtes
authored andcommitted
refactor shouldInvalidateExpression()
1 parent 6de5714 commit c9b031e

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

src/Analyser/MutatingScope.php

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ private function rememberConstructorExpressions(array $currentExpressionTypes):
315315
continue;
316316
}
317317
} elseif ($expr instanceof PropertyFetch) {
318-
if (!$this->isReadonlyPropertyFetchOnThis($expr)) {
318+
if (!$this->isReadonlyPropertyFetch($expr, true)) {
319319
continue;
320320
}
321321
} elseif (!$expr instanceof ConstFetch && !$expr instanceof PropertyInitializationExpr) {
@@ -354,7 +354,7 @@ public function rememberConstructorScope(): self
354354
);
355355
}
356356

357-
private function isReadonlyPropertyFetchOnThis(PropertyFetch $expr): bool
357+
private function isReadonlyPropertyFetch(PropertyFetch $expr, bool $allowOnlyOnThis): bool
358358
{
359359
if (!$this->phpVersion->supportsReadOnlyProperties()) {
360360
return false;
@@ -363,9 +363,12 @@ private function isReadonlyPropertyFetchOnThis(PropertyFetch $expr): bool
363363
while ($expr instanceof PropertyFetch) {
364364
if ($expr->var instanceof Variable) {
365365
if (
366-
! $expr->name instanceof Node\Identifier
367-
|| !is_string($expr->var->name)
368-
|| $expr->var->name !== 'this'
366+
$allowOnlyOnThis
367+
&& (
368+
! $expr->name instanceof Node\Identifier
369+
|| !is_string($expr->var->name)
370+
|| $expr->var->name !== 'this'
371+
)
369372
) {
370373
return false;
371374
}
@@ -4460,14 +4463,12 @@ private function shouldInvalidateExpression(string $exprStringToInvalidate, Expr
44604463
return false;
44614464
}
44624465

4463-
if ($this->phpVersion->supportsReadOnlyProperties() && $expr instanceof PropertyFetch && $expr->name instanceof Node\Identifier && $requireMoreCharacters) {
4464-
$propertyReflection = $this->propertyReflectionFinder->findPropertyReflectionFromNode($expr, $this);
4465-
if ($propertyReflection !== null) {
4466-
$nativePropertyReflection = $propertyReflection->getNativeReflection();
4467-
if ($nativePropertyReflection !== null && $nativePropertyReflection->isReadOnly()) {
4468-
return false;
4469-
}
4470-
}
4466+
if (
4467+
$expr instanceof PropertyFetch
4468+
&& $requireMoreCharacters
4469+
&& $this->isReadonlyPropertyFetch($expr, false)
4470+
) {
4471+
return false;
44714472
}
44724473

44734474
return true;

0 commit comments

Comments
 (0)