| Total Complexity | 5 |
| Total Lines | 74 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 0 | ||
| 1 | <?php |
||
| 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() |
|
| 83 | ] |
||
| 84 | ); |
||
| 85 | } |
||
| 86 | } |
||
| 87 |