Response::protocol()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
namespace Mosaic\Http\Adapters\Psr7;
4
5
use Mosaic\Http\Response as ResponseContract;
6
use Psr\Http\Message\ResponseInterface;
7
8
class Response extends Message implements ResponseContract, ResponseInterface
9
{
10
    /**
11
     * @var ResponseInterface
12
     */
13
    protected $wrapped;
14
15
    /**
16
     * @param ResponseInterface $wrapper
17
     */
18 25
    public function __construct(ResponseInterface $wrapper)
19
    {
20 25
        parent::__construct($wrapper);
21 25
    }
22
23
    /**
24
     * Gets the response status code.
25
     * The status code is a 3-digit integer result code of the server's attempt
26
     * to understand and satisfy the request.
27
     *
28
     * @return int Status code.
29
     */
30 10
    public function status() : int
31
    {
32 10
        return $this->wrapped->getStatusCode();
33
    }
34
35
    /**
36
     * Gets the body of the message.
37
     *
38
     * @return string Returns the body as string.
39
     */
40 10
    public function body() : string
41
    {
42 10
        return (string) $this->wrapped->getBody();
43
    }
44
45
    /**
46
     * @return int|null
47
     */
48 1
    public function size()
49
    {
50 1
        return $this->wrapped->getBody()->getSize();
51
    }
52
53
    /**
54
     * @param string $header
55
     * @param string $value
56
     *
57
     * @return ResponseContract
58
     */
59 1
    public function addHeader(string $header, string $value) : ResponseContract
60
    {
61 1
        return new static($this->wrapped->withHeader($header, $value));
62
    }
63
64
    /**
65
     * @return string
66
     */
67 1
    public function reason() : string
68
    {
69 1
        return $this->wrapped->getReasonPhrase();
70
    }
71
72
    /**
73
     * @return string
74
     */
75 1
    public function protocol() : string
76
    {
77 1
        return $this->wrapped->getProtocolVersion();
78
    }
79
80
    /**
81
     * @return array
82
     */
83 10
    public function headers() : array
84
    {
85 10
        return $this->wrapped->getHeaders();
86
    }
87
88
    /**
89
     * {@inheritdoc}
90
     */
91 1
    public function getStatusCode()
92
    {
93 1
        return $this->wrapped->getStatusCode();
94
    }
95
96
    /**
97
     * {@inheritdoc}
98
     */
99 1
    public function withStatus($code, $reasonPhrase = '')
100
    {
101 1
        return new static($this->wrapped->withStatus($code, $reasonPhrase));
102
    }
103
104
    /**
105
     * {@inheritdoc}
106
     */
107 1
    public function getReasonPhrase()
108
    {
109 1
        return $this->wrapped->getReasonPhrase();
110
    }
111
112
    /**
113
     * @return ResponseInterface
114
     */
115 2
    public function toPsr7() : ResponseInterface
116
    {
117 2
        return $this;
118
    }
119
120
    /**
121
     * @return ResponseInterface
122
     */
123 1
    protected function getWrapped()
124
    {
125 1
        return $this->wrapped;
126
    }
127
}
128