Completed
Branch master (80ac3a)
by kacper
04:34 queued 51s
created

XidDTO   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Test Coverage

Coverage 35.29%

Importance

Changes 0
Metric Value
dl 0
loc 64
ccs 6
cts 17
cp 0.3529
rs 10
c 0
b 0
f 0
wmc 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A jsonSerialize() 0 3 1
A __construct() 0 7 1
A __toString() 0 8 1
A getXid() 0 3 1
A getType() 0 3 1
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
}