Gauge   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 43
rs 10
c 0
b 0
f 0
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A set() 0 3 1
A dec() 0 3 1
A inc() 0 3 1
1
<?php
2
/**
3
 * Metrics type "gauge"
4
 * User: moyo
5
 * Date: 2018/5/18
6
 * Time: 10:27 AM
7
 */
8
9
namespace Carno\Monitor\Metrics;
10
11
use Carno\Monitor\Chips\Metrical\Labeled;
12
use Carno\Monitor\Chips\Metrical\Named;
13
use Carno\Monitor\Chips\Metrical\Reporting;
14
use Carno\Monitor\Chips\Metrical\VExporter;
15
use Carno\Monitor\Contracts\HMRegistry;
16
use Carno\Monitor\Contracts\RAWMetrics;
17
use Carno\Monitor\Contracts\Telemetry;
18
19
class Gauge implements RAWMetrics, HMRegistry, Telemetry
20
{
21
    use Named, Labeled, VExporter, Reporting;
22
23
    /**
24
     * @var float
25
     */
26
    private $value = 0;
27
28
    /**
29
     * Gauge constructor.
30
     * @param float $initial
31
     */
32
    public function __construct(float $initial = 0)
33
    {
34
        $this->value = $initial;
35
    }
36
37
    /**
38
     * @param float $v
39
     * @return float
40
     */
41
    public function inc(float $v = 1) : float
42
    {
43
        return $this->value += $v;
44
    }
45
46
    /**
47
     * @param float $v
48
     * @return float
49
     */
50
    public function dec(float $v = 1) : float
51
    {
52
        return $this->value -= $v;
53
    }
54
55
    /**
56
     * @param float $v
57
     * @return float
58
     */
59
    public function set(float $v) : float
60
    {
61
        return $this->value = $v;
62
    }
63
}
64