Skip to content

Commit 2dc5d4c

Browse files
committed
Adding the InvalidArgument exception
1 parent e5bd272 commit 2dc5d4c

File tree

6 files changed

+19
-11
lines changed

6 files changed

+19
-11
lines changed

CHANGELOG.md

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

77
### Added
88

9-
- Introduce the`MemberContainer` interface.
10-
- Introduce the`ParameterAccess` interface.
9+
- The `MemberContainer` interface.
10+
- The `ParameterAccess` interface.
11+
- The `InvaludArgument` exception.
1112
- `OrderedList`, `InnerList` now implements the `MemberList` interface.
1213
- `Parameters` and `Dictionnary` now implements the PHP `MemberOrderedMap` interface.
1314
- `Token::value` is a readonly property.

src/Dictionary.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
use Iterator;
88
use Throwable;
9-
use TypeError;
109
use function array_key_exists;
1110
use function array_keys;
1211
use function array_map;
@@ -259,7 +258,7 @@ private static function filterMember(StructuredField|ByteSequence|Token|bool|int
259258
{
260259
return match (true) {
261260
$member instanceof InnerList, $member instanceof Item => self::filterForbiddenState($member),
262-
$member instanceof StructuredField => throw new TypeError('Expecting a "'.Item::class.'" or a "'.InnerList::class.'" instance; received a "'.$member::class.'" instead.'),
261+
$member instanceof StructuredField => throw new InvalidArgument('Expecting a "'.Item::class.'" or a "'.InnerList::class.'" instance; received a "'.$member::class.'" instead.'),
263262
default => Item::from($member),
264263
};
265264
}

src/InnerList.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
use Iterator;
88
use Throwable;
9-
use TypeError;
109
use function array_filter;
1110
use function array_map;
1211
use function array_splice;
@@ -51,7 +50,7 @@ private static function filterMember(StructuredField|ByteSequence|Token|bool|int
5150
{
5251
return match (true) {
5352
$member instanceof Item => self::filterForbiddenState($member),
54-
$member instanceof StructuredField => throw new TypeError('Expecting a "'.Item::class.'" instance; received a "'.$member::class.'" instance instead.'),
53+
$member instanceof StructuredField => throw new InvalidArgument('Expecting a "'.Item::class.'" instance; received a "'.$member::class.'" instance instead.'),
5554
default => Item::from($member),
5655
};
5756
}

src/InvalidArgument.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Bakame\Http\StructuredFields;
6+
7+
use InvalidArgumentException;
8+
9+
final class InvalidArgument extends InvalidArgumentException implements StructuredFieldError
10+
{
11+
}

src/OrderedList.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
use Iterator;
88
use Throwable;
9-
use TypeError;
109
use function array_filter;
1110
use function array_map;
1211
use function array_splice;
@@ -50,7 +49,7 @@ private static function filterMember(StructuredField|ByteSequence|Token|bool|int
5049
{
5150
return match (true) {
5251
$member instanceof InnerList, $member instanceof Item => self::filterForbiddenState($member),
53-
$member instanceof StructuredField => throw new TypeError('Expecting a "'.Item::class.'" or a "'.InnerList::class.'" instance; received a "'.$member::class.'" instead.'),
52+
$member instanceof StructuredField => throw new InvalidArgument('Expecting a "'.Item::class.'" or a "'.InnerList::class.'" instance; received a "'.$member::class.'" instead.'),
5453
default => Item::from($member),
5554
};
5655
}

src/Parameters.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
use Iterator;
88
use Throwable;
9-
use TypeError;
109
use function array_key_exists;
1110
use function array_keys;
1211
use function array_map;
@@ -37,7 +36,7 @@ private function __construct(iterable $members = [])
3736

3837
/**
3938
* @throws ForbiddenStateError If the bare item contains parameters
40-
* @throws TypeError If the structured field is not supported
39+
* @throws InvalidArgument If the structured field is not supported
4140
*/
4241
private static function filterMember(Item $item, string|int $offset = null): Item
4342
{
@@ -57,7 +56,7 @@ private static function formatMember(StructuredField|ByteSequence|Token|bool|int
5756
{
5857
return match (true) {
5958
$member instanceof Item => self::filterMember($member),
60-
$member instanceof StructuredField => throw new TypeError('Expecting a "'.Item::class.'" instance; received "'.$member::class.'" instead.'),
59+
$member instanceof StructuredField => throw new InvalidArgument('Expecting a "'.Item::class.'" instance; received "'.$member::class.'" instead.'),
6160
default => Item::from($member),
6261
};
6362
}

0 commit comments

Comments
 (0)