Skip to content

Add dynamic return type to ResponseHeaderBag::getCookies #242

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

Merged
merged 2 commits into from
Feb 1, 2022

Conversation

franmomu
Copy link
Contributor

@franmomu franmomu commented Feb 1, 2022

if (isset($methodCall->getArgs()[0])) {
$argStrings = TypeUtils::getConstantStrings($scope->getType($methodCall->getArgs()[0]->value));

if (count($argStrings) === 1 && $argStrings[0]->getValue() === ResponseHeaderBag::COOKIES_ARRAY) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I worry that asking for runtime value of ResponseHeaderBag::COOKIES_ARRAY might fail here in some projects. Can you please check for ClassConstFetch and check that the user fetches the right constant here? Thanks.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for the guidance, not sure if this is the way you meant, let me know otherwise.

$headerBag->setCookie(Cookie::create('cookie_name'));

assertType('array<int, Symfony\Component\HttpFoundation\Cookie>', $headerBag->getCookies());
assertType('array<string, array<string, array<string, Symfony\Component\HttpFoundation\Cookie>>>', $headerBag->getCookies(ResponseHeaderBag::COOKIES_ARRAY));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also test the FLAT scenario.

@ondrejmirtes ondrejmirtes merged commit 11221af into phpstan:master Feb 1, 2022
@ondrejmirtes
Copy link
Member

Thank you!

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

Successfully merging this pull request may close these issues.

2 participants