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