Passed
Push — develop ( 8c6599...c9bdac )
by Stan
04:29
created

Counter   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Test Coverage

Coverage 77.78%

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 34
ccs 7
cts 9
cp 0.7778
rs 10
c 0
b 0
f 0
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A type() 0 3 1
A incrementBy() 0 9 2
A increment() 0 3 1
1
<?php
2
3
namespace Krenor\Prometheus\Metrics;
4
5
use Krenor\Prometheus\Contracts\Types\Incrementable;
6
use Krenor\Prometheus\Exceptions\PrometheusException;
7
8
abstract class Counter extends Metric implements Incrementable
9
{
10
    /**
11
     * {@inheritdoc}
12
     */
13 7
    public function type(): string
14
    {
15 7
        return 'counter';
16
    }
17
18
    /**
19
     * {@inheritdoc}
20
     *
21
     * @return self
22
     */
23
    public function increment(array $labels = []): Incrementable
24
    {
25
        return $this->incrementBy(1, $labels);
26
    }
27
28
    /**
29
     * {@inheritdoc}
30
     *
31
     * @return self
32
     */
33 6
    public function incrementBy(float $value, array $labels = []): Incrementable
34
    {
35 6
        if ($value < 0) {
36 1
            throw new PrometheusException('Counters can only be incremented by non-negative amounts.');
37
        }
38
39 5
        static::$storage->increment($this, $value, $labels);
40
41 5
        return $this;
42
    }
43
}
44