| 1: | <?php declare(strict_types = 1); |
| 2: | |
| 3: | namespace PHPStan\Node; |
| 4: | |
| 5: | use Override; |
| 6: | use PhpParser\Node\Expr; |
| 7: | use PhpParser\Node\Stmt\Switch_; |
| 8: | use PhpParser\NodeAbstract; |
| 9: | |
| 10: | /** |
| 11: | * Virtual node emitted once per `switch` statement. It pairs the switch subject |
| 12: | * with each non-default `case` condition so rules can inspect the loose `==` |
| 13: | * comparison the `switch` performs, using the scope captured at each case |
| 14: | * (which already excludes the values matched by earlier cases). |
| 15: | * |
| 16: | * @api |
| 17: | */ |
| 18: | final class SwitchConditionNode extends NodeAbstract implements VirtualNode |
| 19: | { |
| 20: | |
| 21: | /** |
| 22: | * @param SwitchConditionArm[] $arms |
| 23: | */ |
| 24: | public function __construct( |
| 25: | private Expr $subject, |
| 26: | private array $arms, |
| 27: | Switch_ $originalNode, |
| 28: | ) |
| 29: | { |
| 30: | parent::__construct($originalNode->getAttributes()); |
| 31: | } |
| 32: | |
| 33: | public function getSubject(): Expr |
| 34: | { |
| 35: | return $this->subject; |
| 36: | } |
| 37: | |
| 38: | /** |
| 39: | * @return SwitchConditionArm[] |
| 40: | */ |
| 41: | public function getArms(): array |
| 42: | { |
| 43: | return $this->arms; |
| 44: | } |
| 45: | |
| 46: | #[Override] |
| 47: | public function getType(): string |
| 48: | { |
| 49: | return 'PHPStan_Node_SwitchCondition'; |
| 50: | } |
| 51: | |
| 52: | /** |
| 53: | * @return string[] |
| 54: | */ |
| 55: | #[Override] |
| 56: | public function getSubNodeNames(): array |
| 57: | { |
| 58: | return []; |
| 59: | } |
| 60: | |
| 61: | } |
| 62: |