Response::withStatus()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 3
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Cakasim\Payone\Sdk\Http\Message;
6
7
use Psr\Http\Message\ResponseInterface;
8
use Psr\Http\Message\StreamInterface;
9
10
/**
11
 * The HTTP response message implementation.
12
 *
13
 * @author Fabian Böttcher <[email protected]>
14
 * @since 0.1.0
15
 */
16
class Response extends AbstractMessage implements ResponseInterface
17
{
18
    /**
19
     * @var int The response code.
20
     */
21
    protected $statusCode;
22
23
    /**
24
     * Constructs an HTTP response.
25
     *
26
     * @param int $code The status code.
27
     * @param string $protocolVersion The HTTP version.
28
     * @param StreamInterface $body The response body.
29
     * @param array $headers The response headers.
30
     */
31
    public function __construct(int $code, string $protocolVersion, StreamInterface $body, array $headers)
32
    {
33
        parent::__construct($protocolVersion, $body, $headers);
34
        $this->setStatusCode($code);
35
    }
36
37
    /**
38
     * @inheritDoc
39
     */
40
    public function getStatusCode()
41
    {
42
        return $this->statusCode;
43
    }
44
45
    /**
46
     * Sets the status code.
47
     *
48
     * @param int $code The status code.
49
     * @return $this
50
     */
51
    protected function setStatusCode(int $code): self
52
    {
53
        $this->statusCode = $code;
54
        return $this;
55
    }
56
57
    /**
58
     * @inheritDoc
59
     */
60
    public function withStatus($code, $reasonPhrase = '')
61
    {
62
        return (clone $this)->setStatusCode($code);
63
    }
64
65
    /**
66
     * @inheritDoc
67
     */
68
    public function getReasonPhrase()
69
    {
70
        return '';
71
    }
72
}
73