Completed
Pull Request — master (#466)
by Anton
14:29 queued 12:20
created

Singleton::__clone()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 0
nc 1
nop 0
dl 0
loc 2
ccs 0
cts 1
cp 0
crap 2
rs 10
c 0
b 0
f 0
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