forked from phpstan/phpstan-src
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInternalThrowPoint.php
More file actions
88 lines (72 loc) · 2.03 KB
/
InternalThrowPoint.php
File metadata and controls
88 lines (72 loc) · 2.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<?php declare(strict_types = 1);
namespace PHPStan\Analyser;
use PhpParser\Node;
use PHPStan\ShouldNotHappenException;
use PHPStan\Type\ObjectType;
use PHPStan\Type\Type;
use PHPStan\Type\TypeCombinator;
use Throwable;
final class InternalThrowPoint
{
/**
* @param Node\Expr|Node\Stmt $node
*/
private function __construct(
private MutatingScope $scope,
private Type $type,
private Node $node,
private bool $explicit,
private bool $canContainAnyThrowable,
)
{
}
public function toPublic(): ThrowPoint
{
if ($this->explicit) {
return ThrowPoint::createExplicit($this->scope, $this->type, $this->node, $this->canContainAnyThrowable);
}
return ThrowPoint::createImplicit($this->scope, $this->node);
}
/**
* @param Node\Expr|Node\Stmt $node
*/
public static function createExplicit(MutatingScope $scope, Type $type, Node $node, bool $canContainAnyThrowable): self
{
return new self($scope, $type, $node, true, $canContainAnyThrowable);
}
/**
* @param Node\Expr|Node\Stmt $node
*/
public static function createImplicit(MutatingScope $scope, Node $node): self
{
return new self($scope, new ObjectType(Throwable::class), $node, explicit: false, canContainAnyThrowable: true);
}
public static function createFromPublic(ThrowPoint $throwPoint): self
{
$scope = $throwPoint->getScope();
if (!$scope instanceof MutatingScope) {
throw new ShouldNotHappenException();
}
return new self($scope, $throwPoint->getType(), $throwPoint->getNode(), $throwPoint->isExplicit(), $throwPoint->canContainAnyThrowable());
}
public function getScope(): MutatingScope
{
return $this->scope;
}
public function getType(): Type
{
return $this->type;
}
public function isExplicit(): bool
{
return $this->explicit;
}
public function canContainAnyThrowable(): bool
{
return $this->canContainAnyThrowable;
}
public function subtractCatchType(Type $catchType): self
{
return new self($this->scope, TypeCombinator::remove($this->type, $catchType), $this->node, $this->explicit, $this->canContainAnyThrowable);
}
}