Passed
Push — develop ( f797f2...23731e )
by Berend
10:41 queued 05:09
created

SingletonTrait   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Test Coverage

Coverage 83.33%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 5
c 1
b 0
f 0
dl 0
loc 27
ccs 5
cts 6
cp 0.8333
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getInstance() 0 7 2
A __construct() 0 1 1
A __clone() 0 1 1
1
<?php
2
3
/**
4
 * This file is part of the miBadger package.
5
 *
6
 * @author Michael Webbers <[email protected]>
7
 * @license http://opensource.org/licenses/Apache-2.0 Apache v2 License
8
 */
9
10
namespace miBadger\Singleton;
11
12
/**
13
 * The singleton trait.
14
 *
15
 * @see http://en.wikipedia.org/wiki/Singleton_pattern
16
 * @since 1.0.0
17
 */
18
trait SingletonTrait
19
{
20
	/** @var static The instance. */
21
	private static $instance;
22
23
	/**
24
	 * Protected constructor to prevent creating a new instance of the Singleton class from outside the object.
25
	 */
26 1
	protected function __construct() { }
27
28
	/**
29
	 * Protected clone method to prevent cloning of the Singleton instance.
30
	 */
31
	protected function __clone() { }
32
33
	/**
34
	 * Returns the only instance of the Singleton class.
35
	 *
36
	 * @return static the only instance of the Singleton class.
37
	 */
38 1
	public static function getInstance()
39
	{
40 1
		if (!isset(self::$instance)) {
41 1
			self::$instance = new static();
42
		}
43
44 1
		return self::$instance;
45
	}
46
}
47