添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

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

Description

I'm not 100% sure that it is a problem of Laravel, or phpstan,
Typehinting in phpstan does not work correctly with laravel collection map function
when it is Illuminate\Database\Eloquent\Collection is trying to map models

Parameter #1 $callback of method                                                        
     Illuminate\Database\Eloquent\Collection<int,Illuminate\Database\Eloquent\Model>::map()  
     expects callable(Illuminate\Database\Eloquent\Model, int): array{id:                    
     string|null, text: string},                                                             
     Closure(App\Models\SerialNumber): array{id: string|null,                       
     text: non-falsy-string} given.       

somehow phpstan das not recognize that SerialNumber is a child class from the Model

If you please can share any of your ideas in stackoverflow
https://stackoverflow.com/questions/76729231/larastan-complains-about-collection-methods-paramaters-after-upgrading-to-larave

Steps To Reproduce

install phpstan and run the checks on your project

Hey there, thanks for reporting this issue.

If you notice improper DocBlock, PHPStan, or IDE warnings while using Laravel, do not create a GitHub issue. Instead, please submit a pull request to fix the problem. Also see our contribution guide.

Thanks!

If only I'd know how to fix it.
It seems to be a deep conflict of architectures between Laravel and PhpStan.
I made an issue report to them phpstan/phpstan#9735
But PhpStan made their descision:

it's dangerous to require ModelA because the callback might be called with a different child of Model

What they call "dangerous", I call - "validation".