Singleton   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
c 1
b 0
f 0
dl 0
loc 37
rs 10
wmc 7

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __wakeup() 0 2 1
A __clone() 0 2 1
A instance() 0 7 2
A boot() 0 2 1
A init() 0 2 1
A __construct() 0 3 1
1
<?php
2
3
namespace Ffcms\Core\Traits;
4
5
/**
6
 * Class Singleton. Basic structure of singleton pattern.
7
 * @package Ffcms\Core\Traits
8
 */
9
trait Singleton
10
{
11
    protected static $instance;
12
13
    /**
14
     * @return static
15
     */
16
    final public static function instance()
17
    {
18
        if (!isset(static::$instance)) {
19
            static::$instance = new static;
20
            static::boot();
21
        }
22
        return static::$instance;
23
    }
24
    
25
    public static function boot()
26
    {
27
    }
28
29
    /**
30
     * Override constructor
31
     */
32
    final private function __construct()
33
    {
34
        $this->init();
35
    }
36
37
    // disable some magic
38
    protected function init()
39
    {
40
    }
41
    final private function __wakeup()
42
    {
43
    }
44
    final private function __clone()
45
    {
46
    }
47
}
48