Passed
Push — phpstorm_php ( 759894...3a8c25 )
by Donald
03:03
created

Singleton   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 5
c 1
b 0
f 0
dl 0
loc 31
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 2 1
A getInstance() 0 7 2
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
    public static function getInstance()
31
    {
32
        if (!self::$instance) {
33
            self::$instance = new self();
34
        }
35
36
        return self::$instance;
37
    }
38
}
39