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

Summary   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A type() 0 3 1
A quantiles() 0 3 1
A __construct() 0 7 3
A observe() 0 5 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 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