HistoricalSwapExchange   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 5
dl 0
loc 38
ccs 0
cts 13
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A quoteHistorical() 0 10 2
1
<?php
2
3
namespace Jarobe\HistoricalMoney\Exchange;
4
5
use Jarobe\HistoricalMoney\Exception\UnsupportedHistoricalDateException;
6
use Jarobe\HistoricalMoney\HistoricalExchange;
7
use Money\Currency;
8
use Money\CurrencyPair;
9
use Money\Exception\UnresolvableCurrencyPairException;
10
use Swap\Swap;
11
use Exchanger\Exception\Exception as ExchangerException;
12
13
final class HistoricalSwapExchange implements HistoricalExchange
14
{
15
    /**
16
     * @var Swap
17
     */
18
    private $swap;
19
20
    /**
21
     * @param Swap $swap
22
     */
23
    public function __construct(Swap $swap)
24
    {
25
        $this->swap = $swap;
26
    }
27
28
    /**
29
     * Returns a currency pair for the passed currencies with the rate coming from a third-party source.
30
     *
31
     * @param \DateTimeInterface $dateTime
32
     * @param Currency           $baseCurrency
33
     * @param Currency           $counterCurrency
34
     *
35
     * @return CurrencyPair
36
     *
37
     * @throws UnsupportedHistoricalDateException When the provided date is not supported
38
     * @throws UnresolvableCurrencyPairException  When there is no currency pair available for the currencies
39
     */
40
    public function quoteHistorical(\DateTimeInterface $dateTime, Currency $baseCurrency, Currency $counterCurrency)
41
    {
42
        try {
43
            $rate = $this->swap->historical($baseCurrency->getCode().'/'.$counterCurrency->getCode(), $dateTime);
44
        } catch (ExchangerException $e) {
45
            throw UnresolvableCurrencyPairException::createFromCurrencies($baseCurrency, $counterCurrency);
46
        }
47
48
        return new CurrencyPair($baseCurrency, $counterCurrency, $rate->getValue());
49
    }
50
}
51