Open eusonlito opened 1 year ago
@eusonlito
Thanks for reporting!
Do you have ide-helper files locally when you run psalm?
No, I don't use IDE helpers.
@eusonlito
From what I found, the issue caused by vendor/psalm/plugin-laravel/cache/models.stubphp
file (available after running psalm). Previously this file was empty, but we fixed it in https://github.com/psalm/psalm-plugin-laravel/releases/tag/v2.1.1, so the latest working version for you will be 2.1.0, but it has an issue of not detecting Model's properties (this is what we have fixed in 2.1.1).
This is all what I know ATM. I'm working on this issue
I've always been confused why ide-helper uses an alias of Model
named Eloquent
(src: https://github.com/barryvdh/laravel-ide-helper/blob/f055d42b3917bf067b8316f27ce538245574cc84/src/Console/ModelsCommand.php#L1011 ). I think that might be the root cause of this.
Perhaps we may need to manually alias Eloquent
to Model
for psalm to know?
I was able to get psalm to run on your project when manually adding this line to your config/app.php
file
'aliases' => [
...
'Eloquent' => Illuminate\Database\Eloquent\Model::class,
],
We should fix this internally, however we have a few options:
1) Always add the Eloquent
alias at runtime in psalm plugin
2) Make a change upstream in ide-helper
to reference the actual Illuminate\Database\Eloquent\Model::class
rather than using the Eloquent
alias
3) one day... remove our reliance on ide-helper entirely
https://github.com/barryvdh/laravel-ide-helper/issues/517 for reference
Maybe the first option would be the easiest to implement at this moment. It would solve this problem with minimal changes. Then you could ask the IDE for the necessary changes to correctly resolve the class :)
yep! Are you up for a PR @eusonlito ?
I think off the top of my head, you may be able to adjust the app aliases at runtime here? https://github.com/psalm/psalm-plugin-laravel/blob/master/src/Providers/ApplicationProvider.php#L112-L121
edit: errr, actually that would only work for plugins. I think you may be able to adjust the config in ApplicationProvider::getApp
...
@mr-feek it's fine? https://github.com/psalm/psalm-plugin-laravel/pull/273/files
Describe the bug
Impacted Versions
Additional context
Error is not always in same file with
--debug-by-line
parameter.Steps
composer install
./vendor/bin/psalm