EventInfo   A
last analyzed

Complexity

Total Complexity 15

Size/Duplication

Total Lines 94
Duplicated Lines 0 %

Test Coverage

Coverage 55.56%

Importance

Changes 0
Metric Value
eloc 35
dl 0
loc 94
ccs 20
cts 36
cp 0.5556
rs 10
c 0
b 0
f 0
wmc 15

11 Methods

Rating   Name   Duplication   Size   Complexity  
A getSizeNoHeader() 0 7 3
A getPos() 0 3 1
A getDateTime() 0 7 2
A jsonSerialize() 0 3 1
A getId() 0 3 1
A getType() 0 3 1
A getSize() 0 3 1
A getTimestamp() 0 3 1
A getFlag() 0 3 1
A __construct() 0 21 2
A getBinLogCurrent() 0 3 1
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 58
    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 58
        $this->timestamp = $timestamp;
33 58
        $this->type = $type;
34 58
        $this->id = $id;
35 58
        $this->size = $size;
36 58
        $this->pos = $pos;
37 58
        $this->flag = $flag;
38 58
        $this->checkSum = $checkSum;
39 58
        $this->binLogCurrent = $binLogCurrent;
40
41 58
        if ($pos > 0) {
42 58
            $this->binLogCurrent->setBinLogPosition($pos);
43
        }
44 58
    }
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 58
    public function getSizeNoHeader(): int
61
    {
62 58
        if (empty($this->sizeNoHeader)) {
63 58
            $this->sizeNoHeader = (true === $this->checkSum ? $this->size - 23 : $this->size - 19);
64
        }
65
66 58
        return $this->sizeNoHeader;
67
    }
68
69
    public function getTimestamp(): int
70
    {
71
        return $this->timestamp;
72
    }
73
74 58
    public function getType(): int
75
    {
76 58
        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
}