使用特征将魔术属性标记为不弃用的docblockClass诗篇错误

发布于 2025-02-10 02:09:31 字数 1908 浏览 0 评论 0原文

我正在尝试使用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:

Image showing PhpStorm issues

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:

enter image description here

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文