Runtime::jsonSerialize()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 5
ccs 3
cts 3
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 Runtime implements \JsonSerializable
8
{
9
    /**
10
     * @var string|null
11
     */
12
    private $name;
13
14
    /**
15
     * @var string|null
16
     */
17
    private $version;
18
19
    /**
20
     * @param string|null $name
21
     * @param string|null $version
22
     */
23 16
    public function __construct($name = null, $version = null)
24
    {
25 16
        $this->name = $name;
26 16
        $this->version = $version;
27 16
    }
28
29
    /**
30
     * @return string|null
31
     */
32 13
    public function name()
33
    {
34 13
        return $this->name;
35
    }
36
37
    /**
38
     * @return string|null
39
     */
40 13
    public function version()
41
    {
42 13
        return $this->version;
43
    }
44
45
    /**
46
     * @return Runtime
47
     */
48 13
    public static function discover()
49
    {
50 13
        return new self(
51 13
            'php',
52 13
            (string) phpversion()
53 13
        );
54
    }
55
56
    /**
57
     * @return array
58
     */
59 1
    public function jsonSerialize()
60
    {
61
        return [
62 1
            'name' => Encoding::keywordField($this->name),
63 1
            'version' => Encoding::keywordField($this->version),
64 1
        ];
65
    }
66
}
67