AbstractResource::sendRequest()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 18
rs 9.6666
c 0
b 0
f 0
cc 1
nc 1
nop 5
1
<?php
2
3
namespace Igorsgm\TibiaDataApi\Resources;
4
5
use Igorsgm\TibiaDataApi\TibiaDataApi;
6
use Psr\Http\Message\UriInterface;
7
8
/**
9
 * Class AbstractResource
10
 * @package Igorsgm\TibiaDataApi\Resources
11
 */
12
class AbstractResource
13
{
14
    /**
15
     * @var TibiaDataApi
16
     */
17
    protected $tibiaData;
18
19
    /**
20
     * AbstractResource constructor.
21
     * @param  TibiaDataApi  $tibiaData
22
     */
23
    public function __construct(TibiaDataApi $tibiaData)
24
    {
25
        $this->tibiaData = $tibiaData;
26
    }
27
28
    /**
29
     * @param  string  $method  HTTP method.
30
     * @param  string|UriInterface  $uri  URI object or string.
31
     * @param  array  $headers
32
     * @param  null  $body
33
     * @param  string  $protocolVersion
34
     * @return \stdClass
35
     * @throws \GuzzleHttp\Exception\GuzzleException
36
     */
37
    protected function sendRequest(
38
        $method,
39
        $uri,
40
        array $headers = [],
41
        $body = null,
42
        $protocolVersion = '1.1'
43
    ): \stdClass {
44
45
        $uri = '/'.config('tibia-data-api.version').'/'.$uri;
46
47
        $response = $this->tibiaData->getHttpClient()->request($method, $uri, [
48
            'headers' => $headers,
49
            'body' => $body,
50
            'version' => $protocolVersion
51
        ]);
52
53
        return json_decode($response->getBody()->getContents());
54
    }
55
}
56