Ticker::new()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 3
dl 0
loc 9
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * Monitor ticker
4
 * User: moyo
5
 * Date: 2018/5/19
6
 * Time: 2:43 PM
7
 */
8
9
namespace Carno\Monitor;
10
11
use Carno\Monitor\Collector\TWorker;
12
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
53
    {
54
        self::$worker && self::$worker->stopping();
55
    }
56
}
57