Passed
Branch staging (dcaea3)
by Tony Karavasilev (Тони
02:31
created

SingleInstancingTrait::getInstance()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 4
c 1
b 0
f 0
dl 0
loc 9
ccs 5
cts 5
cp 1
rs 10
cc 2
nc 2
nop 0
crap 2
1
<?php
2
3
/**
4
 * Trait implementation of getting a single instance of an object.
5
 */
6
7
namespace CryptoManana\Core\Traits\DesignPatterns;
8
9
/**
10
 * Trait SingleInstancingTrait - Reusable implementation of `SingleInstancingInterface`.
11
 *
12
 * @see \CryptoManana\Core\Interfaces\DesignPatterns\SingleInstancingInterface The abstract specification.
13
 *
14
 * @package CryptoManana\Core\Traits\DesignPatterns
15
 */
16
trait SingleInstancingTrait
17
{
18
    /**
19
     * Gives a unified access point for the current object instance.
20
     *
21
     * @return static|null An instance.
22
     */
23 30
    public static function getInstance()
24
    {
25 30
        static $singleInstance = null;
26
27 30
        if ($singleInstance === null) {
28 12
            $singleInstance = new static();
29
        }
30
31 30
        return $singleInstance;
32
    }
33
}
34