Skip to content

Commit

Permalink
feat: simplify code
Browse files Browse the repository at this point in the history
  • Loading branch information
florianv committed Jun 30, 2021
1 parent f605376 commit 9481ff0
Showing 1 changed file with 2 additions and 9 deletions.
11 changes: 2 additions & 9 deletions src/Service/SupportsHistoricalQueries.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
use Exchanger\Contract\ExchangeRate as ExchangeRateContract;
use Exchanger\Contract\ExchangeRateQuery as ExchangeRateQueryContract;
use Exchanger\Contract\HistoricalExchangeRateQuery as HistoricalExchangeRateQueryContract;
use Exchanger\Exception\UnsupportedCurrencyPairException;

/**
* Trait to implement to add historical service support.
Expand All @@ -30,17 +29,11 @@ trait SupportsHistoricalQueries
*/
public function getExchangeRate(ExchangeRateQueryContract $exchangeQuery): ExchangeRateContract
{
$currencyPair = $exchangeQuery->getCurrencyPair();

if ($exchangeQuery instanceof HistoricalExchangeRateQueryContract) {
if ($rate = $this->getHistoricalExchangeRate($exchangeQuery)) {
return $rate;
}
} elseif ($rate = $this->getLatestExchangeRate($exchangeQuery)) {
return $rate;
return $this->getHistoricalExchangeRate($exchangeQuery);
}

throw new UnsupportedCurrencyPairException($currencyPair, $this);
return $this->getLatestExchangeRate($exchangeQuery);
}

/**
Expand Down

0 comments on commit 9481ff0

Please sign in to comment.