or are we unable to understand Lumen's code?
(recently in CI)
------ ----------------------------------------------
Line Providers/AuthServiceProvider.php
------ ----------------------------------------------
33 Offset 'auth' does not exist on
Illuminate\Contracts\Foundation\Application.
------ ----------------------------------------------
https://github.com/laravel/lumen/blob/master/app/Providers/AuthServiceProvider.php#L33
4 years old commit!
No, the error is not in Lumen. Something recently changed (about ArrayAccess) in PHPStan. In 0.12.8 or 0.12.7 and causes this issue.
Funny thing is the same code doesn't produce an error in Laravel. Only in Lumen.
Ok, I can reproduce the error now. I don't know why I couldn't before.
The thing is, \Illuminate\Contracts\Foundation\Application does not implement ArrayAccess, the implementation does (Illuminate\Foundation\Application). That's why we have all this.
This is still working. Our getTypeFromArrayDimFetch implementation returns the correct type for the array access, but the NonexistentOffsetInArrayDimFetchRule rule started to complain now.
As far as I know, there is no way to lie about an interface implements the ArrayAccess to PHPStan. I tried stubs, didn't work. Ideally the Laravel code should be changed, but I don't think so they will be open to this change. So, I don't know what can we do more. @ondrejmirtes any ideas?
I'm not sure if the $type here is about Illuminate\Contracts\Foundation\Application or something else?
If it's about the Application class then besides overriding isOffsetAccessible, you should also override hasOffsetValueType and getOffsetValueType to persuade PHPStan in NonexistentOffsetInArrayDimFetchRule.
Most helpful comment
I'm not sure if the
$typehere is aboutIlluminate\Contracts\Foundation\Applicationor something else?If it's about the Application class then besides overriding
isOffsetAccessible, you should also overridehasOffsetValueTypeandgetOffsetValueTypeto persuade PHPStan inNonexistentOffsetInArrayDimFetchRule.