GameApiRequest::setApiConfiguration()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 0
loc 4
ccs 0
cts 3
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 1
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