Passed
Push — master ( f3d4b9...9aa72c )
by Frank
02:20
created

Context::getRequest()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

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
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 TechDeCo\ElasticApmAgent\Serialization;
8
9
final class Context implements JsonSerializable
10
{
11
    /**
12
     * @var mixed[]|null
13
     */
14
    private $custom;
15
16
    /**
17
     * @var Response|null
18
     */
19
    private $response;
20
21
    /**
22
     * @var Request|null
23
     */
24
    private $request;
25
26
    /**
27
     * @var string[]
28
     */
29
    private $tagList = [];
30
31
    /**
32
     * @var User|null
33
     */
34
    private $user;
35
36
    /**
37
     * @param mixed $value
38
     */
39 2
    public function withCustomVariable(string $name, $value): self
40
    {
41 2
        $me                = clone $this;
42 2
        $me->custom[$name] = $value;
43
44 2
        return $me;
45
    }
46
47 5
    public function getResponse(): ?Response
48
    {
49 5
        return $this->response;
50
    }
51
52 6
    public function withResponse(Response $response): self
53
    {
54 6
        $me           = clone $this;
55 6
        $me->response = $response;
56
57 6
        return $me;
58
    }
59
60 5
    public function getRequest(): ?Request
61
    {
62 5
        return $this->request;
63
    }
64
65 19
    public function withRequest(Request $request): self
66
    {
67 19
        $me          = clone $this;
68 19
        $me->request = $request;
69
70 19
        return $me;
71
    }
72
73 83
    public function withTag(string $tag, string $value): self
74
    {
75 83
        $me                = clone $this;
76 83
        $me->tagList[$tag] = $value;
77
78 83
        return $me;
79
    }
80
81 1
    public function withUser(User $user): self
82
    {
83 1
        $me       = clone $this;
84 1
        $me->user = $user;
85
86 1
        return $me;
87
    }
88
89
    /**
90
     * @return mixed[]
91
     */
92 46
    public function jsonSerialize(): array
93
    {
94 46
        return Serialization::filterUnset([
95 46
            'custom' => $this->custom,
96 46
            'response' => Serialization::serializeOr($this->response),
97 46
            'request' => Serialization::serializeOr($this->request),
98 46
            'tags' => $this->tagList,
99 46
            'user' => Serialization::serializeOr($this->user),
100
        ]);
101
    }
102
}
103