CurlClient   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 2
dl 0
loc 56
ccs 0
cts 24
cp 0
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A call() 0 15 4
A setBasicAuthentication() 0 4 1
A setTimeout() 0 4 1
1
<?php
2
3
namespace DJStarCOM\BookingComSDK\HttpClient;
4
5
use Curl\Curl;
6
use DJStarCOM\BookingComSDK\Exceptions\HttpClientException;
7
use ErrorException;
8
9
/**
10
 * Class HttpClient
11
 * @package DJStarCOM\BookingComSDK\HttpClient
12
 */
13
class CurlClient implements HttpClientInterface
14
{
15
    /**
16
     * @var Curl
17
     */
18
    private $instance;
19
20
    /**
21
     * CurlClient constructor.
22
     * @throws ErrorException
23
     */
24
    public function __construct()
25
    {
26
        $this->instance = new Curl();
27
    }
28
29
    /**
30
     * @param string $method
31
     * @param string $url
32
     * @param array $data
33
     * @return array|string|null
34
     * @throws HttpClientException
35
     */
36
    public function call(string $method, string $url, array $data)
37
    {
38
        \call_user_func([$this->instance, $method], $url, $data);
39
40
        if ($this->instance->error) {
41
            $message = $this->instance->errorMessage;
42
            if ($this->instance->response && property_exists($this->instance->response, 'errors')) {
43
                $message .= '. ' . reset($this->instance->response->errors)->message;
44
            }
45
46
            throw new HttpClientException($message, $this->instance->errorCode);
47
        }
48
49
        return $this->instance->response;
50
    }
51
52
    /**
53
     * @param string $login
54
     * @param string $password
55
     */
56
    public function setBasicAuthentication(string $login, string $password): void
57
    {
58
        $this->instance->setBasicAuthentication($login, $password);
59
    }
60
61
    /**
62
     * @param int $timeout
63
     */
64
    public function setTimeout(int $timeout): void
65
    {
66
        $this->instance->setTimeout($timeout);
67
    }
68
}
69