Skip to content

Commit

Permalink
Merge pull request #31 from ordago/refactor-to-match
Browse files Browse the repository at this point in the history
Refactors to use php match expression
  • Loading branch information
dtorras authored Jun 2, 2024
2 parents d0efaa5 + e3d9564 commit a3c3f29
Showing 1 changed file with 12 additions and 26 deletions.
38 changes: 12 additions & 26 deletions src/RedsysClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
};
}
}

0 comments on commit a3c3f29

Please sign in to comment.