Completed
Push — master ( 7d37a2...fea370 )
by Nikolay
06:21
created

HttpClient::get()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 7
ccs 0
cts 5
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Greenplugin\TelegramBot;
6
7
use Nyholm\Psr7\Request;
8
use Psr\Http\Client\ClientInterface;
9
10
class HttpClient implements HttpClientInterface
11
{
12
    private $client;
13
14
    public function __construct(ClientInterface $client)
15
    {
16
        $this->client = $client;
17
    }
18
19
    public function get(string $path)
20
    {
21
        $request = new Request('GET', $path);
22
23
        $response = $this->client->sendRequest($request);
24
25
        return \json_decode($response->getBody()->getContents());
26
    }
27
28
    public function post(string $path, array $data)
29
    {
30
        $request = new Request('POST', $path, ['Content-Type' => 'application/json'], \json_encode($data));
31
32
        $response = $this->client->sendRequest($request);
33
34
        return \json_decode($response->getBody()->getContents());
35
    }
36
}
37