Skip to content

Commit 98f5558

Browse files
committed
simplify diff
1 parent 5f9d68c commit 98f5558

File tree

1 file changed

+41
-33
lines changed

1 file changed

+41
-33
lines changed

src/Analyser/MutatingScope.php

Lines changed: 41 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -3738,41 +3738,21 @@ private function enterAnonymousFunctionWithoutReflection(
37383738
foreach ($this->invalidateStaticExpressions($this->expressionTypes) as $exprString => $typeHolder) {
37393739
$expr = $typeHolder->getExpr();
37403740

3741-
if (
3742-
$expr instanceof PropertyFetch
3743-
&& $expr->name instanceof Node\Identifier
3744-
&& $expr->var instanceof Variable
3745-
&& is_string($expr->var->name)
3746-
&& $expr->var->name === 'this'
3747-
&& !$closure->static
3748-
&& $this->hasVariableType('this')->yes()
3749-
&& $this->phpVersion->supportsReadOnlyProperties()
3750-
) {
3751-
$propertyReflection = $this->propertyReflectionFinder->findPropertyReflectionFromNode($expr, $this);
3752-
if ($propertyReflection === null) {
3753-
continue;
3754-
}
3755-
$nativePropertyReflection = $propertyReflection->getNativeReflection();
3756-
if ($nativePropertyReflection === null || !$nativePropertyReflection->isReadOnly()) {
3757-
continue;
3758-
}
3759-
} else {
3760-
if ($expr instanceof Variable) {
3761-
continue;
3762-
}
3741+
if ($expr instanceof Variable) {
3742+
continue;
3743+
}
37633744

3764-
$variables = (new NodeFinder())->findInstanceOf([$expr], Variable::class);
3765-
if ($variables === [] && !$this->expressionTypeIsUnchangeable($typeHolder)) {
3766-
continue;
3767-
}
3745+
$variables = (new NodeFinder())->findInstanceOf([$expr], Variable::class);
3746+
if ($variables === [] && !$this->expressionTypeIsUnchangeable($typeHolder)) {
3747+
continue;
3748+
}
37683749

3769-
foreach ($variables as $variable) {
3770-
if (!is_string($variable->name)) {
3771-
continue 2;
3772-
}
3773-
if (!array_key_exists($variable->name, $nonRefVariableNames)) {
3774-
continue 2;
3775-
}
3750+
foreach ($variables as $variable) {
3751+
if (!is_string($variable->name)) {
3752+
continue 2;
3753+
}
3754+
if (!array_key_exists($variable->name, $nonRefVariableNames)) {
3755+
continue 2;
37763756
}
37773757
}
37783758

@@ -3783,6 +3763,34 @@ private function enterAnonymousFunctionWithoutReflection(
37833763
$node = new Variable('this');
37843764
$expressionTypes['$this'] = ExpressionTypeHolder::createYes($node, $this->getType($node));
37853765
$nativeTypes['$this'] = ExpressionTypeHolder::createYes($node, $this->getNativeType($node));
3766+
3767+
if ($this->phpVersion->supportsReadOnlyProperties()) {
3768+
foreach ($this->invalidateStaticExpressions($this->expressionTypes) as $exprString => $typeHolder) {
3769+
$expr = $typeHolder->getExpr();
3770+
3771+
if (
3772+
!$expr instanceof PropertyFetch
3773+
|| !$expr->name instanceof Node\Identifier
3774+
|| !$expr->var instanceof Variable
3775+
|| !is_string($expr->var->name)
3776+
|| $expr->var->name !== 'this'
3777+
) {
3778+
continue;
3779+
}
3780+
3781+
$propertyReflection = $this->propertyReflectionFinder->findPropertyReflectionFromNode($expr, $this);
3782+
if ($propertyReflection === null) {
3783+
continue;
3784+
}
3785+
3786+
$nativePropertyReflection = $propertyReflection->getNativeReflection();
3787+
if ($nativePropertyReflection === null || !$nativePropertyReflection->isReadOnly()) {
3788+
continue;
3789+
}
3790+
3791+
$expressionTypes[$exprString] = $typeHolder;
3792+
}
3793+
}
37863794
}
37873795

37883796
return $this->scopeFactory->create(

0 commit comments

Comments
 (0)