| Total Complexity | 4 |
| Total Lines | 48 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 22 | trait SingletonTrait |
||
| 23 | { |
||
| 24 | /** |
||
| 25 | * Singleton instance. |
||
| 26 | * |
||
| 27 | * @var static|null |
||
| 28 | */ |
||
| 29 | private static $uniqueInstance = null; |
||
| 30 | |||
| 31 | /** |
||
| 32 | * Singleton constructor. |
||
| 33 | * |
||
| 34 | * The constructor is declared private in order to |
||
| 35 | * prevent new instances from being created. |
||
| 36 | * |
||
| 37 | * @codeCoverageIgnore |
||
| 38 | */ |
||
| 39 | final protected function __construct() |
||
| 40 | { |
||
| 41 | } |
||
| 42 | |||
| 43 | /** |
||
| 44 | * Singleton clone method. |
||
| 45 | * |
||
| 46 | * This method is declared private in order to |
||
| 47 | * prevent existing instances from being cloned. |
||
| 48 | * |
||
| 49 | * @return void |
||
| 50 | * @codeCoverageIgnore |
||
| 51 | */ |
||
| 52 | private function __clone() |
||
| 53 | { |
||
| 54 | } |
||
| 55 | |||
| 56 | /** |
||
| 57 | * Singleton getter. |
||
| 58 | * |
||
| 59 | * Use this method in order to get the singleton instance |
||
| 60 | * |
||
| 61 | * @return static|null |
||
| 62 | */ |
||
| 63 | final public static function getInstance(): ?static |
||
|
|
|||
| 64 | { |
||
| 65 | if (self::$uniqueInstance === null) { |
||
| 66 | self::$uniqueInstance = new static(); |
||
| 67 | } |
||
| 68 | |||
| 69 | return self::$uniqueInstance; |
||
| 70 | } |
||
| 72 |