-
Notifications
You must be signed in to change notification settings - Fork 467
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
StrictComparisonOfDifferentTypesRule - tip for always true comparison…
… between enums
- Loading branch information
1 parent
e06c529
commit a327965
Showing
3 changed files
with
65 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
tests/PHPStan/Rules/Comparison/data/strict-comparison-enum-tips.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php // lint >= 8.1 | ||
|
||
namespace StrictComparisonEnumTips; | ||
|
||
enum SomeEnum | ||
{ | ||
|
||
case One; | ||
case Two; | ||
|
||
public function exhaustiveWithSafetyCheck(): int | ||
{ | ||
if ($this === self::One) { | ||
return -1; | ||
} elseif ($this === self::Two) { | ||
return 0; | ||
} else { | ||
throw new \LogicException('New case added, handling missing'); | ||
} | ||
} | ||
|
||
|
||
public function exhaustiveWithSafetyCheck2(): int | ||
{ | ||
if ($this === self::One) { | ||
return -1; | ||
} | ||
|
||
if ($this === self::Two) { | ||
return 0; | ||
} | ||
|
||
throw new \LogicException('New case added, handling missing'); | ||
} | ||
|
||
} |