Completed
Push — master ( 919ad9...9a7348 )
by Victor Hugo
23s
created

LatestExchangeRatesEndpoint::latest()   A

Complexity

Conditions 4
Paths 5

Size

Total Lines 17
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 4

Importance

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