Completed
Pull Request — develop (#1350)
by Naveen
03:35
created

Singleton::get_instance()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 0
dl 0
loc 8
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Wordlift\Common;
4
5
abstract class Singleton {
6
7
	static $instances = array();
8
9
	protected function __construct() {
10
	}
11
12
	public static function get_instance() {
13
		$child_class_name = get_called_class();
14
		if ( ! array_key_exists( $child_class_name, self::$instances ) ) {
15
			self::$instances[ $child_class_name ] = new $child_class_name();
16
		}
17
18
		return self::$instances[ $child_class_name ];
19
	}
20
21
}
22