不正确的对象上的PhpStorm警告(Laravel)

时间:2018-03-19 16:16:29

标签: laravel phpstorm phpoffice

我一直在使用PHPDoc清理一些PhpStorm警告,在某些情况下,引用的对象不正确。这是一个例子:

$Title = $currentSlide->createRichTextShape(); 

CreateRichTextShape()返回RichText,如下所示:

/**
 * Create rich text shape
 *
 * @return \PhpOffice\PhpPresentation\Shape\RichText
 */
public function createRichTextShape()
{
    $shape = new RichText();
    $this->addShape($shape);
    return $shape;
}

一切正常。

然后我尝试在RichText中调用一个函数,例如:

$textRun = $Title->createTextRun( 'Title' );

但是,当鼠标悬停在代码上时,我会收到此警告:

this warning.

PhpStorm认为CreateRichTextShape()在实际返回AbstractShape时返回RichText,因此即使它存在,它也无法在AbstractShape内找到该功能并且记录正确。

请注意,此代码中没有实际错误 - 运行正常。只是想摆脱警告。

1 个答案:

答案 0 :(得分:0)

至少关于Laravel Projects,您可以通过添加

在PhpStorm中清除它

/** @var RichText $Title */

在变量/方法之前。