Completed
Push — master ( 7de195...5f1ca1 )
by Henry
08:39
created

includes/Singleton.php (1 issue)

Labels
Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
namespace Redaxscript;
3
4
use function array_key_exists;
5
6
/**
7
 * abstract class to create a singleton class
8
 *
9
 * @since 2.2.0
10
 *
11
 * @package Redaxscript
12
 * @category Singleton
13
 * @author Henry Ruhs
14
 *
15
 * @codeCoverageIgnore
16
 */
17
18
abstract class Singleton
19
{
20
	/**
21
	 * array of static instances
22
	 */
23
24
	protected static array $_instanceArray = [];
0 ignored issues
show
This code did not parse for me. Apparently, there is an error somewhere around this line:

Syntax error, unexpected T_ARRAY, expecting T_FUNCTION or T_CONST
Loading history...
25
26
	/**
27
	 * constructor of the class
28
	 *
29
	 * @since 2.2.0
30
	 */
31
32
	private function __construct()
33
	{
34
	}
35
36
	/**
37
	 * clone of the class
38
	 *
39
	 * @since 5.0.0
40
	 */
41
42
	private function __clone()
43
	{
44
	}
45
46
	/**
47
	 * get the instance
48
	 *
49
	 * @since 5.0.0
50
	 *
51
	 * @return static
52
	 */
53
54
	public static function getInstance()
55
	{
56
		$className = static::class;
57
58
		/* create instance */
59
60
		if (!array_key_exists($className, static::$_instanceArray))
61
		{
62
			static::$_instanceArray[$className] = new static();
63
		}
64
		return static::$_instanceArray[$className];
65
	}
66
67
	/**
68
	 * clear the instance
69
	 *
70
	 * @since 3.0.0
71
	 */
72
73
	public static function clearInstance() : void
74
	{
75
		$className = static::class;
76
		self::$_instanceArray[$className] = null;
77
	}
78
}
79