Node   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
c 1
b 0
f 0
dl 0
loc 42
ccs 11
cts 11
cp 1
rs 10
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A discover() 0 4 2
A __construct() 0 3 1
A jsonSerialize() 0 4 1
A name() 0 3 1
1
<?php
2
3
namespace ZoiloMora\ElasticAPM\Events\Common\System\Kubernetes;
4
5
use ZoiloMora\ElasticAPM\Helper\Encoding;
6
7
final class Node implements \JsonSerializable
8
{
9
    /**
10
     * Kubernetes node name
11
     *
12
     * @var string|null
13
     */
14
    private $name;
15
16
    /**
17
     * @param string|null $name
18
     */
19 17
    public function __construct($name = null)
20
    {
21 17
        $this->name = $name;
22 17
    }
23
24
    /**
25
     * @return string|null
26
     */
27 1
    public function name()
28
    {
29 1
        return $this->name;
30
    }
31
32
    /**
33
     * @return Node
34
     */
35 14
    public static function discover()
36
    {
37 14
        return new self(
38 14
            getenv('KUBERNETES_NODE_NAME') ?: null
39 14
        );
40
    }
41
42
    /**
43
     * @return array
44
     */
45 1
    public function jsonSerialize()
46
    {
47
        return [
48 1
            'name' => Encoding::keywordField($this->name),
49 1
        ];
50
    }
51
}
52