Passed
Push — master ( 41866b...658441 )
by kacper
05:20
created

EventInfo::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 21
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 10
nc 2
nop 8
dl 0
loc 21
ccs 11
cts 11
cp 1
crap 2
rs 9.9332
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
declare(strict_types=1);
3
4
namespace MySQLReplication\Event;
5
6
use JsonSerializable;
7
use MySQLReplication\BinLog\BinLogCurrent;
8
9
class EventInfo implements JsonSerializable
10
{
11
    private $timestamp;
12
    private $type;
13
    private $id;
14
    private $size;
15
    private $pos;
16
    private $flag;
17
    private $checkSum;
18
    private $sizeNoHeader;
19
    private $dateTime;
20
    private $binLogCurrent;
21
22 57
    public function __construct(
23
        int $timestamp,
24
        int $type,
25
        int $id,
26
        int $size,
27
        int $pos,
28
        int $flag,
29
        bool $checkSum,
30
        BinLogCurrent $binLogCurrent
31
    ) {
32 57
        $this->timestamp = $timestamp;
33 57
        $this->type = $type;
34 57
        $this->id = $id;
35 57
        $this->size = $size;
36 57
        $this->pos = $pos;
37 57
        $this->flag = $flag;
38 57
        $this->checkSum = $checkSum;
39 57
        $this->binLogCurrent = $binLogCurrent;
40
41 57
        if ($pos > 0) {
42 57
            $this->binLogCurrent->setBinLogPosition($pos);
43
        }
44 57
    }
45
46 1
    public function getBinLogCurrent(): BinLogCurrent
47
    {
48 1
        return $this->binLogCurrent;
49
    }
50
51
    public function getDateTime(): string
52
    {
53
        if (empty($this->dateTime)) {
54
            $this->dateTime = date('c', $this->timestamp);
55
        }
56
57
        return $this->dateTime;
58
    }
59
60 57
    public function getSizeNoHeader(): int
61
    {
62 57
        if (empty($this->sizeNoHeader)) {
63 57
            $this->sizeNoHeader = (true === $this->checkSum ? $this->size - 23 : $this->size - 19);
64
        }
65
66 57
        return $this->sizeNoHeader;
67
    }
68
69
    public function getTimestamp(): int
70
    {
71
        return $this->timestamp;
72
    }
73
74 57
    public function getType(): int
75
    {
76 57
        return $this->type;
77
    }
78
79
    public function getId(): int
80
    {
81
        return $this->id;
82
    }
83
84
85
    public function getSize(): int
86
    {
87
        return $this->size;
88
    }
89
90
    public function getPos(): int
91
    {
92
        return $this->pos;
93
    }
94
95
    public function getFlag(): int
96
    {
97
        return $this->flag;
98
    }
99
100
    public function jsonSerialize()
101
    {
102
        return get_object_vars($this);
103
    }
104
}