Completed
Push — master ( 141b27...c8bf3d )
by Victor Hugo
17s queued 10s
created

FixerHttpClient   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 12
c 1
b 0
f 0
dl 0
loc 46
ccs 10
cts 10
cp 1
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getApiKey() 0 3 1
A __construct() 0 12 2
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 18
    public function __construct(string $key, array $config = [])
40
    {
41 18
        if (empty($key)) {
42 3
            throw new MissingAPIKeyException();
43
        }
44
45 15
        $this->apiKey = $key;
46
        $baseConfig = [
47 15
            'base_uri' => self::BASE_URI,
48 15
            RequestOptions::TIMEOUT => self::TIMEOUT
49
        ];
50 15
        parent::__construct(array_merge($baseConfig, $config));
51 15
    }
52
53
    /**
54
     * @return string
55
     */
56 9
    public function getApiKey(): string
57
    {
58 9
        return $this->apiKey;
59
    }
60
}
61