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

HistogramObserver   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 19
ccs 6
cts 6
cp 1
rs 10
c 0
b 0
f 0
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 10 1
1
<?php
2
3
namespace Krenor\Prometheus\Storage\Bindings\Observers;
4
5
use Krenor\Prometheus\Metrics\Histogram;
6
use Krenor\Prometheus\Contracts\Binding;
7
use Tightenco\Collect\Support\Collection;
8
9
class HistogramObserver extends Binding
10
{
11
    /**
12
     * @param Histogram $histogram
13
     * @param Collection $labels
14
     * @param float $value
15
     *
16
     * @return void
17
     */
18 7
    public function __invoke(Histogram $histogram, Collection $labels, float $value): void
19
    {
20
        $bucket = $histogram
21 7
            ->buckets()
22
            ->first(function (float $bucket) use ($value) {
23 7
                return $value <= $bucket;
24 7
            }, '+Inf');
25
26 7
        $this->repository->increment($this->key, $labels->merge(compact('bucket'))->toJson(), 1);
27 6
        $this->repository->increment("{$this->key}:SUM", $labels->toJson(), $value);
28 6
    }
29
}
30