StoresMetrics::labeled()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 2

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 2
eloc 6
c 2
b 0
f 0
nc 2
nop 2
dl 0
loc 12
ccs 7
cts 7
cp 1
crap 2
rs 10
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