Completed
Push — master ( 98e1dc...22775a )
by Alexander
06:03 queued 02:58
created

SingletonInstance::instance()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 0
loc 11
ccs 6
cts 6
cp 1
rs 9.4286
cc 2
eloc 5
nc 2
nop 0
crap 2
1
<?php
2
/**
3
 * Instance method for Singleton pattern
4
 *
5
 * @file      SingletonInstance.php
6
 *
7
 * PHP version 5.4+
8
 *
9
 * @author    Yancharuk Alexander <alex at itvault dot info>
10
 * @copyright © 2012-2015 Alexander Yancharuk <alex at itvault at info>
11
 * @date      2015-12-10 23:09
12
 * @license   The BSD 3-Clause License
13
 *            <http://opensource.org/licenses/BSD-3-Clause>
14
 */
15
16
namespace Veles\Traits;
17
18
trait SingletonInstance
19
{
20
	/** @var  mixed */
21
	protected static $instance;
22
23
	/**
24
	 * Instance method for any class implements Singleton
25
	 *
26
	 * @return mixed
27
	 */
28 3
	public static function instance()
29
	{
30
		// This line fixes phpunit 5.0.5 "last parenthesis" coverage bug
31 3
		if (null === static::$instance) {
32 2
			$class = get_called_class();
33
34 2
			static::$instance = new $class;
35 2
		}
36
37 3
		return static::$instance;
38
	}
39
}
40