Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more precise type info for ResponseInterface::getInfo #328

Open
stof opened this issue Feb 1, 2023 · 1 comment
Open

Add more precise type info for ResponseInterface::getInfo #328

stof opened this issue Feb 1, 2023 · 1 comment

Comments

@stof
Copy link
Contributor

stof commented Feb 1, 2023

\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

@VincentLanglet
Copy link
Contributor

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;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants