psalm / psalm-plugin-laravel

A Psalm plugin for Laravel
MIT License
306 stars 71 forks source link

Config for preventing checking database schema #218

Closed Legion112 closed 2 years ago

Legion112 commented 2 years ago

Describe the bug In the CI environment, we do not have a database for now. I would expect the plugin to keep working even without a database. I understand the plugin trying to get the type from schema. Is it possible to torn this off? Impacted Versions Please paste the output of composer show | grep -E 'psalm|laravel' so we can see what versions are impacted

root@cf7568939b49:/app/bpg# composer show | grep -E 'psalm|laravel'
barryvdh/laravel-debugbar                      v3.5.2    PHP Debugbar integration for Laravel
barryvdh/laravel-ide-helper                    v2.8.2    Laravel IDE Helper, generates correct PHPDocs for all Facade classes, to improve auto-completion.
bensampo/laravel-enum                          v1.38.0   Simple, extensible and powerful enumeration implementation for Laravel.
laravel-doctrine/migrations                    1.3.3     Doctrine Migrations for Laravel
laravel-doctrine/orm                           1.5.10    A Doctrine ORM bridge for Laravel 5
laravel/framework                              v6.20.19  The Laravel Framework.
laravel/socialite                              v5.2.2    Laravel wrapper around OAuth 1 & OAuth 2 libraries.
laravel/tinker                                 v2.6.1    Powerful REPL for the Laravel framework.
laravelcollective/html                         v6.2.1    HTML and Form Builders for the Laravel Framework
paxoffice/laravel-permission-gateway-auth-php  1.26.0    Laravel Permission Gateway Auth provider
psalm/plugin-laravel                           v1.5.1    A Laravel plugin for Psalm
sentry/sentry-laravel                          1.9.0     Laravel SDK for Sentry (https://sentry.io)
vimeo/psalm                                    4.20.0    A static analysis tool for finding errors in PHP applications

Additional context Add any other context about the problem here.

image
mr-feek commented 2 years ago

good question! I don't think there is a way right now, but a PR would be welcome! We also need to narrow down exactly what is trying to connect to the DB -- it might be laravel ide helper

Legion112 commented 2 years ago

Hm... I got what is wrong here. Basically the plunging not that static. It's dynamically trying to determine concrete type of container by this function. ContainerHandler::getFunctionReturnType.

And the interface does not allow you to throw exception here.

image

In case of you cannot create instance of class you should return null.

Probably it would be best if you try to catch the error and return null

Legion112 commented 2 years ago

Basicaly if process of creation of class would require to go to some external system for example database this this method above going to blow.

Legion112 commented 2 years ago

The current problme is that it going to return 0 status code if plugging throw exception while trying to get return type. I suggest to catch Throwable to eliminate chance of such error.

Legion112 commented 2 years ago

https://github.com/psalm/psalm-plugin-laravel/pull/228

mr-feek commented 2 years ago

I tagged 2.0.1 which has this fixed in it :)

Legion112 commented 2 years ago

I need it in previuse laravel version? Could we add it to 1.6.*?

Legion112 commented 2 years ago

https://github.com/psalm/psalm-plugin-laravel/pull/231