Passed
Push — master ( 3aaaf2...ec0174 )
by Anton
06:15 queued 36s
created

Singleton::getInstance()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * Bluz Framework Component
5
 *
6
 * @copyright Bluz PHP Team
7
 * @link      https://github.com/bluzphp/framework
8
 */
9
10
declare(strict_types=1);
11
12
namespace Bluz\Common;
13
14
/**
15
 * Singleton
16
 *
17
 * @package  Bluz\Common
18
 * @author   Anton Shevchuk
19
 * @link     https://github.com/bluzphp/framework/wiki/Trait-Singleton
20
 */
21
trait Singleton
22
{
23
    /**
24
     * @var static singleton instance
25
     */
26
    protected static $instance;
27
28
    /**
29
     * Get instance
30
     *
31
     * @return static
32
     */
33 588
    public static function getInstance()
34
    {
35 588
        return static::$instance ?? (static::$instance = static::initInstance());
36
    }
37
38
    /**
39
     * Initialization of class instance
40
     *
41
     * @return static
42
     */
43 587
    private static function initInstance()
44
    {
45 587
        return new static();
46
    }
47
48
    /**
49
     * Reset instance
50
     *
51
     * @return void
52
     */
53 802
    public static function resetInstance(): void
54
    {
55 802
        static::$instance = null;
56 802
    }
57
58
    /**
59
     * Disabled by access level
60
     */
61 587
    private function __construct()
62
    {
63 587
    }
64
65
    /**
66
     * Disabled by access level
67
     */
68
    private function __clone()
69
    {
70
    }
71
}
72