Skip to content

Commit 2fd3cca

Browse files
committed
Define type alias in phpstan configuration file
1 parent d018eae commit 2fd3cca

File tree

7 files changed

+20
-17
lines changed

7 files changed

+20
-17
lines changed

phpstan.neon

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,5 @@ parameters:
99
- src
1010
ignoreErrors:
1111
reportUnmatchedIgnoredErrors: true
12+
typeAliases:
13+
DataType: '\Bakame\Http\StructuredFields\ByteSequence|\Bakame\Http\StructuredFields\Token|bool|int|float|string'

src/Dictionary.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
use function is_array;
1414

1515
/**
16-
* @phpstan-type DataType ByteSequence|Token|bool|int|float|string
1716
* @implements MemberOrderedMap<string, Item|InnerList<int, Item>>
1817
*/
1918
final class Dictionary implements MemberOrderedMap

src/InnerList.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
use function count;
1313

1414
/**
15-
* @phpstan-type DataType ByteSequence|Token|bool|int|float|string
1615
* @implements MemberList<int, Item>
1716
*/
1817
final class InnerList implements MemberList, ParameterAccess

src/Item.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,6 @@
2020
use function substr;
2121
use function trim;
2222

23-
/**
24-
* @phpstan-type DataType ByteSequence|Token|bool|int|float|string
25-
*/
2623
final class Item implements StructuredField, ParameterAccess
2724
{
2825
private function __construct(

src/OrderedList.php

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@
1414
use function is_array;
1515

1616
/**
17-
* @phpstan-type DataType ByteSequence|Token|bool|int|float|string
18-
* @implements MemberList<int, Item|MemberList<int, Item>>
17+
* @implements MemberList<int, Item|InnerList<int, Item>>
1918
*/
2019
final class OrderedList implements MemberList
2120
{
@@ -28,17 +27,17 @@ private function __construct(Item|InnerList ...$members)
2827
}
2928

3029
/**
31-
* @param MemberList<int, Item>|Item|DataType ...$members
30+
* @param InnerList<int, Item>|Item|DataType ...$members
3231
*
3332
* @return static
3433
*/
35-
public static function from(MemberList|Item|ByteSequence|Token|bool|int|float|string ...$members): self
34+
public static function from(InnerList|Item|ByteSequence|Token|bool|int|float|string ...$members): self
3635
{
3736
return self::fromList($members);
3837
}
3938

4039
/**
41-
* @param iterable<MemberList<int, Item>|Item|DataType> $members
40+
* @param iterable<InnerList<int, Item>|Item|DataType> $members
4241
*/
4342
public static function fromList(iterable $members = []): self
4443
{
@@ -107,7 +106,7 @@ public function hasMembers(): bool
107106
}
108107

109108
/**
110-
* @return Iterator<int, Item|MemberList<int, Item>>
109+
* @return Iterator<int, Item|InnerList<int, Item>>
111110
*/
112111
public function getIterator(): Iterator
113112
{
@@ -147,8 +146,10 @@ public function get(string|int $offset): Item|InnerList
147146

148147
/**
149148
* Inserts members at the beginning of the list.
149+
*
150+
* @param InnerList<int, Item>|Item|DataType ...$members
150151
*/
151-
public function unshift(MemberList|StructuredField|ByteSequence|Token|bool|int|float|string ...$members): self
152+
public function unshift(StructuredField|ByteSequence|Token|bool|int|float|string ...$members): self
152153
{
153154
$this->members = [...array_map(self::filterMember(...), array_values($members)), ...$this->members];
154155

@@ -157,8 +158,10 @@ public function unshift(MemberList|StructuredField|ByteSequence|Token|bool|int|f
157158

158159
/**
159160
* Inserts members at the end of the list.
161+
*
162+
* @param InnerList<int, Item>|Item|DataType ...$members
160163
*/
161-
public function push(MemberList|StructuredField|ByteSequence|Token|bool|int|float|string ...$members): self
164+
public function push(StructuredField|ByteSequence|Token|bool|int|float|string ...$members): self
162165
{
163166
$this->members = [...$this->members, ...array_map(self::filterMember(...), array_values($members))];
164167

@@ -168,9 +171,11 @@ public function push(MemberList|StructuredField|ByteSequence|Token|bool|int|floa
168171
/**
169172
* Inserts members starting at the given index.
170173
*
174+
* @param InnerList<int, Item>|Item|DataType $members
175+
*
171176
* @throws InvalidOffset If the index does not exist
172177
*/
173-
public function insert(int $index, MemberList|StructuredField|ByteSequence|Token|bool|int|float|string ...$members): self
178+
public function insert(int $index, StructuredField|ByteSequence|Token|bool|int|float|string ...$members): self
174179
{
175180
$offset = $this->filterIndex($index);
176181
match (true) {
@@ -186,6 +191,8 @@ public function insert(int $index, MemberList|StructuredField|ByteSequence|Token
186191
/**
187192
* Replaces the member associated with the index.
188193
*
194+
* @param InnerList<int, Item>|Item|DataType $member
195+
*
189196
* @throws InvalidOffset If the index does not exist
190197
*/
191198
public function replace(int $index, StructuredField|ByteSequence|Token|bool|int|float|string $member): self
@@ -248,7 +255,7 @@ public function offsetUnset($offset): void
248255

249256
/**
250257
* @param int|null $offset
251-
* @param MemberList<int, Item>|Item|DataType $value the member to add
258+
* @param InnerList<int, Item>|Item|DataType $value the member to add
252259
*
253260
* @see ::push
254261
* @see ::replace

src/OrderedListTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ public function test_it_can_generate_the_same_value(): void
122122
public function it_implements_the_array_access_interface(): void
123123
{
124124
$sequence = OrderedList::from();
125-
$sequence[] = InnerList::from(42, 69);
125+
$sequence->push(InnerList::from(42, 69));
126126

127127
self::assertTrue(isset($sequence[0]));
128128
self::assertInstanceOf(InnerList::class, $sequence[0]);

src/Parameters.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
use function trim;
1717

1818
/**
19-
* @phpstan-type DataType ByteSequence|Token|bool|int|float|string
2019
* @implements MemberOrderedMap<string, Item>
2120
*/
2221
final class Parameters implements MemberOrderedMap

0 commit comments

Comments
 (0)