Response   A
last analyzed

Complexity

Total Complexity 17

Size/Duplication

Total Lines 76
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 1 Features 0
Metric Value
wmc 17
c 2
b 1
f 0
lcom 2
cbo 0
dl 0
loc 76
ccs 43
cts 43
cp 1
rs 10

10 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 2
A __toString() 0 3 1
A getHeaderString() 0 3 1
B getHeader() 0 24 5
A getUrl() 0 3 1
A getStatusCode() 0 3 1
A getContentType() 0 3 1
A getContentLength() 0 3 1
A getInfo() 0 6 3
A getBody() 0 3 1
1
<?php
2
/**
3
 * spindle/httpclient
4
 * @license CC0-1.0 (Public Domain) https://creativecommons.org/publicdomain/zero/1.0/
5
 * @see https://github.com/spindle/spindle-httpclient
6
 */
7
namespace Spindle\HttpClient;
8
9
class Response {
10
    protected
11
        $body = ''
12
      , $header = ''
13
      , $info
14
      , $headerCache
15
      ;
16
17 4
    function __construct($body, array $info) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
18 4
        if (is_string($body)) {
19 3
            $this->header = substr($body, 0, $info['header_size']);
20 3
            $this->body = substr($body, $info['header_size']);
21 3
        }
22 4
        $this->info = $info;
23 4
    }
24
25 1
    function __toString() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
26 1
        return $this->getBody();
27
    }
28
29 1
    function getHeaderString() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
30 1
        return $this->header;
31
    }
32
33 1
    function getHeader($label = null) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
34 1
        if (! $this->headerCache) {
35 1
            $headerString = rtrim($this->header);
36 1
            $headerString = str_replace(array("\r\n", "\r"), "\n", $headerString);
37 1
            $headerArr = explode("\n", $headerString);
38 1
            array_shift($headerArr);
39
40 1
            $result = array();
41 1
            foreach ($headerArr as $h) {
42 1
                $pos = strpos($h, ':');
43 1
                $key = substr($h, 0, $pos);
44 1
                $value = substr($h, $pos+1);
45 1
                $result[trim($key)] = trim($value);
46 1
            }
47
48 1
            $this->headerCache = $result;
49 1
        }
50
51 1
        if ($label) {
52 1
            return isset($this->headerCache[$label]) ? $this->headerCache[$label] : null;
53
        } else {
54 1
            return $this->headerCache;
55
        }
56
    }
57
58 1
    function getUrl() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
59 1
        return $this->info['url'];
60
    }
61
62 1
    function getStatusCode() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
63 1
        return $this->info['http_code'];
64
    }
65
66 1
    function getContentType() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
67 1
        return $this->info['content_type'];
68
    }
69
70 1
    function getContentLength() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
71 1
        return $this->info['download_content_length'];
72
    }
73
74 1
    function getInfo($label = null) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
75 1
        if ($label && isset($this->info[$label])) {
76 1
            return $this->info[$label];
77
        }
78 1
        return $this->info;
79
    }
80
81 3
    function getBody() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
82 3
        return $this->body;
83
    }
84
}
85