Span   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 16
c 1
b 0
f 0
dl 0
loc 56
ccs 21
cts 21
cp 1
rs 10
wmc 8

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A assertType() 0 4 2
A jsonSerialize() 0 11 2
A assertSubType() 0 4 3
1
<?php
2
3
namespace ZoiloMora\ElasticAPM\Events\MetricSet;
4
5
use ZoiloMora\ElasticAPM\Events\Common\SpanSubtype;
6
use ZoiloMora\ElasticAPM\Events\Common\SpanType;
7
8
final class Span implements \JsonSerializable
9
{
10
    use SpanType;
11
    use SpanSubtype;
12
13
    /**
14
     * @param string $type
15
     * @param string|null $subtype
16
     */
17 5
    public function __construct($type, $subtype)
18
    {
19 5
        $this->assertType($type);
20 4
        $this->assertSubType($subtype);
21
22 3
        $this->type = (string) $type;
23 3
        $this->subtype = $subtype;
24 3
    }
25
26
    /**
27
     * @param mixed $type
28
     *
29
     * @return void
30
     */
31 5
    private function assertType($type)
32
    {
33 5
        if (false === is_string($type)) {
34 1
            throw new \InvalidArgumentException('The [type] must be of type string.');
35
        }
36 4
    }
37
38
    /**
39
     * @param mixed $subtype
40
     *
41
     * @return void
42
     */
43 4
    private function assertSubType($subtype)
44
    {
45 4
        if (null !== $subtype && false === is_string($subtype)) {
46 1
            throw new \InvalidArgumentException('The [subType] must be of type string or null.');
47
        }
48 3
    }
49
50
    /**
51
     * @return array
52
     */
53 2
    public function jsonSerialize()
54
    {
55
        $payload = [
56 2
            'type' => $this->getEncodingType(),
57 2
        ];
58
59 2
        if (null !== $this->subtype) {
60 2
            $payload['subtype'] = $this->getEncodingSubtype();
61 2
        }
62
63 2
        return $payload;
64
    }
65
}
66