Skip to content
Advertisement

Resolve PhpStorm magic method and property warning using PHPDoc @property and @method for $this->stdout->styles

I’m trying to resolve

“Field ‘stdout’ not found in …”

and

“Method … not found in array”

warning using PHPDocumentor notations @property and @method on PhpStorm

enter image description here

I was able to resolve the warning for stdout using:

JavaScript

enter image description here

But now how do you resolve the Method 'styles' not found in array warning? (See screenshot above)


I made up this code to demonstrate what I’m trying to achieve:

JavaScript

This is a CakePhp 2 project using CakePhp’s Command Shell.

stdout->styles is declared in the framework.

For more context this is what my code looks like:

JavaScript

Advertisement

Answer

You need to tell PHPDoc/PhpStorm the correct type for stdout by replacing array with ConsoleOutput in your @property declaration.

JavaScript

In cases where the object is a generic container with its own magic accessors, you can declare an interface solely for code completion by PhpStorm. Simply declare it in a file located in one of the Sources folders for your project.

JavaScript

Then reference FakeForCodeCompletion (preferably a descriptive name) in your class using @property as if it were a real class/interface.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement