Transaction   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 2
dl 0
loc 57
ccs 18
cts 18
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A inProcess() 0 7 1
A onSystem() 0 7 1
A jsonSerialize() 0 9 1
1
<?php
2
declare(strict_types=1);
3
4
namespace TechDeCo\ElasticApmAgent\Request;
5
6
use JsonSerializable;
7
use TechDeCo\ElasticApmAgent\Message\Process;
8
use TechDeCo\ElasticApmAgent\Message\Service;
9
use TechDeCo\ElasticApmAgent\Message\System;
10
use TechDeCo\ElasticApmAgent\Message\Transaction as TransactionMessage;
11
use TechDeCo\ElasticApmAgent\Serialization;
12
13
final class Transaction 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 TransactionMessage[]
27
     */
28
    private $transactionList = [];
29
30
    /**
31
     * @var System
32
     */
33
    private $system;
34
35 26
    public function __construct(Service $service, TransactionMessage ...$transaction)
36
    {
37 26
        $this->service         = $service;
38 26
        $this->transactionList = $transaction;
39 26
    }
40
41 15
    public function inProcess(Process $process): self
42
    {
43 15
        $me          = clone $this;
44 15
        $me->process = $process;
45
46 15
        return $me;
47
    }
48
49 15
    public function onSystem(System $system): self
50
    {
51 15
        $me         = clone $this;
52 15
        $me->system = $system;
53
54 15
        return $me;
55
    }
56
57
    /**
58
     * @return mixed[]
59
     */
60 21
    public function jsonSerialize(): array
61
    {
62 21
        return Serialization::filterUnset([
63 21
            'service' => $this->service->jsonSerialize(),
64 21
            'process' => Serialization::serializeOr($this->process),
65 21
            'system' => Serialization::serializeOr($this->system),
66 21
            'transactions' => Serialization::serialize(...$this->transactionList),
67
        ]);
68
    }
69
}
70