-
Notifications
You must be signed in to change notification settings - Fork 430
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix resolving class const fetch for constant strings #1416
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