Fix resolving class const fetch for constant strings#1416
Fix resolving class const fetch for constant strings#1416ondrejmirtes merged 1 commit intophpstan:1.7.xfrom
Conversation
|
Thank you! Please also open a PR with that namespace slice fix 😊 |
|
Although the reported https://phpstan.org/r/89fb126f-4736-4208-b599-a5264d181e18 demo is fixed, I still need the following fix in my code /w phpstan 1.7.14: /**
* @param MethodCall|StaticCall $methodCall
*/
protected function getMethodCallScopeType(CallLike $methodCall, Scope $scope): Type
{
if ($methodCall instanceof StaticCall) {
+ // while loop needed to fix https://github.com/phpstan/phpstan/issues/7391
$clExpr = $methodCall->class;
+ while ($clExpr instanceof ClassConstFetch && $clExpr->name instanceof Identifier && strtolower($clExpr->name->name) === 'class') {
+ $clExpr = $clExpr->class;
+ }
$classNameType = $scope->getType(new ClassConstFetch($clExpr, 'class'));
if ($classNameType instanceof ConstantStringType) {
return new ObjectType($classNameType->getValue());
} elseif ($classNameType instanceof GenericClassStringType) {
return $classNameType->getGenericType();
}
throw new \Exception('Unexpected scope class name class: ' . get_class($classNameType));
}
return $scope->getType($methodCall->var);
} |
|
Please create a new issue showing exactly what you're trying to accomplish. I though it was about |
|
In custom phpstan extension, I need this code to resolve method class from |
|
You can use phpstan-src/src/Analyser/MutatingScope.php Lines 1732 to 1750 in c4a662a |
|
I tried, but the |
Fix phpstan/phpstan#7391