Gauge::dec()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
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