Response::getErrorMessage()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

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