| Total Complexity | 5 |
| Total Lines | 49 |
| Duplicated Lines | 0 % |
| Coverage | 90% |
| 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 | 588 | public static function getInstance() |
|
| 34 | { |
||
| 35 | 588 | return static::$instance ?? (static::$instance = static::initInstance()); |
|
| 36 | } |
||
| 37 | |||
| 38 | /** |
||
| 39 | * Initialization of class instance |
||
| 40 | * |
||
| 41 | * @return static |
||
| 42 | */ |
||
| 43 | 587 | private static function initInstance() |
|
| 44 | { |
||
| 45 | 587 | return new static(); |
|
| 46 | } |
||
| 47 | |||
| 48 | /** |
||
| 49 | * Reset instance |
||
| 50 | * |
||
| 51 | * @return void |
||
| 52 | */ |
||
| 53 | 802 | public static function resetInstance(): void |
|
| 54 | { |
||
| 55 | 802 | static::$instance = null; |
|
| 56 | 802 | } |
|
| 57 | |||
| 58 | /** |
||
| 59 | * Disabled by access level |
||
| 60 | */ |
||
| 61 | 587 | private function __construct() |
|
| 62 | { |
||
| 63 | 587 | } |
|
| 64 | |||
| 65 | /** |
||
| 66 | * Disabled by access level |
||
| 67 | */ |
||
| 68 | private function __clone() |
||
| 70 | } |
||
| 71 | } |
||
| 72 |