From 912d60b437107c1c25221d252a73352ac4e9ba23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Atakan=20Demircio=C4=9Flu?= <31544037+atakde@users.noreply.github.com> Date: Thu, 30 Jun 2022 00:59:46 +0300 Subject: [PATCH] StaticFactory :: use match instead of if else --- Creational/StaticFactory/StaticFactory.php | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/Creational/StaticFactory/StaticFactory.php b/Creational/StaticFactory/StaticFactory.php index 8ebff07..e63b369 100644 --- a/Creational/StaticFactory/StaticFactory.php +++ b/Creational/StaticFactory/StaticFactory.php @@ -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'), + }; } }