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

Response   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 11
lcom 1
cbo 1
dl 0
loc 62
ccs 18
cts 18
cp 1
rs 10
c 1
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 14 4
A getCode() 0 4 2
A getMessage() 0 4 2
A getData() 0 4 2
A getResponse() 0 4 1
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