Passed
Push — master ( a6375b...78beea )
by Anton
05:54
created

Singleton   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Test Coverage

Coverage 75%

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 56
ccs 9
cts 12
cp 0.75
rs 10
c 0
b 0
f 0
wmc 6

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __clone() 0 2 1
A initInstance() 0 3 1
A getInstance() 0 3 1
A resetInstance() 0 3 1
A __construct() 0 2 1
A __wakeup() 0 2 1
1
<?php
2
/**
3
 * Bluz Framework Component
4
 *
5
 * @copyright Bluz PHP Team
6
 * @link      https://github.com/bluzphp/framework
7
 */
8
9
declare(strict_types=1);
10
11
namespace Bluz\Common;
12
13
/**
14
 * Singleton
15
 *
16
 * @package  Bluz\Common
17
 * @author   Anton Shevchuk
18
 * @link     https://github.com/bluzphp/framework/wiki/Trait-Singleton
19
 */
20
trait Singleton
21
{
22
    /**
23
     * @var static singleton instance
24
     */
25
    protected static $instance;
26
27
    /**
28
     * Get instance
29
     *
30
     * @return static
31
     */
32 603
    public static function getInstance()
33
    {
34 603
        return static::$instance ?? (static::$instance = static::initInstance());
35
    }
36
37
    /**
38
     * Initialization of class instance
39
     *
40
     * @return static
41
     */
42 602
    private static function initInstance()
43
    {
44 602
        return new static;
45
    }
46
47
    /**
48
     * Reset instance
49
     *
50
     * @return void
51
     */
52 847
    public static function resetInstance(): void
53
    {
54 847
        static::$instance = null;
55 847
    }
56
57
    /**
58
     * Disabled by access level
59
     */
60 602
    private function __construct()
61
    {
62 602
    }
63
64
    /**
65
     * Disabled by access level
66
     */
67
    private function __clone()
68
    {
69
    }
70
71
    /**
72
     * Disabled by access level
73
     */
74
    private function __wakeup()
75
    {
76
    }
77
}
78