Larastan: Does Lumen have an internal error?

Created on 27 Jan 2020  路  4Comments  路  Source: nunomaduro/larastan

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

Lumen

Most helpful comment

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.

All 4 comments

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.

Was this page helpful?
0 / 5 - 0 ratings