TracksExecutionTime   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
c 1
b 0
f 0
dl 0
loc 29
ccs 8
cts 8
cp 1
rs 10
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A chronometer() 0 10 1
1
<?php
2
3
namespace Krenor\Prometheus\Metrics\Concerns;
4
5
use Closure;
6
7
trait TracksExecutionTime
8
{
9
    /**
10
     * @param array $labels
11
     * @param int $precision
12
     *
13
     * @return Closure
14
     */
15 3
    public function chronometer(array $labels = [], int $precision = 4): Closure
16
    {
17 3
        $start = microtime(true);
18
19 3
        return function ($labelz = []) use ($labels, $precision, $start) {
20 3
            $delta = microtime(true) - $start;
21
22 3
            $this->track(
23 3
                round($delta, $precision),
24 3
                array_merge($labels, $labelz)
25
            );
26 3
        };
27
    }
28
29
    /**
30
     * @param float $value
31
     * @param array $labels
32
     *
33
     * @return void
34
     */
35
    abstract protected function track(float $value, array $labels = []): void;
36
}
37