Skip to content

Commit 4b41e8b

Browse files
committed
wip
1 parent f06b41b commit 4b41e8b

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

src/Analyser/MutatingScope.php

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
use PHPStan\Node\Printer\ExprPrinter;
5050
use PHPStan\Node\PropertyAssignNode;
5151
use PHPStan\Parser\ArrayMapArgVisitor;
52+
use PHPStan\Parser\ClosureBindArgVisitor;
5253
use PHPStan\Parser\NewAssignedToPropertyVisitor;
5354
use PHPStan\Parser\Parser;
5455
use PHPStan\Php\PhpVersion;
@@ -2025,10 +2026,27 @@ static function (Node $node, Scope $scope) use ($arrowScope, &$arrowFunctionImpu
20252026
if ($this->hasExpressionType($node)->yes()) {
20262027
return $this->expressionTypes[$exprString]->getType();
20272028
}
2029+
2030+
$scopeClassReflection = null;
2031+
$isInClass = $this->isInClass();
2032+
if ($node->class->hasAttribute(ClosureBindArgVisitor::SCOPE_ATTRIBUTE_NAME)) {
2033+
/** @var ?Expr $scopeClassNode */
2034+
$scopeClassNode = $node->class->getAttribute(ClosureBindArgVisitor::SCOPE_ATTRIBUTE_NAME);
2035+
if ($scopeClassNode instanceof Expr\ClassConstFetch
2036+
&& $scopeClassNode->class instanceof Name
2037+
&& $scopeClassNode->name instanceof Node\Identifier
2038+
&& $scopeClassNode->name->toLowerString() === 'class'
2039+
) {
2040+
$classScopeName = $this->resolveName($scopeClassNode->class);
2041+
$isInClass = true;
2042+
$scopeClassReflection = $this->reflectionProvider->getClass($classScopeName);
2043+
}
2044+
}
2045+
20282046
return $this->initializerExprTypeResolver->getClassConstFetchTypeByReflection(
20292047
$node->class,
20302048
$node->name->name,
2031-
$this->isInClass() ? $this->getClassReflection() : null,
2049+
$isInClass ? $scopeClassReflection ?? $this->getClassReflection() : null,
20322050
fn (Expr $expr): Type => $this->getType($expr),
20332051
);
20342052
}

0 commit comments

Comments
 (0)