Completed
Pull Request — master (#19)
by Yuan
01:58
created

ManagerBase   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 2
dl 0
loc 36
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getResponseJson() 0 7 1
1
<?php
2
3
namespace Acquia\LiftClient\Manager;
4
5
use GuzzleHttp\ClientInterface;
6
use Psr\Http\Message\RequestInterface;
7
8
abstract class ManagerBase
9
{
10
    /**
11
     * @var \GuzzleHttp\ClientInterface The request client
12
     */
13
    protected $client;
14
15 96
    /**
16
     * @param \GuzzleHttp\ClientInterface $client The request client
17 96
     */
18 96
    public function __construct(ClientInterface $client)
19
    {
20
        $this->client = $client;
21
    }
22
23
    /**
24
     * Make the given Request and return as JSON Decoded PHP object.
25
     *
26
     * @param \Psr\Http\Message\RequestInterface $request
27
     *
28
     * @return mixed the value encoded in <i>json</i> in appropriate
29
     *               PHP type. Values true, false and
30
     *               null (case-insensitive) are returned as <b>TRUE</b>, <b>FALSE</b>
31
     *               and <b>NULL</b> respectively. <b>NULL</b> is returned if the
32
     *               <i>json</i> cannot be decoded or if the encoded
33
     *               data is deeper than the recursion limit
34
     */
35
    protected function getResponseJson(RequestInterface $request)
36
    {
37
        $response = $this->client->send($request);
38
        $body = (string) $response->getBody();
39
40
        return json_decode($body, true);
41
    }
42
43
}
44