| Total Complexity | 6 |
| Total Lines | 44 |
| Duplicated Lines | 0 % |
| Coverage | 85.71% |
| Changes | 4 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 5 | trait Singleton |
||
| 6 | { |
||
| 7 | 1 | protected function __construct() |
|
| 8 | { |
||
| 9 | // Constructor cannot be public |
||
| 10 | 1 | } |
|
| 11 | |||
| 12 | /** |
||
| 13 | * @throws SingletonException |
||
| 14 | */ |
||
| 15 | 1 | public function __clone() |
|
| 16 | { |
||
| 17 | 1 | throw new SingletonException('You can not clone a singleton.'); |
|
| 18 | } |
||
| 19 | |||
| 20 | /** |
||
| 21 | * @throws SingletonException |
||
| 22 | */ |
||
| 23 | 1 | public function __sleep() |
|
| 24 | { |
||
| 25 | 1 | throw new SingletonException('You can not serialize a singleton.'); |
|
| 26 | } |
||
| 27 | |||
| 28 | /** |
||
| 29 | * @throws SingletonException |
||
| 30 | */ |
||
| 31 | public function __wakeup() |
||
| 34 | } |
||
| 35 | |||
| 36 | /** |
||
| 37 | * @return static |
||
| 38 | */ |
||
| 39 | 3 | public static function getInstance() |
|
| 52 |