czim / laravel-repository

Repository pattern implementation for Laravel
MIT License
51 stars 19 forks source link

Fix DocBlocks where they @return self instead of static #8

Open czim opened 7 years ago

czim commented 7 years ago

This is a blatant lie for a non-final class, so it needs to be addressed.

Tjoosten commented 3 years ago

Can u describe the issue more. I0 want to try resolve the issue

czim commented 3 years ago

A docblock that has @return self when what it does is return $this tends to lie. For instance (in pseudocode):

class A
    // return self?
    function something
        return $this

Class B extends A

Now, calling A::something returns A, which is self. This is fine. But calling B::something returns B, which is not self in the context of the definition 'something', because that would be A.

This is not wrong per se, but it does break things, for instance:

class A
    // return self?
    function something
        return $this

Class B extends A
    function nextFluentCall

Now something like (new B())->something()->nextFluentCall() will make your IDE warn that there is no nextFluentCall method on A, which is correct, but also wrong, since that method does exist on what something() returns in that context.

That's the thing that annoyed me when I made this issue.