AbstractFixerResource   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 74
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 16
dl 0
loc 74
ccs 17
cts 17
cp 1
rs 10
c 0
b 0
f 0
wmc 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A execute() 0 7 1
A parametrize() 0 4 1
A __construct() 0 3 1
A addQueryParam() 0 4 1
A addQueryParams() 0 4 1
1
<?php
2
3
namespace VictorAvelar\Fixer\Resources;
4
5
use VictorAvelar\Fixer\Contracts\ExecutorInterface;
6
use VictorAvelar\Fixer\Contracts\QueryableInterface;
7
use VictorAvelar\Fixer\FixerHttpClient;
8
9
abstract class AbstractFixerResource implements ExecutorInterface, QueryableInterface
10
{
11
    /**
12
     * Execution method.
13
     */
14
    const REQUEST_METHOD = "GET";
15
16
    /**
17
     * @var FixerHttpClient
18
     */
19
    protected $client;
20
21
    /**
22
     * @var string
23
     */
24
    protected $path = "";
25
26
    /**
27
     * Query param.
28
     *
29
     * @var array
30
     */
31
    protected $params = [];
32
33
    /**
34
     * AbstractFixerResource constructor.
35
     *
36
     * @param FixerHttpClient $client
37
     */
38 12
    public function __construct(FixerHttpClient $client)
39
    {
40 12
        $this->client = $client;
41 12
    }
42
43
    /**
44
     * Builds a correct query string considering the params and the token.
45
     *
46
     * @return array
47
     */
48 6
    protected function parametrize(): array
49
    {
50 6
        return array_merge_recursive($this->params, [
51 6
            FixerHttpClient::KEY_NAME => $this->client->getClientKey()
52
        ]);
53
    }
54
55
    /**
56
     * {@inheritdoc}
57
     */
58 3
    public function addQueryParam(string $name, string $value): QueryableInterface
59
    {
60 3
        array_push($this->params, [$name => $value]);
61 3
        return $this;
62
    }
63
64
    /**
65
     * {@inheritdoc}
66
     */
67 3
    public function addQueryParams(array $httpQueryParams): QueryableInterface
68
    {
69 3
        array_push($this->params, $httpQueryParams);
70 3
        return $this;
71
    }
72
73
    /**
74
     * {@inheritdoc}
75
     */
76 6
    public function execute()
77
    {
78 6
        return $this->client->request(
79 6
            self::REQUEST_METHOD,
80 6
            $this->path,
81
            [
82 6
                'query' => $this->parametrize()
83
            ]
84
        );
85
    }
86
}
87