Completed
Push — master ( e91368...26d5da )
by Anton
9s
created

Singleton::__clone()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 2
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
/**
10
 * @namespace
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
     * Set or replace instance
30
     *
31
     * @param  mixed $instance
32
     * @return void
33
     */
34 630
    public static function setInstance($instance)
35
    {
36 630
        static::$instance = $instance;
37 630
    }
38
39
    /**
40
     * Get instance
41
     *
42
     * @return static
43
     */
44 653
    public static function getInstance()
45
    {
46 653
        return static::$instance ?? (static::$instance = static::initInstance());
47
    }
48
49
    /**
50
     * Initialization of class instance
51
     *
52
     * @return static
53
     */
54 1
    protected static function initInstance()
55
    {
56 1
        return new static;
57
    }
58
59
    /**
60
     * Disabled by access level
61
     */
62 1
    protected function __construct()
63
    {
64 1
    }
65
66
    /**
67
     * Disabled by access level
68
     */
69
    protected function __clone()
70
    {
71
    }
72
}
73