Response   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
c 1
b 0
f 0
lcom 1
cbo 1
dl 0
loc 55
ccs 15
cts 15
cp 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A isSuccessful() 0 4 1
A getErrorMessage() 0 8 2
A getErrorCode() 0 8 2
1
<?php
2
3
namespace Bobbyshaw\WatsonVisualRecognition\Message;
4
5
/**
6
 * Response
7
 */
8
class Response extends AbstractResponse
9
{
10
11
    /**
12
     * Constructor
13
     *
14
     * @param  RequestInterface $request
15
     * @param  string $data / response data
16
     */
17 23
    public function __construct(RequestInterface $request, $data)
18
    {
19 23
        parent::__construct($request, $data);
20
21 23
        $this->request = $request;
22 23
        $this->data = json_decode($data);
23 23
    }
24
25
26
    /**
27
     * Whether or not response is successful
28
     *
29
     * @return bool
30
     */
31 9
    public function isSuccessful()
32
    {
33 9
        return !isset($this->data->error);
34
    }
35
36
37
    /**
38
     * Get error message
39
     *
40
     * @return string
41
     */
42 3
    public function getErrorMessage()
43
    {
44 3
        if (!$this->isSuccessful()) {
45 2
            return $this->data->error;
46
        }
47
48 1
        return '';
49
    }
50
51
    /**
52
     * @return bool|int
53
     */
54 2
    public function getErrorCode()
55
    {
56 2
        if (!$this->isSuccessful()) {
57 1
            return $this->data->code;
58
        }
59
60 1
        return false;
61
    }
62
}
63