Service::inEnvironment()   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 1
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 Service implements JsonSerializable
10
{
11
    /**
12
     * @var VersionedName
13
     */
14
    private $agent;
15
16
    /**
17
     * @var string
18
     */
19
    private $name;
20
21
    /**
22
     * @var VersionedName|null
23
     */
24
    private $framework;
25
26
    /**
27
     * @var VersionedName|null
28
     */
29
    private $language;
30
31
    /**
32
     * @var string|null
33
     */
34
    private $environment;
35
36
    /**
37
     * @var VersionedName|null
38
     */
39
    private $runtime;
40
41
    /**
42
     * @var string|null
43
     */
44
    private $version;
45
46 44
    public function __construct(VersionedName $agent, string $name)
47
    {
48 44
        $this->agent = $agent;
49 44
        $this->name  = $name;
50 44
    }
51
52 1
    public function usingFramework(VersionedName $framework): self
53
    {
54 1
        $me            = clone $this;
55 1
        $me->framework = $framework;
56
57 1
        return $me;
58
    }
59
60 1
    public function usingLanguage(VersionedName $language): self
61
    {
62 1
        $me           = clone $this;
63 1
        $me->language = $language;
64
65 1
        return $me;
66
    }
67
68 1
    public function inEnvironment(string $environment): self
69
    {
70 1
        $me              = clone $this;
71 1
        $me->environment = $environment;
72
73 1
        return $me;
74
    }
75
76 1
    public function withRuntime(VersionedName $runtime): self
77
    {
78 1
        $me          = clone $this;
79 1
        $me->runtime = $runtime;
80
81 1
        return $me;
82
    }
83
84 1
    public function atVersion(string $version): self
85
    {
86 1
        $me          = clone $this;
87 1
        $me->version = $version;
88
89 1
        return $me;
90
    }
91
92
    /**
93
     * @return mixed[]
94
     */
95 38
    public function jsonSerialize(): array
96
    {
97 38
        return Serialization::filterUnset([
98 38
            'agent' => Serialization::serializeOr($this->agent),
99 38
            'framework' => Serialization::serializeOr($this->framework),
100 38
            'language' => Serialization::serializeOr($this->language),
101 38
            'name' => $this->name,
102 38
            'environment' => $this->environment,
103 38
            'runtime' => Serialization::serializeOr($this->runtime),
104 38
            'version' => $this->version,
105
        ]);
106
    }
107
}
108