Agent::ephemeralId()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
1
<?php
2
3
namespace ZoiloMora\ElasticAPM\Events\Common\Service;
4
5
use ZoiloMora\ElasticAPM\Helper\Encoding;
6
7
final class Agent implements \JsonSerializable
8
{
9
    const NAME = 'zoilomora/elastic-apm-agent-php';
10
    const VERSION = '1.0.0';
11
12
    /**
13
     * Name of the Elastic APM agent, e.g. "Python"
14
     *
15
     * @var string|null
16
     */
17
    private $name;
18
19
    /**
20
     * Version of the Elastic APM agent, e.g."1.0.0"
21
     *
22
     * @var string|null
23
     */
24
    private $version;
25
26
    /**
27
     * Free format ID used for metrics correlation by some agents
28
     *
29
     * @var string|null
30
     */
31
    private $ephemeralId;
32
33
    /**
34
     * @param string|null $name
35
     * @param string|null $version
36
     * @param string|null $ephemeralId
37
     */
38 20
    private function __construct($name = null, $version = null, $ephemeralId = null)
39
    {
40 20
        $this->name = $name;
41 20
        $this->version = $version;
42 20
        $this->ephemeralId = $ephemeralId;
43 20
    }
44
45
    /**
46
     * @return string|null
47
     */
48 1
    public function name()
49
    {
50 1
        return $this->name;
51
    }
52
53
    /**
54
     * @return string|null
55
     */
56 1
    public function version()
57
    {
58 1
        return $this->version;
59
    }
60
61
    /**
62
     * @return string|null
63
     */
64 1
    public function ephemeralId()
65
    {
66 1
        return $this->ephemeralId;
67
    }
68
69
    /**
70
     * @return Agent
71
     */
72 20
    public static function discover()
73
    {
74 20
        return new self(
75 20
            self::NAME,
76
            self::VERSION
77 20
        );
78
    }
79
80
    /**
81
     * @return array
82
     */
83 1
    public function jsonSerialize()
84
    {
85
        return [
86 1
            'name' => Encoding::keywordField($this->name),
87 1
            'version' => Encoding::keywordField($this->version),
88 1
            'ephemeral_id' => Encoding::keywordField($this->ephemeralId),
89 1
        ];
90
    }
91
}
92