MetricSet   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 21
c 1
b 0
f 0
dl 0
loc 68
ccs 19
cts 19
cp 1
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 12 1
A jsonSerialize() 0 18 3
1
<?php
2
3
namespace ZoiloMora\ElasticAPM\Events\MetricSet;
4
5
use ZoiloMora\ElasticAPM\Events\Common\Tags;
6
use ZoiloMora\ElasticAPM\Events\Common\TimestampEpoch;
7
8
final class MetricSet implements \JsonSerializable
9
{
10
    use TimestampEpoch;
11
12
    /**
13
     * @var Transaction
14
     */
15
    private $transaction;
16
17
    /**
18
     * @var Span|null
19
     */
20
    private $span;
21
22
    /**
23
     * Sampled application metrics collected from the agent.
24
     *
25
     * @var Samples
26
     */
27
    private $samples;
28
29
    /**
30
     * @var Tags|null
31
     */
32
    private $tags;
33
34
    /**
35
     * @param int $timestamp
36
     * @param Samples $samples
37
     * @param Transaction $transaction
38
     * @param Span|null $span
39
     * @param Tags|null $tags
40
     */
41 4
    public function __construct(
42
        $timestamp,
43
        Samples $samples,
44
        Transaction $transaction,
45
        Span $span = null,
46
        Tags $tags = null
47
    ) {
48 4
        $this->timestamp = (int) $timestamp;
49 4
        $this->samples = $samples;
50 4
        $this->transaction = $transaction;
51 4
        $this->span = $span;
52 4
        $this->tags = $tags;
53 4
    }
54
55
    /**
56
     * @return array
57
     */
58 2
    public function jsonSerialize()
59
    {
60
        $payload = [
61 2
            'timestamp' => $this->timestamp,
62 2
            'samples' => $this->samples,
63 2
            'transaction' => $this->transaction,
64 2
        ];
65
66 2
        if (null !== $this->span) {
67 2
            $payload['span'] = $this->span;
68 2
        }
69
70 2
        if (null !== $this->tags) {
71 1
            $payload['tags'] = $this->tags;
72 1
        }
73
74
        return [
75 2
            'metricset' => $payload,
76 2
        ];
77
    }
78
}
79