Suppose I have a class
class Class1
{
public function method1(){
return "hello world";
}
}
and I have another class that uses this in a class
class Class2
{
/** @var $firstClass Class1 */
private $firstClass;
public function __construct($firstClass)
{
$this->firstClass = $firstClass;
}
public function method2()
{
return $this->firstClass-> "I want code completion to work here"
}
}
How do I get the code completion to work using PHPDoc. I've searched phpdoc for scope, declaration, all kinds of stuff. I can't figure out the terms or placement of the comment line for phpdoc to pick this up.
I'm using phpstorm. Help!
Check your class namespaces.
If class have namespace be sure you properly define them in comments or by alias.
Comments example:
...
/** @var \vendor\namespace\Class1 */
private $firstClass;
...
Alias example:
use \vendor\namespace\Class1;
...
/** @var Class1 */
private $firstClass;
...
Check project directories definition.
If your class directories not defined in project settings, PHPStorm can't index those classes. In this case code completion will not work. How to set up project directories in PHPStorm.
Clear PHPStorm cache.
Sometimes PHPStorm cache became invalid. Because of this, codecompletion may not work properly. Official how to cache cleanup.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With