Error::onSystem()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 7
c 0
b 0
f 0
ccs 4
cts 4
cp 1
rs 10
cc 1
nc 1
nop 1
crap 1
1
<?php
2
declare(strict_types=1);
3
4
namespace TechDeCo\ElasticApmAgent\Request;
5
6
use JsonSerializable;
7
use TechDeCo\ElasticApmAgent\Message\Error as ErrorMessage;
8
use TechDeCo\ElasticApmAgent\Message\Process;
9
use TechDeCo\ElasticApmAgent\Message\Service;
10
use TechDeCo\ElasticApmAgent\Message\System;
11
use TechDeCo\ElasticApmAgent\Serialization;
12
13
final class Error implements JsonSerializable
14
{
15
    /**
16
     * @var Service
17
     */
18
    private $service;
19
20
    /**
21
     * @var Process|null
22
     */
23
    private $process;
24
25
    /**
26
     * @var ErrorMessage[]
27
     */
28
    private $errorList = [];
29
30
    /**
31
     * @var System
32
     */
33
    private $system;
34
35 25
    public function __construct(Service $service, ErrorMessage ...$error)
36
    {
37 25
        $this->service   = $service;
38 25
        $this->errorList = $error;
39 25
    }
40
41 14
    public function inProcess(Process $process): self
42
    {
43 14
        $me          = clone $this;
44 14
        $me->process = $process;
45
46 14
        return $me;
47
    }
48
49 14
    public function onSystem(System $system): self
50
    {
51 14
        $me         = clone $this;
52 14
        $me->system = $system;
53
54 14
        return $me;
55
    }
56
57
    /**
58
     * @return mixed[]
59
     */
60 15
    public function jsonSerialize(): array
61
    {
62 15
        return Serialization::filterUnset([
63 15
            'service' => $this->service->jsonSerialize(),
64 15
            'process' => Serialization::serializeOr($this->process),
65 15
            'errors' => Serialization::serialize(...$this->errorList),
66 15
            'system' => Serialization::serializeOr($this->system),
67
        ]);
68
    }
69
}
70