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
{
if ($type == 'number') {
return new FormatNumber();
} elseif ($type == 'string') {
return new FormatString();
}
throw new InvalidArgumentException('Unknown format given');
return match($type) {
'number' => new FormatNumber(),
'string' => new FormatString(),
default => throw new InvalidArgumentException('Unknown format given'),
};
}
}