Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

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

InvalidArgumentException Could not get class storage for eloquent #271

Open
eusonlito opened this issue Jan 18, 2023 · 8 comments
Open

InvalidArgumentException Could not get class storage for eloquent #271

eusonlito opened this issue Jan 18, 2023 · 8 comments
Labels
bug Something isn't working good first issue Good for newcomers help wanted Extra attention is needed

Comments

@eusonlito
Copy link

Describe the bug

InvalidArgumentException Could not get class storage for eloquent
Emitted in /var/www/vendor/vimeo/psalm/src/Psalm/Internal/Provider/ClassLikeStorageProvider.php:45
Stack trace in the forked worker:
#0 /var/www/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/ClassAnalyzer.php(783): Psalm\Internal\Provider\ClassLikeStorageProvider->get()
#1 /var/www/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/ClassAnalyzer.php(416): Psalm\Internal\Analyzer\ClassAnalyzer::addContextProperties()
#2 /var/www/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/FileAnalyzer.php(203): Psalm\Internal\Analyzer\ClassAnalyzer->analyze()
#3 /var/www/vendor/vimeo/psalm/src/Psalm/Internal/Codebase/Analyzer.php(1581): Psalm\Internal\Analyzer\FileAnalyzer->analyze()
#4 /var/www/vendor/vimeo/psalm/src/Psalm/Internal/Fork/Pool.php(209): Psalm\Internal\Codebase\Analyzer->analysisWorker()
#5 /var/www/vendor/vimeo/psalm/src/Psalm/Internal/Codebase/Analyzer.php(373): Psalm\Internal\Fork\Pool->__construct()
#6 /var/www/vendor/vimeo/psalm/src/Psalm/Internal/Codebase/Analyzer.php(272): Psalm\Internal\Codebase\Analyzer->doAnalysis()
#7 /var/www/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/ProjectAnalyzer.php(651): Psalm\Internal\Codebase\Analyzer->analyzeFiles()
#8 /var/www/vendor/vimeo/psalm/src/Psalm/Internal/Cli/Psalm.php(380): Psalm\Internal\Analyzer\ProjectAnalyzer->check()
#9 /var/www/vendor/vimeo/psalm/psalm(9): Psalm\Internal\Cli\Psalm::run()
#10 /var/www/vendor/bin/psalm(120): include('...')
#11 {main}

  at vendor/vimeo/psalm/src/Psalm/Internal/Fork/Pool.php:397
    393▕                                  * @psalm-suppress MixedArgument
    394▕                                  */
    395▕                                 posix_kill($child_pid, SIGTERM);
    396▕                             }
  ➜ 397▕                             throw new Exception($message->message);
    398▕                         } else {
    399▕                             error_log('Child should return ForkMessage - response type=' . gettype($message));
    400▕                             $this->did_have_error = true;
    401▕                         }

Impacted Versions

php -v 

PHP 8.1.14 (cli) (built: Jan 13 2023 10:43:50) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.14, Copyright (c) Zend Technologies
    with Zend OPcache v8.1.14, Copyright (c), by Zend Technologies

./vendor/bin/psalm -v

Psalm 5.4.0@62db5d4f6a7ae0a20f7cc5a4952d730272fc0863

composer show | grep -E 'psalm|laravel'

barryvdh/laravel-debugbar                      v3.7.0             PHP Debugbar integration for Laravel
barryvdh/laravel-ide-helper                    v2.12.3            Laravel IDE Helper, generates correct PHPDocs for all Facade classes, to improve auto-completion.
eusonlito/laravel-meta                         v3.2.3             A package to manage Header Meta Tags
eusonlito/laravel-packer                       v2.2.6             A package for pack css and javascript files
laravel/framework                              v9.48.0            The Laravel Framework.
laravel/helpers                                v1.6.0             Provides backwards compatibility for helpers in the latest Laravel release.
laravel/pint                                   v1.4.0             An opinionated code formatter for PHP.
laravel/serializable-closure                   v1.2.2             Laravel Serializable Closure provides an easy and secure way to serialize closures in PHP.
psalm/plugin-laravel                           v2.2.0             A Laravel plugin for Psalm
sentry/sentry-laravel                          3.1.3              Laravel SDK for Sentry (https://sentry.io)
spatie/laravel-ignition                        1.6.4              A beautiful error page for Laravel applications.
spatie/laravel-ray                             1.32.0             Easily debug Laravel apps
vimeo/psalm                                    5.4.0              A static analysis tool for finding errors in PHP applications

Additional context

Error is not always in same file with --debug-by-line parameter.

Steps

  1. Clone https://github.com/eusonlito/GPS-Tracker.git
  2. Install composer packages composer install
  3. Launch ./vendor/bin/psalm
@eusonlito eusonlito added the bug Something isn't working label Jan 18, 2023
@alies-dev
Copy link
Collaborator

@eusonlito

Thanks for reporting!

Do you have ide-helper files locally when you run psalm?

@eusonlito
Copy link
Author

No, I don't use IDE helpers.

@alies-dev
Copy link
Collaborator

@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

@mr-feek
Copy link
Collaborator

mr-feek commented Jan 18, 2023

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?

@mr-feek
Copy link
Collaborator

mr-feek commented Jan 18, 2023

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

barryvdh/laravel-ide-helper#517 for reference

@mr-feek mr-feek added good first issue Good for newcomers help wanted Extra attention is needed labels Jan 18, 2023
@eusonlito
Copy link
Author

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 :)

@mr-feek
Copy link
Collaborator

mr-feek commented Jan 18, 2023

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...

eusonlito added a commit to eusonlito/psalm-plugin-laravel that referenced this issue Jan 18, 2023
@eusonlito
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants