LatestExchangeRatesEndpoint   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 11
c 1
b 0
f 0
dl 0
loc 30
ccs 9
cts 9
cp 1
rs 10
wmc 4

1 Method

Rating   Name   Duplication   Size   Complexity  
A latest() 0 17 4
1
<?php
2
3
namespace Deltatuts\Fixer\Endpoint;
4
5
use Psr\Http\Message\ResponseInterface;
6
use GuzzleHttp\Exception\GuzzleException;
7
use Deltatuts\Fixer\Request\GetLatestExchangeRatesRequest;
8
use Deltatuts\Fixer\Exception\InvalidCurrencyCodeException;
9
10
/**
11
 * Class LatestExchangeRatesEndpoint.
12
 */
13
class LatestExchangeRatesEndpoint extends AbstractBaseEndpoint
14
{
15
    public const ENDPOINT_URI = 'latest';
16
17
    /**
18
     * Returns the latest spot price for the supported currencies.
19
     *
20
     * @param string $baseCurrency base currency alpha3 code (if different than EUR)
21
     * @param array  $symbols      array of alpha3 codes to filter the response
22
     *
23
     * @throws InvalidCurrencyCodeException
24
     * @throws GuzzleException
25
     */
26
    public function latest(string $baseCurrency = null, array $symbols = []): ResponseInterface
27
    {
28 6
        $params = [];
29
        if ($baseCurrency) {
30 6
            if (strlen($baseCurrency) != 3) {
31 6
                throw new InvalidCurrencyCodeException($baseCurrency);
32 6
            }
33 3
            $params['base'] = $baseCurrency;
34
        }
35 3
36
        if (!empty($symbols)) {
37
            $params['symbols'] = implode(',', $symbols);
38 3
        }
39 3
40
        $req = new GetLatestExchangeRatesRequest($this->buildUri($params));
41
42 3
        return $this->client->send($req);
43
    }
44
}
45