Response::thatIsFinished()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 7
c 0
b 0
f 0
ccs 4
cts 4
cp 1
rs 10
cc 1
nc 1
nop 0
crap 1
1
<?php
2
declare(strict_types=1);
3
4
namespace TechDeCo\ElasticApmAgent\Message;
5
6
use JsonSerializable;
7
use Psr\Http\Message\ResponseInterface;
8
use TechDeCo\ElasticApmAgent\Serialization;
9
10
final class Response implements JsonSerializable
11
{
12
    /**
13
     * @var bool|null
14
     */
15
    private $finished;
16
17
    /**
18
     * @var mixed[]
19
     */
20
    private $headerList = [];
21
22
    /**
23
     * @var bool|null
24
     */
25
    private $hasHeadersSent;
26
27
    /**
28
     * @var int|null
29
     */
30
    private $httpStatusCode;
31
32 4
    public static function fromHttpResponse(ResponseInterface $response): self
33
    {
34 4
        return (new self())->resultingInStatusCode($response->getStatusCode());
35
    }
36
37 1
    public function thatIsFinished(): self
38
    {
39 1
        $me           = clone $this;
40 1
        $me->finished = true;
41
42 1
        return $me;
43
    }
44
45 1
    public function thatIsNotFinished(): self
46
    {
47 1
        $me           = clone $this;
48 1
        $me->finished = false;
49
50 1
        return $me;
51
    }
52
53
    /**
54
     * @param mixed $value
55
     */
56 4
    public function withHeader(string $name, $value): self
57
    {
58 4
        $me                    = clone $this;
59 4
        $me->headerList[$name] = $value;
60
61 4
        return $me;
62
    }
63
64 1
    public function thatHasSentHeaders(): self
65
    {
66 1
        $me                 = clone $this;
67 1
        $me->hasHeadersSent = true;
68
69 1
        return $me;
70
    }
71
72 1
    public function thatHasNotSentHeaders(): self
73
    {
74 1
        $me                 = clone $this;
75 1
        $me->hasHeadersSent = false;
76
77 1
        return $me;
78
    }
79
80 7
    public function resultingInStatusCode(int $httpStatusCode): self
81
    {
82 7
        $me                 = clone $this;
83 7
        $me->httpStatusCode = $httpStatusCode;
84
85 7
        return $me;
86
    }
87
88
    /**
89
     * @return mixed[]
90
     */
91 9
    public function jsonSerialize(): array
92
    {
93 9
        return Serialization::filterUnset([
94 9
            'finished' => $this->finished,
95 9
            'headers' => $this->headerList,
96 9
            'headers_sent' => $this->hasHeadersSent,
97 9
            'status_code' => $this->httpStatusCode,
98
        ]);
99
    }
100
}
101