| Total Complexity | 5 | 
| Total Lines | 48 | 
| Duplicated Lines | 0 % | 
| Coverage | 0% | 
| Changes | 1 | ||
| Bugs | 0 | Features | 0 | 
| 1 | <?php | ||
| 7 | class Singleton | ||
| 8 | { | ||
| 9 | /** | ||
| 10 | * Singleton instances will be stored in this register. | ||
| 11 | * | ||
| 12 | * @var array | ||
| 13 | */ | ||
| 14 | private static $instances = array(); | ||
| 15 | |||
| 16 | /** | ||
| 17 | * Singleton's constructor should not be public. However, it can't be | ||
| 18 | * private either if we want to allow subclassing. | ||
| 19 | */ | ||
| 20 | protected function __construct() | ||
| 21 |     { | ||
| 22 | // Unreachable. | ||
| 23 | } | ||
| 24 | |||
| 25 | /** | ||
| 26 | * Cloning and unserialization are not permitted for singletons. | ||
| 27 | */ | ||
| 28 | protected function __clone() | ||
| 30 | // Unreachable. | ||
| 31 | } | ||
| 32 | |||
| 33 | /** | ||
| 34 | * @throws Exception | ||
| 35 | * | ||
| 36 | * @return void | ||
| 37 | */ | ||
| 38 | public function __wakeup(): void | ||
| 39 |     { | ||
| 40 |         throw new Exception('Cannot unserialize singleton'); | ||
| 41 | } | ||
| 42 | |||
| 43 | /** | ||
| 44 | * The method you use to get the Singleton's instance. | ||
| 45 | */ | ||
| 46 | public static function getInstance(): self | ||
| 55 | } | ||
| 56 | } | ||
| 57 |