Skip to content

Commit d8bd0a6

Browse files
committed
minor #47654 Convert switch cases to match expression (tigitz)
This PR was merged into the 6.2 branch. Discussion ---------- Convert switch cases to match expression | Q | A | ------------- | --- | Branch? | 6.2 | Bug fix? | no | New feature? | no <!-- please update src/**/CHANGELOG.md files --> | Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Tickets | - | License | MIT | Doc PR | Continuation of symfony/symfony#45433 using [rector rule ](https://github.com/rectorphp/rector/blob/main/docs/rector_rules_overview.md#changeswitchtomatchrector) `@fancyweb` friendly ping as you've worked on it previously. Commits ------- f3ec7ac324 Convert switch cases to match expression
2 parents d1033e5 + 7c17b69 commit d8bd0a6

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)