PHPStorm doesn't show suggestions when call method return Object

Hi, I have two code with same function like that:

Frist code (It's show suggestion of object Joiner).

Second code.

As you can see in my second code, suggestions is not available. So my question is: How to make it work or else How long we can do it?

Thank you.

0

Hi there,

IDE does not know what getClass() method returns with such dynamic code (that cannot be analysed using static analysis).

Few possible ways:

1) Typehint local variable using PHPDoc comment:

/** @var \Joiner $abc */
$abc = ...

2) or try Advanced Metadata (used by other plugin frameworks like Laravel/Symfony/service containers/etc; best example perhaps: Laravel IDE helper package for Laravel) -- may work for your code: https://confluence.jetbrains.com/display/PhpStorm/PhpStorm+Advanced+Metadata

 

 

0
Avatar
Permanently deleted user

Hi Andriy,

Thank you for reply soon, I'm trying with plugin Laravel IDE Helper, So Can you help me config it?

0

Laravel IDE Helper wouldn’t help you here as it’s not Laravel, Andriy just advised it as an example of what the metadata file could look like.
In your (quite simple) case, you can create a file called .phpstorm.meta.php in the project root and put the following contents there:

<?php
namespace PHPSTORM_META {
    override(
        \Tester::getClass( 0 ),
        map(
            [
                '' => '\@',
            ]
        )
    );
}


1

请先登录再写评论。