HistogramObserver::__invoke()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 5
c 1
b 0
f 0
nc 1
nop 3
dl 0
loc 8
ccs 6
cts 6
cp 1
crap 1
rs 10
1
<?php
2
3
namespace Krenor\Prometheus\Storage\Bindings\Observers;
4
5
use Krenor\Prometheus\Contracts\Binding;
6
use Krenor\Prometheus\Metrics\Histogram;
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 7
        $bucket = $histogram
21 7
            ->buckets()
22 7
            ->first(fn(float $bucket) => $value <= $bucket, '+Inf');
23
24 7
        $this->repository->increment($this->key, $labels->merge(compact('bucket'))->toJson(), 1);
25 6
        $this->repository->increment("{$this->key}:SUM", $labels->toJson(), $value);
26 6
    }
27
}
28