From 5396752cebbe323df5a74c592cee76cd9f485a6f Mon Sep 17 00:00:00 2001 From: Daniel Subiabre Date: Tue, 26 Nov 2024 13:54:08 +0100 Subject: [PATCH] Update ExchangeLocator method names --- src/Library/Economy/Currency/ExchangeLocator.php | 12 ++++++------ src/Library/Economy/MoneyService.php | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Library/Economy/Currency/ExchangeLocator.php b/src/Library/Economy/Currency/ExchangeLocator.php index f125071..00a715f 100644 --- a/src/Library/Economy/Currency/ExchangeLocator.php +++ b/src/Library/Economy/Currency/ExchangeLocator.php @@ -7,7 +7,7 @@ use Brick\Money\Exception\CurrencyConversionException; class ExchangeLocator { /** - * @var ExchangeInterface[] + * @var array */ private array $exchanges; @@ -33,9 +33,9 @@ class ExchangeLocator } /** - * @return ExchangeInterface[] + * @return array */ - public function getExchanges(): array + public function getAll(): array { return $this->exchanges; } @@ -45,10 +45,10 @@ class ExchangeLocator * * @throws \Exception When the $name does not match to that of an implemented Exchange */ - public function getExchange(string $name): ExchangeInterface + public function getByName(string $name): ExchangeInterface { if (!\array_key_exists($name, $this->exchanges)) { - throw new \Exception("No such Exchange with the name $name"); + throw new \Exception("No such Exchange with the name '$name'"); } return $this->exchanges[$name]; @@ -60,7 +60,7 @@ class ExchangeLocator * * @throws CurrencyConversionException If the exchange rate is not available */ - public function getExchangeFor(string $source, string $target): ExchangeInterface + public function get(string $source, string $target): ExchangeInterface { foreach ($this->exchanges as $exchange) { try { diff --git a/src/Library/Economy/MoneyService.php b/src/Library/Economy/MoneyService.php index c6649fc..e7078f8 100644 --- a/src/Library/Economy/MoneyService.php +++ b/src/Library/Economy/MoneyService.php @@ -78,7 +78,7 @@ class MoneyService return self::toBrick($money); } - $exchange = $this->exchangeLocator->getExchangeFor($fromCurrency, $toCurrency); + $exchange = $this->exchangeLocator->get($fromCurrency, $toCurrency); return self::toBrick($exchange->convert(self::toBrick($money), $toCurrency)); }