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

Summary::__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 Summary extends Metric implements Observable
11
{
12
    /**
13
     * @var int[]
14
     */
15
    protected $quantiles = [
16
        .01,
17
        .05,
18
        .5,
19
        .9,
20
        .99,
21
    ];
22
23
    /**
24
     * {@inheritdoc}
25
     */
26 9
    public function __construct()
27
    {
28 9
        parent::__construct();
29
30 9
        foreach ($this->labels as $label) {
31 9
            if (preg_match('/^quantile$/', $label)) {
32 9
                throw new LabelException('The label `quantile` is used internally to designate summary quantiles.');
33
            }
34
        }
35 9
    }
36
37
    /**
38
     * {@inheritdoc}
39
     */
40 4
    final public function type(): string
41
    {
42 4
        return 'summary';
43
    }
44
45
    /**
46
     * {@inheritdoc}
47
     */
48 4
    public function observe(float $value, array $labels): self
49
    {
50 4
        static::$storage->observe($this, $value, $labels);
51
52 4
        return $this;
53
    }
54
55
    /**
56
     * @return Collection
57
     */
58 6
    public function quantiles(): Collection
59
    {
60 6
        return new Collection($this->quantiles);
61
    }
62
}
63