Passed
Push — develop ( 8c6599...c9bdac )
by Stan
04:29
created

StoresMetrics::bucket()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 2
dl 0
loc 7
ccs 4
cts 4
cp 1
crap 1
rs 9.4285
c 0
b 0
f 0
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 45
    protected function labeled(Metric $metric, array $labels): Collection
20
    {
21 45
        $expected = $metric->labels()->count();
22 45
        $actual = count($labels);
23
24 45
        if ($expected !== $actual) {
25 5
            throw new LabelException("Expected {$expected} label values but {$actual} were given.");
26
        }
27
28 40
        return new Collection([
29 40
            'labels' => $metric->labels()->combine($labels),
30
        ]);
31
    }
32
}
33