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