FixerHttpClient   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getApiKey() 0 3 1
A __construct() 0 13 2
A initEndpoints() 0 4 1
1
<?php
2
3
namespace Deltatuts\Fixer;
4
5
use GuzzleHttp\RequestOptions;
6
use GuzzleHttp\Client;
7
use Deltatuts\Fixer\Exception\MissingAPIKeyException;
8
use Deltatuts\Fixer\Endpoint\SymbolsEndpoint;
9
use Deltatuts\Fixer\Endpoint\LatestExchangeRatesEndpoint;
10
11
/**
12
 * Class FixerHttpClient.
13
 */
14
class FixerHttpClient extends Client
15
{
16
    public const BASE_URI = 'http://data.fixer.io/api';
17
18
    /**
19
     * Time to wait in seconds before interrupting the request.
20
     */
21
    public const TIMEOUT = 5;
22
23
    /**
24
     * @var string
25
     */
26
    private $apiKey;
27
28
    /**
29
     * @var SymbolsEndpoint
30
     */
31
    public $symbols;
32
33
    /**
34
     * @var LatestExchangeRatesEndpoint
35
     */
36
    public $rates;
37
38
    /**
39
     * FixerHttpClient constructor.
40
     *
41
     * @throws MissingAPIKeyException
42
     */
43
    public function __construct(string $key, array $config = [])
44
    {
45
        if (empty($key)) {
46 27
            throw new MissingAPIKeyException();
47
        }
48 27
49 3
        $this->apiKey = $key;
50
        $baseConfig = [
51
            'base_uri' => self::BASE_URI,
52 24
            RequestOptions::TIMEOUT => self::TIMEOUT,
53
        ];
54 24
        parent::__construct(array_merge($baseConfig, $config));
55 24
        $this->initEndpoints();
56
    }
57 24
58 24
    public function getApiKey(): string
59 24
    {
60
        return $this->apiKey;
61
    }
62
63
    /**
64 15
     * Initializes all the supported endpoints.
65
     */
66 15
    private function initEndpoints()
67
    {
68
        $this->symbols = new SymbolsEndpoint($this);
69
        $this->rates = new LatestExchangeRatesEndpoint($this);
70
    }
71
}
72