phpstan-symfony icon indicating copy to clipboard operation
phpstan-symfony copied to clipboard

Add more precise type info for ResponseInterface::getInfo

Open stof opened this issue 2 years ago • 1 comments

\Symfony\Contracts\HttpClient\ResponseInterface::getInfo defines the return type as mixed in phpdoc. However, when the value of the argument is known, we could have more precise info thanks to the type defined for a bunch of known info keys (if the key is unknown in the interface contract, the type will indeed be mixed): https://github.com/symfony/symfony/blob/22a2729f371eb4bc8b08330a872291b9712e93da/src/Symfony/Contracts/HttpClient/ResponseInterface.php#L81-L109

stof avatar Feb 01 '23 14:02 stof

Can't it be done directly with a conditional return type ?

/**
 * @return ($type is null ? array : ($type is 'foo' ? bool : ($type is 'bar' ? string : ...)))
 */
public function getInfo(string $type = null): mixed;

VincentLanglet avatar Feb 01 '23 16:02 VincentLanglet