RotateEvent   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Test Coverage

Coverage 94.74%

Importance

Changes 0
Metric Value
eloc 16
c 0
b 0
f 0
dl 0
loc 37
ccs 18
cts 19
cp 0.9474
rs 10
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A getSizeToRemoveByVersion() 0 7 3
A makeRotateEventDTO() 0 14 1
1
<?php
2
declare(strict_types=1);
3
4
namespace MySQLReplication\Event;
5
6
use MySQLReplication\BinaryDataReader\BinaryDataReader;
7
use MySQLReplication\BinLog\BinLogServerInfo;
8
use MySQLReplication\Event\DTO\RotateDTO;
9
10
/**
11
 * @see https://dev.mysql.com/doc/internals/en/rotate-event.html
12
 */
13
class RotateEvent extends EventCommon
14
{
15
    private $binLogServerInfo;
16
17 1
    public function __construct(
18
        BinLogServerInfo $binLogServerInfo,
19
        EventInfo $eventInfo,
20
        BinaryDataReader $binaryDataReader
21
    ) {
22 1
        parent::__construct($eventInfo, $binaryDataReader);
23 1
        $this->binLogServerInfo = $binLogServerInfo;
24
    }
25
26 1
    public function makeRotateEventDTO(): RotateDTO
27
    {
28 1
        $binFilePos = (int)$this->binaryDataReader->readUInt64();
29 1
        $binFileName = $this->binaryDataReader->read(
30 1
            $this->eventInfo->getSizeNoHeader() - $this->getSizeToRemoveByVersion()
31 1
        );
32
33 1
        $this->eventInfo->getBinLogCurrent()->setBinLogPosition($binFilePos);
34 1
        $this->eventInfo->getBinLogCurrent()->setBinFileName($binFileName);
35
36 1
        return new RotateDTO(
37 1
            $this->eventInfo,
38 1
            $binFilePos,
39 1
            $binFileName
40 1
        );
41
    }
42
43 1
    private function getSizeToRemoveByVersion(): int
44
    {
45 1
        if ($this->binLogServerInfo->isMariaDb() && $this->binLogServerInfo->getRevision() <= 10) {
46
            return 0;
47
        }
48
49 1
        return 8;
50
    }
51
}
52