-
Notifications
You must be signed in to change notification settings - Fork 426
/
TemplateConstantIntegerType.php
54 lines (45 loc) · 1.2 KB
/
TemplateConstantIntegerType.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
<?php declare(strict_types = 1);
namespace PHPStan\Type\Generic;
use PHPStan\Type\Constant\ConstantIntegerType;
use PHPStan\Type\Traits\UndecidedComparisonCompoundTypeTrait;
use PHPStan\Type\Type;
/** @api */
final class TemplateConstantIntegerType extends ConstantIntegerType implements TemplateType
{
/** @use TemplateTypeTrait<ConstantIntegerType> */
use TemplateTypeTrait;
use UndecidedComparisonCompoundTypeTrait;
public function __construct(
TemplateTypeScope $scope,
TemplateTypeStrategy $templateTypeStrategy,
TemplateTypeVariance $templateTypeVariance,
string $name,
ConstantIntegerType $bound,
)
{
parent::__construct($bound->getValue());
$this->scope = $scope;
$this->strategy = $templateTypeStrategy;
$this->variance = $templateTypeVariance;
$this->name = $name;
$this->bound = $bound;
}
public function traverse(callable $cb): Type
{
$newBound = $cb($this->getBound());
if ($this->getBound() !== $newBound && $newBound instanceof ConstantIntegerType) {
return new self(
$this->scope,
$this->strategy,
$this->variance,
$this->name,
$newBound,
);
}
return $this;
}
protected function shouldGeneralizeInferredType(): bool
{
return false;
}
}