Completed
Pull Request — master (#397)
by Anton
05:51
created

Singleton::__wakeup()   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
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 659
    public static function getInstance()
33
    {
34 659
        return static::$instance ?? (static::$instance = static::initInstance());
35
    }
36
37
    /**
38
     * Initialization of class instance
39
     *
40
     * @return static
41
     */
42 1
    private static function initInstance()
43
    {
44 1
        return new static;
45
    }
46
47
    /**
48
     * Disabled by access level
49
     */
50 1
    private function __construct()
51
    {
52 1
    }
53
54
    /**
55
     * Disabled by access level
56
     */
57
    private function __clone()
58
    {
59
    }
60
61
    /**
62
     * Disabled by access level
63
     */
64
    private function __wakeup()
65
    {
66
    }
67
}
68