1

I have been cleaning up some PhpStorm warnings using PHPDoc and in some cases there are objects referenced incorrectly. Here's an example:

$Title = $currentSlide->createRichTextShape(); 

CreateRichTextShape() returns as RichText as seen here:

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

This all works fine.

Then I try to call a function within RichText such as:

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

However, when hovering over the code I receive this warning:

this warning.

PhpStorm thinks CreateRichTextShape() is returning an AbstractShape when it is actually returning a RichText, so it can't find the function within AbstractShape even though it exists and is documented correctly.

Note that there are no actual errors in this code - it runs fine. Just want to get rid of the warnings.

LazyOne
  • 158,824
  • 45
  • 388
  • 391
Programmer
  • 144
  • 1
  • 10
  • Need more info / a sample project perhaps. Based purely on info you have provided (PHPDoc for `createRichTextShape()`) it should not report `AbstractShape`. Right now it looks like you have much more code there that may create such "interference" (e.g. assigning multiple different values to the same variable / reusing variable / different typehint in another place etc). May also be worth trying `File | Invalidate Cache...` and restart IDE (just in case). Better code sample is needed. I also suggest invoking `View | Quick Definition` on variables/methods etc to see what IDE thinks about them. – LazyOne Mar 19 '18 at 18:18
  • It's Laravel project .. you may be using DI/CI (e.g. `app('some-service')->` or alike) and it may have different (more generic) typehint etc. – LazyOne Mar 19 '18 at 18:20
  • @LazyOne I tried both of those attempts to no avail. Quick definition defined the variable as AbstractShape when the method was returning a RichText. Ended up simply adding a PHPDoc to declare the variable as a RichText. Looked something like this: `/** @var RichText $Title */ – Programmer Mar 22 '18 at 20:36

1 Answers1

0

At least regarding Laravel Projects, you can clear this up in PhpStorm by adding

/** @var RichText $Title */

before the variable/method.

Programmer
  • 144
  • 1
  • 10