@@ -22,11 +22,11 @@ |
||
22 | 22 | */ |
23 | 23 | final class Resource_ implements Type |
24 | 24 | { |
25 | - /** |
|
26 | - * Returns a rendered output of the Type as it would be used in a DocBlock. |
|
27 | - */ |
|
28 | - public function __toString(): string |
|
29 | - { |
|
30 | - return 'resource'; |
|
31 | - } |
|
25 | + /** |
|
26 | + * Returns a rendered output of the Type as it would be used in a DocBlock. |
|
27 | + */ |
|
28 | + public function __toString(): string |
|
29 | + { |
|
30 | + return 'resource'; |
|
31 | + } |
|
32 | 32 | } |
@@ -22,11 +22,11 @@ |
||
22 | 22 | */ |
23 | 23 | final class Callable_ implements Type |
24 | 24 | { |
25 | - /** |
|
26 | - * Returns a rendered output of the Type as it would be used in a DocBlock. |
|
27 | - */ |
|
28 | - public function __toString(): string |
|
29 | - { |
|
30 | - return 'callable'; |
|
31 | - } |
|
25 | + /** |
|
26 | + * Returns a rendered output of the Type as it would be used in a DocBlock. |
|
27 | + */ |
|
28 | + public function __toString(): string |
|
29 | + { |
|
30 | + return 'callable'; |
|
31 | + } |
|
32 | 32 | } |
@@ -22,11 +22,11 @@ |
||
22 | 22 | */ |
23 | 23 | final class Mixed_ implements Type |
24 | 24 | { |
25 | - /** |
|
26 | - * Returns a rendered output of the Type as it would be used in a DocBlock. |
|
27 | - */ |
|
28 | - public function __toString(): string |
|
29 | - { |
|
30 | - return 'mixed'; |
|
31 | - } |
|
25 | + /** |
|
26 | + * Returns a rendered output of the Type as it would be used in a DocBlock. |
|
27 | + */ |
|
28 | + public function __toString(): string |
|
29 | + { |
|
30 | + return 'mixed'; |
|
31 | + } |
|
32 | 32 | } |
@@ -26,13 +26,13 @@ |
||
26 | 26 | */ |
27 | 27 | final class Compound extends AggregatedType |
28 | 28 | { |
29 | - /** |
|
30 | - * Initializes a compound type (i.e. `string|int`) and tests if the provided types all implement the Type interface. |
|
31 | - * |
|
32 | - * @param array<Type> $types |
|
33 | - */ |
|
34 | - public function __construct(array $types) |
|
35 | - { |
|
36 | - parent::__construct($types, '|'); |
|
37 | - } |
|
29 | + /** |
|
30 | + * Initializes a compound type (i.e. `string|int`) and tests if the provided types all implement the Type interface. |
|
31 | + * |
|
32 | + * @param array<Type> $types |
|
33 | + */ |
|
34 | + public function __construct(array $types) |
|
35 | + { |
|
36 | + parent::__construct($types, '|'); |
|
37 | + } |
|
38 | 38 | } |
@@ -22,11 +22,11 @@ |
||
22 | 22 | */ |
23 | 23 | class Boolean implements Type |
24 | 24 | { |
25 | - /** |
|
26 | - * Returns a rendered output of the Type as it would be used in a DocBlock. |
|
27 | - */ |
|
28 | - public function __toString(): string |
|
29 | - { |
|
30 | - return 'bool'; |
|
31 | - } |
|
25 | + /** |
|
26 | + * Returns a rendered output of the Type as it would be used in a DocBlock. |
|
27 | + */ |
|
28 | + public function __toString(): string |
|
29 | + { |
|
30 | + return 'bool'; |
|
31 | + } |
|
32 | 32 | } |
@@ -22,62 +22,62 @@ |
||
22 | 22 | */ |
23 | 23 | abstract class AbstractList implements Type |
24 | 24 | { |
25 | - /** @var Type */ |
|
26 | - protected $valueType; |
|
25 | + /** @var Type */ |
|
26 | + protected $valueType; |
|
27 | 27 | |
28 | - /** @var Type|null */ |
|
29 | - protected $keyType; |
|
28 | + /** @var Type|null */ |
|
29 | + protected $keyType; |
|
30 | 30 | |
31 | - /** @var Type */ |
|
32 | - protected $defaultKeyType; |
|
31 | + /** @var Type */ |
|
32 | + protected $defaultKeyType; |
|
33 | 33 | |
34 | - /** |
|
35 | - * Initializes this representation of an array with the given Type. |
|
36 | - */ |
|
37 | - public function __construct(?Type $valueType = null, ?Type $keyType = null) |
|
38 | - { |
|
39 | - if ($valueType === null) { |
|
40 | - $valueType = new Mixed_(); |
|
41 | - } |
|
34 | + /** |
|
35 | + * Initializes this representation of an array with the given Type. |
|
36 | + */ |
|
37 | + public function __construct(?Type $valueType = null, ?Type $keyType = null) |
|
38 | + { |
|
39 | + if ($valueType === null) { |
|
40 | + $valueType = new Mixed_(); |
|
41 | + } |
|
42 | 42 | |
43 | - $this->valueType = $valueType; |
|
44 | - $this->defaultKeyType = new Compound([new String_(), new Integer()]); |
|
45 | - $this->keyType = $keyType; |
|
46 | - } |
|
43 | + $this->valueType = $valueType; |
|
44 | + $this->defaultKeyType = new Compound([new String_(), new Integer()]); |
|
45 | + $this->keyType = $keyType; |
|
46 | + } |
|
47 | 47 | |
48 | - /** |
|
49 | - * Returns the type for the keys of this array. |
|
50 | - */ |
|
51 | - public function getKeyType(): Type |
|
52 | - { |
|
53 | - return $this->keyType ?? $this->defaultKeyType; |
|
54 | - } |
|
48 | + /** |
|
49 | + * Returns the type for the keys of this array. |
|
50 | + */ |
|
51 | + public function getKeyType(): Type |
|
52 | + { |
|
53 | + return $this->keyType ?? $this->defaultKeyType; |
|
54 | + } |
|
55 | 55 | |
56 | - /** |
|
57 | - * Returns the value for the keys of this array. |
|
58 | - */ |
|
59 | - public function getValueType(): Type |
|
60 | - { |
|
61 | - return $this->valueType; |
|
62 | - } |
|
56 | + /** |
|
57 | + * Returns the value for the keys of this array. |
|
58 | + */ |
|
59 | + public function getValueType(): Type |
|
60 | + { |
|
61 | + return $this->valueType; |
|
62 | + } |
|
63 | 63 | |
64 | - /** |
|
65 | - * Returns a rendered output of the Type as it would be used in a DocBlock. |
|
66 | - */ |
|
67 | - public function __toString(): string |
|
68 | - { |
|
69 | - if ($this->keyType) { |
|
70 | - return 'array<' . $this->keyType . ',' . $this->valueType . '>'; |
|
71 | - } |
|
64 | + /** |
|
65 | + * Returns a rendered output of the Type as it would be used in a DocBlock. |
|
66 | + */ |
|
67 | + public function __toString(): string |
|
68 | + { |
|
69 | + if ($this->keyType) { |
|
70 | + return 'array<' . $this->keyType . ',' . $this->valueType . '>'; |
|
71 | + } |
|
72 | 72 | |
73 | - if ($this->valueType instanceof Mixed_) { |
|
74 | - return 'array'; |
|
75 | - } |
|
73 | + if ($this->valueType instanceof Mixed_) { |
|
74 | + return 'array'; |
|
75 | + } |
|
76 | 76 | |
77 | - if ($this->valueType instanceof Compound) { |
|
78 | - return '(' . $this->valueType . ')[]'; |
|
79 | - } |
|
77 | + if ($this->valueType instanceof Compound) { |
|
78 | + return '(' . $this->valueType . ')[]'; |
|
79 | + } |
|
80 | 80 | |
81 | - return $this->valueType . '[]'; |
|
82 | - } |
|
81 | + return $this->valueType . '[]'; |
|
82 | + } |
|
83 | 83 | } |
@@ -67,7 +67,7 @@ discard block |
||
67 | 67 | public function __toString(): string |
68 | 68 | { |
69 | 69 | if ($this->keyType) { |
70 | - return 'array<' . $this->keyType . ',' . $this->valueType . '>'; |
|
70 | + return 'array<'.$this->keyType.','.$this->valueType.'>'; |
|
71 | 71 | } |
72 | 72 | |
73 | 73 | if ($this->valueType instanceof Mixed_) { |
@@ -75,9 +75,9 @@ discard block |
||
75 | 75 | } |
76 | 76 | |
77 | 77 | if ($this->valueType instanceof Compound) { |
78 | - return '(' . $this->valueType . ')[]'; |
|
78 | + return '('.$this->valueType.')[]'; |
|
79 | 79 | } |
80 | 80 | |
81 | - return $this->valueType . '[]'; |
|
81 | + return $this->valueType.'[]'; |
|
82 | 82 | } |
83 | 83 | } |
@@ -30,96 +30,96 @@ |
||
30 | 30 | */ |
31 | 31 | abstract class AggregatedType implements Type, IteratorAggregate |
32 | 32 | { |
33 | - /** |
|
34 | - * @psalm-allow-private-mutation |
|
35 | - * @var array<int, Type> |
|
36 | - */ |
|
37 | - private $types = []; |
|
38 | - |
|
39 | - /** @var string */ |
|
40 | - private $token; |
|
41 | - |
|
42 | - /** |
|
43 | - * @param array<Type> $types |
|
44 | - */ |
|
45 | - public function __construct(array $types, string $token) |
|
46 | - { |
|
47 | - foreach ($types as $type) { |
|
48 | - $this->add($type); |
|
49 | - } |
|
50 | - |
|
51 | - $this->token = $token; |
|
52 | - } |
|
53 | - |
|
54 | - /** |
|
55 | - * Returns the type at the given index. |
|
56 | - */ |
|
57 | - public function get(int $index): ?Type |
|
58 | - { |
|
59 | - if (!$this->has($index)) { |
|
60 | - return null; |
|
61 | - } |
|
62 | - |
|
63 | - return $this->types[$index]; |
|
64 | - } |
|
65 | - |
|
66 | - /** |
|
67 | - * Tests if this compound type has a type with the given index. |
|
68 | - */ |
|
69 | - public function has(int $index): bool |
|
70 | - { |
|
71 | - return array_key_exists($index, $this->types); |
|
72 | - } |
|
73 | - |
|
74 | - /** |
|
75 | - * Tests if this compound type contains the given type. |
|
76 | - */ |
|
77 | - public function contains(Type $type): bool |
|
78 | - { |
|
79 | - foreach ($this->types as $typePart) { |
|
80 | - // if the type is duplicate; do not add it |
|
81 | - if ((string) $typePart === (string) $type) { |
|
82 | - return true; |
|
83 | - } |
|
84 | - } |
|
85 | - |
|
86 | - return false; |
|
87 | - } |
|
88 | - |
|
89 | - /** |
|
90 | - * Returns a rendered output of the Type as it would be used in a DocBlock. |
|
91 | - */ |
|
92 | - public function __toString(): string |
|
93 | - { |
|
94 | - return implode($this->token, $this->types); |
|
95 | - } |
|
96 | - |
|
97 | - /** |
|
98 | - * @return ArrayIterator<int, Type> |
|
99 | - */ |
|
100 | - public function getIterator(): ArrayIterator |
|
101 | - { |
|
102 | - return new ArrayIterator($this->types); |
|
103 | - } |
|
104 | - |
|
105 | - /** |
|
106 | - * @psalm-suppress ImpureMethodCall |
|
107 | - */ |
|
108 | - private function add(Type $type): void |
|
109 | - { |
|
110 | - if ($type instanceof self) { |
|
111 | - foreach ($type->getIterator() as $subType) { |
|
112 | - $this->add($subType); |
|
113 | - } |
|
114 | - |
|
115 | - return; |
|
116 | - } |
|
117 | - |
|
118 | - // if the type is duplicate; do not add it |
|
119 | - if ($this->contains($type)) { |
|
120 | - return; |
|
121 | - } |
|
122 | - |
|
123 | - $this->types[] = $type; |
|
124 | - } |
|
33 | + /** |
|
34 | + * @psalm-allow-private-mutation |
|
35 | + * @var array<int, Type> |
|
36 | + */ |
|
37 | + private $types = []; |
|
38 | + |
|
39 | + /** @var string */ |
|
40 | + private $token; |
|
41 | + |
|
42 | + /** |
|
43 | + * @param array<Type> $types |
|
44 | + */ |
|
45 | + public function __construct(array $types, string $token) |
|
46 | + { |
|
47 | + foreach ($types as $type) { |
|
48 | + $this->add($type); |
|
49 | + } |
|
50 | + |
|
51 | + $this->token = $token; |
|
52 | + } |
|
53 | + |
|
54 | + /** |
|
55 | + * Returns the type at the given index. |
|
56 | + */ |
|
57 | + public function get(int $index): ?Type |
|
58 | + { |
|
59 | + if (!$this->has($index)) { |
|
60 | + return null; |
|
61 | + } |
|
62 | + |
|
63 | + return $this->types[$index]; |
|
64 | + } |
|
65 | + |
|
66 | + /** |
|
67 | + * Tests if this compound type has a type with the given index. |
|
68 | + */ |
|
69 | + public function has(int $index): bool |
|
70 | + { |
|
71 | + return array_key_exists($index, $this->types); |
|
72 | + } |
|
73 | + |
|
74 | + /** |
|
75 | + * Tests if this compound type contains the given type. |
|
76 | + */ |
|
77 | + public function contains(Type $type): bool |
|
78 | + { |
|
79 | + foreach ($this->types as $typePart) { |
|
80 | + // if the type is duplicate; do not add it |
|
81 | + if ((string) $typePart === (string) $type) { |
|
82 | + return true; |
|
83 | + } |
|
84 | + } |
|
85 | + |
|
86 | + return false; |
|
87 | + } |
|
88 | + |
|
89 | + /** |
|
90 | + * Returns a rendered output of the Type as it would be used in a DocBlock. |
|
91 | + */ |
|
92 | + public function __toString(): string |
|
93 | + { |
|
94 | + return implode($this->token, $this->types); |
|
95 | + } |
|
96 | + |
|
97 | + /** |
|
98 | + * @return ArrayIterator<int, Type> |
|
99 | + */ |
|
100 | + public function getIterator(): ArrayIterator |
|
101 | + { |
|
102 | + return new ArrayIterator($this->types); |
|
103 | + } |
|
104 | + |
|
105 | + /** |
|
106 | + * @psalm-suppress ImpureMethodCall |
|
107 | + */ |
|
108 | + private function add(Type $type): void |
|
109 | + { |
|
110 | + if ($type instanceof self) { |
|
111 | + foreach ($type->getIterator() as $subType) { |
|
112 | + $this->add($subType); |
|
113 | + } |
|
114 | + |
|
115 | + return; |
|
116 | + } |
|
117 | + |
|
118 | + // if the type is duplicate; do not add it |
|
119 | + if ($this->contains($type)) { |
|
120 | + return; |
|
121 | + } |
|
122 | + |
|
123 | + $this->types[] = $type; |
|
124 | + } |
|
125 | 125 | } |
@@ -56,7 +56,7 @@ |
||
56 | 56 | */ |
57 | 57 | public function get(int $index): ?Type |
58 | 58 | { |
59 | - if (!$this->has($index)) { |
|
59 | + if ( ! $this->has($index)) { |
|
60 | 60 | return null; |
61 | 61 | } |
62 | 62 |
@@ -22,30 +22,30 @@ |
||
22 | 22 | */ |
23 | 23 | final class Expression implements Type |
24 | 24 | { |
25 | - /** @var Type */ |
|
26 | - protected $valueType; |
|
27 | - |
|
28 | - /** |
|
29 | - * Initializes this representation of an array with the given Type. |
|
30 | - */ |
|
31 | - public function __construct(Type $valueType) |
|
32 | - { |
|
33 | - $this->valueType = $valueType; |
|
34 | - } |
|
35 | - |
|
36 | - /** |
|
37 | - * Returns the value for the keys of this array. |
|
38 | - */ |
|
39 | - public function getValueType(): Type |
|
40 | - { |
|
41 | - return $this->valueType; |
|
42 | - } |
|
43 | - |
|
44 | - /** |
|
45 | - * Returns a rendered output of the Type as it would be used in a DocBlock. |
|
46 | - */ |
|
47 | - public function __toString(): string |
|
48 | - { |
|
49 | - return '(' . $this->valueType . ')'; |
|
50 | - } |
|
25 | + /** @var Type */ |
|
26 | + protected $valueType; |
|
27 | + |
|
28 | + /** |
|
29 | + * Initializes this representation of an array with the given Type. |
|
30 | + */ |
|
31 | + public function __construct(Type $valueType) |
|
32 | + { |
|
33 | + $this->valueType = $valueType; |
|
34 | + } |
|
35 | + |
|
36 | + /** |
|
37 | + * Returns the value for the keys of this array. |
|
38 | + */ |
|
39 | + public function getValueType(): Type |
|
40 | + { |
|
41 | + return $this->valueType; |
|
42 | + } |
|
43 | + |
|
44 | + /** |
|
45 | + * Returns a rendered output of the Type as it would be used in a DocBlock. |
|
46 | + */ |
|
47 | + public function __toString(): string |
|
48 | + { |
|
49 | + return '(' . $this->valueType . ')'; |
|
50 | + } |
|
51 | 51 | } |
@@ -46,6 +46,6 @@ |
||
46 | 46 | */ |
47 | 47 | public function __toString(): string |
48 | 48 | { |
49 | - return '(' . $this->valueType . ')'; |
|
49 | + return '('.$this->valueType.')'; |
|
50 | 50 | } |
51 | 51 | } |
@@ -20,19 +20,19 @@ |
||
20 | 20 | */ |
21 | 21 | final class Iterable_ extends AbstractList |
22 | 22 | { |
23 | - /** |
|
24 | - * Returns a rendered output of the Type as it would be used in a DocBlock. |
|
25 | - */ |
|
26 | - public function __toString(): string |
|
27 | - { |
|
28 | - if ($this->keyType) { |
|
29 | - return 'iterable<' . $this->keyType . ',' . $this->valueType . '>'; |
|
30 | - } |
|
23 | + /** |
|
24 | + * Returns a rendered output of the Type as it would be used in a DocBlock. |
|
25 | + */ |
|
26 | + public function __toString(): string |
|
27 | + { |
|
28 | + if ($this->keyType) { |
|
29 | + return 'iterable<' . $this->keyType . ',' . $this->valueType . '>'; |
|
30 | + } |
|
31 | 31 | |
32 | - if ($this->valueType instanceof Mixed_) { |
|
33 | - return 'iterable'; |
|
34 | - } |
|
32 | + if ($this->valueType instanceof Mixed_) { |
|
33 | + return 'iterable'; |
|
34 | + } |
|
35 | 35 | |
36 | - return 'iterable<' . $this->valueType . '>'; |
|
37 | - } |
|
36 | + return 'iterable<' . $this->valueType . '>'; |
|
37 | + } |
|
38 | 38 | } |
@@ -26,13 +26,13 @@ |
||
26 | 26 | public function __toString(): string |
27 | 27 | { |
28 | 28 | if ($this->keyType) { |
29 | - return 'iterable<' . $this->keyType . ',' . $this->valueType . '>'; |
|
29 | + return 'iterable<'.$this->keyType.','.$this->valueType.'>'; |
|
30 | 30 | } |
31 | 31 | |
32 | 32 | if ($this->valueType instanceof Mixed_) { |
33 | 33 | return 'iterable'; |
34 | 34 | } |
35 | 35 | |
36 | - return 'iterable<' . $this->valueType . '>'; |
|
36 | + return 'iterable<'.$this->valueType.'>'; |
|
37 | 37 | } |
38 | 38 | } |