Passed
Push — master ( d81171...ddb4d4 )
by Frank
02:35
created

Context   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 84
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 1
dl 0
loc 84
ccs 27
cts 27
cp 1
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A withCustomVariable() 0 7 1
A withRequest() 0 7 1
A withTag() 0 7 1
A jsonSerialize() 0 10 1
A withResponse() 0 7 1
A withUser() 0 7 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 1
    public function withCustomVariable(string $name, $value): self
40
    {
41 1
        $me                = clone $this;
42 1
        $me->custom[$name] = $value;
43
44 1
        return $me;
45
    }
46
47 1
    public function withResponse(Response $response): self
48
    {
49 1
        $me           = clone $this;
50 1
        $me->response = $response;
51
52 1
        return $me;
53
    }
54
55 13
    public function withRequest(Request $request): self
56
    {
57 13
        $me          = clone $this;
58 13
        $me->request = $request;
59
60 13
        return $me;
61
    }
62
63 37
    public function withTag(string $tag, string $value): self
64
    {
65 37
        $me                = clone $this;
66 37
        $me->tagList[$tag] = $value;
67
68 37
        return $me;
69
    }
70
71 1
    public function withUser(User $user): self
72
    {
73 1
        $me       = clone $this;
74 1
        $me->user = $user;
75
76 1
        return $me;
77
    }
78
79
    /**
80
     * @return mixed[]
81
     */
82 46
    public function jsonSerialize(): array
83
    {
84 46
        return Serialization::filterUnset([
85 46
            'custom' => $this->custom,
86 46
            'response' => Serialization::serializeOr($this->response),
87 46
            'request' => Serialization::serializeOr($this->request),
88 46
            'tags' => $this->tagList,
89 46
            'user' => Serialization::serializeOr($this->user),
90
        ]);
91
    }
92
}
93