-
Notifications
You must be signed in to change notification settings - Fork 546
Enabling constructor check for class-string variables #3661
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
Conversation
7663d06 to
f6c5c24
Compare
f6c5c24 to
18529dc
Compare
|
This pull request has been marked as ready for review. |
18529dc to
615d5e6
Compare
|
|
||
| $type = $scope->getType($node->class); | ||
|
|
||
| if (str_starts_with($type->describe(VerbosityLevel::precise()), 'class-string')) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could this use Type->isClassStringType()?
| $classStringObjectType = $type->getClassStringObjectType(); | ||
|
|
||
| return array_map( | ||
| static fn (string $name): array => [$name, true], | ||
| array_filter($classStringObjectType->getObjectClassNames(), function (string $name): bool { | ||
| $reflectionClass = $this->reflectionProvider->getClass($name); | ||
| return !$reflectionClass->isAbstract() && !$reflectionClass->isInterface(); | ||
| }), | ||
| ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could this be shortened with Type->getObjectClassReflections()?
staabm
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm thanks.
please give ondej some time to work thru the queue of open PRs
|
|
||
| $type = $scope->getType($node->class); | ||
|
|
||
| if (str_starts_with($type->describe(VerbosityLevel::precise()), 'class-string')) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm sorry, rule logic can't rely on string type descriptions.
|
Thank you! |
Changed to check constructor arguments when creating an instance from a variable containing a class-string.
Skip checking if T in class-string is abstract or interface.
resolve phpstan/phpstan#12010