AbstractBaseEndpoint   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A buildUri() 0 7 1
A __construct() 0 3 1
1
<?php
2
3
namespace Deltatuts\Fixer\Endpoint;
4
5
use Deltatuts\Fixer\FixerHttpClient;
6
use GuzzleHttp\ClientInterface;
7
8
abstract class AbstractBaseEndpoint
9
{
10
    /**
11
     * Path to be appended after the base URI.
12
     *
13
     * @var string
14
     */
15
    public const ENDPOINT_URI = '';
16
17
    /**
18
     * HTTP GET method.
19
     *
20
     * @var string
21
     */
22
    public const GET = 'GET';
23
24
    /**
25
     * Keyword to pass the API key on each call.
26
     */
27
    public const ACCESS_PARAM = 'access_key';
28
29
    /**
30
     * @var FixerHttpClient
31
     */
32
    protected $client;
33
34
    /**
35
     * AbstractBaseEndpoint constructor.
36
     *
37
     * @param ClientInterface $client
38 24
     */
39
    public function __construct(FixerHttpClient $client)
40 24
    {
41 24
        $this->client = $client;
42
    }
43
44
    /**
45
     * Query parameters to be appended to the endpoint URI.
46
     */
47
    public function buildUri(array $params = []): string
48
    {
49 15
        $params[self::ACCESS_PARAM] = $this->client->getApiKey();
50
51 15
        $query = http_build_query($params);
52
53 15
        return join('?', [static::ENDPOINT_URI, $query]);
54
    }
55
}
56