Destination::jsonSerialize()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 4
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 6
ccs 4
cts 4
cp 1
crap 1
rs 10
1
<?php
2
3
namespace ZoiloMora\ElasticAPM\Events\Span\Context;
4
5
use ZoiloMora\ElasticAPM\Events\Span\Context\Destination\Service;
6
use ZoiloMora\ElasticAPM\Helper\Encoding;
7
8
/**
9
 * An object containing contextual data about the destination for spans
10
 */
11
final class Destination implements \JsonSerializable
12
{
13
    /**
14
     * Destination network address:
15
     * - Hostname (e.g. 'localhost')
16
     * - FQDN (e.g. 'elastic.co')
17
     * - IPv4 (e.g. '127.0.0.1')
18
     * - IPv6 (e.g. '::1')
19
     *
20
     * @var string|null
21
     */
22
    private $address;
23
24
    /**
25
     * Destination network port (e.g. 443)
26
     *
27
     * @var int|null
28
     */
29
    private $port;
30
31
    /**
32
     * Destination service context
33
     *
34
     * @var Service|null
35
     */
36
    private $service;
37
38
    /**
39
     * @param string|null $address
40
     * @param int|null $port
41
     * @param Service|null $service
42
     */
43 2
    public function __construct($address, $port, Service $service = null)
44
    {
45 2
        $this->address = $address;
46 2
        $this->port = $port;
47 2
        $this->service = $service;
48 2
    }
49
50
    /**
51
     * @return string|null
52
     */
53 1
    public function address()
54
    {
55 1
        return $this->address;
56
    }
57
58
    /**
59
     * @return int|null
60
     */
61 1
    public function port()
62
    {
63 1
        return $this->port;
64
    }
65
66
    /**
67
     * @return Service|null
68
     */
69 1
    public function service()
70
    {
71 1
        return $this->service;
72
    }
73
74
    /**
75
     * @return array
76
     */
77 1
    public function jsonSerialize()
78
    {
79
        return [
80 1
            'address' => Encoding::keywordField($this->address),
81 1
            'port' => $this->port,
82 1
            'service' => $this->service,
83 1
        ];
84
    }
85
}
86