Histogram   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 11
dl 0
loc 33
rs 10
c 0
b 0
f 0
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A observe() 0 11 3
1
<?php
2
/**
3
 * Metrics type "histogram"
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\HBuckets;
12
use Carno\Monitor\Chips\Metrical\HExporter;
13
use Carno\Monitor\Chips\Metrical\Labeled;
14
use Carno\Monitor\Chips\Metrical\Named;
15
use Carno\Monitor\Chips\Metrical\Reporting;
16
use Carno\Monitor\Contracts\HMRegistry;
17
use Carno\Monitor\Contracts\RAWMetrics;
18
use Carno\Monitor\Contracts\Telemetry;
19
20
class Histogram implements RAWMetrics, HMRegistry, Telemetry
21
{
22
    use Named, Labeled, HBuckets, HExporter, Reporting;
23
24
    /**
25
     * @var int
26
     */
27
    private $count = 0;
28
29
    /**
30
     * @var float
31
     */
32
    private $sum = 0;
33
34
    /**
35
     * @var array
36
     */
37
    private $buckets = [];
38
39
    /**
40
     * @param float $v
41
     */
42
    public function observe(float $v) : void
43
    {
44
        foreach ($this->bounds as $idx => $bound) {
45
            if ($v < $bound) {
46
                $this->buckets[$idx] ++;
47
                break;
48
            }
49
        }
50
51
        $this->count ++;
52
        $this->sum += $v;
53
    }
54
}
55