Skip to content

Commit 2976a1a

Browse files
committed
Improve Ite;::fromHttpValue implementation
1 parent 8773484 commit 2976a1a

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

src/Item.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
use function count;
1212
use function preg_match;
1313
use function str_contains;
14-
use function strlen;
1514
use function substr;
1615
use function trim;
1716

@@ -45,11 +44,12 @@ public static function fromHttpValue(Stringable|string $httpValue): self
4544
}
4645

4746
[$value, $offset] = Parser::parseBareItem($itemString);
48-
if (!str_contains($itemString, ';') && $offset !== strlen($itemString)) {
47+
$remainder = substr($itemString, $offset);
48+
if ('' !== $remainder && !str_contains($remainder, ';')) {
4949
throw new SyntaxError('The HTTP textual representation "'.$httpValue.'" for an item contains invalid characters.');
5050
}
5151

52-
return new self(new Value($value), Parameters::fromHttpValue(substr($itemString, $offset)));
52+
return new self(new Value($value), Parameters::fromHttpValue($remainder));
5353
}
5454

5555
/**

src/Parameters.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ private function __construct(iterable $members = [])
5151
private static function filterMember(mixed $member): object
5252
{
5353
return match (true) {
54-
$member instanceof ValueAccess && $member instanceof ParameterAccess => $member->parameters()->hasNoMembers() ? $member : throw new InvalidArgument('The instance of "'.$member::class.'" is not a Bare Item.'),
54+
$member instanceof ValueAccess && $member instanceof ParameterAccess => $member->parameters()->hasNoMembers() ? $member : throw new InvalidArgument('The "'.$member::class.'" instance is not a Bare Item.'),
5555
$member instanceof StructuredField => throw new InvalidArgument('An instance of "'.$member::class.'" can not be a member of "'.self::class.'".'),
5656
default => Item::new($member),
5757
};

0 commit comments

Comments
 (0)