Skip to content

Commit b34244d

Browse files
committed
Improve Item Datatype classes
1 parent c05b3a5 commit b34244d

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

src/ByteSequence.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
final class ByteSequence
1313
{
1414
private function __construct(
15-
private string $value
15+
private readonly string $value
1616
) {
1717
}
1818

@@ -21,12 +21,15 @@ private function __construct(
2121
*/
2222
public static function fromEncoded(Stringable|string $encodedValue): self
2323
{
24-
if (1 !== preg_match('/^(?<bytes>[a-z\d+\/=]*)$/i', (string) $encodedValue, $matches)) {
24+
$encodedValue = (string) $encodedValue;
25+
if (1 !== preg_match('/^[a-z\d+\/=]*$/i', $encodedValue)) {
2526
throw new SyntaxError('Invalid character in byte sequence');
2627
}
2728

28-
/** @var string $decoded */
29-
$decoded = base64_decode($matches['bytes'], true);
29+
$decoded = base64_decode($encodedValue, true);
30+
if (false === $decoded) {
31+
throw new SyntaxError('Invalid character in byte sequence');
32+
}
3033

3134
return new self($decoded);
3235
}

src/Item.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
final class Item implements StructuredField, ParameterAccess
2424
{
2525
private function __construct(
26-
private Token|ByteSequence|int|float|string|bool $value,
26+
private readonly Token|ByteSequence|int|float|string|bool $value,
2727
public readonly Parameters $parameters
2828
) {
2929
}

0 commit comments

Comments
 (0)