Client::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 2
crap 1
1
<?php
2
3
namespace ZenCash\Rpc\Native;
4
5
use GuzzleHttp\ClientInterface as IHttpClient;
6
use GuzzleHttp\Exception\ClientException;
7
use GuzzleHttp\Exception\GuzzleException as IException;
8
use GuzzleHttp\Exception\ServerException;
9
use Psr\Http\Message\ResponseInterface;
10
use ZenCash\Rpc\Client as IClient;
11
use ZenCash\Rpc\Command;
12
use ZenCash\Rpc\Rpc;
13
14
final class Client implements IClient
15
{
16
    private $rpc;
17
    private $httpClient;
18
19 1
    public function __construct(Rpc $rpc, IHttpClient $httpClient)
20
    {
21 1
        $this->rpc = $rpc;
22 1
        $this->httpClient = $httpClient;
23 1
    }
24
25
    /** @throws IException|ServerException|ClientException */
26 1
    public function execute(Command $command): ResponseInterface
27
    {
28 1
        return $this->httpClient->request('POST', $this->rpc->getAddress(), [
29 1
            'headers' => [
30
                'Content-Type' => 'text/plain'
31
            ],
32 1
            'auth' => [ $this->rpc->getUser(), $this->rpc->getPassword() ],
33 1
            'json' => $command
34
        ]);
35
    }
36
}
37