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

ManagerBase::getResponseJson()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 0
cts 0
cp 0
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 1
crap 2
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