代码之家  ›  专栏  ›  技术社区  ›  olechafm

PhpStorm-fluent界面

  •  1
  • olechafm  · 技术社区  · 6 年前

    在类内使用fluent接口并尝试从该类的另一个函数逐个调用该类的函数时

    f、 e。

    mainFunction()
    {
        $this
            ->func1()
            ->func2()
            ->func3()
            ->func4()
            ->func5()
        ;
    }
    

    调用第4个函数后,PhpStorm无法将调用与函数定义连接起来,因此第5个函数定义将获取信息

    未使用的私有方法func5私有方法的直接用法有 找不到。

    电话会收到信息

    在引用的方法中找不到方法“func5”,在中找不到 主题类。

    是否为此设置了任何可配置的限制?

    1 回复  |  直到 6 年前
        1
  •  0
  •   nibra    6 年前

    您遇到了PhpStorm 6的一个已知错误,该错误应该在版本中正式修复
    8.0.4 (139.1803): WI-17801 Fluent-style chaining type loss with return this/static

    如果将类名指定为返回类型,则可以解决此问题:

    class FooBar
    {
        // ...
    
        private function func1(): FooBar
        {
            return $this;
        }
    
        // ...  
    }
    

    或者,对于旧的PHP版本,

    class FooBar
    {
        // ...
    
        /**
         * @return FooBar
         */
        private function func1()
        {
            return $this;
        }
    
        // ...  
    }