forked from vimeo/psalm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TIntMask.php
71 lines (56 loc) · 1.65 KB
/
TIntMask.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?php
namespace Psalm\Type\Atomic;
use function substr;
/**
* Represents the type that is the result of a bitmask combination of its parameters.
* `int-mask<1, 2, 4>` corresponds to `0|1|2|3|4|5|6|7`
*/
final class TIntMask extends TInt
{
/** @var non-empty-array<TLiteralInt|TClassConstant> */
public $values;
/** @param non-empty-array<TLiteralInt|TClassConstant> $values */
public function __construct(array $values)
{
$this->values = $values;
}
public function getKey(bool $include_extra = true): string
{
$s = '';
foreach ($this->values as $value) {
$s .= $value->getKey() . ', ';
}
return 'int-mask<' . substr($s, 0, -2) . '>';
}
public function getId(bool $exact = true, bool $nested = false): string
{
$s = '';
foreach ($this->values as $value) {
$s .= $value->getId($exact) . ', ';
}
return 'int-mask<' . substr($s, 0, -2) . '>';
}
/**
* @param array<lowercase-string, string> $aliased_classes
*
*/
public function toNamespacedString(
?string $namespace,
array $aliased_classes,
?string $this_class,
bool $use_phpdoc_format
): string {
if ($use_phpdoc_format) {
return 'int';
}
$s = '';
foreach ($this->values as $value) {
$s .= $value->toNamespacedString($namespace, $aliased_classes, $this_class, false) . ', ';
}
return 'int-mask<' . substr($s, 0, -2) . '>';
}
public function canBeFullyExpressedInPhp(int $analysis_php_version_id): bool
{
return false;
}
}