Skip to content

Commit 7c17b69

Browse files
committed
Convert switch cases to match expression
1 parent 8123526 commit 7c17b69

File tree

1 file changed

+7
-12
lines changed

1 file changed

+7
-12
lines changed

Normalizer/UidNormalizer.php

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -46,18 +46,13 @@ public function __construct(array $defaultContext = [])
4646
*/
4747
public function normalize(mixed $object, string $format = null, array $context = []): array|string|int|float|bool|\ArrayObject|null
4848
{
49-
switch ($context[self::NORMALIZATION_FORMAT_KEY] ?? $this->defaultContext[self::NORMALIZATION_FORMAT_KEY]) {
50-
case self::NORMALIZATION_FORMAT_CANONICAL:
51-
return (string) $object;
52-
case self::NORMALIZATION_FORMAT_BASE58:
53-
return $object->toBase58();
54-
case self::NORMALIZATION_FORMAT_BASE32:
55-
return $object->toBase32();
56-
case self::NORMALIZATION_FORMAT_RFC4122:
57-
return $object->toRfc4122();
58-
}
59-
60-
throw new LogicException(sprintf('The "%s" format is not valid.', $context[self::NORMALIZATION_FORMAT_KEY] ?? $this->defaultContext[self::NORMALIZATION_FORMAT_KEY]));
49+
return match ($context[self::NORMALIZATION_FORMAT_KEY] ?? $this->defaultContext[self::NORMALIZATION_FORMAT_KEY]) {
50+
self::NORMALIZATION_FORMAT_CANONICAL => (string) $object,
51+
self::NORMALIZATION_FORMAT_BASE58 => $object->toBase58(),
52+
self::NORMALIZATION_FORMAT_BASE32 => $object->toBase32(),
53+
self::NORMALIZATION_FORMAT_RFC4122 => $object->toRfc4122(),
54+
default => throw new LogicException(sprintf('The "%s" format is not valid.', $context[self::NORMALIZATION_FORMAT_KEY] ?? $this->defaultContext[self::NORMALIZATION_FORMAT_KEY])),
55+
};
6156
}
6257

6358
public function supportsNormalization(mixed $data, string $format = null, array $context = []): bool

0 commit comments

Comments
 (0)