mirror of
https://github.com/DesignPatternsPHP/DesignPatternsPHP.git
synced 2025-08-04 05:57:25 +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
|
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');
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user