简体   繁体   English

如何在phpstorm中为代码完成注释类

[英]How to comment class for code completion in phpstorm

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. 如何使用PHPDoc使代码完成工作。 I've searched phpdoc for scope, declaration, all kinds of stuff. 我搜索了phpdoc的范围,声明,各种东西。 I can't figure out the terms or placement of the comment line for phpdoc to pick this up. 我无法弄清楚phpdoc的注释行的术语或位置来选择它。

I'm using phpstorm. 我正在使用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. 如果您的类目录未在项目设置中定义,则PHPStorm无法索引这些类。 In this case code completion will not work. 在这种情况下,代码完成将不起作用。 How to set up project directories in PHPStorm . 如何在PHPStorm中设置项目目录


Clear PHPStorm cache. 清除PHPStorm缓存。

Sometimes PHPStorm cache became invalid. 有时PHPStorm缓存变得无效。 Because of this, codecompletion may not work properly. 因此,代码完成可能无法正常工作。 Official how to cache cleanup . 官方如何缓存清理

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM