Response::__toString()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

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