FixerHttpClient::__construct()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 2
eloc 8
c 2
b 0
f 0
nc 2
nop 2
dl 0
loc 13
ccs 6
cts 6
cp 1
crap 2
rs 10
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