GameApiRequest::__construct()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 5
ccs 4
cts 4
cp 1
rs 9.4286
cc 2
eloc 3
nc 2
nop 2
crap 2
1
<?php namespace GameScan\Core\Request\Api;
2
3
use GameScan\Core\Request\Api\Http\Client;
4
5
/**
6
 * Class GameApiRequest
7
 *
8
 * Used for request api of each games
9
 * @package GameScan\Core\Request\Api
10
 */
11
class GameApiRequest
12
{
13
14
    protected $apiConfiguration;
15
    protected $apiRequest;
16
17 14
    public function __construct(ApiConfigurationInterface $apiConfiguration, ApiRequestInterface $apiRequest = null)
18
    {
19 14
        $this->apiConfiguration = $apiConfiguration;
20 14
        $this->apiRequest = $apiRequest !== null ? $apiRequest : new Client();
21 14
    }
22
23
    public function setApiConfiguration(ApiConfigurationInterface $apiConfiguration)
24
    {
25
        $this->apiConfiguration = $apiConfiguration;
26
    }
27
28
    /**
29
     * Request a ressource of an api with the get http method
30
     * @param $ressourceToGrab
31
     * @param array|null $parameters
32
     * @return string
33
     */
34 14
    public function get($ressourceToGrab, array $parameters = null)
35
    {
36 14
        $this->apiRequest->clean();
37 14
        $this->apiRequest->setHeaders($this->apiConfiguration->getHeaders());
38 14
        $this->apiRequest->setParameters($this->apiConfiguration->getParameters());
39
40 14
        return $this->apiRequest->get($ressourceToGrab, $parameters);
41
    }
42
}
43