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

AbstractBaseEndpoint::buildUri()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
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 4
cts 4
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
    const ENDPOINT_URI = '';
16
17
    /**
18
     * HTTP GET method.
19
     *
20
     * @var string
21
     */
22
    const GET = 'GET';
23
24
    /**
25
     * Keyword to pass the API key on each call.
26
     */
27
    const ACCESS_PARAM = 'access_token';
28
29
    /**
30
     * @var ClientInterface|FixerHttpClient
31
     */
32
    protected $client;
33
34
    /**
35
     * AbstractBaseEndpoint constructor.
36
     * @param ClientInterface $client
37
     */
38 9
    public function __construct(ClientInterface $client)
39
    {
40 9
        $this->client = $client;
41 9
    }
42
43
    /**
44
     * Query parameters to be appended to the endpoint URI.
45
     *
46
     * @param array $params
47
     * @return string
48
     */
49 9
    public function buildUri(array $params = []): string
50
    {
51 9
        $params[self::ACCESS_PARAM] = $this->client->getApiKey();
52
53 9
        $query = http_build_query($params);
54
55 9
        return join('?', [static::ENDPOINT_URI, $query]);
56
    }
57
}
58