Is your feature request related to a problem? Please describe.
PhpStan complains about my generated API classes, because they can return either an API object or a PSR response interface. So code like this:
$client = $this->getApiClient();
$result = $client->findController($params);
$list = $result?->getList();
Gives errors like this:
Call to an undefined method App\Generated\Model\SystemControllerList|Psr\Http\Message\ResponseInterface::getList().
Where the client method looks like this:
/**
* @return null|\App\Generated\Model\SystemControllerList|\Psr\Http\Message\ResponseInterface
*/
public function findController(array $queryParameters = [], string $fetch = self::FETCH_OBJECT)
Describe the solution you'd like
Use conditional return types, because we know when ResponseInterface is returned:
/**
* @return null|($fetch is 'object' ? \App\Generated\Model\SystemControllerList : \Psr\Http\Message\ResponseInterface)
*/
public function findController(array $queryParameters = [], string $fetch = self::FETCH_OBJECT)
Unfortunately we have to use the fixed string "object" instead of the constant in the expression, but it's fine since it's all generated code anyway.
Describe alternatives you've considered
Currently we post-process files after generation :(
Is your feature request related to a problem? Please describe.
PhpStan complains about my generated API classes, because they can return either an API object or a PSR response interface. So code like this:
Gives errors like this:
Where the client method looks like this:
Describe the solution you'd like
Use conditional return types, because we know when
ResponseInterfaceis returned:Unfortunately we have to use the fixed string "object" instead of the constant in the expression, but it's fine since it's all generated code anyway.
Describe alternatives you've considered
Currently we post-process files after generation :(