ImgurResponse   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 20%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 7
c 1
b 0
f 1
lcom 1
cbo 2
dl 0
loc 53
ccs 3
cts 15
cp 0.2
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getBody() 0 15 4
A getHeaders() 0 4 1
A getRateLimit() 0 4 1
1
<?php
2
3
namespace Mechpave\ImgurClient\Http;
4
5
use Psr\Http\Message\ResponseInterface;
6
7
/**
8
 * Class ImgurResponse
9
 * @package Mechpave\ImgurClient\Http
10
 */
11
class ImgurResponse implements ImgurResponseInterface
12
{
13
    /**
14
     * Guzzle response
15
     * @var ResponseInterface
16
     */
17
    protected $response;
18
19
    /**
20
     * ImgurResponse constructor.
21
     * @param ResponseInterface $response
22
     */
23 1
    public function __construct(ResponseInterface $response)
24
    {
25 1
        $this->response = $response;
26 1
    }
27
28
    /**
29
     * @inheritdoc
30
     * @throws \Exception
31
     */
32
    public function getBody()
33
    {
34
        if (!is_callable([$this->response, 'getBody']) ||
35
            !is_callable([$this->response->getBody(), 'getContents'])) {
36
            throw new \Exception('Could not retrieve response body');
37
        }
38
39
        $body = json_decode($this->response->getBody()->getContents(), true);
40
41
        if (empty($body)) {
42
            throw new \Exception('Could not retrieve response body');
43
        }
44
45
        return $body;
46
    }
47
48
    /**
49
     * @return array
50
     */
51
    public function getHeaders()
52
    {
53
        // TODO: Implement getHeaders() method.
54
    }
55
56
    /**
57
     * @return mixed
58
     */
59
    public function getRateLimit()
60
    {
61
        // TODO: Implement getRateLimit() method.
62
    }
63
}