|
49 | 49 | use PHPStan\Node\Printer\ExprPrinter; |
50 | 50 | use PHPStan\Node\PropertyAssignNode; |
51 | 51 | use PHPStan\Parser\ArrayMapArgVisitor; |
| 52 | +use PHPStan\Parser\ClosureBindArgVisitor; |
52 | 53 | use PHPStan\Parser\NewAssignedToPropertyVisitor; |
53 | 54 | use PHPStan\Parser\Parser; |
54 | 55 | use PHPStan\Php\PhpVersion; |
@@ -2025,10 +2026,27 @@ static function (Node $node, Scope $scope) use ($arrowScope, &$arrowFunctionImpu |
2025 | 2026 | if ($this->hasExpressionType($node)->yes()) { |
2026 | 2027 | return $this->expressionTypes[$exprString]->getType(); |
2027 | 2028 | } |
| 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 | + |
2028 | 2046 | return $this->initializerExprTypeResolver->getClassConstFetchTypeByReflection( |
2029 | 2047 | $node->class, |
2030 | 2048 | $node->name->name, |
2031 | | - $this->isInClass() ? $this->getClassReflection() : null, |
| 2049 | + $isInClass ? $scopeClassReflection ?? $this->getClassReflection() : null, |
2032 | 2050 | fn (Expr $expr): Type => $this->getType($expr), |
2033 | 2051 | ); |
2034 | 2052 | } |
|
0 commit comments