Uh oh!
There was an error while loading. Please reload this page.
Fix generics signature of config() and model() - #7660
Conversation
MGatner
left a comment
There was a problem hiding this comment.
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.
paulbalandan
commented
Jul 6, 2023
paulbalandan
commented
Jul 6, 2023
If we are to enforce
So, tightening the two functions can be breaking changes. |
MGatner
commented
Jul 7, 2023
I responded on Slack. I don't think all of those Config files need to be loadable via |
kenjis
commented
Jul 13, 2023
These classes are required before the Autoloader instantiation:
|
kenjis
commented
Jul 25, 2023
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.phpvendor/bin/phpstan analyse -v test.phpIn line 7, PHPStan gives the inferred type as
App|nullsince it does not know ifAppis a valid class string or not. In PHPStan parlance, this is a "maybe" class string, thus it can beAppornull. 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: