Passed
Branch master (4f0f9e)
by Louis
17:08
created

Response::__construct()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 14
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 14
ccs 10
cts 10
cp 1
rs 9.2
c 1
b 0
f 0
cc 4
eloc 7
nc 4
nop 1
crap 4
1
<?php
2
3
namespace EtherpadLite;
4
5
class Response
6
{
7
    const CODE_OK = 0;
8
    const CODE_WRONG_PARAMETERS = 1;
9
    const CODE_INTERNAL_ERROR = 2;
10
    const CODE_NO_SUCH_FUNCTION = 3;
11
    const CODE_NO_OR_WRONG_API_KEY = 4;
12
13
    private $response = array();
14
15
    /**
16
     * @param \Guzzle\Http\Message\Response $response
17
     */
18 4
    public function __construct(\Guzzle\Http\Message\Response $response)
19
    {
20 4
        if ($response->isSuccessful()) {
21 4
            $this->response = $response->json();
22
23 4
            if (is_array($this->response)) {
24 4
                foreach ($this->response as $key => $value) {
25 4
                    $this->response[$key] = $value;
26 4
                }
27 4
            }
28 4
        } else {
0 ignored issues
show
Unused Code introduced by
This else statement is empty and can be removed.

This check looks for the else branches of if statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These else branches can be removed.

if (rand(1, 6) > 3) {
print "Check failed";
} else {
    //print "Check succeeded";
}

could be turned into

if (rand(1, 6) > 3) {
    print "Check failed";
}

This is much more concise to read.

Loading history...
29
            // TODO: Error handling
30
        }
31 4
    }
32
33
    /**
34
     * @return string|null
35
     */
36 4
    public function getCode()
37
    {
38 4
        return isset($this->response['code']) ? $this->response['code'] : null;
39
    }
40
41
    /**
42
     * @return string|null
43
     */
44 4
    public function getMessage()
45
    {
46 4
        return isset($this->response['message']) ? $this->response['message'] : null;
47
    }
48
49
    /**
50
     * @return string|null
51
     */
52 4
    public function getData()
53
    {
54 4
        return isset($this->response['data']) ? $this->response['data'] : null;
55
    }
56
57
    /**
58
     * Returns the entire response from Etherpad Lite API
59
     *
60
     * @return array
61
     */
62 4
    public function getResponse()
63
    {
64 4
        return $this->response;
65
    }
66
}
67