Completed
Push — master ( ffda8d...a99b9b )
by Timo
03:15
created

CachedResponse::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 7
ccs 6
cts 6
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
namespace hamburgscleanest\GuzzleAdvancedThrottle\Cache;
4
5
use GuzzleHttp\Psr7\Response;
6
use Psr\Http\Message\ResponseInterface;
7
8
/**
9
 * Class CachedResponse
10
 * @package hamburgscleanest\GuzzleAdvancedThrottle\Cache
11
 */
12
class CachedResponse
13
{
14
15
    /** @var array */
16
    private $_headers;
17
    /** @var string */
18
    private $_body;
19
    /** @var string */
20
    private $_protocol;
21
    /** @var int */
22
    private $_statusCode;
23
    /** @var string */
24
    private $_reason;
25
26
27
    /**
28
     * CachedResponse constructor.
29
     * @param ResponseInterface $response
30
     */
31 14
    public function __construct(ResponseInterface $response)
32
    {
33 14
        $this->_headers = $response->getHeaders();
34 14
        $this->_body = (string) $response->getBody();
35 14
        $this->_protocol = $response->getProtocolVersion();
36 14
        $this->_statusCode = $response->getStatusCode();
37 14
        $this->_reason = $response->getReasonPhrase();
38 14
    }
39
40
    /**
41
     * @return Response
42
     */
43 11
    public function getResponse() : Response
44
    {
45 11
        return new Response(
46 11
            $this->_statusCode,
47 11
            $this->_headers,
48 11
            $this->_body,
49 11
            $this->_protocol,
50 11
            $this->_reason
51
        );
52
    }
53
}
54