Skip to content

Commit c1def9e

Browse files
committed
Remove Parameters::fromItems
1 parent 7b16f3d commit c1def9e

File tree

4 files changed

+12
-25
lines changed

4 files changed

+12
-25
lines changed

src/Dictionary.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,20 +57,20 @@ public static function fromHttpValue(string $httpValue): self
5757
*
5858
* @return array{0:string, 1:string}
5959
*/
60-
private static function extractPair(string $element): array
60+
private static function extractPair(string $pair): array
6161
{
62-
$element = trim($element);
62+
$pair = trim($pair);
6363

64-
if ('' === $element) {
65-
throw new SyntaxError('Dictionary pair can not be empty.');
64+
if ('' === $pair) {
65+
throw new SyntaxError('The HTTP textual representation for a dictionary pair can not be empty.');
6666
}
6767

68-
if (1 !== preg_match('/^(?<key>[a-z*][a-z0-9.*_-]*)(=)?(?<value>.*)/', $element, $found)) {
69-
throw new SyntaxError("The HTTP textual representation `$element` for a dictionary pair contains invalid characters.");
68+
if (1 !== preg_match('/^(?<key>[a-z*][a-z0-9.*_-]*)(=)?(?<value>.*)/', $pair, $found)) {
69+
throw new SyntaxError("The HTTP textual representation `$pair` for a dictionary pair contains invalid characters.");
7070
}
7171

7272
if (rtrim($found['key']) !== $found['key'] || ltrim($found['value']) !== $found['value']) {
73-
throw new SyntaxError("The HTTP textual representation `$element` for a dictionary pair contains invalid characters.");
73+
throw new SyntaxError("The HTTP textual representation `$pair` for a dictionary pair contains invalid characters.");
7474
}
7575

7676
$found['value'] = trim($found['value']);

src/InnerList.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public function __construct(iterable $elements = [], iterable $parameters = [])
2828
$this->push($element);
2929
}
3030

31-
$this->parameters = $parameters instanceof Parameters ? $parameters : Parameters::fromItems($parameters);
31+
$this->parameters = $parameters instanceof Parameters ? $parameters : new Parameters($parameters);
3232
}
3333

3434
public static function fromHttpValue(string $httpValue): self

src/Item.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public static function from(
2424
is_float($value) => self::filterDecimal($value),
2525
is_string($value) => self::filterString($value),
2626
default => $value,
27-
}, $parameters instanceof Parameters ? $parameters : Parameters::fromItems($parameters));
27+
}, $parameters instanceof Parameters ? $parameters : new Parameters($parameters));
2828
}
2929

3030
public static function filterDecimal(float $value): float

src/Parameters.php

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,29 +17,16 @@ final class Parameters implements Countable, IteratorAggregate, StructuredField
1717
private array $elements;
1818

1919
/**
20-
* @param iterable<string, Item> $elements
20+
* @param iterable<array-key, Item|Token|ByteSequence|float|int|bool|string> $elements
2121
*/
2222
public function __construct(iterable $elements = [])
2323
{
2424
$this->elements = [];
25-
foreach ($elements as $key => $value) {
26-
$this->set($key, $value);
25+
foreach ($elements as $key => $element) {
26+
$this->set($key, self::filterElement($element));
2727
}
2828
}
2929

30-
/**
31-
* @param iterable<array-key, Item|Token|ByteSequence|float|int|bool|string> $items
32-
*/
33-
public static function fromItems(iterable $items): self
34-
{
35-
$instance = new self();
36-
foreach ($items as $key => $item) {
37-
$instance->set($key, self::filterElement($item));
38-
}
39-
40-
return $instance;
41-
}
42-
4330
private static function filterElement(Item|ByteSequence|Token|bool|int|float|string $element): Item
4431
{
4532
return match (true) {

0 commit comments

Comments
 (0)