Reporting   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 16
dl 0
loc 44
rs 10
c 0
b 0
f 0
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A register() 0 3 1
A deregister() 0 3 1
A reporting() 0 9 2
A typed() 0 8 1
1
<?php
2
/**
3
 * As reporter
4
 * User: moyo
5
 * Date: 2018/5/18
6
 * Time: 5:54 PM
7
 */
8
9
namespace Carno\Monitor\Chips\Metrical;
10
11
use Carno\Monitor\Contracts\Metrical;
12
use Carno\Monitor\Harvester;
13
use Carno\Monitor\Metrics\Counter;
14
use Carno\Monitor\Metrics\Gauge;
15
use Carno\Monitor\Metrics\Histogram;
16
use Carno\Monitor\Metrics\Summary;
17
18
trait Reporting
19
{
20
    /**
21
     * @param int $period
22
     * @return static
23
     */
24
    public function register(int $period = 5) : self
25
    {
26
        return Harvester::join($this, $period);
0 ignored issues
show
Bug Best Practice introduced by
The expression return Carno\Monitor\Har...r::join($this, $period) returns the type Carno\Monitor\Contracts\Telemetry which is incompatible with the type-hinted return Carno\Monitor\Chips\Metrical\Reporting.
Loading history...
Bug introduced by
$this of type Carno\Monitor\Chips\Metrical\Reporting is incompatible with the type Carno\Monitor\Contracts\Telemetry expected by parameter $source of Carno\Monitor\Harvester::join(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

26
        return Harvester::join(/** @scrutinizer ignore-type */ $this, $period);
Loading history...
27
    }
28
29
    /**
30
     */
31
    public function deregister() : void
32
    {
33
        Harvester::forget($this);
0 ignored issues
show
Bug introduced by
$this of type Carno\Monitor\Chips\Metrical\Reporting is incompatible with the type Carno\Monitor\Contracts\Telemetry expected by parameter $source of Carno\Monitor\Harvester::forget(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

33
        Harvester::forget(/** @scrutinizer ignore-type */ $this);
Loading history...
34
    }
35
36
    /**
37
     * @return array
38
     */
39
    public function reporting() : array
40
    {
41
        return empty($this->name) ? [] : [
42
            $this->typed(),
43
            $this->name,
44
            $this->grouped,
45
            $this->description,
46
            $this->labels,
47
            $this->data()
0 ignored issues
show
Bug introduced by
It seems like data() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

47
            $this->/** @scrutinizer ignore-call */ 
48
                   data()
Loading history...
48
        ];
49
    }
50
51
    /**
52
     * @return string
53
     */
54
    private function typed() : string
55
    {
56
        return [
57
            Counter::class => Metrical::COUNTER,
58
            Gauge::class => Metrical::GAUGE,
59
            Histogram::class => Metrical::HISTOGRAM,
60
            Summary::class => Metrical::SUMMARY,
61
        ][static::class];
62
    }
63
}
64