Skip to content

Commit 41bed8d

Browse files
committed
Bugfix Parameters:merge and InnerList::merge
1 parent 19f0835 commit 41bed8d

File tree

4 files changed

+22
-21
lines changed

4 files changed

+22
-21
lines changed

README.md

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,12 @@ The `toHttpValue` method returns the normalized string representation suited for
7474

7575
#### Types
7676

77-
Defined in the RFC, this package translates them to PHP native type when possible.
77+
Defined in the RFC, bare type are translated to PHP native type when possible. Two additional classes:
7878

79-
The information is represented in the table below:
79+
- `Bakame\Http\StructuredFields\Token` and
80+
- `Bakame\Http\StructuredFields\ByteSequence`
81+
82+
are used to represent non-native types as shown in the table below:
8083

8184
| HTTP DataType | Returned value | validation method |
8285
|---------------|----------------------|------------------------|
@@ -87,17 +90,10 @@ The information is represented in the table below:
8790
| Token | class `Token` | `Item::isToken` |
8891
| Byte Sequence | class `ByteSequence` | `Item::isByteSequence` |
8992

90-
Two additional classes:
91-
92-
- `Bakame\Http\StructuredFields\Token` and
93-
- `Bakame\Http\StructuredFields\ByteSequence`
94-
95-
are used to represent non-native types.
96-
9793
#### Parameters
9894

9995
As explain in the RFC, `Parameters` are containers of `Item` instances. It can be associated
100-
to other structure **BUT** the items it contains can not themselves contain `Parameters`
96+
to other structures **BUT** the items it contains can not themselves contain `Parameters`
10197
instance. More on parameters public API will be cover in subsequent paragraphs.
10298

10399
#### Examples

src/InnerList.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,10 @@ public function remove(int ...$indexes): void
147147
public function merge(self ...$others): void
148148
{
149149
foreach ($others as $other) {
150-
$this->elements = [...$this->elements, ...$other->elements];
150+
foreach ($other as $value) {
151+
$this->push($value);
152+
$this->parameters->merge($other->parameters());
153+
}
151154
}
152155
}
153156

src/InnerListTest.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -153,10 +153,10 @@ public function it_can_returns_the_container_element_keys(): void
153153
*/
154154
public function it_can_merge_one_or_more_instances(): void
155155
{
156-
$instance1 = new InnerList([Item::from(false)]);
157-
$instance2 = new InnerList([Item::from(true)]);
158-
$instance3 = new InnerList([Item::from(42)]);
159-
$expected = new InnerList([Item::from(false), Item::from(true), Item::from(42)]);
156+
$instance1 = new InnerList([false], ['foo' => 'bar']);
157+
$instance2 = new InnerList([true]);
158+
$instance3 = new InnerList([42], ['foo' => 'baz']);
159+
$expected = new InnerList([false, true, 42], ['foo' => 'baz']);
160160

161161
$instance1->merge($instance2, $instance3);
162162

@@ -169,7 +169,7 @@ public function it_can_merge_one_or_more_instances(): void
169169
*/
170170
public function it_can_merge_without_argument_and_not_throw(): void
171171
{
172-
$instance = new InnerList([Item::from(false)]);
172+
$instance = new InnerList([false]);
173173
$instance->merge();
174174
self::assertCount(1, $instance);
175175
}
@@ -179,10 +179,10 @@ public function it_can_merge_without_argument_and_not_throw(): void
179179
*/
180180
public function it_can_merge_two_or_more_instances_to_yield_different_result(): void
181181
{
182-
$instance1 = new InnerList([Item::from(false)]);
183-
$instance2 = new InnerList([Item::from(true)]);
184-
$instance3 = new InnerList([Item::from(42)]);
185-
$expected = new InnerList([Item::from(42), Item::from(true), Item::from(false)]);
182+
$instance1 = new InnerList([false], ['foo' => 'bar']);
183+
$instance2 = new InnerList([true]);
184+
$instance3 = new InnerList([42], ['foo' => 'baz']);
185+
$expected = new InnerList([42, true, false], ['foo' => 'bar']);
186186

187187
$instance3->merge($instance2, $instance1);
188188

src/Parameters.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,9 @@ public function prepend(string $key, Item|ByteSequence|Token|bool|int|float|stri
208208
public function merge(self ...$others): void
209209
{
210210
foreach ($others as $other) {
211-
$this->elements = [...$this->elements, ...$other->elements];
211+
foreach ($other as $key => $value) {
212+
$this->set($key, $value);
213+
}
212214
}
213215
}
214216
}

0 commit comments

Comments
 (0)