Skip to content
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

The ReflectionClassConstructorThrowTypeExtension can be improved to support object. #5195

Closed
VincentLanglet opened this issue Jun 19, 2021 · 2 comments · Fixed by phpstan/phpstan-src#566
Labels
Milestone

Comments

@VincentLanglet
Copy link
Contributor

Feature request

The ReflectionClassConstructorThrowTypeExtension only check for constantString

So

new \ReflectionClass(Foo::class);

is not throwing an exception.

But

new \ReflectionClass(new Foo());

does.

The Extension is doing

foreach (TypeUtils::getConstantStrings($valueType) as $constantString) {
     if (!$this->reflectionProvider->hasClass($constantString->getValue())) {
          return $methodReflection->getThrowType();
     }

     $valueType = TypeCombinator::remove($valueType, $constantString);
}

checking for Bar::class|Foo::class|...

What would be the equivalent way to check for Bar|Foo|... @ondrejmirtes ? I can do the PR.

@ondrejmirtes
Copy link
Member

The extension should return null if (new ObjectWithoutClassType())->isSuperTypeOf($valueType)->yes().

@github-actions
Copy link

github-actions bot commented Aug 2, 2021

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 2, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants