GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

PrometheusPrinter::print()   B
last analyzed

Complexity

Conditions 7
Paths 7

Size

Total Lines 36
Code Lines 22

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 7
eloc 22
c 1
b 0
f 0
nc 7
nop 1
dl 0
loc 36
rs 8.6346
1
<?php declare(strict_types=1);
2
3
namespace ReactInspector\Printer\Prometheus;
4
5
use ReactInspector\Metric;
6
use ReactInspector\Printer\Printer;
7
use function array_key_exists;
8
use function array_keys;
9
use function array_merge;
10
use function count;
11
use function floor;
12
use function strlen;
13
14
final class PrometheusPrinter implements Printer
15
{
16
    private const NL = "\n";
17
18
    public function print(Metric $metric): string
19
    {
20
        if (count($metric->measurements()->get()) === 0) {
21
            return '';
22
        }
23
24
        $string = '';
25
        if (strlen($metric->config()->description()) > 0) {
26
            $string = '# HELP ' . $metric->config()->name() . ' ' . $metric->config()->description() . self::NL;
27
        }
28
29
        $string .= '# TYPE ' . $metric->config()->name() . ' ' . $metric->config()->type() . self::NL;
30
31
        foreach ($metric->measurements()->get() as $measurement) {
32
            $string  .= $metric->config()->name();
33
            $tags     = array_merge($metric->tags()->get(), $measurement->tags()->get());
34
            $tagCount = count($tags);
35
            if ($tagCount > 0) {
36
                $tagKeys = array_keys($tags);
37
                $string .= '{';
38
                for ($i = 0; $i < $tagCount; $i++) {
39
                    $string .= $tags[$tagKeys[$i]]->key() . '="' . $tags[$tagKeys[$i]]->value() . '"';
40
                    if (! array_key_exists($i + 1, $tagKeys)) {
41
                        continue;
42
                    }
43
44
                    $string .= ',';
45
                }
46
47
                $string .= '}';
48
            }
49
50
            $string .= ' ' . $measurement->value() . ' ' . floor($metric->time() * 1000) . self::NL;
51
        }
52
53
        return $string . self::NL;
54
    }
55
}
56