Passed
Branch 2.0 (d24509)
by Donald
02:04
created

Singleton::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 0
nc 1
nop 0
dl 0
loc 2
ccs 0
cts 0
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php namespace Chekote\NounStore;
2
3
/**
4
 * Ensures that one (and only one) instance of the class exists.
5
 */
6
trait Singleton
7
{
8
    /** @var self */
9
    protected static $instance;
10
11
    /**
12
     * Singleton constructor.
13
     *
14
     * Exists purely to restrict visibility.
15
     *
16
     * @codeCoverageIgnore
17
     */
18
    protected function __construct()
19
    {
20
        // do nothing
21
    }
22
23
    /**
24
     * Provides access to one (and only one) instance of this class.
25
     *
26
     * Subsequent calls to this method will return the same instance.
27
     *
28
     * @return self
29
     */
30 2
    public static function getInstance()
31
    {
32 2
        if (!self::$instance) {
33 1
            self::$instance = new self();
34
        }
35
36 2
        return self::$instance;
37
    }
38
}
39