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