Skip to content

Commit eb456bd

Browse files
committed
simplify diff
1 parent 4713464 commit eb456bd

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
@@ -3731,41 +3731,21 @@ private function enterAnonymousFunctionWithoutReflection(
37313731
foreach ($this->invalidateStaticExpressions($this->expressionTypes) as $exprString => $typeHolder) {
37323732
$expr = $typeHolder->getExpr();
37333733

3734-
if (
3735-
$expr instanceof PropertyFetch
3736-
&& $expr->name instanceof Node\Identifier
3737-
&& $expr->var instanceof Variable
3738-
&& is_string($expr->var->name)
3739-
&& $expr->var->name === 'this'
3740-
&& !$closure->static
3741-
&& $this->hasVariableType('this')->yes()
3742-
&& $this->phpVersion->supportsReadOnlyProperties()
3743-
) {
3744-
$propertyReflection = $this->propertyReflectionFinder->findPropertyReflectionFromNode($expr, $this);
3745-
if ($propertyReflection === null) {
3746-
continue;
3747-
}
3748-
$nativePropertyReflection = $propertyReflection->getNativeReflection();
3749-
if ($nativePropertyReflection === null || !$nativePropertyReflection->isReadOnly()) {
3750-
continue;
3751-
}
3752-
} else {
3753-
if ($expr instanceof Variable) {
3754-
continue;
3755-
}
3734+
if ($expr instanceof Variable) {
3735+
continue;
3736+
}
37563737

3757-
$variables = (new NodeFinder())->findInstanceOf([$expr], Variable::class);
3758-
if ($variables === [] && !$this->expressionTypeIsUnchangeable($typeHolder)) {
3759-
continue;
3760-
}
3738+
$variables = (new NodeFinder())->findInstanceOf([$expr], Variable::class);
3739+
if ($variables === [] && !$this->expressionTypeIsUnchangeable($typeHolder)) {
3740+
continue;
3741+
}
37613742

3762-
foreach ($variables as $variable) {
3763-
if (!is_string($variable->name)) {
3764-
continue 2;
3765-
}
3766-
if (!array_key_exists($variable->name, $nonRefVariableNames)) {
3767-
continue 2;
3768-
}
3743+
foreach ($variables as $variable) {
3744+
if (!is_string($variable->name)) {
3745+
continue 2;
3746+
}
3747+
if (!array_key_exists($variable->name, $nonRefVariableNames)) {
3748+
continue 2;
37693749
}
37703750
}
37713751

@@ -3776,6 +3756,34 @@ private function enterAnonymousFunctionWithoutReflection(
37763756
$node = new Variable('this');
37773757
$expressionTypes['$this'] = ExpressionTypeHolder::createYes($node, $this->getType($node));
37783758
$nativeTypes['$this'] = ExpressionTypeHolder::createYes($node, $this->getNativeType($node));
3759+
3760+
if ($this->phpVersion->supportsReadOnlyProperties()) {
3761+
foreach ($this->invalidateStaticExpressions($this->expressionTypes) as $exprString => $typeHolder) {
3762+
$expr = $typeHolder->getExpr();
3763+
3764+
if (
3765+
!$expr instanceof PropertyFetch
3766+
|| !$expr->name instanceof Node\Identifier
3767+
|| !$expr->var instanceof Variable
3768+
|| !is_string($expr->var->name)
3769+
|| $expr->var->name !== 'this'
3770+
) {
3771+
continue;
3772+
}
3773+
3774+
$propertyReflection = $this->propertyReflectionFinder->findPropertyReflectionFromNode($expr, $this);
3775+
if ($propertyReflection === null) {
3776+
continue;
3777+
}
3778+
3779+
$nativePropertyReflection = $propertyReflection->getNativeReflection();
3780+
if ($nativePropertyReflection === null || !$nativePropertyReflection->isReadOnly()) {
3781+
continue;
3782+
}
3783+
3784+
$expressionTypes[$exprString] = $typeHolder;
3785+
}
3786+
}
37793787
}
37803788

37813789
return $this->scopeFactory->create(

0 commit comments

Comments
 (0)