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

HttpClient   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 3
eloc 9
dl 0
loc 25
ccs 0
cts 15
cp 0
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A get() 0 7 1
A post() 0 7 1
A __construct() 0 3 1
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