Skip to content

Commit f10f3c8

Browse files
committed
Update Interface signature
1 parent 7246539 commit f10f3c8

11 files changed

+40
-45
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ All Notable changes to `bakame/http-strucured-fields` will be documented in this
66

77
### Added
88

9-
- None
9+
- **[BC Break]** `MemberContainer::remove` methods get added to the interface.
1010

1111
### Fixed
1212

@@ -22,6 +22,7 @@ All Notable changes to `bakame/http-strucured-fields` will be documented in this
2222
### Removed
2323

2424
- **[BC Break]** `OrderedList` is removed use `OuterList`.
25+
- **[BC Break]** `MemberList::remove` and `MemberOrderedMap::remove` methods are removed from the interface.
2526

2627
## [0.7.0] - 2023-02-06
2728

src/ByteSequenceTest.php

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -32,34 +32,32 @@ public function it_will_fail_on_invalid_decoded_string(): void
3232
#[Test]
3333
public function it_can_decode_base64_field(): void
3434
{
35-
$source = 'cHJldGVuZCB0aGlzIGlzIGJpbmFyeSBjb250ZW50Lg==';
36-
$item = ByteSequence::fromEncoded($source);
35+
$encoded = 'cHJldGVuZCB0aGlzIGlzIGJpbmFyeSBjb250ZW50Lg==';
36+
$value = ByteSequence::fromEncoded($encoded);
3737

38-
self::assertSame('pretend this is binary content.', $item->decoded());
39-
self::assertSame($source, $item->encoded());
38+
self::assertSame('pretend this is binary content.', $value->decoded());
39+
self::assertSame($encoded, $value->encoded());
4040
}
4141

4242
#[Test]
4343
public function it_can_encode_raw_field(): void
4444
{
4545
$decoded = 'pretend this is binary content.';
46-
$source = 'cHJldGVuZCB0aGlzIGlzIGJpbmFyeSBjb250ZW50Lg==';
47-
$item = ByteSequence::fromDecoded($decoded);
46+
$encoded = 'cHJldGVuZCB0aGlzIGlzIGJpbmFyeSBjb250ZW50Lg==';
47+
$value = ByteSequence::fromDecoded($decoded);
4848

49-
self::assertSame('pretend this is binary content.', $item->decoded());
50-
self::assertSame($source, $item->encoded());
49+
self::assertSame('pretend this is binary content.', $value->decoded());
50+
self::assertSame($encoded, $value->encoded());
5151
}
5252

5353
#[Test]
5454
public function it_can_compare_instances(): void
5555
{
5656
$decoded = 'pretend this is binary content.';
57-
$source = 'cHJldGVuZCB0aGlzIGlzIGJpbmFyeSBjb250ZW50Lg==';
58-
$value1 = ByteSequence::fromDecoded($decoded);
59-
$value2 = ByteSequence::fromEncoded($source);
60-
$value3 = ByteSequence::fromDecoded($source);
57+
$encoded = 'cHJldGVuZCB0aGlzIGlzIGJpbmFyeSBjb250ZW50Lg==';
58+
$value = ByteSequence::fromDecoded($decoded);
6159

62-
self::assertTrue($value1->equals($value2));
63-
self::assertFalse($value1->equals($value3));
60+
self::assertTrue($value->equals(ByteSequence::fromEncoded($encoded)));
61+
self::assertFalse($value->equals(ByteSequence::fromDecoded($encoded)));
6462
}
6563
}

src/Dictionary.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,10 +222,10 @@ public function add(string $key, StructuredField|Token|ByteSequence|DateTimeInte
222222
return new self($members);
223223
}
224224

