ElasticApmTracerSingleton   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 33
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 33
ccs 9
cts 9
cp 1
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A instance() 0 7 2
A inject() 0 7 2
1
<?php
2
3
namespace ZoiloMora\ElasticAPM;
4
5
final class ElasticApmTracerSingleton
6
{
7
    /**
8
     * @var ElasticApmTracer
9
     */
10
    private static $instance = null;
11
12
    /**
13
     * @param ElasticApmTracer $instance
14
     *
15
     * @throws \Exception
16
     */
17 2
    public static function inject(ElasticApmTracer $instance)
18
    {
19 2
        if (null !== self::$instance) {
20 1
            throw new \Exception('Already an injected object, it cannot be replaced.');
21
        }
22
23 2
        self::$instance = $instance;
24 2
    }
25
26
    /**
27
     * @return ElasticApmTracer
28
     *
29
     * @throws \Exception
30
     */
31 2
    public static function instance()
32
    {
33 2
        if (null === self::$instance) {
34 1
            throw new \Exception('The instance has not yet been injected.');
35
        }
36
37 1
        return self::$instance;
38
    }
39
}
40