Service   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 17
c 1
b 0
f 0
dl 0
loc 68
ccs 23
cts 23
cp 1
rs 10
wmc 7

4 Methods

Rating   Name   Duplication   Size   Complexity  
A assertLanguage() 0 4 2
A __construct() 0 13 1
A assertRuntime() 0 8 3
A create() 0 9 1
1
<?php
2
3
namespace ZoiloMora\ElasticAPM\Events\Metadata;
4
5
use ZoiloMora\ElasticAPM\Configuration\CoreConfiguration;
6
use ZoiloMora\ElasticAPM\Events\Common\Service as ServiceBase;
7
use ZoiloMora\ElasticAPM\Events\Common\Service\Framework;
8
use ZoiloMora\ElasticAPM\Events\Common\Service\Language;
9
use ZoiloMora\ElasticAPM\Events\Common\Service\Node;
10
use ZoiloMora\ElasticAPM\Events\Common\Service\Runtime;
11
12
final class Service extends ServiceBase
13
{
14
    /**
15
     * @param string $name
16
     * @param Language $language
17
     * @param Runtime $runtime
18
     * @param Framework|null $framework
19
     * @param string|null $environment
20
     * @param string|null $version
21
     * @param Node|null $node
22
     */
23 16
    public function __construct(
24
        $name,
25
        Language $language,
26
        Runtime $runtime,
27
        Framework $framework = null,
28
        $environment = null,
29
        $version = null,
30
        Node $node = null
31
    ) {
32 16
        parent::__construct(null, $framework, $language, $name, $environment, $runtime, $version, $node);
33
34 16
        $this->assertLanguage();
35 15
        $this->assertRuntime();
36 13
    }
37
38
    /**
39
     * @return void
40
     *
41
     * @throws \InvalidArgumentException
42
     */
43 16
    private function assertLanguage()
44
    {
45 16
        if (null === $this->language()->name()) {
46 1
            throw new \InvalidArgumentException('The [name] of the language is mandatory in the service.');
47
        }
48 15
    }
49
50
    /**
51
     * @return void
52
     *
53
     * @throws \InvalidArgumentException
54
     */
55 15
    private function assertRuntime()
56
    {
57 15
        if (null === $this->runtime()->name()) {
58 1
            throw new \InvalidArgumentException('The [name] of the runtime is mandatory in the service.');
59
        }
60
61 14
        if (null === $this->runtime()->version()) {
62 1
            throw new \InvalidArgumentException('The [version] of the runtime is mandatory in the service.');
63
        }
64 13
    }
65
66
    /**
67
     * @param CoreConfiguration $coreConfiguration
68
     *
69
     * @return Service
70
     */
71 12
    public static function create(CoreConfiguration $coreConfiguration)
72
    {
73 12
        return new self(
74 12
            $coreConfiguration->appName(),
75 12
            Language::discover(),
76 12
            Runtime::discover(),
77 12
            Framework::create($coreConfiguration),
78 12
            $coreConfiguration->environment(),
79 12
            $coreConfiguration->appVersion()
80 12
        );
81
    }
82
}
83