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

SingletonTrait::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 1
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 0
c 1
b 0
f 0
dl 0
loc 1
ccs 1
cts 1
cp 1
rs 10
cc 1
nc 1
nop 0
crap 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