psalm / psalm-plugin-laravel

A Psalm plugin for Laravel
MIT License
302 stars 72 forks source link

Model.stubphp doesn't implement interfaces #179

Closed caugner closed 3 years ago

caugner commented 3 years ago

Describe the bug The abstract Model class implements several interfaces, and so does the Model.stubphp:

https://github.com/psalm/psalm-plugin-laravel/blob/28b697a39aa96986733aae79415bfd776306436f/stubs/Model.stubphp#L17

However, Model.stubphp doesn't implement them. This causes PhpStorm inspection errors ("General" > "Class hierarchy checks") on classes extending Model:

Class must be declared abstract or implement methods 'getRouteKey', 'getQueueableRelations', 'getQueueableId', 'resolveChildRouteBinding', 'jsonSerialize', 'toJson', 'offsetSet', 'getRouteKeyName', 'resolveRouteBinding', 'offsetGet', 'offsetExists', 'getQueueableConnection', 'offsetUnset', 'toArray'

Impacted Versions

andrey-helldar/laravel-lang-publisher v10.0.4   Publisher lang files for the Laravel Framework, Jetstream, Fortify, Cashier, Spark and Nova from Laravel-Lang/lang
andrey-helldar/laravel-support        v2.0.1    Various helper files for the Laravel and Lumen frameworks
barryvdh/laravel-ide-helper           v2.9.1    Laravel IDE Helper, generates correct PHPDocs for all Facade classes, to improve auto-completion.
beyondcode/laravel-dump-server        1.7.0     Symfony Var-Dump Server for Laravel
fruitcake/laravel-cors                v2.0.4    Adds CORS (Cross-Origin Resource Sharing) headers support in your Laravel application
laravel-lang/lang                     10.0.2    Languages for Laravel
laravel/framework                     v8.49.2   The Laravel Framework.
laravel/sail                          v1.8.4    Docker files for running a basic Laravel application.
laravel/sanctum                       v2.11.2   Laravel Sanctum provides a featherweight authentication system for SPAs and simple APIs.
laravel/tinker                        v2.6.1    Powerful REPL for the Laravel framework.
laravel/ui                            v3.3.0    Laravel UI utilities and presets.
psalm/plugin-laravel                  v1.4.5    A Laravel plugin for Psalm
sentry/sentry-laravel                 2.7.0     Laravel SDK for Sentry (https://sentry.io)
spatie/laravel-ray                    1.17.4    Easily debug Laravel apps
vimeo/psalm                           4.8.1     A static analysis tool for finding errors in PHP applications

Additional context A workaround might be for users of this plugin to move psalm (and all psalm plugins, including this one) to vendor-bin using composer-bin-plugin, because stubs in the vendor-bin/*/vendor folders are (probably?) ignored by PhpStorm.

mr-feek commented 3 years ago

This causes PhpStorm inspection errors ("General" > "Class hierarchy checks") on classes extending Model

How come phpstorm is interpreting these classes? They intentionally don't end in .php to prevent this!

https://psalm.dev/docs/running_psalm/plugins/authoring_plugins/#stub-files

By convention, stub files have .phpstub extension to avoid IDEs treating them as actual php code

caugner commented 3 years ago

I must have configured *.stubphp to be recognised as PHP when I was working on the PRs, and wasn't aware that this affects all projects. šŸ¤¦

grafik

caugner commented 3 years ago

Closing this, as removing that file name pattern again resolved the issue for me.