mirror of
https://github.com/DesignPatternsPHP/DesignPatternsPHP.git
synced 2025-07-31 12:10:10 +02:00
StaticFactory :: use match instead of if else
This commit is contained in:
@@ -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'),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user