Total Complexity | 6 |
Total Lines | 56 |
Duplicated Lines | 0 % |
Coverage | 75% |
Changes | 0 |
1 | <?php |
||
21 | trait Singleton |
||
22 | { |
||
23 | /** |
||
24 | * @var static singleton instance |
||
25 | */ |
||
26 | protected static $instance; |
||
27 | |||
28 | /** |
||
29 | * Get instance |
||
30 | * |
||
31 | * @return static |
||
32 | */ |
||
33 | 605 | public static function getInstance() |
|
34 | { |
||
35 | 605 | return static::$instance ?? (static::$instance = static::initInstance()); |
|
36 | } |
||
37 | |||
38 | /** |
||
39 | * Initialization of class instance |
||
40 | * |
||
41 | * @return static |
||
42 | */ |
||
43 | 604 | private static function initInstance() |
|
44 | { |
||
45 | 604 | return new static(); |
|
46 | } |
||
47 | |||
48 | /** |
||
49 | * Reset instance |
||
50 | * |
||
51 | * @return void |
||
52 | */ |
||
53 | 819 | public static function resetInstance(): void |
|
54 | { |
||
55 | 819 | static::$instance = null; |
|
56 | 819 | } |
|
57 | |||
58 | /** |
||
59 | * Disabled by access level |
||
60 | */ |
||
61 | 604 | private function __construct() |
|
62 | { |
||
63 | 604 | } |
|
64 | |||
65 | /** |
||
66 | * Disabled by access level |
||
67 | */ |
||
68 | private function __clone() |
||
70 | } |
||
71 | |||
72 | /** |
||
73 | * Disabled by access level |
||
74 | */ |
||
75 | private function __wakeup() |
||
77 | } |
||
78 | } |
||
79 |