Test Failed
Pull Request — master (#34)
by kacper
03:15
created

EventInfo::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 21
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 2.2275

Importance

Changes 0
Metric Value
cc 2
eloc 10
nc 2
nop 8
dl 0
loc 21
ccs 8
cts 13
cp 0.6153
crap 2.2275
rs 9.3142
c 0
b 0
f 0

How to fix   Many Parameters   

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

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