HistogramObserver   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 17
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 6
c 1
b 0
f 0
dl 0
loc 17
ccs 6
cts 6
cp 1
rs 10
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 8 1
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