- Issue created by @dpi
- 🇧🇪Belgium borisson_ Mechelen, 🇧🇪
I'm unsure about this, while we do allow phpstan types to be added in code since a recent coding standards update, this would be the first time we'd be adding a type like this as far as I know.
I'm not sure it was the intention of the coding standards committee to allow us to introduce a typing as complex as this one.
How do we make sure we keep the type compatible with the actual array structure, can phpstan help us with this or is that something we'd need to define in a test?
Should we not bother?I do see the value in doing this though, it makes IDE's so much happier.
- 🇦🇺Australia dpi Perth, Australia
How do we make sure we keep the type compatible with the actual array structure, can phpstan help us with this or is that something we'd need to define in a test?
Should we not bother?When our internal usage changes, either regular runtime or tests, PHPStan will display errors.
For example if we add a new array key to the structure, and a test makes use of that new key, PHPStan will complain the key does not exist.
The same applies to removals, type changes, restructures, etc.
- 🇮🇹Italy mondrake 🇮🇹
This would be very very nice, but aside from @borisson_ comment above, I wonder whether we are ready for it.
If I am not mistaken, https://phpstan.org/user-guide/rule-levels, the actual checking of the array shapes' contents will start from PHPStan level 5 above; we are currently struggling with level 1...
So we may be introducing non-validated typing that could become a barrier rather that a facilitation to move to upper levels. Happy to be mistaken though.
- 🇧🇪Belgium borisson_ Mechelen, 🇧🇪
If I am not mistaken, https://phpstan.org/user-guide/rule-levels, the actual checking of the array shapes' contents will start from PHPStan level 5 above; we are currently struggling with level 1...
This is already noted in the Issue Summary as well. I agree - I don't think we can start doing this without us being on level 5 as well, because the arguments in #7 need level 5 to be valid.
- 🇦🇺Australia dpi Perth, Australia
the actual checking of the array shapes' contents will start from PHPStan level 5 above; we are currently struggling with level 1...
- I don't think we can start doing this without us being on level 5 as well,
Level 2, not 5, by the looks: https://phpstan.org/r/63bdb4f4-ca81-4423-8828-9da62ef4a5c9
According to that try page, perhaps it is enforcable with just enabling
reportPossiblyNonexistentGeneralArrayOffset
, and we could baseline on that.Stan and typing doesnt start and end with core. This change benefits, and is driven by, contrib and custom code.
As a project using PHPStan Lvl 9 + Strict I can immediately benefit from this.
Whether we enforce this in core now or later shouldn't matter too much, if non-core is consuming it, then it can also be responsible for reporting back to core. Just like we have to right now with the multitude of unenforced defective PHPDocs. When it comes time to core enforcing it, the amount of code is drastically reduced to simple bulk fixups, just like we would with existing PHPStan bulk changes.