Completed
Push — master ( 077610...3e9689 )
by Nazar
04:13
created

Singleton

Complexity

Total Complexity 0

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 0
c 2
b 0
f 1
lcom 0
cbo 1
dl 0
loc 29

1 Method

Rating   Name   Duplication   Size   Complexity  
B instance() 0 23 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\\Request',
31
			'cs\\Response',
32
			'cs\\Route',
33
			'cs\\Session'
34
		];
35
		if (in_array($class, $request_specific_classes)) {
36
			$objects_pool = &objects_pool();
37
			if (isset($objects_pool[$class]) && $objects_pool[$class]) {
38
				return $objects_pool[$class];
39
			}
40
			return self::instance_prototype($objects_pool[$class], $check);
41
		}
42
		return self::instance_prototype($instance, $check);
43
	}
44
}
45