ExchangeService::getSupportedCurrencies()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
eloc 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace App\ExchangeRates;
6
7
use App\Entity\ExchangeEnquiry;
8
use App\ExchangeRates\Provider\ProviderInterface;
9
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
64
    {
65
        return $this->provider->getSupportedCurrencies();
66
    }
67
}
68