ElasticApmTracerSingleton::inject()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 3
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 7
ccs 4
cts 4
cp 1
crap 2
rs 10
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