Is there any type casting for PHPDocumentor in PHPStorm? My PHPStorm IntelliSense is stubborn and i need to teach him how to behave.
This is my case:
I have a manager that instantiates classes that all extend same class. Usually i would cast my class after it was returned but PHP doesn't know how to do that. IntelliSense and PHPDocumentor support would be enough for me but i don't know how to type cast.
This is the code:
class Plugin
{
}
class HelloPlugin extends Plugin
{
public function hello()
{
}
}
class PluginManager
{
/** @var HelloPlugin */
public $helloPlugin;
function __construct()
{
$this->helloPlugin = $this->getPlugin('HelloPlugin');
// Here my PHPStorm IntelliSense doesn't provide 'hello()' function for 'helloPlugin' because return type overwrote original type
// I get error: method 'hello' not found in class
$this->helloPlugin->hello();
}
/**
* @param string $pluginClass
* @return Plugin
*/
function getPlugin($pluginClass)
{
return new $pluginClass;
}
}
I do not think it's actually possible :( , unless you rewrite your code somehow (just for PhpStorm ... no way).
Your code and PHPDoc is fine -- it's an IDE issue -- it temporarily (within that method only) overwrites manually provided type hint with the one it detects (it will work fine in other methods). Please vote: http://youtrack.jetbrains.com/issue/WI-17047