I'm trying to use PhpDoc to hint all the deprecated magic properties set on a Laravel Model using the mixin described in this answer.
I am using JetBrains PhpStorm 2022.1.1, PHP 8.1.6 and Psalm 4.23.0
I have a trait, defined in app/Models/Traits/PhpDoc/ProductPhpDocTrait.php
:
<?php
namespace App\Models\Traits\PhpDoc;
/**
* @property int id
* @property int type
*/
trait ProductPhpDocTrait
{
/**
* @deprecated
* @var string $display_status ;
*/
public string $display_status;
}
And I'm using this trait on my model in app/Models/Product.php
:
<?php
namespace App\Models;
/**
* @mixin App\Models\Traits\PhpDoc\ProductPhpDocTrait
*/
class Product extends Model implements HasLinkableTexts
{
//...
}
Autocomplete is now working for the properties documented in the trait, and those which are deprecated are now marked with strikethrough.
But Psalm is throwing the following error:
ERROR: UndefinedDocblockClass - app/Models/Product.php:21:7 - Docblock-defined class, interface or enum named App\Models\Traits\PhpDoc\ProductPhpDocTrait does not exist (see https://psalm.dev/200)
class Product extends Model implements HasLinkableTexts
(the line & character reference the opening class
definition)
It seems that the namespace is fine up until two levels above where the file resides:
If I move the trait up a level (in the filesystem and the namespace) to app/Models/Traits/ProductPhpDocTrait.php
, PhpStorm still flags the error as two levels up the namespace:
If I move the trait into the Models folder (and update the namespace), I still get the same Psalm error that the trait does not exist.
How can I resolve this, such that I can hint deprecated magic properties with the code passing static analysis?