Passed
Pull Request — master (#6)
by Moln
05:27
created

XidDTO::__toString()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 6
nc 1
nop 0
dl 0
loc 8
ccs 0
cts 6
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
declare(strict_types=1);
3
4
namespace MySQLReplication\Event\DTO;
5
6
use MySQLReplication\Definitions\ConstEventsNames;
7
use MySQLReplication\Event\EventInfo;
8
9
class XidDTO extends EventDTO
10
{
11
    private $type = ConstEventsNames::XID;
12
    private $xid;
13
14 6
    public function __construct(
15
        EventInfo $eventInfo,
16
        string $xid
17
    ) {
18 6
        parent::__construct($eventInfo);
19
20 6
        $this->xid = $xid;
21
    }
22
23
    public function getXid(): string
24
    {
25
        return $this->xid;
26
    }
27
28
    public function __toString(): string
29
    {
30
        return PHP_EOL .
31
            '=== Event ' . $this->getType() . ' === ' . PHP_EOL .
32
            'Date: ' . $this->eventInfo->getDateTime() . PHP_EOL .
33
            'Log position: ' . $this->eventInfo->getPos() . PHP_EOL .
34
            'Event size: ' . $this->eventInfo->getSize() . PHP_EOL .
35
            'Transaction ID: ' . $this->xid . PHP_EOL;
36
    }
37
38 6
    public function getType(): string
39
    {
40 6
        return $this->type;
41
    }
42
43
    public function jsonSerialize()
44
    {
45
        return get_object_vars($this);
46
    }
47
}