1: <?php declare(strict_types = 1);
2:
3: namespace PHPStan\Node;
4:
5: use Override;
6: use PhpParser\Node\Name;
7: use PhpParser\Node\Stmt\Catch_;
8: use PhpParser\NodeAbstract;
9: use PHPStan\Turbo\ReferencedByTurboExtension;
10: use PHPStan\Type\Type;
11:
12: /**
13: * Virtual node emitted once for each type in a `catch` clause, whether or not
14: * the try block can throw it - unlike CatchWithUnthrownExceptionNode, which is
15: * emitted only for the dead ones. Rules analysing a trait need both outcomes
16: * to tell whether a catch is dead in every class using it.
17: *
18: * @api
19: */
20: #[ReferencedByTurboExtension(key: 'catchTypeNode')]
21: final class CatchTypeNode extends NodeAbstract implements VirtualNode
22: {
23:
24: public function __construct(
25: private Catch_ $originalNode,
26: private Name $typeNode,
27: private Type $caughtType,
28: private Type $originalCaughtType,
29: private bool $thrown,
30: )
31: {
32: parent::__construct($originalNode->getAttributes());
33: }
34:
35: public function getOriginalNode(): Catch_
36: {
37: return $this->originalNode;
38: }
39:
40: public function getTypeNode(): Name
41: {
42: return $this->typeNode;
43: }
44:
45: /**
46: * The caught type without the types caught by the preceding catch clauses;
47: * NeverType when they already catch all of it.
48: */
49: public function getCaughtType(): Type
50: {
51: return $this->caughtType;
52: }
53:
54: public function getOriginalCaughtType(): Type
55: {
56: return $this->originalCaughtType;
57: }
58:
59: public function isThrown(): bool
60: {
61: return $this->thrown;
62: }
63:
64: #[Override]
65: public function getType(): string
66: {
67: return 'PHPStan_Node_CatchTypeNode';
68: }
69:
70: /**
71: * @return string[]
72: */
73: #[Override]
74: public function getSubNodeNames(): array
75: {
76: return [];
77: }
78:
79: }
80: