Failed Conditions
Push — develop_3.0 ( 80553c...f9d8ad )
by Adrien
31:09
created

Singleton   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 85.71%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
lcom 1
cbo 0
dl 0
loc 31
ccs 6
cts 7
cp 0.8571
rs 10
c 1
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A init() 0 1 1
A __wakeup() 0 1 1
A __clone() 0 1 1
A getInstance() 0 6 2
1
<?php
2
3
namespace Box\Spout\Common;
4
5
/**
6
 * Class Singleton
7
 * Defines a class as a singleton.
8
 *
9
 * @package Box\Spout\Common
10
 */
11
trait Singleton
12
{
13
    protected static $instance;
14
15
    /**
16
     * @return static
17
     */
18 209
    final public static function getInstance()
19
    {
20 209
        return isset(static::$instance)
21
            ? static::$instance
22 209
            : static::$instance = new static;
23
    }
24
25
    /**
26
     * Singleton constructor.
27
     */
28 2
    final private function __construct()
29
    {
30 2
        $this->init();
31 2
    }
32
33
    /**
34
     * Initializes the singleton
35
     * @return void
36
     */
37
    protected function init() {}
38
39
    final private function __wakeup() {}
40
    final private function __clone() {}
41
}
42