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

Singleton   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 31
ccs 4
cts 4
cp 1
rs 10
c 0
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getInstance() 0 7 2
A __construct() 0 2 1
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