Counter::incrementBy()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 2
dl 0
loc 9
ccs 5
cts 5
cp 1
crap 2
rs 10
c 0
b 0
f 0
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
    public function increment(array $labels = []): static
22
    {
23
        return $this->incrementBy(1, $labels);
24
    }
25
26
    /**
27
     * {@inheritdoc}
28
     */
29 6
    public function incrementBy(float $value, array $labels = []): static
30
    {
31 6
        if ($value < 0) {
32 1
            throw new PrometheusException('Counters can only be incremented by non-negative amounts.');
33
        }
34
35 5
        static::$storage->increment($this, $value, $labels);
36
37 5
        return $this;
38
    }
39
}
40