Completed
Push — master ( 122153...1ebbbc )
by Nazar
04:18
created

Singleton

Complexity

Total Complexity 0

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A instance() 0 21 4
1
<?php
2
/**
3
 * @package   Http server
4
 * @category  modules
5
 * @author    Nazar Mokrynskyi <[email protected]>
6
 * @copyright Copyright (c) 2015-2016, Nazar Mokrynskyi
7
 * @license   MIT License, see license.txt
8
 */
9
namespace cs;
10
use
11
	cs\Singleton\Base;
12
13
/**
14
 * @inheritdoc
15
 */
16
trait Singleton {
17
	use Base;
18
	/**
19
	 * @inheritdoc
20
	 */
21
	static function instance ($check = false) {
22
		static $instance;
23
		$class                    = get_called_class();
24
		$request_specific_classes = [
25
			'cs\\Event',
26
			'cs\\Index',
27
			'cs\\Menu',
28
			'cs\\Page',
29
			'cs\\Page\\Meta',
30
			'cs\\Route',
31
			'cs\\Session'
32
		];
33
		if (in_array($class, $request_specific_classes)) {
34
			$objects_pool = &objects_pool();
35
			if (isset($objects_pool[$class]) && $objects_pool[$class]) {
36
				return $objects_pool[$class];
37
			}
38
			return self::instance_prototype($objects_pool[$class], $check);
39
		}
40
		return self::instance_prototype($instance, $check);
41
	}
42
}
43