22
22
*
23
23
* @phpstan-import-type SfItem from StructuredField
24
24
* @phpstan-import-type SfItemInput from StructuredField
25
+ *
25
26
* @implements MemberList<int, SfItem>
26
27
*/
27
28
final class InnerList implements MemberList, ParameterAccess
@@ -62,11 +63,18 @@ public static function fromHttpValue(Stringable|string $httpValue): self
62
63
}
63
64
64
65
/**
65
- * Returns a new instance.
66
+ * Returns a new instance with an iter.
67
+ *
68
+ * @param iterable<SfItemInput> $value
69
+ * @param iterable<string, SfItemInput> $parameters
66
70
*/
67
- public static function new ( StructuredField | Token | ByteSequence | DateTimeInterface | string | int | float | bool ... $ members ): self
71
+ public static function fromAssociative ( iterable $ value , iterable $ parameters ): self
68
72
{
69
- return new self ($ members , Parameters::new ());
73
+ if (!$ parameters instanceof Parameters) {
74
+ $ parameters = Parameters::fromAssociative ($ parameters );
75
+ }
76
+
77
+ return new self ($ value , $ parameters );
70
78
}
71
79
72
80
/**
@@ -93,32 +101,11 @@ public static function fromPair(array $pair): self
93
101
}
94
102
95
103
/**
96
- * Returns a new instance with an iter.
97
- *
98
- * @param iterable<SfItemInput> $value
99
- * @param iterable<string, SfItemInput> $parameters
104
+ * Returns a new instance.
100
105
*/
101
- public static function fromAssociative (iterable $ value , iterable $ parameters ): self
102
- {
103
- if (!$ parameters instanceof Parameters) {
104
- $ parameters = Parameters::fromAssociative ($ parameters );
105
- }
106
-
107
- return new self ($ value , $ parameters );
108
- }
109
-
110
- public function parameters (): Parameters
111
- {
112
- return $ this ->parameters ;
113
- }
114
-
115
- public function parameter (string $ key ): mixed
106
+ public static function new (StructuredField |Token |ByteSequence |DateTimeInterface |string |int |float |bool ...$ members ): self
116
107
{
117
- try {
118
- return $ this ->parameters ->get ($ key )->value ();
119
- } catch (StructuredFieldError ) {
120
- return null ;
121
- }
108
+ return new self ($ members , Parameters::new ());
122
109
}
123
110
124
111
public function toHttpValue (): string
@@ -139,6 +126,25 @@ public function toPair(): array
139
126
return [$ this ->members , $ this ->parameters ];
140
127
}
141
128
129
+ public function getIterator (): Iterator
130
+ {
131
+ yield from $ this ->members ;
132
+ }
133
+
134
+ public function parameters (): Parameters
135
+ {
136
+ return $ this ->parameters ;
137
+ }
138
+
139
+ public function parameter (string $ key ): mixed
140
+ {
141
+ try {
142
+ return $ this ->parameters ->get ($ key )->value ();
143
+ } catch (StructuredFieldError ) {
144
+ return null ;
145
+ }
146
+ }
147
+
142
148
public function count (): int
143
149
{
144
150
return count ($ this ->members );
@@ -162,11 +168,6 @@ public function keys(): array
162
168
return array_keys ($ this ->members );
163
169
}
164
170
165
- public function getIterator (): Iterator
166
- {
167
- yield from $ this ->members ;
168
- }
169
-
170
171
public function has (string |int ...$ keys ): bool
171
172
{
172
173
foreach ($ keys as $ offset ) {
@@ -208,34 +209,6 @@ public function get(string|int $key): StructuredField
208
209
return $ this ->members [$ index ];
209
210
}
210
211
211
- /**
212
- * @param int $offset
213
- */
214
- public function offsetExists (mixed $ offset ): bool
215
- {
216
- return $ this ->has ($ offset );
217
- }
218
-
219
- /**
220
- * @param int $offset
221
- *
222
- * @return SfItem
223
- */
224
- public function offsetGet (mixed $ offset ): mixed
225
- {
226
- return $ this ->get ($ offset );
227
- }
228
-
229
- public function offsetUnset (mixed $ offset ): void
230
- {
231
- throw new ForbiddenOperation (self ::class.' instance can not be updated using ' .ArrayAccess::class.' methods. ' );
232
- }
233
-
234
- public function offsetSet (mixed $ offset , mixed $ value ): void
235
- {
236
- throw new ForbiddenOperation (self ::class.' instance can not be updated using ' .ArrayAccess::class.' methods. ' );
237
- }
238
-
239
212
/**
240
213
* Inserts members at the beginning of the list.
241
214
*/
@@ -288,8 +261,13 @@ public function replace(int $key, StructuredField|Token|ByteSequence|DateTimeInt
288
261
throw InvalidOffset::dueToIndexNotFound ($ key );
289
262
}
290
263
264
+ $ member = self ::filterMember ($ member );
265
+ if ($ member == $ this ->members [$ offset ]) {
266
+ return $ this ;
267
+ }
268
+
291
269
$ members = $ this ->members ;
292
- $ members [$ offset ] = $ member ;
270
+ $ members [$ offset ] = self :: filterMember ( $ member) ;
293
271
294
272
return new self ($ members , $ this ->parameters );
295
273
}
@@ -315,6 +293,34 @@ public function remove(string|int ...$keys): static
315
293
), $ this ->parameters );
316
294
}
317
295
296
+ /**
297
+ * @param int $offset
298
+ */
299
+ public function offsetExists (mixed $ offset ): bool
300
+ {
301
+ return $ this ->has ($ offset );
302
+ }
303
+
304
+ /**
305
+ * @param int $offset
306
+ *
307
+ * @return SfItem
308
+ */
309
+ public function offsetGet (mixed $ offset ): mixed
310
+ {
311
+ return $ this ->get ($ offset );
312
+ }
313
+
314
+ public function offsetUnset (mixed $ offset ): void
315
+ {
316
+ throw new ForbiddenOperation (self ::class.' instance can not be updated using ' .ArrayAccess::class.' methods. ' );
317
+ }
318
+
319
+ public function offsetSet (mixed $ offset , mixed $ value ): void
320
+ {
321
+ throw new ForbiddenOperation (self ::class.' instance can not be updated using ' .ArrayAccess::class.' methods. ' );
322
+ }
323
+
318
324
public function withParameters (Parameters $ parameters ): static
319
325
{
320
326
return ($ this ->parameters ->toHttpValue () === $ parameters ->toHttpValue ()) ? $ this : new self ($ this ->members , $ parameters );
0 commit comments