Completed
Push — master ( 83cea8...e47c19 )
by Anton
17s queued 12s
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 resetInstance() 0 3 1
A __construct() 0 2 1
A __wakeup() 0 2 1
A initInstance() 0 3 1
A getInstance() 0 3 1
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