GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

CurrCurr   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 3
dl 0
loc 54
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 2
A getExchangeRates() 0 4 1
A getExchangeRateByCurrency() 0 12 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SteffenBrand\CurrCurr;
6
7
use SteffenBrand\CurrCurr\Client\EcbClient;
8
use SteffenBrand\CurrCurr\Client\EcbClientInterface;
9
use SteffenBrand\CurrCurr\Exception\CurrencyNotSupportedException;
10
use SteffenBrand\CurrCurr\Exception\ExchangeRatesMappingFailedException;
11
use SteffenBrand\CurrCurr\Exception\ExchangeRatesRequestFailedException;
12
use SteffenBrand\CurrCurr\Model\Currency;
13
use SteffenBrand\CurrCurr\Model\ExchangeRate;
14
15
/**
16
 * Class CurrCurr
17
 * @package SteffenBrand\CurrCurr
18
 */
19
class CurrCurr
20
{
21
    /**
22
     * @var EcbClientInterface
23
     */
24
    private $client;
25
26
    /**
27
     * CurrCurr constructor.
28
     *
29
     * @param EcbClientInterface $client The ECB Client to use, leave blank for default ECB Client
30
     */
31
    public function __construct(EcbClientInterface $client = null)
32
    {
33
        if (null === $client) {
34
            $client = new EcbClient();
35
        }
36
        $this->client = $client;
37
    }
38
39
    /**
40
     * Delivers the current exchange rates based on EUR from the ECB.
41
     *
42
     * @throws ExchangeRatesMappingFailedException
43
     * @throws ExchangeRatesRequestFailedException
44
     * @return ExchangeRate[]
45
     */
46
    public function getExchangeRates(): array
47
    {
48
        return $this->client->getExchangeRates();
49
    }
50
51
    /**
52
     * Delivers the current exchange rates for a specific currency based on EUR from the ECB.
53
     *
54
     * @param string $currencyAbbr The currency to be requested. Use constants from Currency.
55
     * @return ExchangeRate
56
     * @throws ExchangeRatesMappingFailedException
57
     * @throws ExchangeRatesRequestFailedException
58
     * @throws CurrencyNotSupportedException
59
     */
60
    public function getExchangeRateByCurrency(string $currencyAbbr): ExchangeRate
61
    {
62
        $exchangeRates = $this->getExchangeRates();
63
64
        if (false === \array_key_exists($currencyAbbr, $exchangeRates) ||
65
            false === \in_array($currencyAbbr, Currency::ALLOWED_CURRENCIES, true))
66
        {
67
            throw new CurrencyNotSupportedException();
68
        }
69
70
        return $exchangeRates[$currencyAbbr];
71
    }
72
}