GameApiRequest::get()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

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