google-api-php-client-services icon indicating copy to clipboard operation
google-api-php-client-services copied to clipboard

Add PHPDoc to (generated?) models to increase usability

Open holtkamp opened this issue 10 years ago • 15 comments

Currently the PHP Documentation of the model classes is lacking, which makes it harder to use them / understand them. Since the model classes are probably generated, a change to the generator should be able to facilitate this. Not sure where to post this issue though, is the generator also on GitHub?

For example Google_Service_Calendar_Event::setStart() has a type-hint that a Google_Service_Calendar_EventDateTime object should be used, but getStart() does not have a PHPDoc @return hint:

class Google_Service_Calendar_Event
{
  public function setStart(Google_Service_Calendar_EventDateTime $start)
  {
    $this->start = $start;
  }

  //Current approach, no PHPDoc
  public function getStart()
  {
    return $this->start;
  }

  /**
   * Preferred approach
   * @return Google_Service_Calendar_EventDateTime
   */
  public function getStart()
  {
    return $this->start;
  }

  /**
   * as of PHP7
   * @return Google_Service_Calendar_EventDateTime
   */
  public function getStart() : Google_Service_Calendar_EventDateTime
  {
    return $this->start;
  }
}

Currently using the API Client and specific services is quite an 'adventure' / puzzle of finding out how everything works and by trial and error find out the proper way. Does Google use the PHP API Services themselves as well? I would say out of frustration one would add such type hints quite quickly ;)

holtkamp avatar Aug 15 '16 08:08 holtkamp

+1 to this, without the phpdoc is really hard to know what are the classes of the objects of all the classes.

Zeyckler avatar Feb 14 '17 15:02 Zeyckler

+1 IDEs can't auto complete without docblocks! What is the status of this?

asimlqt avatar Jun 26 '17 17:06 asimlqt

@asimlqt thanks for the +1, not sure somebody is monitoring this repository though. It seems @bshaffer is the lead developer. @bshaffer, should we report such requests elsewhere?

holtkamp avatar Jun 27 '17 09:06 holtkamp

@holtkamp believe it or not, we'll actually be adding this soon :)

bshaffer avatar Jun 27 '17 17:06 bshaffer

Unfortunately we need to preserve BC for now, so the second option is what we are implementing.

bshaffer avatar Jun 27 '17 17:06 bshaffer

Unfortunately we need to preserve BC for now, so the second option is what we are implementing.

Aah, that is already great! Thanks for the heads-up!

holtkamp avatar Jun 27 '17 18:06 holtkamp

This has been added! Check out v0.13!

bshaffer avatar Jul 07 '17 16:07 bshaffer

Nice! @bshaffer

Some feedback, look at this line: https://github.com/google/google-api-php-client-services/blob/b8c3ee8adab9eaffc3825cabc12740ad6e2ed76f/src/Google/Service/Calendar/Events.php#L80-L86

The proper return type would probably suggest an array / collection, so @return Google_Service_Calendar_Event[] would be better: suggest it is iterable.

Currently my IDE (PHPStorm) still needs an explicit typehint:

/* @var GoogleCalendarEvent $calendarEvent */
foreach ($calendarEvents->getItems() as $calendarEvent) {
    echo $calendarEvent->getStart()->getDateTime();
}

holtkamp avatar Jul 11 '17 21:07 holtkamp

@bshaffer minor bump on this?

holtkamp avatar Sep 05 '17 12:09 holtkamp

@bshaffer can this issue be re-opened?

holtkamp avatar Sep 14 '17 11:09 holtkamp

@bshaffer tiresless bump on this? Minimal effort, maximum awesome this seems to me! 🚀

holtkamp avatar Jan 29 '18 12:01 holtkamp

@mattwhisenhunt @bshaffer can this issue be re-opened? See my comment https://github.com/google/google-api-php-client-services/issues/28#issuecomment-314583187

holtkamp avatar May 07 '18 08:05 holtkamp

@mattwhisenhunt @bshaffer happy birthday to this issue

https://github.com/googleapis/google-api-php-client-services/blob/d41fea99f90d7935bd57cf654bf271072fe584f1/src/Google/Service/Calendar/Events.php#L81

Anyone monitoring this issue?

holtkamp avatar Jun 27 '19 12:06 holtkamp

@holtkamp that's definitely something we need to address. Would you mind opening a fresh issue for us?

dwsupplee avatar Jun 27 '19 15:06 dwsupplee

@dwsupplee sure! See https://github.com/googleapis/google-api-php-client-services/issues/172

holtkamp avatar Jun 30 '19 09:06 holtkamp