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

Singleton::getInstance()   A

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 0
Metric Value
cc 2
eloc 3
nc 2
nop 0
dl 0
loc 7
ccs 4
cts 4
cp 1
crap 2
rs 9.4285
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