Skip to content

Conversation

@staabm
Copy link
Contributor

@staabm staabm commented Jan 22, 2026

allows detecting of dead code like

if ($flagState->yes()) {
	if ($flagState->no()) {
	}
}

@ondrejmirtes ondrejmirtes merged commit a448b24 into phpstan:2.1.x Jan 22, 2026
629 of 638 checks passed
@ondrejmirtes
Copy link
Member

Oh nice! Thank you.

@staabm staabm deleted the trin branch January 22, 2026 12:22
@staabm
Copy link
Contributor Author

staabm commented Jan 23, 2026

I think we could narrow the types even more, but atm phpdoc cannot express it well enough I guess.

e.g.

TrinaryLogic->createFromBoolean() can only return TrinaryLogic::YES, TrinaryLogic::NO
TrinaryLogic->createYes() can only return TrinaryLogic::YES
TrinaryLogic->createNo() can only return TrinaryLogic::NO
TrinaryLogic->createMaybe() can only return TrinaryLogic::MAYBE
TrinaryLogic->negate() will leave MAYBE untouched, but invert YES/NO

and conditional types like
when $trinary->yes() is false, this means either $trinary->no()|$trinary->maybe() will be true

might be easier to express in case we can turn TrinaryLogic into a real enum so we could subtract enum-cases

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