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

SingletonInstance   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 1 Features 0
Metric Value
wmc 2
c 1
b 1
f 0
lcom 1
cbo 0
dl 0
loc 22
ccs 6
cts 6
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A instance() 0 11 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