Completed
Push — master ( 83cea8...e47c19 )
by Anton
17s queued 12s
created

Singleton::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 0
nc 1
nop 0
dl 0
loc 2
ccs 1
cts 1
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 605
    public static function getInstance()
34
    {
35 605
        return static::$instance ?? (static::$instance = static::initInstance());
36
    }
37
38
    /**
39
     * Initialization of class instance
40
     *
41
     * @return static
42
     */
43 604
    private static function initInstance()
44
    {
45 604
        return new static();
46
    }
47
48
    /**
49
     * Reset instance
50
     *
51
     * @return void
52
     */
53 819
    public static function resetInstance(): void
54
    {
55 819
        static::$instance = null;
56 819
    }
57
58
    /**
59
     * Disabled by access level
60
     */
61 604
    private function __construct()
62
    {
63 604
    }
64
65
    /**
66
     * Disabled by access level
67
     */
68
    private function __clone()
69
    {
70
    }
71
72
    /**
73
     * Disabled by access level
74
     */
75
    private function __wakeup()
76
    {
77
    }
78
}
79