Skip to content

Commit b1b803b

Browse files
committed
Usage of merge method made consistent
1 parent b0ab252 commit b1b803b

File tree

8 files changed

+12
-125
lines changed

8 files changed

+12
-125
lines changed

CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ All Notable changes to `bakame/http-strucured-fields` will be documented in this
1212
- `OrderedList::from` named constructor which accepts a variadic list of members items
1313
- `Token::fromString` named constructor which accepts `string` and `Stringable` object
1414
- `Parameter::values` returns an array of all the values contained inside the `Parameters` instance
15-
- `Parameter::merge` accepts any iterable that can be accepted by `Parameter::fromAssociative` as variadic parameter
1615
- **[BC Break]** `InnerList::fromList` to replace `InnerList::fromMembers`
1716
- **[BC Break]** `OrderedList::fromList` to replace `OrderedList::fromMembers`
1817
- **[BC Break]** `Parameter::value` to replace `InnerList::parameter` and `Item::parameter`
@@ -21,6 +20,8 @@ All Notable changes to `bakame/http-strucured-fields` will be documented in this
2120

2221
- `ByteSequence::fromDecoded` named constructor also accepts a `Stringable` object
2322
- `ByteSequence::fromEncoded` named constructor also accepts a `Stringable` object
23+
- `Dictionary::merge` accepts any iterable that can be accepted by `Dictionary::fromAssociative` as variadic parameter
24+
- `Parameter::merge` accepts any iterable that can be accepted by `Parameter::fromAssociative` as variadic parameter
2425
- **[BC Break]** `OrderedList::__construct` is made private use `OrderedList::from` instead
2526
- **[BC Break]** `InnerList::__construct` is made private use `InnerList::fromList` instead
2627
- **[BC Break]** `Token::__construct` is made private use `Token::fromString` instead
@@ -39,6 +40,8 @@ All Notable changes to `bakame/http-strucured-fields` will be documented in this
3940
- **[BC Break]** `Item::value()` replaced by `Item::value` public readonly property
4041
- **[BC Break]** `Item::parameters()` replaced by `Item::parameters` public readonly property
4142
- **[BC Break]** `InnerList::parameters()` replaced by `InnerList::parameters` public readonly property
43+
- **[BC Break]** `InnerList::merge()` use `InnerList::push()` or `InnerList::unshift()` instead
44+
- **[BC Break]** `OrderedList::merge()` use `OrderedList::push()` or `OrderedList::unshift()` instead
4245

4346
## [0.1.0] - 2022-03-18
4447

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use Bakame\Http\StructuredFields\Item;
2626
$field = Item::from("/terms", ['rel' => "copyright", 'anchor' => '#foo']);
2727
echo $field->toHttpValue(); //display "/terms";rel="copyright";anchor="#foo"
2828
echo $field->value; //display "/terms"
29-
echo $field->parameter->value('rel'); //display "copyright"
29+
echo $field->parameters->value('rel'); //display "copyright"
3030
```
3131

3232
System Requirements
@@ -160,7 +160,6 @@ At any given time it is possible with each of these objects to:
160160
- iterate over each contained member and its optional associated key via the `IteratorAggregate` interface;
161161
- tell whether the container is empty via an `isEmpty` method;
162162
- know the number of members contained in the container via the `Countable` interface;
163-
- merge multiple instance of **the same type** using the `merge` method;
164163
- clear the container using the `clear` method;
165164

166165
```php
@@ -189,6 +188,7 @@ key to its members as such they expose the following methods:
189188
- `prepend` always add an element at the beginning of the container, if already present the previous value is removed;
190189
- `delete` to remove elements based on their associated keys;
191190
- `keys` to list all existing keys for the ordered maps as an array list;
191+
- `merge` merge multiple instances of iterable structure as associative constructs;
192192

