-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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 generics signature of config()
and model()
#7660
Fix generics signature of config()
and model()
#7660
Conversation
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 would prefer to see the stricter definitions. Our User Guide sets the expectation:
... which returns a new instance of a Config class...
... returns a new instance of a Model class...
Just because they can be used to return another class in the same directory doesn't mean we want that to happen. We could tighten Factories by adding instanceOf
directives to the calls if there is a problem with this not being explicit.
If we are to enforce
So, tightening the two functions can be breaking changes. |
I responded on Slack. I don't think all of those Config files need to be loadable via |
These classes are required before the Autoloader instantiation:
|
I sent #7735 to fix the bug in this PR. |
Description
Since the current undocumented behavior of
config()
andmodel()
is to allow any class string as name input and return their respective instances, then I believe we should change the generics signature to account this fact.How to test
test.php
vendor/bin/phpstan analyse -v test.php
In line 7, PHPStan gives the inferred type as
App|null
since it does not know ifApp
is a valid class string or not. In PHPStan parlance, this is a "maybe" class string, thus it can beApp
ornull
. More precise type inference will come once our own phpstan extension is out, which is currently in development.This PR also fixes the resulting error in code in Toolbar.
Related: #7224 #7254
Checklist: