Skip to content

Adjusts getOption return type if no default value. #95

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 1 commit into from
Oct 1, 2020

Conversation

ddebin
Copy link
Contributor

@ddebin ddebin commented Aug 21, 2020

I read discussion in #45 about adding int type for getOption. But reading Symfony source code and doing some tests, int type is only possible if an int default value has been passed to addOption.

@ondrejmirtes
Copy link
Member

Hi, this doesn't look like the right solution. With your modification, getOption() will never contain int but in reality it can (in case the default value is null).

@ddebin
Copy link
Contributor Author

ddebin commented Oct 1, 2020

Hi, this doesn't look like the right solution. With your modification, getOption() will never contain int but in reality it can (in case the default value is null).

@ondrejmirtes No that's right. You cannot get an int from getOption unless you pass an int as default value.

@ondrejmirtes
Copy link
Member

Yeah but with your changes, PHPStan will never think it’s an int, right?

@ddebin
Copy link
Contributor Author

ddebin commented Oct 1, 2020

I'm not sure if I understand your reply but $optType = TypeCombinator::union($optType, $scope->getTypeFromValue($option->getDefault())); adds int type if default value is an int.

@ondrejmirtes
Copy link
Member

Oh I haven’t noticed that. Is this covered by a test?

@ddebin
Copy link
Contributor Author

ddebin commented Oct 1, 2020

Oh I haven’t noticed that. Is this covered by a test?

Yes with untouched

yield ['$bb', 'int|string|null'];
yield ['$cc', 'int|string'];

@ondrejmirtes
Copy link
Member

Perfect, I'll release it then. Thank you!

@ondrejmirtes ondrejmirtes merged commit 34a3af9 into phpstan:master Oct 1, 2020
@ondrejmirtes
Copy link
Member

Tagged as 0.12.8.

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