Singleton::__construct()   A
last analyzed

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 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 0
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 2
ccs 0
cts 0
cp 0
crap 2
rs 10
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
    protected static self $instance;
9
10
    /**
11
     * Singleton constructor.
12
     *
13
     * Exists purely to restrict visibility.
14
     *
15
     * @codeCoverageIgnore
16
     */
17
    protected function __construct()
18
    {
19
        // do nothing
20
    }
21
22
    /**
23
     * Provides access to one (and only one) instance of this class.
24
     *
25
     * Subsequent calls to this method will return the same instance.
26
     *
27
     * @return self
28
     */
29
    public static function getInstance(): self
30 2
    {
31
        if (!isset(self::$instance)) {
32 2
            self::$instance = new self();
33 1
        }
34
35
        return self::$instance;
36 2
    }
37
}
38