-
Notifications
You must be signed in to change notification settings - Fork 428
/
ConditionalExpressionHolder.php
56 lines (47 loc) · 1.15 KB
/
ConditionalExpressionHolder.php
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
<?php declare(strict_types = 1);
namespace PHPStan\Analyser;
use PHPStan\ShouldNotHappenException;
use PHPStan\Type\Type;
use PHPStan\Type\VerbosityLevel;
use function count;
use function implode;
use function sprintf;
class ConditionalExpressionHolder
{
/**
* @param array<string, Type> $conditionExpressionTypes
*/
public function __construct(
private array $conditionExpressionTypes,
private VariableTypeHolder $typeHolder,
)
{
if (count($conditionExpressionTypes) === 0) {
throw new ShouldNotHappenException();
}
}
/**
* @return array<string, Type>
*/
public function getConditionExpressionTypes(): array
{
return $this->conditionExpressionTypes;
}
public function getTypeHolder(): VariableTypeHolder
{
return $this->typeHolder;
}
public function getKey(): string
{
$parts = [];
foreach ($this->conditionExpressionTypes as $exprString => $type) {
$parts[] = $exprString . '=' . $type->describe(VerbosityLevel::precise());
}
return sprintf(
'%s => %s (%s)',
implode(' && ', $parts),
$this->typeHolder->getType()->describe(VerbosityLevel::precise()),
$this->typeHolder->getCertainty()->describe(),
);
}
}