Completed
Pull Request — master (#34)
by kacper
04:15 queued 42s
created

XidDTO::jsonSerialize()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace MySQLReplication\Event\DTO;
4
5
use MySQLReplication\Definitions\ConstEventsNames;
6
use MySQLReplication\Event\EventInfo;
7
8
/**
9
 * Class XidDTO
10
 * @package MySQLReplication\Event\DTO
11
 */
12
class XidDTO extends EventDTO
13
{
14
    /**
15
     * @var string
16
     */
17
    private $type = ConstEventsNames::XID;
18
    /**
19
     * @var string
20
     */
21
    private $xid;
22
23
    /**
24
     * GTIDLogEventDTO constructor.
25
     * @param EventInfo $eventInfo
26
     * @param string $xid
27
     */
28 3
    public function __construct(
29
        EventInfo $eventInfo,
30
        $xid
31
    ) {
32 3
        parent::__construct($eventInfo);
33
34 3
        $this->xid = $xid;
35 3
    }
36
37
    /**
38
     * @return string
39
     */
40
    public function getXid()
41
    {
42
        return $this->xid;
43
    }
44
45
    /**
46
     * @return string
47
     */
48 3
    public function getType()
49
    {
50 3
        return $this->type;
51
    }
52
53
    /**
54
     * @return string
55
     */
56
    public function __toString()
57
    {
58
        return PHP_EOL .
59
            '=== Event ' . $this->getType() . ' === ' . PHP_EOL .
60
            'Date: ' . $this->eventInfo->getDateTime() . PHP_EOL .
61
            'Log position: ' . $this->eventInfo->getPos() . PHP_EOL .
62
            'Event size: ' . $this->eventInfo->getSize() . PHP_EOL .
63
            'Transaction ID: ' . $this->xid . PHP_EOL;
64
    }
65
66
    /**
67
     * Specify data which should be serialized to JSON
68
     * @link http://php.net/manual/en/jsonserializable.jsonserialize.php
69
     * @return mixed data which can be serialized by <b>json_encode</b>,
70
     * which is a value of any type other than a resource.
71
     * @since 5.4.0
72
     */
73
    public function jsonSerialize()
74
    {
75
        return get_object_vars($this);
76
    }
77
}