Skip to content

Conversation

vrana
Copy link
Contributor

@vrana vrana commented Sep 5, 2025

This code is fine:

match ($this) {
	self::ONE => 'One',
	self::TWO => 'Two',
	self::THREE => 'Three',
};

Enabling reportAlwaysTrueInLastCondition forces me to write worse code:

match ($this) {
	self::ONE => 'One',
	self::TWO => 'Two',
	default => 'Three',
};

It's worse for two reasons:

  1. self::THREE is not explicitly listed making it less obvious what the last arm does.
  2. If I add another case to the enum then the first code will correctly report an error but the second won't.

@ondrejmirtes ondrejmirtes merged commit 0fbb507 into phpstan:2.1.x Sep 5, 2025
446 of 454 checks passed
@vrana vrana deleted the reportAlwaysTrueInLastMatchCondition branch September 12, 2025 19:27
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