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

More precise falsey isset() #2708

Merged
merged 7 commits into from
Nov 2, 2023
Merged

More precise falsey isset() #2708

merged 7 commits into from
Nov 2, 2023

Conversation

staabm
Copy link
Contributor

@staabm staabm commented Nov 1, 2023

split off parts out from #2657 since it gets too complicated.

lets do it one step at a time instead

@staabm staabm marked this pull request as ready for review November 1, 2023 12:35
@phpstan-bot
Copy link
Collaborator

This pull request has been marked as ready for review.

src/Analyser/TypeSpecifier.php Outdated Show resolved Hide resolved

$type = $scope->getType($var);
if (
!$type instanceof MixedType && !TypeCombinator::containsNull($type)
Copy link
Member

Choose a reason for hiding this comment

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

!$type instanceof MixedType && doesn't need to be there as TypeCombinator::containsNull will never return true for MixedType

Copy link
Contributor Author

Choose a reason for hiding this comment

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

without this explicit MixedType check the

function mixedIsset(mixed $m): void
{
	if (isset($m)) {
		assertType("mixed~null", $m);
	} else {
		assertType("null", $m);
	}
}

case will not succeed. I turned the conditions arround, maybe its more readable now.

@ondrejmirtes
Copy link
Member

I knew deep down the condition really wasn't needed. instanceof of a specific type is also usually a red flag: 001ad45

@ondrejmirtes ondrejmirtes merged commit 01a0de2 into phpstan:1.10.x Nov 2, 2023
73 checks passed
@staabm staabm deleted the not-isset branch November 2, 2023 14:21
@ondrejmirtes
Copy link
Member

Thank you.

@staabm
Copy link
Contributor Author

staabm commented Nov 2, 2023

awesome, thanks!

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