Language::name()   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
/**
8
 * Name and version of the programming language used
9
 */
10
final class Language implements \JsonSerializable
11
{
12
    /**
13
     * @var string|null
14
     */
15
    private $name;
16
17
    /**
18
     * @var string|null
19
     */
20
    private $version;
21
22
    /**
23
     * @param string|null $name
24
     * @param string|null $version
25
     */
26 16
    public function __construct($name = null, $version = null)
27
    {
28 16
        $this->name = $name;
29 16
        $this->version = $version;
30 16
    }
31
32
    /**
33
     * @return string|null
34
     */
35 13
    public function name()
36
    {
37 13
        return $this->name;
38
    }
39
40
    /**
41
     * @return string|null
42
     */
43 1
    public function version()
44
    {
45 1
        return $this->version;
46
    }
47
48
    /**
49
     * @return Language
50
     */
51 13
    public static function discover()
52
    {
53 13
        return new self(
54 13
            'php',
55 13
            (string) phpversion()
56 13
        );
57
    }
58
59
    /**
60
     * @return array
61
     */
62 1
    public function jsonSerialize()
63
    {
64
        return [
65 1
            'name' => Encoding::keywordField($this->name),
66 1
            'version' => Encoding::keywordField($this->version),
67 1
        ];
68
    }
69
}
70