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