Exporter::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 0
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 2
ccs 1
cts 1
cp 1
crap 1
rs 10
1
<?php
2
3
namespace Krenor\Prometheus\Contracts;
4
5
use Krenor\Prometheus\Sample;
6
use Tightenco\Collect\Support\Collection;
7
use Krenor\Prometheus\MetricFamilySamples;
8
use Krenor\Prometheus\Storage\Concerns\StoresMetrics;
9
10
abstract class Exporter
11
{
12
    use StoresMetrics;
13
14
    /**
15
     * Exporter constructor.
16
     *
17
     * @param array $data
18
     */
19 37
    public function __construct(protected array $data)
20
    {
21
        //
22 37
    }
23
24
    /**
25
     * @param Metric $metric
26
     * @param float $value
27
     * @param array $labels
28
     *
29
     * @return MetricFamilySamples
30
     */
31 37
    protected function sampled(Metric $metric, float $value, array $labels = []): MetricFamilySamples
32
    {
33 37
        return new MetricFamilySamples($metric, new Collection([
34 37
            new Sample(
35 37
                $metric->key(),
36
                $value,
37 37
                $this->labeled($metric, $labels)->get('labels')
0 ignored issues
show
Bug introduced by
It seems like $this->labeled($metric, $labels)->get('labels') can also be of type null; however, parameter $labels of Krenor\Prometheus\Sample::__construct() does only seem to accept Tightenco\Collect\Support\Collection, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

37
                /** @scrutinizer ignore-type */ $this->labeled($metric, $labels)->get('labels')
Loading history...
38
            ),
39
        ]));
40
    }
41
}
42