Passed
Push — master ( 3cbbeb...011897 )
by Victor Hugo
13:58
created

AbstractEndpoint::buildURI()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
namespace VictorAvelar\Fixer\Endpoints;
4
5
use VictorAvelar\Fixer\FixerHttpClient;
6
7
abstract class AbstractEndpoint
8
{
9
    /**
10
     * @var FixerHttpClient
11
     */
12
    protected $client;
13
14
    /**
15
     * @var string
16
     */
17
    protected $path = "";
18
19
    /**
20
     * AbstractEndpoint constructor.
21
     *
22
     * @param FixerHttpClient $client
23
     */
24
    public function __construct(FixerHttpClient $client)
25
    {
26
        $this->client = $client;
27
    }
28
29
    /**
30
     * Builds the correct URI to perform requests.
31
     *
32
     * @param array $params
33
     *
34
     * @return string
35
     */
36
    public function buildURI(array $params = []): string
37
    {
38
        return join('?', [$this->path, $this->attachQueryParams($params)]);
39
    }
40
41
    /**
42
     * Attach query params to the request.
43
     *
44
     * @param array $params
45
     *
46
     * @return string
47
     */
48
    private function attachQueryParams(array $params = []): string
49
    {
50
        return http_build_query(array_merge($params, [
51
            FixerHttpClient::KEY_NAME => $this->client->getClientKey()
52
        ]));
53
    }
54
}
55