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

Support for null returns

Open jdelaune opened this issue 2 years ago • 4 comments

I would be useful for the models to have null return types where needed as otherwise we need to add phpstan overrides in our code. An example being Google\Service\Calendar\Event->getOrganizer() which says it always returns an EventOrganizer when it can also return null.

Describe the solution you'd like

For the return to be marked as null e.g.

  /**
   * @return EventOrganizer|null
   */
  public function getOrganizer()
  {
    return $this->organizer;
  }

jdelaune avatar Nov 24 '22 10:11 jdelaune

Thanks for reporting this! I am open to the idea, but not looking forward to the 10,000+ lines of code this would change 😛

bshaffer avatar Dec 29 '22 16:12 bshaffer

This would be more than useful, it currently being incorrect can (and has) led to production bugs.

rodnaph avatar Jan 13 '23 10:01 rodnaph

@bshaffer surely this is just (😉) an update to the generator in https://github.com/googleapis/google-api-php-client-services?

caveat: I haven't looked at the generator

bendavies avatar Jan 13 '23 10:01 bendavies

the phpstan level could also be increased here, which will expose a lot of incorrect docblock issues.

bendavies avatar Jan 13 '23 10:01 bendavies