0

If you could be so kind to take a look at the project I'm working on at this line ( the function api() ).

https://github.com/wtfzdotnet/php-tmdb-api/blob/develop/lib/Tmdb/Client.php#L79

What is the correct way here for IDE's to actually auto complete the methods of the returned object instances? The way I'm using it right now returns all the methods from all the possible return objects.

Short; how do I make sure the IDE recognizes auto-complete methods for objects being returned are defined by a switch statement? I'd like to know what the proper way is for the IDE auto-completing this, and as well the best PHPDoc strategy ( It does have an interface, which however is empty for time being ).

Update 1

As the first comment suggested I tried to adjust the case for 'movies' as a test to:

case 'movies':
    return $this->getMovieApi();

and added

/**
 * @return Api\Movies
 */
private function getMovieApi(){
    return new Api\Movies($this);
}

But this does not function as expected when trying to call:

$client->api('movies')->[try_autocomplete]

However when I change the scope of getMovieApi to public and call this directly as:

$client->getMovieApi()->[try_autocomplete]

It works as expected, however I really prefer my initial method, as this looks cleaner ( atleast to me ). Is it really impossible to get proper auto-completion if return values are derived from a switch statement?

wtfzdotnet
  • 1,022
  • 8
  • 11

1 Answers1

0

Proper way would be create all this get methods with they own @return: getConfiguration, getAuthentication and etc.

sectus
  • 15,605
  • 5
  • 55
  • 97
  • I was trying to avoid this honestly, but guessing there is no other option I'll give this shot in a couple of minutes when I continue working on this **public** project :-) mentioned it wrongly earlier I see early in the morning. Thanks for the prompt response! – wtfzdotnet Nov 02 '13 at 22:49
  • It works when you call the method directly, however it doesn't when you get the object from the switch statement ( which I would prefer ). – wtfzdotnet Nov 02 '13 at 23:05
  • @wtfzdotnet, it's bad practice. You are trying to create something like God Method. – sectus Nov 03 '13 at 01:26
  • accepted your answer as that is what I ended up doing instead :-) – wtfzdotnet Mar 23 '14 at 21:35