| Total Complexity | 4 |
| Total Lines | 56 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 10 | class ExchangeService |
||
| 11 | { |
||
| 12 | /** |
||
| 13 | * @var ProviderInterface |
||
| 14 | */ |
||
| 15 | protected $provider; |
||
| 16 | |||
| 17 | /** |
||
| 18 | * @var CalculatorInterface |
||
| 19 | */ |
||
| 20 | protected $calculator; |
||
| 21 | |||
| 22 | /** |
||
| 23 | * Exchange constructor. |
||
| 24 | * |
||
| 25 | * @param ProviderInterface $provider |
||
| 26 | * @param CalculatorInterface $calculator |
||
| 27 | */ |
||
| 28 | public function __construct(ProviderInterface $provider, CalculatorInterface $calculator) |
||
| 29 | { |
||
| 30 | $this->provider = $provider; |
||
| 31 | $this->calculator = $calculator; |
||
| 32 | } |
||
| 33 | |||
| 34 | /** |
||
| 35 | * @param string $baseCurrency ISO 4217 Currency Code of base currency |
||
| 36 | * @param string $targetCurrency ISO 4217 Currency Code of base currency |
||
| 37 | * |
||
| 38 | * @return float |
||
| 39 | */ |
||
| 40 | public function getExchangeRate(string $baseCurrency, string $targetCurrency): float |
||
| 41 | { |
||
| 42 | return $this->provider->getLatestExchangeRate($baseCurrency, $targetCurrency); |
||
| 43 | } |
||
| 44 | |||
| 45 | /** |
||
| 46 | * @param ExchangeEnquiry $enquiry |
||
| 47 | * |
||
| 48 | * @return float |
||
| 49 | */ |
||
| 50 | public function exchange(ExchangeEnquiry $enquiry): float |
||
| 51 | { |
||
| 52 | $exchangeRate = $this->provider->getLatestExchangeRate( |
||
| 53 | $enquiry->getBaseCurrency(), |
||
| 54 | $enquiry->getTargetCurrency() |
||
| 55 | ); |
||
| 56 | |||
| 57 | return $this->calculator->exchange($enquiry->getAmount(), $exchangeRate); |
||
| 58 | } |
||
| 59 | |||
| 60 | /** |
||
| 61 | * @return array |
||
| 62 | */ |
||
| 63 | public function getSupportedCurrencies(): array |
||
| 66 | } |
||
| 67 | } |
||
| 68 |