GuzzleAdapter::send()   A
last analyzed

Complexity

Conditions 4
Paths 8

Size

Total Lines 18
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 14
CRAP Score 4

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 4
eloc 13
c 2
b 0
f 0
nc 8
nop 3
dl 0
loc 18
ccs 14
cts 14
cp 1
crap 4
rs 9.8333
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