StaticFactory :: use match instead of if else

This commit is contained in:
Atakan Demircioğlu
2022-06-30 00:59:46 +03:00
parent b2d6414f81
commit 912d60b437

View File

@@ -14,12 +14,10 @@ final class StaticFactory
{ {
public static function factory(string $type): Formatter public static function factory(string $type): Formatter
{ {
if ($type == 'number') { return match($type) {
return new FormatNumber(); 'number' => new FormatNumber(),
} elseif ($type == 'string') { 'string' => new FormatString(),
return new FormatString(); default => throw new InvalidArgumentException('Unknown format given'),
} };
throw new InvalidArgumentException('Unknown format given');
} }
} }