CoreConfiguration   A
last analyzed

Complexity

Total Complexity 12

Size/Duplication

Total Lines 154
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 39
c 1
b 0
f 0
dl 0
loc 154
ccs 42
cts 42
cp 1
rs 10
wmc 12

11 Methods

Rating   Name   Duplication   Size   Complexity  
A active() 0 3 1
A metricSet() 0 3 1
A getDefaultConfig() 0 10 1
A stacktraceLimit() 0 3 1
A __construct() 0 19 2
A environment() 0 3 1
A appName() 0 3 1
A frameworkName() 0 3 1
A create() 0 3 1
A appVersion() 0 3 1
A frameworkVersion() 0 3 1
1
<?php
2
3
namespace ZoiloMora\ElasticAPM\Configuration;
4
5
final class CoreConfiguration
6
{
7
    /**
8
     * @var bool
9
     */
10
    private $active;
11
12
    /**
13
     * @var string
14
     */
15
    private $appName;
16
17
    /**
18
     * @var string
19
     */
20
    private $appVersion;
21
22
    /**
23
     * @var string
24
     */
25
    private $frameworkName;
26
27
    /**
28
     * @var string
29
     */
30
    private $frameworkVersion;
31
32
    /**
33
     * @var string
34
     */
35
    private $environment;
36
37
    /**
38
     * @var int
39
     */
40
    private $stacktraceLimit;
41
42
    /**
43
     * @var bool
44
     */
45
    private $metricSet;
46
47
    /**
48
     * @param array $config
49
     */
50 14
    public function __construct(array $config)
51
    {
52 14
        if (false === array_key_exists('appName', $config)) {
53 1
            throw new \InvalidArgumentException('Missing appName value');
54
        }
55
56 13
        $config = array_merge(
57 13
            $this->getDefaultConfig(),
58
            $config
59 13
        );
60
61 13
        $this->active = (bool) $config['active'];
62 13
        $this->appName = (string) $config['appName'];
63 13
        $this->appVersion = (string) $config['appVersion'];
64 13
        $this->frameworkName = (string) $config['frameworkName'];
65 13
        $this->frameworkVersion = (string) $config['frameworkVersion'];
66 13
        $this->environment = (string) $config['environment'];
67 13
        $this->stacktraceLimit = (int) $config['stacktraceLimit'];
68 13
        $this->metricSet = (bool) $config['metricSet'];
69 13
    }
70
71
    /**
72
     * @param array $config
73
     *
74
     * @return CoreConfiguration
75
     */
76 14
    public static function create(array $config)
77
    {
78 14
        return new self($config);
79
    }
80
81
    /**
82
     * @return array
83
     */
84 13
    private function getDefaultConfig()
85
    {
86
        return [
87 13
            'active' => true,
88 13
            'appVersion' => '',
89 13
            'frameworkName' => null,
90 13
            'frameworkVersion' => null,
91 13
            'environment' => 'dev',
92 13
            'stacktraceLimit' => 0,
93 13
            'metricSet' => true,
94 13
        ];
95
    }
96
97
    /**
98
     * @return bool
99
     */
100 4
    public function active()
101
    {
102 4
        return $this->active;
103
    }
104
105
    /**
106
     * @return string
107
     */
108 12
    public function appName()
109
    {
110 12
        return $this->appName;
111
    }
112
113
    /**
114
     * @return string
115
     */
116 12
    public function appVersion()
117
    {
118 12
        return $this->appVersion;
119
    }
120
121
    /**
122
     * @return string
123
     */
124 12
    public function frameworkName()
125
    {
126 12
        return $this->frameworkName;
127
    }
128
129
    /**
130
     * @return string
131
     */
132 12
    public function frameworkVersion()
133
    {
134 12
        return $this->frameworkVersion;
135
    }
136
137
    /**
138
     * @return string
139
     */
140 12
    public function environment()
141
    {
142 12
        return $this->environment;
143
    }
144
145
    /**
146
     * @return int
147
     */
148 5
    public function stacktraceLimit()
149
    {
150 5
        return $this->stacktraceLimit;
151
    }
152
153
    /**
154
     * @return bool
155
     */
156 12
    public function metricSet()
157
    {
158 12
        return $this->metricSet;
159
    }
160
}
161