225-
public function remove(string ...$keys): static
225+
public function remove(string|int ...$keys): static
226226
{
227227
$members = $this->members;
228-
foreach ($keys as $key) {
228+
foreach (array_filter($keys, static fn (string|int $key): bool => is_string($key)) as $key) {
229229
unset($members[$key]);
230230
}
231231

src/DictionaryTest.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,8 @@ public function it_can_be_instantiated_with_an_collection_of_item_or_inner_list(
2525
self::assertSame(['string', $stringItem], $instance->pair(0));
2626
self::assertSame($stringItem, $instance->get('string'));
2727
self::assertTrue($instance->has('string'));
28-
self::assertEquals(
29-
[['string', $stringItem], ['boolean', $booleanItem]],
30-
[...$instance->toPairs()]
31-
);
32-
28+
self::assertFalse($instance->has('not-present'));
29+
self::assertEquals([['string', $stringItem], ['boolean', $booleanItem]], [...$instance->toPairs()]);
3330
self::assertEquals($arrayParams, [...$instance]);
3431
}
3532

@@ -45,6 +42,7 @@ public function it_can_be_instantiated_with_key_value_pairs(): void
4542
self::assertSame($stringItem, $instance->get('string'));
4643
self::assertTrue($instance->has('string'));
4744
self::assertEquals($arrayParams, [...$instance->toPairs()]);
45+
self::assertEquals(['string' => $stringItem, 'boolean' => $booleanItem], [...$instance]);
4846
}
4947

5048
#[Test]

src/InnerList.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,10 +226,13 @@ public function replace(int $index, StructuredField|Token|ByteSequence|DateTimeI
226226
/**
227227
* Delete members associated with the list of instance indexes.
228228
*/
229-
public function remove(int ...$indexes): static
229+
public function remove(string|int ...$indexes): static
230230
{
231231
$offsets = array_filter(
232-
array_map(fn (int $index): int|null => $this->filterIndex($index), $indexes),
232+
array_map(
233+
fn (int $index): int|null => $this->filterIndex($index),
234+
array_filter($indexes, static fn (string|int $key): bool => is_int($key))
235+
),
233236
fn (int|null $index): bool => null !== $index
234237
);
235238

src/MemberContainer.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,12 @@ public function get(string|int $offset): StructuredField;
3535
* Tells whether the instance contain a members at the specified offset.
3636
*/
3737
public function has(string|int $offset): bool;
38+
39+
/**
40+
* Deletes members associated with the list of submitted keys.
41+
*
42+
* This method MUST retain the state of the current instance, and return
43+
* an instance that contains the specified changes.
44+
*/
45+
public function remove(string|int ...$indexes): static;
3846
}

src/MemberList.php

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,4 @@ public function insert(int $index, StructuredField ...$members): static;
4646
* @throws InvalidOffset If the index does not exist
4747
*/
4848
public function replace(int $index, StructuredField $member): static;
49-
50-
/**
51-
* Deletes members associated with the list of submitted keys.
52-
*
53-
* This method MUST retain the state of the current instance, and return
54-
* an instance that contains the specified changes.
55-
*/
56-
public function remove(int ...$indexes): static;
5749
}

src/MemberOrderedMap.php

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,6 @@ public function keys(): array;
5252
*/
5353
public function add(string $key, StructuredField $member): static;
5454

55-
/**
56-
* Deletes members associated with the list of submitted keys.
57-
*
58-
* This method MUST retain the state of the current instance, and return
59-
* an instance that contains the specified changes.
60-
*/
61-
public function remove(string ...$keys): static;
62-
6355
/**
6456
* Adds a member at the end of the instance and deletes any previous reference to the key if present.
6557
*

src/OuterList.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,10 +202,13 @@ public function replace(int $index, StructuredField|Token|ByteSequence|DateTimeI
202202
/**
203203
* Deletes members associated with the list of instance indexes.
204204
*/
205-
public function remove(int ...$indexes): static
205+
public function remove(string|int ...$indexes): static
206206
{
207207
$offsets = array_filter(
208-
array_map(fn (int $index): int|null => $this->filterIndex($index), $indexes),
208+
array_map(
209+
fn (int $index): int|null => $this->filterIndex($index),
210+
array_filter($indexes, static fn (string|int $key): bool => is_int($key))
211+
),
209212
fn (int|null $index): bool => null !== $index
210213
);
211214

src/Parameters.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,10 +235,10 @@ public function add(string $key, StructuredField|Token|ByteSequence|DateTimeInte
235235
return new self($members);
236236
}
237237

238-
public function remove(string ...$keys): static
238+
public function remove(string|int ...$keys): static
239239
{
240240
$members = $this->members;
241-
foreach ($keys as $key) {
241+
foreach (array_filter($keys, static fn (string|int $key): bool => is_string($key)) as $key) {
242242
unset($members[$key]);
243243
}
244244

0 commit comments

Comments
 (0)