marksitko / laravel-unsplash

Powerful Unsplash package for Laravel
MIT License
80 stars 17 forks source link

Remove incorrect PHPDoc @return tags, so IDEs can provide autocompletion #3

Closed JackWH closed 2 years ago

JackWH commented 3 years ago

In PhpStorm, autocompletion of methods is currently broken for this package. For example, Unsplash::search()->term('test')->toJson() stops all autocompletion after the search() method.

PhpStorm does not recognise the chained term() or toJson() methods because the traits all set self-referential @return docblock tags:

     /**
      * Search photos
      * Get a single page of photo results for a query.
      * @link https://unsplash.com/documentation#search-photos
      *
      * @return MarkSitko\LaravelUnsplash\Endpoints\Search
      */
     public function search()
     {
        $this->apiCall = [
            'endpoint' => 'search/photos',
        ];
        return $this;
    }

Because of this @return tag, PhpStorm assumes return $this; is returning another instance of the Search trait — when it's actually returning the original instance of \MarkSitko\LaravelUnsplash\Unsplash (via inheritance of the UnsplashAPI trait).

Removing these @return tags lets PhpStorm parse the class inheritance correctly, and provide full autocompletion.

Thanks for a great package!

marksitko commented 3 years ago

Hey @JackWH, i didn't realize that because i am a VSCode user. So Thanks for your improvement.

I would accept your PR, but is there may a way to leave the @returnstatements in the DocBlock? I mean the correct way that PHP Storm would parse it correct too. Let me know if there are any way or not.

Thanks for your commitment!

marksitko commented 2 years ago

Closed due to inactivity