From e3d95649d1574596216aa0292b1444c32aa752ae Mon Sep 17 00:00:00 2001 From: ordago Date: Sat, 1 Jun 2024 15:30:10 +0100 Subject: [PATCH] refactors to use php match expression --- src/RedsysClient.php | 38 ++++++++++++-------------------------- 1 file changed, 12 insertions(+), 26 deletions(-) diff --git a/src/RedsysClient.php b/src/RedsysClient.php index b198c00..39c4e13 100644 --- a/src/RedsysClient.php +++ b/src/RedsysClient.php @@ -24,35 +24,21 @@ public function __construct( public function getBaseUrl(): string { - if ($this->environment === Environment::Production) { - return 'https://sis.redsys.es/sis'; - } - - if ($this->environment === Environment::Test) { - return 'https://sis-t.redsys.es:25443/sis'; - } - - if ($this->environment === Environment::Custom) { - return $this->customBaseUrl; - } - - throw new \Exception('Redsys undefined environment'); + return match($this->environment) { + Environment::Production => 'https://sis.redsys.es/sis', + Environment::Test => 'https://sis-t.redsys.es:25443/sis', + Environment::Custom => $this->customBaseUrl, + default => throw new \Exception('Redsys undefined environment'), + }; } public function getRestBaseUrl(): string { - if ($this->environment === Environment::Production) { - return 'https://sis.redsys.es/sis/rest'; - } - - if ($this->environment === Environment::Test) { - return 'https://sis-t.redsys.es:25443/sis/rest'; - } - - if ($this->environment === Environment::Custom) { - return $this->customBaseUrl; - } - - throw new \Exception('Redsys undefined environment'); + return match ($this->environment) { + Environment::Production => 'https://sis.redsys.es/sis/rest', + Environment::Test => 'https://sis-t.redsys.es:25443/sis/rest', + Environment::Custom => $this->customBaseUrl, + default => throw new \Exception('Redsys undefined environment'), + }; } }