Skip to content

Commit 520c1b5

Browse files
committed
optional paramters for fromPair is made mandatory
1 parent ed27770 commit 520c1b5

File tree

5 files changed

+24
-10
lines changed

5 files changed

+24
-10
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,15 @@ All Notable changes to `bakame/http-strucured-fields` will be documented in this
2121

2222
- Improve annotation using `@phpstan-type`
2323
- `Value` internal class to improve Item public API;
24+
- **[BC Break]** `::fromAssociative` and `::fromPair` the `$parameters` argument is now required;
2425

2526
### Deprecated
2627

2728
- None
2829

2930
### Removed
3031

32+
- **[BC Break]** Remove `Stringable` automatically converted into a string type.
3133
- **[BC Break]** `InnerList::fromPairParameters` use `InnerList::fromPair` instead.
3234
- **[BC Break]** `InnerList::fromAssociativeParameters` use `InnerList::fromAssociative` instead.
3335
- **[BC Break]** `Value` interface use a combination of `ValueAccess` **and** `ParameterAccess` instead.

src/InnerList.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,11 @@ public static function new(StructuredField|Token|ByteSequence|DateTimeInterface|
7171
/**
7272
* @param array{
7373
* 0:iterable<SfItemInput>,
74-
* 1?:MemberOrderedMap<string, SfItem>|iterable<array{0:string, 1:SfItemInput}>
74+
* 1:MemberOrderedMap<string, SfItem>|iterable<array{0:string, 1:SfItemInput}>
7575
* } $pair
7676
*/
7777
public static function fromPair(array $pair): self
7878
{
79-
$pair[1] = $pair[1] ?? [];
80-
8179
if (!array_is_list($pair)) { /* @phpstan-ignore-line */
8280
throw new SyntaxError('The pair must be represented by an array as a list.');
8381
}

src/Item.php

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ private function __construct(
3434
* in compliance with RFC8941.
3535
*
3636
* @see https://www.rfc-editor.org/rfc/rfc8941.html#section-3.3
37+
*
38+
* @throws SyntaxError If the HTTP value can not be parsed
3739
*/
3840
public static function fromHttpValue(Stringable|string $httpValue): self
3941
{
@@ -54,6 +56,8 @@ public static function fromHttpValue(Stringable|string $httpValue): self
5456
* Returns a new instance from a value type and an iterable of key-value parameters.
5557
*
5658
* @param iterable<string, SfItemInput> $parameters
59+
*
60+
* @throws SyntaxError If the value or the parameters are not valid
5761
*/
5862
public static function fromAssociative(mixed $value, iterable $parameters): self
5963
{
@@ -67,13 +71,13 @@ public static function fromAssociative(mixed $value, iterable $parameters): self
6771
/**
6872
* @param array{
6973
* 0:SfItemInput,
70-
* 1?:MemberOrderedMap<string, SfItem>|iterable<array{0:string, 1:SfItemInput}>
74+
* 1:MemberOrderedMap<string, SfItem>|iterable<array{0:string, 1:SfItemInput}>
7175
* } $pair
76+
*
77+
* @throws SyntaxError If the pair or its content is not valid.
7278
*/
7379
public static function fromPair(array $pair): self
7480
{
75-
$pair[1] = $pair[1] ?? [];
76-
7781
if (!array_is_list($pair)) { /* @phpstan-ignore-line */
7882
throw new SyntaxError('The pair must be represented by an array as a list.');
7983
}
@@ -92,11 +96,11 @@ public static function fromPair(array $pair): self
9296
/**
9397
* Returns a new bare instance from value.
9498
*
95-
* @throws SyntaxError If the value is not valid to create a Bare Item.
99+
* @throws SyntaxError If the value is not valid.
96100
*/
97101
public static function new(mixed $value): self
98102
{
99-
return new self(new Value($value), Parameters::new());
103+
return self::fromValue(new Value($value));
100104
}
101105

102106
/**
@@ -109,6 +113,8 @@ private static function fromValue(Value $value): self
109113

110114
/**
111115
* Returns a new instance from a string.
116+
*
117+
* @throws SyntaxError if the string is invalid
112118
*/
113119
public static function fromString(Stringable|string $value): self
114120
{
@@ -117,6 +123,8 @@ public static function fromString(Stringable|string $value): self
117123

118124
/**
119125
* Returns a new instance from an encoded byte sequence and an iterable of key-value parameters.
126+
*
127+
* @throws SyntaxError if the sequence is invalid
120128
*/
121129
public static function fromEncodedByteSequence(Stringable|string $value): self
122130
{
@@ -125,6 +133,8 @@ public static function fromEncodedByteSequence(Stringable|string $value): self
125133

126134
/**
127135
* Returns a new instance from a decoded byte sequence and an iterable of key-value parameters.
136+
*
137+
* @throws SyntaxError if the sequence is invalid
128138
*/
129139
public static function fromDecodedByteSequence(Stringable|string $value): self
130140
{
@@ -133,6 +143,8 @@ public static function fromDecodedByteSequence(Stringable|string $value): self
133143

134144
/**
135145
* Returns a new instance from a Token and an iterable of key-value parameters.
146+
*
147+
* @throws SyntaxError if the token is invalid
136148
*/
137149
public static function fromToken(Stringable|string $value): self
138150
{
@@ -141,6 +153,8 @@ public static function fromToken(Stringable|string $value): self
141153

142154
/**
143155
* Returns a new instance from a timestamp and an iterable of key-value parameters.
156+
*
157+
* @throws SyntaxError if the timestamp value is not supported
144158
*/
145159
public static function fromTimestamp(int $timestamp): self
146160
{

src/ItemTest.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -349,10 +349,8 @@ public function it_fails_to_access_unknown_parameter_values(): void
349349
public function it_can_create_an_item_from_a_array_of_pairs(): void
350350
{
351351
$instance1 = Item::new(Token::fromString('babayaga'));
352-
$instance2 = Item::fromPair([Token::fromString('babayaga')]);
353352
$instance3 = Item::fromPair([Token::fromString('babayaga'), []]);
354353

355-
self::assertEquals($instance2, $instance1);
356354
self::assertEquals($instance3, $instance1);
357355
}
358356

src/ValueAccess.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ public function type(): Type;
2828
* an instance that contains the specified value change.
2929
*
3030
* @param ValueAccess|SfTypeInput $value
31+
*
32+
* @throws SyntaxError If the value is invalid or not supported
3133
*/
3234
public function withValue(mixed $value): static;
3335
}

0 commit comments

Comments
 (0)