AbstractApi::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
4
namespace slavkluev\Bizon365\Api;
5
6
use GuzzleHttp\Exception\ClientException;
7
use slavkluev\Bizon365\Client;
8
9
abstract class AbstractApi
10
{
11
    protected $client;
12
13 39
    public function __construct(Client $client)
14
    {
15 39
        $this->client = $client;
16 39
    }
17
18
    /**
19
     * @param string $url
20
     * @return mixed
21
     * @throws ClientException
22
     */
23 27
    protected function get(string $url)
24
    {
25 27
        $guzzleClient = $this->client->getHttpClient();
26 27
        return $this->decodeJson($guzzleClient->get($url)->getBody());
27
    }
28
29
    /**
30
     * @param string $url
31
     * @param array $data
32
     * @return mixed
33
     * @throws ClientException
34
     */
35 9
    protected function post(string $url, array $data = [])
36
    {
37 9
        $guzzleClient = $this->client->getHttpClient();
38 9
        return $this->decodeJson($guzzleClient->post($url, ['json' => $data])->getBody());
39
    }
40
41 36
    protected function decodeJson(string $json)
42
    {
43 36
        return json_decode($json, true);
44
    }
45
}
46