Skip to content

Conversation

@ValeriyMaslenikov
Copy link

… which returns $this.

Hi guys. To use correct autocomplete and type highlighting in IDE, like PhpStorm let's use static keyword instead of class name in @return block.

In this case IDE will notify us that methodFromB() doesn't exist, because it will expect that method iWillReturnThis returns class A:

class A {
 /**
  * @return A
  */
  public function iWillReturnThis() { 
    return $this; 
  }
} 

class B extends A {
  public function methodFromB() { }
}

(new B())->iWillReturnThis()->methodFromB()

In this case it works well:

class A {
 /**
  * @return static
  */
  public function iWillReturnThis() { 
    return $this; 
  }
} 
...

And to make fluent interface highlighting works well with public properties, let's use phpDoc @var near property declaration, like:

class A {
  /** @var B */
  public $B;
}
class B {
  public function method();
}

(new A())->B->method()

@eric-urban
Copy link
Contributor

@ValeriyMaslenikov thanks for the suggestions! We will keep these in mind for a future release.

Copy link

@ColleenKeegan ColleenKeegan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Return $this

@eric-urban
Copy link
Contributor

@ValeriyMaslenikov thanks again for the feedback. We resolved most PHP doc issues in version 13.0.1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants