SingletonTrait   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
c 1
b 0
f 0
lcom 0
cbo 1
dl 0
loc 29
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A __clone() 0 3 1
A __wakeup() 0 3 1
1
<?php
2
namespace Fwolf\Base\Singleton;
3
4
/**
5
 * Singleton pattern implement
6
 *
7
 * Use only when class REALLY NEED to be singleton, that is say, if class has
8
 * more than one instances, may cause error or waste mass resource. Because
9
 * singleton may introduce tight coupling and hard to mock.
10
 *
11
 * @see         http://www.phptherightway.com/pages/Design-Patterns.html
12
 *
13
 * Illegal usage will cause fatal error and cannot catch, so skip test.
14
 * @codeCoverageIgnore
15
 *
16
 * @copyright   Copyright 2013-2016 Fwolf
17
 * @license     http://opensource.org/licenses/MIT MIT
18
 */
19
trait SingletonTrait
20
{
21
    use SingleInstanceTrait;
22
23
24
    /**
25
     * Prevent 'new' operator from outside
26
     */
27
    protected function __construct()
28
    {
29
    }
30
31
32
    /**
33
     * Prevent clone method
34
     */
35
    private function __clone()
36
    {
37
    }
38
39
40
    /**
41
     * Prevent unserialize method
42
     */
43
    /** @noinspection PhpUnusedPrivateMethodInspection */
44
    private function __wakeup()
45
    {
46
    }
47
}
48