1: <?php declare(strict_types = 1);
2:
3: namespace PHPStan\Analyser;
4:
5: use PhpParser\Node;
6: use PHPStan\Type\ObjectType;
7: use PHPStan\Type\Type;
8: use PHPStan\Type\TypeCombinator;
9: use Throwable;
10:
11: /**
12: * @api
13: * @final
14: */
15: class ThrowPoint
16: {
17:
18: /**
19: * @param Node\Expr|Node\Stmt $node
20: */
21: private function __construct(
22: private MutatingScope $scope,
23: private Type $type,
24: private Node $node,
25: private bool $explicit,
26: private bool $canContainAnyThrowable,
27: )
28: {
29: }
30:
31: /**
32: * @param Node\Expr|Node\Stmt $node
33: */
34: public static function createExplicit(MutatingScope $scope, Type $type, Node $node, bool $canContainAnyThrowable): self
35: {
36: return new self($scope, $type, $node, true, $canContainAnyThrowable);
37: }
38:
39: /**
40: * @param Node\Expr|Node\Stmt $node
41: */
42: public static function createImplicit(MutatingScope $scope, Node $node): self
43: {
44: return new self($scope, new ObjectType(Throwable::class), $node, false, true);
45: }
46:
47: public function getScope(): MutatingScope
48: {
49: return $this->scope;
50: }
51:
52: public function getType(): Type
53: {
54: return $this->type;
55: }
56:
57: /**
58: * @return Node\Expr|Node\Stmt
59: */
60: public function getNode()
61: {
62: return $this->node;
63: }
64:
65: public function isExplicit(): bool
66: {
67: return $this->explicit;
68: }
69:
70: public function canContainAnyThrowable(): bool
71: {
72: return $this->canContainAnyThrowable;
73: }
74:
75: public function subtractCatchType(Type $catchType): self
76: {
77: return new self($this->scope, TypeCombinator::remove($this->type, $catchType), $this->node, $this->explicit, $this->canContainAnyThrowable);
78: }
79:
80: }
81: