4

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:

* @property array stdout

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:

* @method array $stdout->styles(array $name, array $items)

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:

<?
class InvoiceShell extends AppShell {
    public $uses = array('Invoice', 'Request');

    public function main() {

        $this->stdout->styles('success', ['text' => 'green']);
        $this->stdout->styles('danger', ['text' => 'red']);
        $this->stdout->styles('bold', ['bold' => true]);

        .
        .
        .
    }
}
6
  • 1) What is stdout? 2) How it's declared? 3) if it's used like stdout->styles .. then why are you trying to declare stdout as array (when it's clearly an object here)? 3) * @method array $stdout->styles(array $name, array $items) -- completely wrong -- you cannot declare sub-property/sub-method this way -- only direct elements. This means (using your example) * @method array styles(array $name, array $items) at best (which is still wrong for your case -- but this is just to illustrate the right syntax). Commented Jul 19, 2016 at 14:49
  • Have a look at correct syntax: github.com/phpDocumentor/fig-standards/blob/master/proposed/… Commented Jul 19, 2016 at 14:49
  • @lazyone Thanks for replying, I've added more information to the question. stdout and styles are defined in the CakePHP framework. It is outside of my control. Commented Jul 19, 2016 at 14:56
  • So .. what stdout is? What type is it? Because you can easily use * @property MyStdoutClass $stdout and that's it (just use correct class name instead of MyStdoutClass). Unfortunately I'm not CakePHP user so cannot give you 100% correct solution straight away without knowing details. P.S. If you do not know what type stdout is -- you may try debugging such script -- xdebug will tell what type/class it is. Commented Jul 19, 2016 at 15:00
  • Thanks @LazyOne! I found the type, it's ConsoleOutput. @property ConsoleOutput stdout worked. If you'd like you can you create an answer out of this and I'll be more than happy to accept as as answer. Commented Jul 19, 2016 at 15:12

2 Answers 2

4

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

/**
 * My cool class is cool.
 *
 * @property ConsoleOutput $stdout
 */

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.

/**
 * @method mixed styles(string, mixed)
 * @method ...
 */
interface FakeForCodeCompletion { }

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

Sign up to request clarification or add additional context in comments.

Comments

0

Those with a similar problem can use this.

/** @var $items \Data\Items | mixed */

$items = new \Data\Items;

$items->method('data');
$items->item->method('data');

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.