Passed
Pull Request — master (#27)
by kacper
02:45
created

EventInfo::getSizeNoHeader()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 5
cts 5
cp 1
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 4
nc 3
nop 0
crap 3
1
<?php
2
3
namespace MySQLReplication\Event;
4
5
/**
6
 * Class EventInfo
7
 * @package MySQLReplication\BinLog
8
 */
9
class EventInfo implements \JsonSerializable
10
{
11
    /**
12
     * @var int
13
     */
14
    private $timestamp;
15
    /**
16
     * @var string
17
     */
18
    private $type;
19
    /**
20
     * @var int
21
     */
22
    private $id;
23
    /**
24
     * @var int
25
     */
26
    private $size;
27
    /**
28
     * @var int
29
     */
30
    private $pos;
31
    /**
32
     * @var string
33
     */
34
    private $flag;
35
    /**
36
     * @var bool
37
     */
38
    private $checkSum;
39
    /**
40
     * @var int
41
     */
42
    private $sizeNoHeader;
43
    /**
44
     * @var string
45
     */
46
    private $dateTime;
47
48
    /**
49
     * EventInfo constructor.
50
     * @param int $timestamp
51
     * @param string $type
52
     * @param int $id
53
     * @param int $size
54
     * @param int $pos
55
     * @param string $flag
56
     * @param bool $checkSum
57
     */
58 54
    public function __construct(
59
        $timestamp,
60
        $type,
61
        $id,
62
        $size,
63
        $pos,
64
        $flag,
65
        $checkSum
66
    ) {
67 54
        $this->timestamp = $timestamp;
68 54
        $this->type = $type;
69 54
        $this->id = $id;
70 54
        $this->size = $size;
71 54
        $this->pos = $pos;
72 54
        $this->flag = $flag;
73 54
        $this->checkSum = $checkSum;
74 54
    }
75
76
    /**
77
     * @return string
78
     */
79
    public function getDateTime()
80
    {
81
        if (empty($this->dateTime)) {
82
            $this->dateTime = date('c', $this->timestamp);
83
        }
84
85
        return $this->dateTime;
86
    }
87
88
    /**
89
     * @return string
90
     */
91 54
    public function getSizeNoHeader()
92
    {
93 54
        if (empty($this->sizeNoHeader)) {
94 54
            $this->sizeNoHeader = (true === $this->checkSum ? $this->size - 23 : $this->size - 19);
95 54
        }
96
97 54
        return $this->sizeNoHeader;
98
    }
99
100
    /**
101
     * @return int
102
     */
103
    public function getTimestamp()
104
    {
105
        return $this->timestamp;
106
    }
107
108
    /**
109
     * @return string
110
     */
111 54
    public function getType()
112
    {
113 54
        return $this->type;
114
    }
115
116
    /**
117
     * @return int
118
     */
119
    public function getId()
120
    {
121
        return $this->id;
122
    }
123
124
    /**
125
     * @return int
126
     */
127
    public function getSize()
128
    {
129
        return $this->size;
130
    }
131
132
    /**
133
     * @return int
134
     */
135
    public function getPos()
136
    {
137
        return $this->pos;
138
    }
139
140
    /**
141
     * @return string
142
     */
143
    public function getFlag()
144
    {
145
        return $this->flag;
146
    }
147
148
    /**
149
     * Specify data which should be serialized to JSON
150
     * @link http://php.net/manual/en/jsonserializable.jsonserialize.php
151
     * @return mixed data which can be serialized by <b>json_encode</b>,
152
     * which is a value of any type other than a resource.
153
     * @since 5.4.0
154
     */
155
    public function jsonSerialize()
156
    {
157
        return get_object_vars($this);
158
    }
159
}