Skip to content

Commit e3e50dc

Browse files
committed
Improve interface return type
1 parent 5cc190b commit e3e50dc

File tree

7 files changed

+39
-63
lines changed

7 files changed

+39
-63
lines changed

src/Dictionary.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ public function pair(int $index): array
209209
/**
210210
* @throws SyntaxError If the string key is not a valid
211211
*/
212-
public function set(string $key, StructuredField|Token|ByteSequence|DateTimeInterface|Stringable|string|int|float|bool $member): self
212+
public function set(string $key, StructuredField|Token|ByteSequence|DateTimeInterface|Stringable|string|int|float|bool $member): static
213213
{
214214
$this->members[MapKey::fromString($key)->value] = self::filterMember($member);
215215

@@ -225,7 +225,7 @@ private static function filterMember(StructuredField|Token|ByteSequence|DateTime
225225
};
226226
}
227227

228-
public function delete(string ...$keys): self
228+
public function delete(string ...$keys): static
229229
{
230230
foreach ($keys as $key) {
231231
unset($this->members[$key]);
@@ -234,21 +234,21 @@ public function delete(string ...$keys): self
234234
return $this;
235235
}
236236

237-
public function clear(): self
237+
public function clear(): static
238238
{
239239
$this->members = [];
240240

241241
return $this;
242242
}
243243

244-
public function append(string $key, StructuredField|Token|ByteSequence|DateTimeInterface|Stringable|string|int|float|bool $member): self
244+
public function append(string $key, StructuredField|Token|ByteSequence|DateTimeInterface|Stringable|string|int|float|bool $member): static
245245
{
246246
unset($this->members[$key]);
247247

248248
return $this->set($key, $member);
249249
}
250250

251-
public function prepend(string $key, StructuredField|Token|ByteSequence|DateTimeInterface|Stringable|string|int|float|bool $member): self
251+
public function prepend(string $key, StructuredField|Token|ByteSequence|DateTimeInterface|Stringable|string|int|float|bool $member): static
252252
{
253253
unset($this->members[$key]);
254254

@@ -260,7 +260,7 @@ public function prepend(string $key, StructuredField|Token|ByteSequence|DateTime
260260
/**
261261
* @param iterable<string, InnerList<int, Value>|Value|DataType> ...$others
262262
*/
263-
public function mergeAssociative(iterable ...$others): self
263+
public function mergeAssociative(iterable ...$others): static
264264
{
265265
foreach ($others as $other) {
266266
$this->members = [...$this->members, ...self::fromAssociative($other)->members];
@@ -272,7 +272,7 @@ public function mergeAssociative(iterable ...$others): self
272272
/**
273273
* @param MemberOrderedMap<string, Value|InnerList<int, Value>>|iterable<array{0:string, 1:InnerList<int, Value>|Value|DataType}> ...$others
274274
*/
275-
public function mergePairs(MemberOrderedMap|iterable ...$others): self
275+
public function mergePairs(MemberOrderedMap|iterable ...$others): static
276276
{
277277
foreach ($others as $other) {
278278
$this->members = [...$this->members, ...self::fromPairs($other)->members];

src/InnerList.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ private function __construct(private readonly Parameters $parameters, iterable $
3333
/**
3434
* Returns a new instance.
3535
*/
36-
public static function from(Value|Token|ByteSequence|DateTimeInterface|Stringable|string|int|float|bool ...$members): self
36+
public static function from(Value|Token|ByteSequence|DateTimeInterface|Stringable|string|int|float|bool ...$members): static
3737
{
3838
return new self(Parameters::create(), $members);
3939
}
@@ -147,7 +147,7 @@ public function get(string|int $offset): Value
147147
/**
148148
* Insert members at the beginning of the list.
149149
*/
150-
public function unshift(StructuredField|Token|ByteSequence|DateTimeInterface|Stringable|string|int|float|bool ...$members): self
150+
public function unshift(StructuredField|Token|ByteSequence|DateTimeInterface|Stringable|string|int|float|bool ...$members): static
151151
{
152152
$this->members = [...array_map(self::filterMember(...), array_values($members)), ...$this->members];
153153

@@ -157,7 +157,7 @@ public function unshift(StructuredField|Token|ByteSequence|DateTimeInterface|Str
157157
/**
158158
* Insert members at the end of the list.
159159
*/
160-
public function push(StructuredField|Token|ByteSequence|DateTimeInterface|Stringable|string|int|float|bool ...$members): self
160+
public function push(StructuredField|Token|ByteSequence|DateTimeInterface|Stringable|string|int|float|bool ...$members): static
161161
{
162162
$this->members = [...$this->members, ...array_map(self::filterMember(...), array_values($members))];
163163

@@ -178,7 +178,7 @@ private static function filterMember(StructuredField|Token|ByteSequence|DateTime
178178
*
179179
* @throws InvalidOffset If the index does not exist
180180
*/
181-
public function insert(int $index, StructuredField|Token|ByteSequence|DateTimeInterface|Stringable|string|int|float|bool ...$members): self
181+
public function insert(int $index, StructuredField|Token|ByteSequence|DateTimeInterface|Stringable|string|int|float|bool ...$members): static
182182
{
183183
$offset = $this->filterIndex($index);
184184
match (true) {
@@ -191,7 +191,7 @@ public function insert(int $index, StructuredField|Token|ByteSequence|DateTimeIn
191191
return $this;
192192
}
193193

194-
public function replace(int $index, StructuredField|Token|ByteSequence|DateTimeInterface|Stringable|string|int|float|bool $member): self
194+
public function replace(int $index, StructuredField|Token|ByteSequence|DateTimeInterface|Stringable|string|int|float|bool $member): static
195195
{
196196
if (null === ($offset = $this->filterIndex($index))) {
197197
throw InvalidOffset::dueToIndexNotFound($index);
@@ -205,7 +205,7 @@ public function replace(int $index, StructuredField|Token|ByteSequence|DateTimeI
205205
/**
206206
* Delete members associated with the list of instance indexes.
207207
*/
208-
public function remove(int ...$indexes): self
208+
public function remove(int ...$indexes): static
209209
{
210210
$offsets = array_filter(
211211
array_map(fn (int $index): int|null => $this->filterIndex($index), $indexes),
@@ -219,7 +219,7 @@ public function remove(int ...$indexes): self
219219
return $this;
220220
}
221221

222-
public function clear(): self
222+
public function clear(): static
223223
{
224224
$this->members = [];
225225

src/MemberContainer.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,8 @@ public function hasMembers(): bool;
2929

3030
/**
3131
* Removes all members from the instance.
32-
*
33-
* @return self<TKey, TValue>
3432
*/
35-
public function clear(): self;
33+
public function clear(): static;
3634

3735
/**
3836
* @return Iterator<TKey, TValue>

src/MemberList.php

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,38 +13,28 @@ interface MemberList extends MemberContainer
1313
{
1414
/**
1515
* Inserts members at the beginning of the list.
16-
*
17-
* @return MemberList<TKey, TValue>
1816
*/
19-
public function unshift(StructuredField ...$members): self;
17+
public function unshift(StructuredField ...$members): static;
2018

2119
/**
2220
* Inserts members at the end of the list.
23-
*
24-
* @return MemberList<TKey, TValue>
2521
*/
26-
public function push(StructuredField ...$members): self;
22+
public function push(StructuredField ...$members): static;
2723

2824
/**
2925
* Inserts members at the index.
3026
*
3127
* @throws InvalidOffset If the index does not exist
32-
*
33-
* @return MemberList<TKey, TValue>
3428
*/
35-
public function insert(int $index, StructuredField ...$members): self;
29+
public function insert(int $index, StructuredField ...$members): static;
3630

3731
/**
3832
* Replaces the member associated with the index.
39-
*
40-
* @return MemberList<TKey, TValue>
4133
*/
42-
public function replace(int $index, StructuredField $member): self;
34+
public function replace(int $index, StructuredField $member): static;
4335

4436
/**
4537
* Deletes members associated with the given indexes.
46-
*
47-
* @return MemberList<TKey, TValue>
4838
*/
49-
public function remove(int ...$indexes): self;
39+
public function remove(int ...$indexes): static;
5040
}

src/MemberOrderedMap.php

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -46,51 +46,39 @@ public function keys(): array;
4646
* Adds a member at the end of the instance otherwise updates the value associated with the key if already present.
4747
*
4848
* @throws SyntaxError If the string key is not a valid
49-
*
50-
* @return MemberOrderedMap<TKey, TValue>
5149
*/
52-
public function set(string $key, StructuredField $member): self;
50+
public function set(string $key, StructuredField $member): static;
5351

5452
/**
5553
* Deletes members associated with the list of submitted keys.
56-
*
57-
* @return MemberOrderedMap<TKey, TValue>
5854
*/
59-
public function delete(string ...$keys): self;
55+
public function delete(string ...$keys): static;
6056

6157
/**
6258
* Adds a member at the end of the instance and deletes any previous reference to the key if present.
6359
*
6460
* @throws SyntaxError If the string key is not a valid
65-
*
66-
* @return MemberOrderedMap<TKey, TValue>
6761
*/
68-
public function append(string $key, StructuredField $member): self;
62+
public function append(string $key, StructuredField $member): static;
6963

7064
/**
7165
* Adds a member at the beginning of the instance and deletes any previous reference to the key if present.
7266
*
7367
* @throws SyntaxError If the string key is not a valid
74-
*
75-
* @return MemberOrderedMap<TKey, TValue>
7668
*/
77-
public function prepend(string $key, StructuredField $member): self;
69+
public function prepend(string $key, StructuredField $member): static;
7870

7971
/**
8072
* Merges multiple instances using iterable associative structures.
8173
*
8274
* @param iterable<TKey, TValue> ...$others
83-
*
84-
* @return MemberOrderedMap<TKey, TValue>
8575
*/
86-
public function mergeAssociative(iterable ...$others): self;
76+
public function mergeAssociative(iterable ...$others): static;
8777

8878
/**
8979
* Merges multiple instances using iterable pairs.
9080
*
9181
* @param MemberOrderedMap<TKey, TValue>|iterable<array{0:TKey, 1:TValue}> ...$others
92-
*
93-
* @return MemberOrderedMap<TKey, TValue>
9482
*/
95-
public function mergePairs(MemberOrderedMap|iterable ...$others): self;
83+
public function mergePairs(MemberOrderedMap|iterable ...$others): static;
9684
}

src/OrderedList.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ public function get(string|int $offset): Value|InnerList
130130
/**
131131
* Inserts members at the beginning of the list.
132132
*/
133-
public function unshift(StructuredField|Token|ByteSequence|DateTimeInterface|Stringable|string|int|float|bool ...$members): self
133+
public function unshift(StructuredField|Token|ByteSequence|DateTimeInterface|Stringable|string|int|float|bool ...$members): static
134134
{
135135
$this->members = [...array_map(self::filterMember(...), array_values($members)), ...$this->members];
136136

@@ -140,7 +140,7 @@ public function unshift(StructuredField|Token|ByteSequence|DateTimeInterface|Str
140140
/**
141141
* Inserts members at the end of the list.
142142
*/
143-
public function push(StructuredField|Token|ByteSequence|DateTimeInterface|Stringable|string|int|float|bool ...$members): self
143+
public function push(StructuredField|Token|ByteSequence|DateTimeInterface|Stringable|string|int|float|bool ...$members): static
144144
{
145145
$this->members = [...$this->members, ...array_map(self::filterMember(...), array_values($members))];
146146

@@ -152,7 +152,7 @@ public function push(StructuredField|Token|ByteSequence|DateTimeInterface|String
152152
*
153153
* @throws InvalidOffset If the index does not exist
154154
*/
155-
public function insert(int $index, StructuredField|Token|ByteSequence|DateTimeInterface|Stringable|string|int|float|bool ...$members): self
155+
public function insert(int $index, StructuredField|Token|ByteSequence|DateTimeInterface|Stringable|string|int|float|bool ...$members): static
156156
{
157157
$offset = $this->filterIndex($index);
158158
match (true) {
@@ -170,7 +170,7 @@ public function insert(int $index, StructuredField|Token|ByteSequence|DateTimeIn
170170
*
171171
* @throws InvalidOffset If the index does not exist
172172
*/
173-
public function replace(int $index, StructuredField|Token|ByteSequence|DateTimeInterface|Stringable|string|int|float|bool $member): self
173+
public function replace(int $index, StructuredField|Token|ByteSequence|DateTimeInterface|Stringable|string|int|float|bool $member): static
174174
{
175175
if (null === ($offset = $this->filterIndex($index))) {
176176
throw InvalidOffset::dueToIndexNotFound($index);
@@ -184,7 +184,7 @@ public function replace(int $index, StructuredField|Token|ByteSequence|DateTimeI
184184
/**
185185
* Deletes members associated with the list of instance indexes.
186186
*/
187-
public function remove(int ...$indexes): self
187+
public function remove(int ...$indexes): static
188188
{
189189
$offsets = array_filter(
190190
array_map(fn (int $index): int|null => $this->filterIndex($index), $indexes),
@@ -198,7 +198,7 @@ public function remove(int ...$indexes): self
198198
return $this;
199199
}
200200

201-
public function clear(): self
201+
public function clear(): static
202202
{
203203
$this->members = [];
204204

src/Parameters.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ public function pair(int $index): array
227227
/**
228228
* Adds a member at the end of the instance otherwise updates the value associated with the key if already present.
229229
*/
230-
public function set(string $key, StructuredField|Token|ByteSequence|DateTimeInterface|Stringable|string|int|float|bool $member): self
230+
public function set(string $key, StructuredField|Token|ByteSequence|DateTimeInterface|Stringable|string|int|float|bool $member): static
231231
{
232232
$this->members[MapKey::fromString($key)->value] = self::filterMember($member);
233233

@@ -246,7 +246,7 @@ private static function filterMember(StructuredField|Token|ByteSequence|DateTime
246246
/**
247247
* Deletes members associated with the list of submitted keys.
248248
*/
249-
public function delete(string ...$keys): self
249+
public function delete(string ...$keys): static
250250
{
251251
foreach ($keys as $key) {
252252
unset($this->members[$key]);
@@ -255,7 +255,7 @@ public function delete(string ...$keys): self
255255
return $this;
256256
}
257257

258-
public function clear(): self
258+
public function clear(): static
259259
{
260260
$this->members = [];
261261

@@ -265,7 +265,7 @@ public function clear(): self
265265
/**
266266
* Adds a member at the end of the instance and deletes any previous reference to the key if present.
267267
*/
268-
public function append(string $key, StructuredField|Token|ByteSequence|DateTimeInterface|Stringable|string|int|float|bool $member): self
268+
public function append(string $key, StructuredField|Token|ByteSequence|DateTimeInterface|Stringable|string|int|float|bool $member): static
269269
{
270270
unset($this->members[$key]);
271271

@@ -275,7 +275,7 @@ public function append(string $key, StructuredField|Token|ByteSequence|DateTimeI
275275
/**
276276
* Adds a member at the beginning of the instance and deletes any previous reference to the key if present.
277277
*/
278-
public function prepend(string $key, StructuredField|Token|ByteSequence|DateTimeInterface|Stringable|string|int|float|bool $member): self
278+
public function prepend(string $key, StructuredField|Token|ByteSequence|DateTimeInterface|Stringable|string|int|float|bool $member): static
279279
{
280280
unset($this->members[$key]);
281281

@@ -289,7 +289,7 @@ public function prepend(string $key, StructuredField|Token|ByteSequence|DateTime
289289
*
290290
* @param iterable<string, Value|DataType> ...$others
291291
*/
292-
public function mergeAssociative(iterable ...$others): self
292+
public function mergeAssociative(iterable ...$others): static
293293
{
294294
foreach ($others as $other) {
295295
$this->members = [...$this->members, ...self::fromAssociative($other)->members];
@@ -303,7 +303,7 @@ public function mergeAssociative(iterable ...$others): self
303303
*
304304
* @param MemberOrderedMap<string, Value>|iterable<array{0:string, 1:Value|DataType}> ...$others
305305
*/
306-
public function mergePairs(MemberOrderedMap|iterable ...$others): self
306+
public function mergePairs(MemberOrderedMap|iterable ...$others): static
307307
{
308308
foreach ($others as $other) {
309309
$this->members = [...$this->members, ...self::fromPairs($other)->members];

0 commit comments

Comments
 (0)