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

Singleton   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 60%

Importance

Changes 0
Metric Value
dl 0
loc 48
ccs 6
cts 10
cp 0.6
rs 10
c 0
b 0
f 0
wmc 5
lcom 1
cbo 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getInstance() 0 4 1
A initInstance() 0 4 1
A __construct() 0 3 1
A __clone() 0 3 1
A __wakeup() 0 3 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 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