Skip to content

Commit 4ddefa8

Browse files
committed
re-use logic from preparational PR
1 parent 8814779 commit 4ddefa8

File tree

1 file changed

+34
-27
lines changed

1 file changed

+34
-27
lines changed

src/Analyser/MutatingScope.php

Lines changed: 34 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,37 @@ public function rememberConstructorScope(): self
369369
);
370370
}
371371

372+
private function isReadonlyPropertyFetchOnThis(PropertyFetch $expr): bool
373+
{
374+
while ($expr instanceof PropertyFetch) {
375+
if ($expr->var instanceof Variable) {
376+
if (
377+
! $expr->name instanceof Node\Identifier
378+
|| !is_string($expr->var->name)
379+
|| $expr->var->name !== 'this'
380+
) {
381+
return false;
382+
}
383+
} elseif (!$expr->var instanceof PropertyFetch) {
384+
return false;
385+
}
386+
387+
$propertyReflection = $this->propertyReflectionFinder->findPropertyReflectionFromNode($expr, $this);
388+
if ($propertyReflection === null) {
389+
return false;
390+
}
391+
392+
$nativePropertyReflection = $propertyReflection->getNativeReflection();
393+
if ($nativePropertyReflection === null || !$nativePropertyReflection->isReadOnly()) {
394+
return false;
395+
}
396+
397+
$expr = $expr->var;
398+
}
399+
400+
return true;
401+
}
402+
372403
/** @api */
373404
public function isInClass(): bool
374405
{
@@ -3739,36 +3770,12 @@ private function enterAnonymousFunctionWithoutReflection(
37393770
foreach ($nonStaticExpressions as $exprString => $typeHolder) {
37403771
$expr = $typeHolder->getExpr();
37413772

3742-
if (
3743-
!$expr instanceof PropertyFetch
3744-
) {
3773+
if (!$expr instanceof PropertyFetch) {
37453774
continue;
37463775
}
37473776

3748-
while ($expr instanceof PropertyFetch) {
3749-
if ($expr->var instanceof Variable) {
3750-
if (
3751-
! $expr->name instanceof Node\Identifier
3752-
|| !is_string($expr->var->name)
3753-
|| $expr->var->name !== 'this'
3754-
) {
3755-
continue 2;
3756-
}
3757-
} elseif (!$expr->var instanceof PropertyFetch) {
3758-
continue 2;
3759-
}
3760-
3761-
$propertyReflection = $this->propertyReflectionFinder->findPropertyReflectionFromNode($expr, $this);
3762-
if ($propertyReflection === null) {
3763-
continue 2;
3764-
}
3765-
3766-
$nativePropertyReflection = $propertyReflection->getNativeReflection();
3767-
if ($nativePropertyReflection === null || !$nativePropertyReflection->isReadOnly()) {
3768-
continue 2;
3769-
}
3770-
3771-
$expr = $expr->var;
3777+
if (!$this->isReadonlyPropertyFetchOnThis($expr)) {
3778+
continue;
37723779
}
37733780

37743781
$expressionTypes[$exprString] = $typeHolder;

0 commit comments

Comments
 (0)