AbstractBaseEndpoint::buildUri()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

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