StoresMetrics   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A labeled() 0 12 2
1
<?php
2
3
namespace Krenor\Prometheus\Storage\Concerns;
4
5
use Krenor\Prometheus\Contracts\Metric;
6
use Tightenco\Collect\Support\Collection;
7
use Krenor\Prometheus\Exceptions\LabelException;
8
9
trait StoresMetrics
10
{
11
    /**
12
     * @param Metric $metric
13
     * @param array $labels
14
     *
15
     * @throws LabelException
16
     *
17
     * @return Collection
18
     */
19 82
    protected function labeled(Metric $metric, array $labels): Collection
20
    {
21 82
        $expected = $metric->labels()->count();
22 82
        $actual = count($labels);
23
24 82
        if ($expected !== $actual) {
25 5
            throw new LabelException("Expected {$expected} label values but {$actual} were given.");
26
        }
27
28
        // FIXME: Only return the value.
29 77
        return new Collection([
30 77
            'labels' => $metric->labels()->combine($labels),
31
        ]);
32
    }
33
}
34