使用特征将魔术属性标记为不弃用的docblockClass诗篇错误
我正在尝试使用phpdoc使用 mixin 。
使用的是Jetbrains Phpstorm 2022.1.1,Php 8.1.6和Psalm 4.23.0
我有一个特征,在app/models/trait/phpdoc/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;
}
我 我在app/models/product.php
中的模型上的特征:
<?php
namespace App\Models;
/**
* @mixin App\Models\Traits\PhpDoc\ProductPhpDocTrait
*/
class Product extends Model implements HasLinkableTexts
{
//...
}
自动填充现在正在为特征记录的属性工作,而被弃用的属性则用罢工标记。
但是psalm正在抛出以下错误:
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
(line&amp;字符引用开口class
定义)
看来,命名空间很好,直到文件占据的两个级别:
如果我将特质移动到一个级别(在文件系统和命名空间中)到app/models/trait/productphpdoctrait.php
,则phpstorm仍然标记为命名空间的两个级别:
如果我将特质移动到模型文件夹中(并更新名称空间),我仍然会得到与不存在的诗篇错误。
我如何解决这个问题,以便可以通过通过静态分析的代码暗示贬低的魔法属性?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论