193193
```php
194194
use Bakame\Http\StructuredFields\Dictionary;

phpstan.neon

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,6 @@ parameters:
99
ignoreErrors:
1010
- message: '#Method Bakame\\Http\\StructuredFields\\Parameters::merge\(\) has parameter \$others with no value type specified in iterable type iterable.#'
1111
path: src/Parameters.php
12+
- message: '#Method Bakame\\Http\\StructuredFields\\Dictionary::merge\(\) has parameter \$others with no value type specified in iterable type iterable.#'
13+
path: src/Dictionary.php
1214
reportUnmatchedIgnoredErrors: true

src/Dictionary.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,11 +253,13 @@ public function prepend(string $key, InnerList|Item|ByteSequence|Token|bool|int|
253253

254254
/**
255255
* Merge multiple instances.
256+
*
257+
* iterable<array-key, InnerList|Item|Token|ByteSequence|float|int|bool|string> ...$others
256258
*/
257-
public function merge(self ...$others): void
259+
public function merge(iterable ...$others): void
258260
{
259261
foreach ($others as $other) {
260-
$this->members = [...$this->members, ...$other->members];
262+
$this->members = [...$this->members, ...self::fromAssociative($other)->members];
261263
}
262264
}
263265
}

src/InnerList.php

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -184,15 +184,4 @@ public function clear(): void
184184
{
185185
$this->members = [];
186186
}
187-
188-
/**
189-
* Merge multiple instances.
190-
*/
191-
public function merge(self ...$others): void
192-
{
193-
foreach ($others as $other) {
194-
$this->members = [...$this->members, ...$other->members];
195-
$this->parameters->merge($other->parameters);
196-
}
197-
}
198187
}

src/InnerListTest.php

Lines changed: 0 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -114,48 +114,6 @@ public function it_fails_to_return_an_member_with_invalid_index(): void
114114
$instance->get(3);
115115
}
116116

117-
/**
118-
* @test
119-
*/
120-
public function it_can_merge_one_or_more_instances(): void
121-
{
122-
$instance1 = InnerList::fromList([false], ['foo' => 'bar']);
123-
$instance2 = InnerList::from(true);
124-
$instance3 = InnerList::fromList([42], ['foo' => 'baz']);
125-
$expected = InnerList::fromList([false, true, 42], ['foo' => 'baz']);
126-
127-
$instance1->merge($instance2, $instance3);
128-
129-
self::assertCount(3, $instance1);
130-
self::assertSame($expected->toHttpValue(), $instance1->toHttpValue());
131-
}
132-
133-
/**
134-
* @test
135-
*/
136-
public function it_can_merge_without_argument_and_not_throw(): void
137-
{
138-
$instance = InnerList::from(false);
139-
$instance->merge();
140-
self::assertCount(1, $instance);
141-
}
142-
143-
/**
144-
* @test
145-
*/
146-
public function it_can_merge_two_or_more_instances_to_yield_different_result(): void
147-
{
148-
$instance1 = InnerList::fromList([false], ['foo' => 'bar']);
149-
$instance2 = InnerList::from(true);
150-
$instance3 = InnerList::fromList([42], ['foo' => 'baz']);
151-
$expected = InnerList::fromList([42, true, false], ['foo' => 'bar']);
152-
153-
$instance3->merge($instance2, $instance1);
154-
155-
self::assertCount(3, $instance3);
156-
self::assertSame($expected->toHttpValue(), $instance3->toHttpValue());
157-
}
158-
159117
/**
160118
* @test
161119
*/
@@ -189,19 +147,4 @@ public function it_fails_to_access_unknown_parameter_values(): void
189147
$instance = InnerList::fromList([false], ['foo' => 'bar']);
190148
$instance->parameters->value('bar');
191149
}
192-
193-
/**
194-
* @test
195-
*/
196-
public function it_can_exchange_parameters(): void
197-
{
198-
$instance = InnerList::from(false, true, 42, 'forty-two');
199-
200-
self::assertCount(0, $instance->parameters);
201-
$instance->parameters->clear();
202-
$instance->parameters->merge(['foo' => 'bar']);
203-
204-
self::assertCount(1, $instance->parameters);
205-
self::assertSame('bar', $instance->parameters->value('foo'));
206-
}
207150
}

src/OrderedList.php

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -195,14 +195,4 @@ public function clear(): void
195195
{
196196
$this->members = [];
197197
}
198-
199-
/**
200-
* Merge multiple instances.
201-
*/
202-
public function merge(self ...$others): void
203-
{
204-
foreach ($others as $other) {
205-
$this->members = [...$this->members, ...$other->members];
206-
}
207-
}
208198
}

src/OrderedListTest.php

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -115,48 +115,6 @@ public function it_fails_to_return_an_member_with_invalid_index(): void
115115
$instance->get(3);
116116
}
117117

118-
/**
119-
* @test
120-
*/
121-
public function it_can_merge_one_or_more_instances(): void
122-
{
123-
$instance1 = OrderedList::fromList([Item::from(false)]);
124-
$instance2 = OrderedList::fromList([Item::from(true)]);
125-
$instance3 = OrderedList::fromList([Item::from(42)]);
126-
$expected = OrderedList::fromList([Item::from(false), Item::from(true), Item::from(42)]);
127-
128-
$instance1->merge($instance2, $instance3);
129-
130-
self::assertCount(3, $instance1);
131-
self::assertSame($expected->toHttpValue(), $instance1->toHttpValue());
132-
}
133-
134-
/**
135-
* @test
136-
*/
137-
public function it_can_merge_two_or_more_instances_to_yield_different_result(): void
138-
{
139-
$instance1 = OrderedList::fromList([Item::from(false)]);
140-
$instance2 = OrderedList::fromList([Item::from(true)]);
141-
$instance3 = OrderedList::fromList([Item::from(42)]);
142-
$expected = OrderedList::fromList([Item::from(42), Item::from(true), Item::from(false)]);
143-
144-
$instance3->merge($instance2, $instance1);
145-
146-
self::assertCount(3, $instance3);
147-
self::assertSame($expected->toHttpValue(), $instance3->toHttpValue());
148-
}
149-
150-
/**
151-
* @test
152-
*/
153-
public function it_can_merge_without_argument_and_not_throw(): void
154-
{
155-
$instance = OrderedList::fromList([Item::from(false)]);
156-
$instance->merge();
157-
self::assertCount(1, $instance);
158-
}
159-
160118
/**
161119
* @test
162120
*/

0 commit comments

Comments
 (0)