Client   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 65
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 4
Bugs 0 Features 2
Metric Value
wmc 7
c 4
b 0
f 2
lcom 1
cbo 2
dl 0
loc 65
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 6 1
A post() 0 4 1
A sendRequest() 0 8 2
1
<?php
2
3
namespace Streak;
4
5
use GuzzleHttp\ClientInterface;
6
7
class Client
8
{
9
    protected $handler;
10
11
    public function __construct(ClientInterface $handler)
12
    {
13
        $this->handler = $handler;
14
    }
15
16
    /**
17
     * Shortcut to make a GET request
18
     *
19
     * @return array|string
20
     */
21
    public function get($path, array $options = [], $withJson = true)
22
    {
23
        return $this->sendRequest('GET', $path, $options, $withJson);
24
    }
25
26
    /**
27
     * Shortcut to make a PUT request
28
     *
29
     * @return array
30
     */
31
    public function put($path, array $options = [])
32
    {
33
        return $this->sendRequest('PUT', $path, $options);
34
    }
35
36
    /**
37
     * Shortcut to make a DELETE request
38
     *
39
     * @return boolean
40
     */
41
    public function delete($path, array $options = [])
42
    {
43
        $response = $this->sendRequest('DELETE', $path, $options);
44
45
        return $response['success'];
46
    }
47
48
    /**
49
     * Shortcut to make a POST request
50
     *
51
     * @return array
52
     */
53
    public function post($path, array $options = [])
54
    {
55
        return $this->sendRequest('POST', $path, $options);
56
    }
57
58
    /**
59
     * Make the HTTP request through the handler
60
     *
61
     * @return array|string
62
     */
63
    public function sendRequest($method, $path, array $options = [], $withJson = true)
64
    {
65
        $response = $this->handler->request($method, $path, $options);
66
67
        $body = (string)$response->getBody();
68
69
        return $withJson ? json_decode($body, true) : $body;
70
    }
71
}
72