psalm / psalm-plugin-laravel

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

Properties using foreignUuid omitted from stub #146

Closed eithed closed 3 years ago

eithed commented 3 years ago

Describe the bug

For a class with following migration:

Schema::create('bound_policy_transactions', function (Blueprint $table) {
    $table->uuid('id')->primary();
    $table->foreignUuid('bound_policy_id')->constrained();
    $table->foreignUuid('bound_policy_term_id')->constrained();

following _ide_helper_models.php is generated:

namespace App\Models{
/**
 * App\Models\BoundPolicyTransaction
 *
 * @property string $id
 * @property string $bound_policy_id
 * @property string $bound_policy_term_id

and following models.stubphp is generated:

namespace App\Models{
/**
 * App\Models\BoundPolicyTransaction
 *
 * @mixin IdeHelperBoundPolicyTransaction
 * @property string $id

thus triggering Magic instance property App\Models\BoundPolicyTransaction::$bound_policy_id is not defined.

As a workaround one can replace the migration syntax with:

$table->uuid('bound_policy_id');
$table->foreign('bound_policy_id')->references('id')->on('bound_policies');

$table->uuid('bound_policy_term_id');
$table->foreign('bound_policy_term_id')->references('id')->on('bound_policy_terms');

which will correctly include the fields in models.stubphp

Impacted Versions

barryvdh/laravel-ide-helper                      v2.9.1             Laravel IDE Helper, generates correct PHPDocs for all Facade classes, to improve auto-completion.
cknow/laravel-money                              v6.1.0             Laravel Money
fruitcake/laravel-cors                           v2.0.4             Adds CORS (Cross-Origin Resource Sharing) headers support in your Laravel application
jessarcher/laravel-castable-data-transfer-object v2.0.0             Automatically cast JSON columns to rich PHP objects in Laravel using Spatie's data-transfer-object class
laravel/framework                                v8.41.0            The Laravel Framework.
laravel/horizon                                  v5.7.6             Dashboard and code-driven configuration for Laravel queues.
laravel/tinker                                   v2.6.1             Powerful REPL for the Laravel framework.
morrislaptop/laravel-popo-caster                 v0.5.0             Automatically cast JSON columns to rich PHP objects in Laravel using Symfony's Serializer
psalm/plugin-laravel                             v1.4.5             A Laravel plugin for Psalm
spatie/laravel-activitylog                       3.17.0             A very simple activity logger to monitor the users of your website or application
spatie/laravel-enum                              2.5.0              Laravel Enum support
spatie/laravel-event-sourcing                    4.10.2             The easiest way to get started with event sourcing in Laravel
spatie/laravel-json-api-paginate                 1.10.0             A paginator that plays nice with the JSON API spec
spatie/laravel-query-builder                     3.3.4              Easily build Eloquent queries from API requests
spatie/laravel-ray                               1.17.4             Easily debug Laravel apps
spatie/laravel-schemaless-attributes             1.8.3              Add schemaless attributes to Eloquent models
spatie/laravel-webhook-client                    2.7.5              Receive webhooks in Laravel apps
vimeo/psalm                                      4.7.2              A static analysis tool for finding errors in PHP applications
mr-feek commented 3 years ago

I'll happily merge a PR fixing this @eithed ! My gut feeling is that we might be overriding the command method that generates the foreign uuid properties

eithed commented 3 years ago

@mr-feek created a PR fixing this https://github.com/psalm/psalm-plugin-laravel/pull/150