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

Histogram::__construct()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
eloc 4
nc 3
nop 0
dl 0
loc 7
ccs 5
cts 5
cp 1
crap 3
rs 9.4285
c 0
b 0
f 0
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