Error   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 123
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 11
lcom 1
cbo 2
dl 0
loc 123
ccs 45
cts 45
cp 1
rs 10
c 0
b 0
f 0

10 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A fromException() 0 8 1
A fromLog() 0 8 1
A inContext() 0 7 1
A withCulprit() 0 7 1
A causedByException() 0 7 1
A withId() 0 7 1
A withLog() 0 7 1
A correlatedToTransactionId() 0 7 1
A jsonSerialize() 0 12 2
1
<?php
2
declare(strict_types=1);
3
4
namespace TechDeCo\ElasticApmAgent\Message;
5
6
use JsonSerializable;
7
use Ramsey\Uuid\UuidInterface;
8
use TechDeCo\ElasticApmAgent\Serialization;
9
10
final class Error implements JsonSerializable
11
{
12
    /**
13
     * @var Context|null
14
     */
15
    private $context;
16
17
    /**
18
     * @var string|null
19
     */
20
    private $culprit;
21
22
    /**
23
     * @var Exception|null
24
     */
25
    private $exception;
26
27
    /**
28
     * @var UuidInterface|null
29
     */
30
    private $id;
31
32
    /**
33
     * @var Log|null
34
     */
35
    private $log;
36
37
    /**
38
     * @var Timestamp
39
     */
40
    private $timestamp;
41
42
    /**
43
     * @var UuidInterface|null
44
     */
45
    private $transactionId;
46
47 28
    private function __construct()
48
    {
49 28
    }
50
51 14
    public static function fromException(Exception $exception, Timestamp $timestamp): self
52
    {
53 14
        $me            = new Error();
54 14
        $me->exception = $exception;
55 14
        $me->timestamp = $timestamp;
56
57 14
        return $me;
58
    }
59
60 14
    public static function fromLog(Log $log, Timestamp $timestamp): self
61
    {
62 14
        $me            = new Error();
63 14
        $me->log       = $log;
64 14
        $me->timestamp = $timestamp;
65
66 14
        return $me;
67
    }
68
69 14
    public function inContext(Context $context): self
70
    {
71 14
        $me          = clone $this;
72 14
        $me->context = $context;
73
74 14
        return $me;
75
    }
76
77 1
    public function withCulprit(string $culprit): self
78
    {
79 1
        $me          = clone $this;
80 1
        $me->culprit = $culprit;
81
82 1
        return $me;
83
    }
84
85 1
    public function causedByException(Exception $exception): self
86
    {
87 1
        $me            = clone $this;
88 1
        $me->exception = $exception;
89
90 1
        return $me;
91
    }
92
93 14
    public function withId(UuidInterface $id): self
94
    {
95 14
        $me     = clone $this;
96 14
        $me->id = $id;
97
98 14
        return $me;
99
    }
100
101 1
    public function withLog(Log $log): self
102
    {
103 1
        $me      = clone $this;
104 1
        $me->log = $log;
105
106 1
        return $me;
107
    }
108
109 14
    public function correlatedToTransactionId(UuidInterface $id): self
110
    {
111 14
        $me                = clone $this;
112 14
        $me->transactionId = $id;
113
114 14
        return $me;
115
    }
116
117
    /**
118
     * @return mixed[]
119
     */
120 18
    public function jsonSerialize(): array
121
    {
122 18
        return Serialization::filterUnset([
123 18
            'context' => Serialization::serializeOr($this->context),
124 18
            'culprit' => $this->culprit,
125 18
            'exception' => Serialization::serializeOr($this->exception),
126 18
            'id' => $this->id ? $this->id->toString() : null,
127 18
            'log' => Serialization::serializeOr($this->log),
128 18
            'timestamp' => Serialization::serializeOr($this->timestamp),
129 18
            'transaction' => Serialization::serializeOr($this->transactionId),
130
        ]);
131
    }
132
}
133