Harvester::join()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 2
dl 0
loc 8
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * Metrics harvester
4
 * User: moyo
5
 * Date: 28/12/2017
6
 * Time: 4:05 PM
7
 */
8
9
namespace Carno\Monitor;
10
11
use Carno\Container\DI;
12
use Carno\Monitor\Collector\HScanner;
13
use Carno\Monitor\Contracts\Telemetry;
14
15
class Harvester
16
{
17
    /**
18
     * @var HScanner
19
     */
20
    private static $scanner = null;
21
22
    /**
23
     * @param Telemetry $source
24
     * @param int $period
25
     * @return Telemetry
26
     */
27
    public static function join(Telemetry $source, int $period = 5) : Telemetry
28
    {
29
        if (DI::has(Daemon::class)) {
30
            (self::$scanner ?? self::$scanner = new HScanner(DI::get(Daemon::class)))
31
                ->sourcing($source, $period)
32
            ;
33
        }
34
        return $source;
35
    }
36
37
    /**
38
     * @param Telemetry $source
39
     */
40
    public static function forget(Telemetry $source) : void
41
    {
42
        self::$scanner && self::$scanner->removing($source);
43
    }
44
45
    /**
46
     */
47
    public static function shutdown() : void
48
    {
49
        self::$scanner && self::$scanner->stopping();
50
    }
51
}
52