| 1: | <?php declare(strict_types = 1); |
| 2: | |
| 3: | namespace PHPStan\Node; |
| 4: | |
| 5: | use PhpParser\Node\Expr; |
| 6: | use PHPStan\Analyser\Scope; |
| 7: | |
| 8: | /** |
| 9: | * A single non-default `case` of a `switch`, paired with the scope captured |
| 10: | * right after the case condition was processed (which already excludes the |
| 11: | * values matched by earlier terminating cases). |
| 12: | * |
| 13: | * @api |
| 14: | */ |
| 15: | final class SwitchConditionArm |
| 16: | { |
| 17: | |
| 18: | public function __construct( |
| 19: | private Expr $caseCondition, |
| 20: | private Scope $scope, |
| 21: | private int $line, |
| 22: | private bool $isLast, |
| 23: | ) |
| 24: | { |
| 25: | } |
| 26: | |
| 27: | public function getCaseCondition(): Expr |
| 28: | { |
| 29: | return $this->caseCondition; |
| 30: | } |
| 31: | |
| 32: | public function getScope(): Scope |
| 33: | { |
| 34: | return $this->scope; |
| 35: | } |
| 36: | |
| 37: | public function getLine(): int |
| 38: | { |
| 39: | return $this->line; |
| 40: | } |
| 41: | |
| 42: | /** |
| 43: | * Whether this is the last non-default `case` of the `switch` (only a |
| 44: | * `default` may follow it), in which case an always-true comparison is fine |
| 45: | * because it does not make any subsequent `case` unreachable. A trailing |
| 46: | * `default` is not considered a `case` it would make unreachable. |
| 47: | */ |
| 48: | public function isLast(): bool |
| 49: | { |
| 50: | return $this->isLast; |
| 51: | } |
| 52: | |
| 53: | } |
| 54: |