File tree Expand file tree Collapse file tree 3 files changed +25
-12
lines changed Expand file tree Collapse file tree 3 files changed +25
-12
lines changed Original file line number Diff line number Diff line change @@ -423,7 +423,7 @@ use Bakame\Http\StructuredFields\InnerList;
423
423
use Bakame\Http\StructuredFields\ValueAccess;
424
424
425
425
InnerList::fromAssociative(iterable<string , Value|DataType > $parameters, ...$members): self;
426
- InnerList::fromPairs( iterable<array {0:string, 1:Value|DataType} >} $parameters, ...$members ): self;
426
+ InnerList::fromPair(array{0:list< Item >, iterable<array {0:string, 1:Value|DataType} >} $pair ): self;
427
427
```
428
428
429
429
## Contributing
Original file line number Diff line number Diff line change @@ -59,13 +59,28 @@ public static function from(StructuredField|Value|Token|ByteSequence|DateTimeInt
59
59
}
60
60
61
61
/**
62
- * @param MemberOrderedMap<string, SfItem>|iterable<array{0:string, 1:SfItemInput}> $parameters
62
+ * @param array{
63
+ * 0:iterable<SfItemInput>,
64
+ * 1?:MemberOrderedMap<string, SfItem>|iterable<array{0:string, 1:SfItemInput}>
65
+ * } $pair
63
66
*/
64
- public static function fromPairs (
65
- iterable $ parameters ,
66
- StructuredField |Value |Token |ByteSequence |DateTimeInterface |Stringable |string |int |float |bool ...$ members
67
- ): self {
68
- return new self (Parameters::fromPairs ($ parameters ), $ members );
67
+ public static function fromPair (array $ pair ): self
68
+ {
69
+ $ pair [1 ] = $ pair [1 ] ?? [];
70
+
71
+ if (!array_is_list ($ pair )) { /* @phpstan-ignore-line */
72
+ throw new SyntaxError ('The pair must be represented by an array as a list. ' );
73
+ }
74
+
75
+ if (2 !== count ($ pair )) { /* @phpstan-ignore-line */
76
+ throw new SyntaxError ('The pair first value should be the member list and the optional second value the inner list parameters. ' );
77
+ }
78
+
79
+ if (!$ pair [1 ] instanceof Parameters) {
80
+ $ pair [1 ] = Parameters::fromPairs ($ pair [1 ]);
81
+ }
82
+
83
+ return new self ($ pair [1 ], $ pair [0 ]);
69
84
}
70
85
71
86
/**
Original file line number Diff line number Diff line change @@ -195,12 +195,10 @@ public function it_can_create_via_with_parameters_method_a_new_object(): void
195
195
'a ' ,
196
196
true
197
197
);
198
- $ instance1bis = InnerList::fromPairs (
198
+ $ instance1bis = InnerList::fromPair ([
199
+ [Token::fromString ('babayaga ' ), 'a ' , true ],
199
200
[['a ' , true ]],
200
- Token::fromString ('babayaga ' ),
201
- 'a ' ,
202
- true
203
- );
201
+ ]);
204
202
$ instance2 = $ instance1 ->withParameters (Parameters::fromAssociative (['a ' => true ]));
205
203
$ instance3 = $ instance1 ->withParameters (Parameters::fromAssociative (['a ' => false ]));
206
204
You can’t perform that action at this time.
0 commit comments