forked from phpstan/phpstan-src
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathKeyOfType.php
More file actions
81 lines (64 loc) · 1.52 KB
/
Copy pathKeyOfType.php
File metadata and controls
81 lines (64 loc) · 1.52 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
<?php declare(strict_types = 1);
namespace PHPStan\Type;
use PHPStan\Type\Generic\TemplateTypeVariance;
use PHPStan\Type\Traits\LateResolvableTypeTrait;
use PHPStan\Type\Traits\NonGeneralizableTypeTrait;
use function sprintf;
/** @api */
class KeyOfType implements CompoundType, LateResolvableType
{
use LateResolvableTypeTrait;
use NonGeneralizableTypeTrait;
public function __construct(private Type $type)
{
}
public function getType(): Type
{
return $this->type;
}
public function getReferencedClasses(): array
{
return $this->type->getReferencedClasses();
}
public function getReferencedTemplateTypes(TemplateTypeVariance $positionVariance): array
{
return $this->type->getReferencedTemplateTypes($positionVariance);
}
public function equals(Type $type): bool
{
return $type instanceof self
&& $this->type->equals($type->type);
}
public function describe(VerbosityLevel $level): string
{
return sprintf('key-of<%s>', $this->type->describe($level));
}
public function isResolvable(): bool
{
return !TypeUtils::containsTemplateType($this->type);
}
protected function getResult(): Type
{
return $this->type->getIterableKeyType();
}
/**
* @param callable(Type): Type $cb
*/
public function traverse(callable $cb): Type
{
$type = $cb($this->type);
if ($this->type === $type) {
return $this;
}
return new KeyOfType($type);
}
/**
* @param mixed[] $properties
*/
public static function __set_state(array $properties): Type
{
return new self(
$properties['type'],
);
}
}