GuzzleAdapter   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 22
c 2
b 0
f 0
dl 0
loc 35
ccs 22
cts 22
cp 1
rs 10
wmc 6

2 Methods

Rating   Name   Duplication   Size   Complexity  
A send() 0 18 4
A getClient() 0 13 2
1
<?php
2
3
namespace Guillermoandrae\Highrise\Http;
4
5
use GuzzleHttp\Client;
6
use GuzzleHttp\Psr7\Request;
7
8
class GuzzleAdapter extends AbstractAdapter
9
{
10 25
    public function getClient(): Client
11
    {
12 25
        if (!$this->client) {
13 1
            $this->setClient(new Client([
14 1
                'base_uri' => sprintf('https://%s.highrisehq.com', $this->getSubdomain()),
15
                'headers' => [
16 1
                    'Content-Type' => 'application/xml',
17 1
                    'User-Agent' => static::HEADER_DEFAULT_USER_AGENT,
18
                ],
19 1
                'auth' => [$this->getToken(), $this->getPassword()]
20
            ]));
21
        }
22 25
        return $this->client;
23
    }
24
25 24
    protected function send(string $method, string $uri, array $options = [])
26
    {
27 24
        $headers = [];
28 24
        if (isset($options['headers'])) {
29 1
            $headers = $options['headers'];
30 1
            unset($options['headers']);
31
        }
32 24
        $body = '';
33 24
        if (isset($options['body'])) {
34 4
            $body = $options['body'];
35 4
            unset($options['body']);
36
        }
37 24
        if (isset($options['query'])) {
38 5
            $uri .= '?' . http_build_query($options['query']);
39 5
            unset($options['body']);
40
        }
41 24
        $this->lastRequest = new Request($method, $uri, $headers, $body);
42 24
        $this->lastResponse = $this->getClient()->send($this->lastRequest, $options);
43 23
    }
44
}
45