Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHPStorm not recognising more than 2 chained public methods

Tags:

php

ide

phpstorm

This doesn't affect the code, but it is kind of annoying.

I have these 3 methods inside my controller:

public function chainOne()
{
    return $this;
}

public function chainTwo()
{
    return $this;
}

public function chainThree()
{
    return $this;
}

The method that is being called once hitting the specific route is this:

public function indexAction()
{

    $this->chainOne()
            ->chainTwo()
            ->chainThree();

}

PHPStorm says method chainThree() not found in class $this. But the code inside chainThree() is being executed without a problem.

How can I fix it? Is it a bug?

like image 685
Such Much Code Avatar asked Oct 20 '25 17:10

Such Much Code


1 Answers

You can use docblocks to help PHPStorm recognize the return value:

public class Foo
{

    /**
    * @return Foo $this
    */
    public function chainOne()
    {
        return $this;
    }

    /**
    * @return Foo $this
    */
    public function chainTwo()
    {
        return $this;
    }

    /**
    * @return Foo $this
    */
    public function chainThree()
    {
        return $this;
    }

}
like image 189
taxicala Avatar answered Oct 22 '25 07:10

taxicala



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!