Skip to content

Add config to check BenevolentUnion #1930

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
Oct 28, 2022

Conversation

VincentLanglet
Copy link
Contributor

@VincentLanglet VincentLanglet commented Oct 27, 2022

@phpstan-bot
Copy link
Collaborator

This pull request has been marked as ready for review.

@@ -76,6 +76,7 @@ parameters:
checkNullables: false
checkThisOnly: true
checkUnionTypes: false
checkBenevolentUnionTypes: false
Copy link
Contributor

Choose a reason for hiding this comment

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

should it be true on bleedingEdge?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

CheckUnionTypes is not true on bleedingEdge, so checkBenevolentUnionTypes which is stricter shouldn't be true too.

Copy link
Member

Choose a reason for hiding this comment

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

checkBenevolentUnionTypes will never be true by default, that's why it's "benevolent".

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But I'm kinda worried about someone using the config

checkUnionTypes: false
checkBenevolentUnionTypes: true

what should be the behavior ?

  • checking both ?
  • checking none ?
  • only checking the benevolent ?
  • throwing an error ?


if (
$this->checkBenevolentUnionTypes
&& $acceptedType instanceof BenevolentUnionType
Copy link
Member

Choose a reason for hiding this comment

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

This is too naive - will not see nested BenevolentUnionType. Needs similar logic as checkExplicitMixed and use TypeTraverser.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have a test for (\DateTimeImmutable|false) and for array<(\DateTimeImmutable|false)>.

What do you have in mind with "nested BenevolentUnionType", I'll add new tests.

Copy link
Contributor

Choose a reason for hiding this comment

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

I guess things like (float|int)|string

Verified

This commit was signed with the committer’s verified signature. The key has expired.
ondrejmirtes Ondřej Mirtes

Verified

This commit was signed with the committer’s verified signature. The key has expired.
ondrejmirtes Ondřej Mirtes
@ondrejmirtes
Copy link
Member

I think it's fine as it is. Please also send a documentation update to https://phpstan.org/config-reference (https://github.com/phpstan/phpstan/edit/1.9.x/website/src/config-reference.md).

Thank you.

@ondrejmirtes ondrejmirtes merged commit f5d37bb into phpstan:1.9.x Oct 28, 2022
@VincentLanglet VincentLanglet deleted the benevolentUnion branch October 28, 2022 10:46
@VincentLanglet
Copy link
Contributor Author

I think it's fine as it is. Please also send a documentation update to https://phpstan.org/config-reference (https://github.com/phpstan/phpstan/edit/1.9.x/website/src/config-reference.md).

Thank you.

Sure, I started phpstan/phpstan#8234

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.

It isn't reporting when you return a variable that could be false
4 participants