Singleton   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 60%

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A __clone() 0 3 1
A __wakeup() 0 3 1
A getInstance() 0 8 2
1
<?php
2
declare(strict_types=1);
3
4
namespace codenixsv\Patterns\Creational\Singleton;
5
6
/**
7
 * Class Singleton
8
 * @package codenixsv\Patterns\Creational\Singleton
9
 */
10
final class Singleton
11
{
12
    /**
13
     * @var Singleton
14
     */
15
    private static $instance;
16
17
    /**
18
     * Singleton constructor.
19
     */
20 1
    private function __construct()
21
    {
22 1
    }
23
24
    /**
25
     * Clone magic method
26
     */
27
    private function __clone()
28
    {
29
    }
30
31
    /**
32
     * Wakeup magic method
33
     */
34
    private function __wakeup()
35
    {
36
    }
37
38
    /**
39
     * @return Singleton
40
     */
41 1
    public static function getInstance(): Singleton
42
    {
43 1
        if (!self::$instance) {
44 1
            self::$instance = new self();
45
        }
46
47 1
        return self::$instance;
48
    }
49
}
50