Completed
Push — master ( 98fc75...1c7a02 )
by Rémy
03:43
created

Client   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 77
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
c 1
b 0
f 0
lcom 1
cbo 3
dl 0
loc 77
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A get() 0 4 1
A put() 0 4 1
A delete() 0 4 1
A post() 0 4 1
A sendRequest() 0 10 2
1
<?php
2
3
namespace XoteliaClient;
4
5
use GuzzleHttp\ClientInterface;
6
use GuzzleHttp\Exception\ClientException;
7
use GuzzleHttp\Message\Response;
8
9
class Client
10
{
11
    /**
12
     * @var ClientInterface
13
     */
14
    protected $handler;
15
16
    /**
17
     * @param ClientInterface $handler
18
     */
19
    public function __construct(ClientInterface $handler)
20
    {
21
        $this->handler = $handler;
22
    }
23
24
    /**
25
     * @param string $path
26
     * @param array $options
27
     *
28
     * @return Response
29
     */
30
    public function get($path, array $options = [])
31
    {
32
        return $this->sendRequest('GET', $path, $options);
33
    }
34
35
    /**
36
     * @param string $path
37
     * @param array $options
38
     *
39
     * @return Response
40
     */
41
    public function put($path, array $options = [])
42
    {
43
        return $this->sendRequest('PUT', $path, $options);
44
    }
45
46
    /**
47
     * @param string $path
48
     * @param array $options
49
     *
50
     * @return Response
51
     */
52
    public function delete($path, array $options = [])
53
    {
54
        return $this->sendRequest('DELETE', $path, $options);
55
    }
56
57
    /**
58
     * @param string $path
59
     * @param array $options
60
     *
61
     * @return Response
62
     */
63
    public function post($path, array $options = [])
64
    {
65
        return $this->sendRequest('POST', $path, $options);
66
    }
67
68
    /**
69
     * @param string $method
70
     * @param string $path
71
     * @param array $options
72
     *
73
     * @return array
74
     */
75
    public function sendRequest($method, $path, array $options = [])
76
    {
77
        try {
78
            $response = $this->handler->send($this->handler->createRequest($method, $path, $options));
79
        } catch (ClientException $ex) {
80
            $response = $ex->getResponse();
81
        }
82
83
        return $response->json();
84
    }
85
}
86