| Total Complexity | 5 |
| Total Lines | 42 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 13 | class Ticker |
||
| 14 | { |
||
| 15 | /** |
||
| 16 | * @var int |
||
| 17 | */ |
||
| 18 | private static $idg = 0; |
||
| 19 | |||
| 20 | /** |
||
| 21 | * @var TWorker |
||
| 22 | */ |
||
| 23 | private static $worker = null; |
||
| 24 | |||
| 25 | /** |
||
| 26 | * @param array $metrics |
||
| 27 | * @param callable $worker |
||
| 28 | * @param int $period |
||
| 29 | * @return string |
||
| 30 | */ |
||
| 31 | public static function new(array $metrics, callable $worker, int $period = 5) : string |
||
| 32 | { |
||
| 33 | $idg = sprintf('tw-%d', self::$idg ++); |
||
| 34 | |||
| 35 | (self::$worker ?? self::$worker = new TWorker) |
||
| 36 | ->adding($idg, $metrics, $worker, $period) |
||
| 37 | ; |
||
| 38 | |||
| 39 | return $idg; |
||
| 40 | } |
||
| 41 | |||
| 42 | /** |
||
| 43 | * @param string $id |
||
| 44 | */ |
||
| 45 | public static function stop(string $id) : void |
||
| 46 | { |
||
| 47 | self::$worker && self::$worker->removing($id); |
||
| 48 | } |
||
| 49 | |||
| 50 | /** |
||
| 51 | */ |
||
| 52 | public static function exit() : void |
||
| 55 | } |
||
| 56 | } |
||
| 57 |