MetricsSetBuilder   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A execute() 0 36 2
1
<?php
2
3
namespace ZoiloMora\ElasticAPM\Processor\MetricSetProcessor;
4
5
use ZoiloMora\ElasticAPM\Events\MetricSet\MetricSet;
6
use ZoiloMora\ElasticAPM\Events\MetricSet\Sample;
7
use ZoiloMora\ElasticAPM\Events\MetricSet\Samples;
8
use ZoiloMora\ElasticAPM\Events\Transaction\Transaction;
9
10
final class MetricsSetBuilder
11
{
12
    /**
13
     * @param Transaction $transaction
14
     * @param Span[] $spans
15
     *
16
     * @return MetricSet[]
17
     */
18 1
    public function execute(Transaction $transaction, array $spans)
19
    {
20 1
        $result = [];
21
22 1
        $result[] = new MetricSet(
23 1
            $transaction->timestamp(),
24 1
            Samples::from([
25 1
                new Sample('transaction.duration.count', 1),
26 1
                new Sample('transaction.duration.sum.us', $transaction->duration()),
27 1
                new Sample('transaction.breakdown.count', 1)
28 1
            ]),
29 1
            new \ZoiloMora\ElasticAPM\Events\MetricSet\Transaction(
30 1
                $transaction->name(),
31 1
                $transaction->type()
32 1
            )
33 1
        );
34
35 1
        foreach ($spans as $span) {
36 1
            $result[] = new MetricSet(
37 1
                $transaction->timestamp(),
38 1
                Samples::from([
39 1
                    new Sample('span.self_time.count', $span->count()),
40 1
                    new Sample('span.self_time.sum.us', $span->sum())
41 1
                ]),
42 1
                new \ZoiloMora\ElasticAPM\Events\MetricSet\Transaction(
43 1
                    $transaction->name(),
44 1
                    $transaction->type()
45 1
                ),
46 1
                new \ZoiloMora\ElasticAPM\Events\MetricSet\Span(
47 1
                    $span->type(),
48 1
                    $span->subtype()
49 1
                )
50 1
            );
51 1
        }
52
53 1
        return $result;
54
    }
55
}
56