Passed
Push — develop ( d53231...ea980c )
by Stan
02:32
created

Histogram   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 57
ccs 13
cts 13
cp 1
rs 10
c 0
b 0
f 0
wmc 6

4 Methods

Rating   Name   Duplication   Size   Complexity  
A buckets() 0 3 1
A observe() 0 5 1
A __construct() 0 7 3
A type() 0 3 1
1
<?php
2
3
namespace Krenor\Prometheus\Metrics;
4
5
use Krenor\Prometheus\Contracts\Metric;
6
use Tightenco\Collect\Support\Collection;
7
use Krenor\Prometheus\Exceptions\LabelException;
8
use Krenor\Prometheus\Contracts\Types\Observable;
9
10
abstract class Histogram extends Metric implements Observable
11
{
12
    /**
13
     * @var int[]
14
     */
15
    protected $buckets = [
16
        .005,
17
        .01,
18
        .025,
19
        .05,
20
        .1,
21
        .25,
22
        .5,
23
        1,
24
        2.5,
25
        5,
26
        10,
27
    ];
28
29
    /**
30
     * {@inheritdoc}
31
     */
32 16
    public function __construct()
33
    {
34 16
        parent::__construct();
35
36 16
        foreach ($this->labels as $label) {
37 16
            if (preg_match('/^le$/', $label)) {
38 16
                throw new LabelException('The label `le` is used internally to designate buckets.');
39
            }
40
        }
41 16
    }
42
43
    /**
44
     * {@inheritdoc}
45
     */
46 4
    final public function type(): string
47
    {
48 4
        return 'histogram';
49
    }
50
51
    /**
52
     * {@inheritdoc}
53
     */
54 4
    public function observe(float $value, array $labels): self
55
    {
56 4
        static::$storage->observe($this, $value, $labels);
57
58 4
        return $this;
59
    }
60
61
    /**
62
     * @return Collection
63
     */
64 11
    public function buckets(): Collection
65
    {
66 11
        return new Collection($this->buckets);
67
    }
68
}
69