Completed
Pull Request — master (#34)
by kacper
04:27
created

TableMapDTO   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Test Coverage

Coverage 30%

Importance

Changes 0
Metric Value
dl 0
loc 67
ccs 6
cts 20
cp 0.3
rs 10
c 0
b 0
f 0
wmc 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __toString() 0 11 1
A jsonSerialize() 0 3 1
A __construct() 0 7 1
A getTableMap() 0 3 1
A getType() 0 3 1
1
<?php
2
3
namespace MySQLReplication\Event\DTO;
4
5
use MySQLReplication\Definitions\ConstEventsNames;
6
use MySQLReplication\Event\EventInfo;
7
use MySQLReplication\Event\RowEvent\TableMap;
8
9
/**
10
 * Class TableMapDTO
11
 * @package MySQLReplication\DTO
12
 */
13
class TableMapDTO extends EventDTO
14
{
15
    /**
16
     * @var string
17
     */
18
    private $type = ConstEventsNames::TABLE_MAP;
19
    /**
20
     * @var TableMap
21
     */
22
    private $tableMap;
23
24
    /**
25
     * TableMapDTO constructor.
26
     * @param EventInfo $eventInfo
27
     * @param TableMap $tableMap
28
     */
29 52
    public function __construct(
30
        EventInfo $eventInfo,
31
        TableMap $tableMap
32
    ) {
33 52
        parent::__construct($eventInfo);
34
35 52
        $this->tableMap = $tableMap;
36 52
    }
37
38
    /**
39
     * @return string
40
     */
41
    public function __toString()
42
    {
43
        return PHP_EOL .
44
            '=== Event ' . $this->getType() . ' === ' . PHP_EOL .
45
            'Date: ' . $this->eventInfo->getDateTime() . PHP_EOL .
46
            'Log position: ' . $this->eventInfo->getPos() . PHP_EOL .
47
            'Event size: ' . $this->eventInfo->getSize() . PHP_EOL .
48
            'Table: ' . $this->tableMap->getTable() . PHP_EOL .
49
            'Database: ' . $this->tableMap->getDatabase() . PHP_EOL .
50
            'Table Id: ' . $this->tableMap->getTableId() . PHP_EOL .
51
            'Columns amount: ' . $this->tableMap->getColumnsAmount() . PHP_EOL;
52
    }
53
54
    /**
55
     * @return string
56
     */
57 50
    public function getType()
58
    {
59 50
        return $this->type;
60
    }
61
62
    /**
63
     * Specify data which should be serialized to JSON
64
     * @link http://php.net/manual/en/jsonserializable.jsonserialize.php
65
     * @return mixed data which can be serialized by <b>json_encode</b>,
66
     * which is a value of any type other than a resource.
67
     * @since 5.4.0
68
     */
69
    public function jsonSerialize()
70
    {
71
        return get_object_vars($this);
72
    }
73
74
    /**
75
     * @return TableMap
76
     */
77
    public function getTableMap()
78
    {
79
        return $this->tableMap;
80
    }
81
}