Passed
Branch master (a6a24c)
by kacper
04:55
created

EventSubscribers   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 130
Duplicated Lines 0 %

Test Coverage

Coverage 72.34%

Importance

Changes 0
Metric Value
dl 0
loc 130
ccs 34
cts 47
cp 0.7234
rs 10
c 0
b 0
f 0
wmc 13

13 Methods

Rating   Name   Duplication   Size   Complexity  
A onTableMap() 0 3 1
A onDelete() 0 3 1
A onHeartbeat() 0 3 1
A getSubscribedEvents() 0 14 1
A onQuery() 0 3 1
A onGTID() 0 3 1
A onWrite() 0 3 1
A allEvents() 0 2 1
A onUpdate() 0 3 1
A onRotate() 0 3 1
A onFormatDescription() 0 3 1
A onMariaDbGtid() 0 3 1
A onXID() 0 3 1
1
<?php
2
3
namespace MySQLReplication\Event;
4
5
use MySQLReplication\Definitions\ConstEventsNames;
6
use MySQLReplication\Event\DTO\DeleteRowsDTO;
7
use MySQLReplication\Event\DTO\EventDTO;
8
use MySQLReplication\Event\DTO\FormatDescriptionEventDTO;
9
use MySQLReplication\Event\DTO\GTIDLogDTO;
10
use MySQLReplication\Event\DTO\HeartbeatDTO;
11
use MySQLReplication\Event\DTO\MariaDbGtidLogDTO;
12
use MySQLReplication\Event\DTO\QueryDTO;
13
use MySQLReplication\Event\DTO\RotateDTO;
14
use MySQLReplication\Event\DTO\TableMapDTO;
15
use MySQLReplication\Event\DTO\UpdateRowsDTO;
16
use MySQLReplication\Event\DTO\WriteRowsDTO;
17
use MySQLReplication\Event\DTO\XidDTO;
18
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
19
20
/**
21
 * Class EventSubscribers
22
 * @package MySQLReplication\Event
23
 */
24
class EventSubscribers implements EventSubscriberInterface
25
{
26
    /**
27
     * Returns an array of event names this subscriber wants to listen to.
28
     *
29
     * The array keys are event names and the value can be:
30
     *
31
     *  * The method name to call (priority defaults to 0)
32
     *  * An array composed of the method name to call and the priority
33
     *  * An array of arrays composed of the method names to call and respective
34
     *    priorities, or 0 if unset
35
     *
36
     * For instance:
37
     *
38
     *  * array('eventName' => 'methodName')
39
     *  * array('eventName' => array('methodName', $priority))
40
     *  * array('eventName' => array(array('methodName1', $priority), array('methodName2')))
41
     *
42
     * @return array The event names to listen to
43
     */
44 54
    public static function getSubscribedEvents()
45
    {
46
        return [
47 54
            ConstEventsNames::TABLE_MAP => 'onTableMap',
48 54
            ConstEventsNames::UPDATE => 'onUpdate',
49 54
            ConstEventsNames::DELETE => 'onDelete',
50 54
            ConstEventsNames::GTID => 'onGTID',
51 54
            ConstEventsNames::QUERY => 'onQuery',
52 54
            ConstEventsNames::ROTATE => 'onRotate',
53 54
            ConstEventsNames::XID => 'onXID',
54 54
            ConstEventsNames::WRITE => 'onWrite',
55 54
            ConstEventsNames::MARIADB_GTID => 'onMariaDbGtid',
56 54
            ConstEventsNames::FORMAT_DESCRIPTION => 'onFormatDescription',
57 54
            ConstEventsNames::HEARTBEAT => 'onHeartbeat',
58 54
        ];
59
    }
60
61
    /**
62
     * @param UpdateRowsDTO $event
63
     */
64 1
    public function onUpdate(UpdateRowsDTO $event)
65
    {
66 1
        $this->allEvents($event);
67 1
    }
68
69
    /**
70
     * @param EventDTO $event
71
     */
72
    protected function allEvents(EventDTO $event)
73
    {
74
    }
75
76
    /**
77
     * @param TableMapDTO $event
78
     */
79 50
    public function onTableMap(TableMapDTO $event)
80
    {
81 50
        $this->allEvents($event);
82 50
    }
83
84
    /**
85
     * @param DeleteRowsDTO $event
86
     */
87 1
    public function onDelete(DeleteRowsDTO $event)
88
    {
89 1
        $this->allEvents($event);
90 1
    }
91
92
    /**
93
     * @param GTIDLogDTO $event
94
     */
95
    public function onGTID(GTIDLogDTO $event)
96
    {
97
        $this->allEvents($event);
98
    }
99
100
    /**
101
     * @param QueryDTO $event
102
     */
103 54
    public function onQuery(QueryDTO $event)
104
    {
105 54
        $this->allEvents($event);
106 54
    }
107
108
    /**
109
     * @param RotateDTO $event
110
     */
111
    public function onRotate(RotateDTO $event)
112
    {
113
        $this->allEvents($event);
114
    }
115
116
    /**
117
     * @param XidDTO $event
118
     */
119 3
    public function onXID(XidDTO $event)
120
    {
121 3
        $this->allEvents($event);
122 3
    }
123
124
    /**
125
     * @param WriteRowsDTO $event
126
     */
127 52
    public function onWrite(WriteRowsDTO $event)
128
    {
129 52
        $this->allEvents($event);
130 52
    }
131
132
    /**
133
     * @param MariaDbGtidLogDTO $event
134
     */
135
    public function onMariaDbGtid(MariaDbGtidLogDTO $event)
136
    {
137
        $this->allEvents($event);
138
    }
139
140
    /**
141
     * @param FormatDescriptionEventDTO $event
142
     */
143 54
    public function onFormatDescription(FormatDescriptionEventDTO $event)
144
    {
145 54
        $this->allEvents($event);
146 54
    }
147
148
    /**
149
     * @param HeartbeatDTO $event
150
     */
151
    public function onHeartbeat(HeartbeatDTO $event)
152
    {
153
        $this->allEvents($event);
154
    }
155
}