@@ -15,7 +15,7 @@ final class Dictionary implements Countable, IteratorAggregate, StructuredField
15
15
{
16
16
private function __construct (
17
17
/** @var array<string, Item|InnerList> */
18
- private array $ elements = []
18
+ private array $ members = []
19
19
) {
20
20
}
21
21
@@ -25,13 +25,13 @@ private function __construct(
25
25
* its keys represent the dictionary entry key
26
26
* its values represent the dictionary entry value
27
27
*
28
- * @param iterable<string, InnerList|Item|ByteSequence|Token|bool|int|float|string> $elements
28
+ * @param iterable<string, InnerList|Item|ByteSequence|Token|bool|int|float|string> $members
29
29
*/
30
- public static function fromAssociative (iterable $ elements = []): self
30
+ public static function fromAssociative (iterable $ members = []): self
31
31
{
32
32
$ instance = new self ();
33
- foreach ($ elements as $ index => $ element ) {
34
- $ instance ->set ($ index , $ element );
33
+ foreach ($ members as $ index => $ member ) {
34
+ $ instance ->set ($ index , $ member );
35
35
}
36
36
37
37
return $ instance ;
@@ -40,17 +40,17 @@ public static function fromAssociative(iterable $elements = []): self
40
40
/**
41
41
* Returns a new instance from a pair iterable construct.
42
42
*
43
- * Each element is composed of an array with two elements
44
- * the first element represents the instance entry key
45
- * the second element represents the instance entry value
43
+ * Each member is composed of an array with two elements
44
+ * the first member represents the instance entry key
45
+ * the second member represents the instance entry value
46
46
*
47
47
* @param iterable<array{0:string, 1:InnerList|Item|ByteSequence|Token|bool|int|float|string}> $pairs
48
48
*/
49
49
public static function fromPairs (iterable $ pairs = []): self
50
50
{
51
51
$ instance = new self ();
52
- foreach ($ pairs as [$ key , $ element ]) {
53
- $ instance ->set ($ key , $ element );
52
+ foreach ($ pairs as [$ key , $ member ]) {
53
+ $ instance ->set ($ key , $ member );
54
54
}
55
55
56
56
return $ instance ;
@@ -69,10 +69,10 @@ public static function fromHttpValue(string $httpValue): self
69
69
public function toHttpValue (): string
70
70
{
71
71
$ returnValue = [];
72
- foreach ($ this ->elements as $ key => $ element ) {
72
+ foreach ($ this ->members as $ key => $ member ) {
73
73
$ returnValue [] = match (true ) {
74
- $ element instanceof Item && true === $ element ->value () => $ key .$ element ->parameters ()->toHttpValue (),
75
- default => $ key .'= ' .$ element ->toHttpValue (),
74
+ $ member instanceof Item && true === $ member ->value () => $ key .$ member ->parameters ()->toHttpValue (),
75
+ default => $ key .'= ' .$ member ->toHttpValue (),
76
76
};
77
77
}
78
78
@@ -81,21 +81,21 @@ public function toHttpValue(): string
81
81
82
82
public function count (): int
83
83
{
84
- return count ($ this ->elements );
84
+ return count ($ this ->members );
85
85
}
86
86
87
87
public function isEmpty (): bool
88
88
{
89
- return [] === $ this ->elements ;
89
+ return [] === $ this ->members ;
90
90
}
91
91
92
92
/**
93
93
* @return Iterator<string, Item|InnerList>
94
94
*/
95
95
public function getIterator (): Iterator
96
96
{
97
- foreach ($ this ->elements as $ index => $ element ) {
98
- yield $ index => $ element ;
97
+ foreach ($ this ->members as $ index => $ member ) {
98
+ yield $ index => $ member ;
99
99
}
100
100
}
101
101
@@ -106,8 +106,8 @@ public function getIterator(): Iterator
106
106
*/
107
107
public function toPairs (): Iterator
108
108
{
109
- foreach ($ this ->elements as $ index => $ element ) {
110
- yield [$ index , $ element ];
109
+ foreach ($ this ->members as $ index => $ member ) {
110
+ yield [$ index , $ member ];
111
111
}
112
112
}
113
113
@@ -116,21 +116,21 @@ public function toPairs(): Iterator
116
116
*/
117
117
public function keys (): array
118
118
{
119
- return array_keys ($ this ->elements );
119
+ return array_keys ($ this ->members );
120
120
}
121
121
122
122
public function has (string $ key ): bool
123
123
{
124
- return array_key_exists ($ key , $ this ->elements );
124
+ return array_key_exists ($ key , $ this ->members );
125
125
}
126
126
127
127
public function get (string $ key ): Item |InnerList
128
128
{
129
- if (!array_key_exists ($ key , $ this ->elements )) {
129
+ if (!array_key_exists ($ key , $ this ->members )) {
130
130
throw InvalidOffset::dueToKeyNotFound ($ key );
131
131
}
132
132
133
- return $ this ->elements [$ key ];
133
+ return $ this ->members [$ key ];
134
134
}
135
135
136
136
public function hasPair (int $ index ): bool
@@ -140,10 +140,10 @@ public function hasPair(int $index): bool
140
140
141
141
private function filterIndex (int $ index ): int |null
142
142
{
143
- $ max = count ($ this ->elements );
143
+ $ max = count ($ this ->members );
144
144
145
145
return match (true ) {
146
- [] === $ this ->elements , 0 > $ max + $ index , 0 > $ max - $ index - 1 => null ,
146
+ [] === $ this ->members , 0 > $ max + $ index , 0 > $ max - $ index - 1 => null ,
147
147
0 > $ index => $ max + $ index ,
148
148
default => $ index ,
149
149
};
@@ -160,19 +160,19 @@ public function pair(int $index): array
160
160
}
161
161
162
162
return [
163
- array_keys ($ this ->elements )[$ offset ],
164
- array_values ($ this ->elements )[$ offset ],
163
+ array_keys ($ this ->members )[$ offset ],
164
+ array_values ($ this ->members )[$ offset ],
165
165
];
166
166
}
167
167
168
168
/**
169
- * Add an element at the end of the instance if the key is new otherwise update the value associated with the key.
169
+ * Add a member at the end of the instance if the key is new otherwise update the value associated with the key.
170
170
*/
171
- public function set (string $ key , InnerList |Item |ByteSequence |Token |bool |int |float |string $ element ): void
171
+ public function set (string $ key , InnerList |Item |ByteSequence |Token |bool |int |float |string $ member ): void
172
172
{
173
173
self ::validateKey ($ key );
174
174
175
- $ this ->elements [$ key ] = self ::filterElement ( $ element );
175
+ $ this ->members [$ key ] = self ::filterMember ( $ member );
176
176
}
177
177
178
178
/**
@@ -185,54 +185,54 @@ private static function validateKey(string $key): void
185
185
}
186
186
}
187
187
188
- private static function filterElement (InnerList |Item |ByteSequence |Token |bool |int |float |string $ element ): InnerList |Item
188
+ private static function filterMember (InnerList |Item |ByteSequence |Token |bool |int |float |string $ member ): InnerList |Item
189
189
{
190
190
return match (true ) {
191
- $ element instanceof InnerList, $ element instanceof Item => $ element ,
192
- default => Item::from ($ element ),
191
+ $ member instanceof InnerList, $ member instanceof Item => $ member ,
192
+ default => Item::from ($ member ),
193
193
};
194
194
}
195
195
196
196
/**
197
- * Delete elements associated with the list of submitted keys.
197
+ * Delete members associated with the list of submitted keys.
198
198
*/
199
199
public function delete (string ...$ keys ): void
200
200
{
201
201
foreach ($ keys as $ key ) {
202
- unset($ this ->elements [$ key ]);
202
+ unset($ this ->members [$ key ]);
203
203
}
204
204
}
205
205
206
206
/**
207
- * Remove all elements from the instance.
207
+ * Remove all members from the instance.
208
208
*/
209
209
public function clear (): void
210
210
{
211
- $ this ->elements = [];
211
+ $ this ->members = [];
212
212
}
213
213
214
214
/**
215
- * Add an element at the end of the instance if the key is new delete any previous reference to the key.
215
+ * Add a member at the end of the instance if the key is new delete any previous reference to the key.
216
216
*/
217
- public function append (string $ key , InnerList |Item |ByteSequence |Token |bool |int |float |string $ element ): void
217
+ public function append (string $ key , InnerList |Item |ByteSequence |Token |bool |int |float |string $ member ): void
218
218
{
219
219
self ::validateKey ($ key );
220
220
221
- unset($ this ->elements [$ key ]);
221
+ unset($ this ->members [$ key ]);
222
222
223
- $ this ->elements [$ key ] = self ::filterElement ( $ element );
223
+ $ this ->members [$ key ] = self ::filterMember ( $ member );
224
224
}
225
225
226
226
/**
227
- * Add an element at the beginning of the instance if the key is new delete any previous reference to the key.
227
+ * Add a member at the beginning of the instance if the key is new delete any previous reference to the key.
228
228
*/
229
- public function prepend (string $ key , InnerList |Item |ByteSequence |Token |bool |int |float |string $ element ): void
229
+ public function prepend (string $ key , InnerList |Item |ByteSequence |Token |bool |int |float |string $ member ): void
230
230
{
231
231
self ::validateKey ($ key );
232
232
233
- unset($ this ->elements [$ key ]);
233
+ unset($ this ->members [$ key ]);
234
234
235
- $ this ->elements = [...[$ key => self ::filterElement ( $ element )], ...$ this ->elements ];
235
+ $ this ->members = [...[$ key => self ::filterMember ( $ member )], ...$ this ->members ];
236
236
}
237
237
238
238
/**
@@ -241,7 +241,7 @@ public function prepend(string $key, InnerList|Item|ByteSequence|Token|bool|int|
241
241
public function merge (self ...$ others ): void
242
242
{
243
243
foreach ($ others as $ other ) {
244
- $ this ->elements = [...$ this ->elements , ...$ other ->elements ];
244
+ $ this ->members = [...$ this ->members , ...$ other ->members ];
245
245
}
246
246
}
247
247
}
0 commit comments