Completed
Pull Request — master (#1)
by Victor Hugo
04:00
created

FixerHttpClient::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 7
c 1
b 0
f 0
nc 2
nop 2
dl 0
loc 12
ccs 0
cts 11
cp 0
crap 6
rs 10
1
<?php
2
3
namespace Deltatuts\Fixer;
4
5
use Deltatuts\Fixer\Exception\MissingAPIKeyException;
6
use GuzzleHttp\Client;
7
use GuzzleHttp\RequestOptions;
8
9
/**
10
 * Class FixerHttpClient
11
 * @package Deltatuts\Fixer
12
 */
13
class FixerHttpClient extends Client
14
{
15
    /**
16
     * @var string
17
     */
18
    const BASE_URI = "http://data.fixer.io/api";
19
20
    /**
21
     * Time to wait in seconds before interrupting the request.
22
     *
23
     * @var string
24
     */
25
    const TIMEOUT = 5;
26
27
    /**
28
     * @var string
29
     */
30
    private $apiKey;
31
32
    /**
33
     * FixerHttpClient constructor.
34
     *
35
     * @param string $key
36
     * @param array $config
37
     * @throws MissingAPIKeyException
38
     */
39
    public function __construct(string $key, array $config = [])
40
    {
41
        if (empty($key)) {
42
            throw new MissingAPIKeyException();
43
        }
44
45
        $this->apiKey = $key;
46
        $baseConfig = [
47
            'base_uri' => self::BASE_URI,
48
            RequestOptions::TIMEOUT => self::TIMEOUT
49
        ];
50
        parent::__construct(array_merge($baseConfig, $config));
51
    }
52
}
53