Conditions | 17 |
Paths | 16 |
Total Lines | 86 |
Code Lines | 43 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 1 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
76 | public function consume() |
||
77 | { |
||
78 | $binaryDataReader = $this->packageService->makePackageFromBinaryData( |
||
79 | $this->socketConnect->getPacket(false) |
||
80 | ); |
||
81 | |||
82 | // "ok" value on first byte continue |
||
83 | $binaryDataReader->advance(1); |
||
84 | |||
85 | // decode all events data |
||
86 | $eventInfo = new EventInfo( |
||
87 | $binaryDataReader->readInt32(), |
||
88 | $binaryDataReader->readUInt8(), |
||
89 | $binaryDataReader->readInt32(), |
||
90 | $binaryDataReader->readInt32(), |
||
91 | $binaryDataReader->readInt32(), |
||
92 | $binaryDataReader->readUInt16(), |
||
93 | $this->socketConnect->getCheckSum() |
||
94 | ); |
||
95 | |||
96 | if (ConstEventType::TABLE_MAP_EVENT === $eventInfo->getType()) |
||
97 | { |
||
98 | $event = $this->rowEventService->makeRowEvent($binaryDataReader, $eventInfo)->makeTableMapDTO(); |
||
99 | if ($event !== null) |
||
100 | { |
||
101 | $this->eventDispatcher->dispatch(ConstEventsNames::TABLE_MAP, $event); |
||
102 | } |
||
103 | } |
||
104 | else |
||
105 | { |
||
106 | if ([] !== $this->config->getEventsOnly() && !in_array($eventInfo->getType(), $this->config->getEventsOnly(), true)) |
||
107 | { |
||
108 | return; |
||
109 | } |
||
110 | |||
111 | if (in_array($eventInfo->getType(), $this->config->getEventsIgnore(), true)) |
||
112 | { |
||
113 | return; |
||
114 | } |
||
115 | |||
116 | if (in_array($eventInfo->getType(), [ConstEventType::UPDATE_ROWS_EVENT_V1, ConstEventType::UPDATE_ROWS_EVENT_V2], true)) |
||
117 | { |
||
118 | $event = $this->rowEventService->makeRowEvent($binaryDataReader, $eventInfo)->makeUpdateRowsDTO(); |
||
119 | if ($event !== null) |
||
120 | { |
||
121 | $this->eventDispatcher->dispatch(ConstEventsNames::UPDATE, $event); |
||
122 | } |
||
123 | } |
||
124 | elseif (in_array($eventInfo->getType(), [ConstEventType::WRITE_ROWS_EVENT_V1, ConstEventType::WRITE_ROWS_EVENT_V2], true)) |
||
125 | { |
||
126 | $event = $this->rowEventService->makeRowEvent($binaryDataReader, $eventInfo)->makeWriteRowsDTO(); |
||
127 | if ($event !== null) |
||
128 | { |
||
129 | $this->eventDispatcher->dispatch(ConstEventsNames::WRITE, $event); |
||
130 | } |
||
131 | } |
||
132 | elseif (in_array($eventInfo->getType(), [ConstEventType::DELETE_ROWS_EVENT_V1, ConstEventType::DELETE_ROWS_EVENT_V2], true)) |
||
133 | { |
||
134 | $event = $this->rowEventService->makeRowEvent($binaryDataReader, $eventInfo)->makeDeleteRowsDTO(); |
||
135 | if ($event !== null) |
||
136 | { |
||
137 | $this->eventDispatcher->dispatch(ConstEventsNames::DELETE, $event); |
||
138 | } |
||
139 | } |
||
140 | elseif (ConstEventType::XID_EVENT === $eventInfo->getType()) |
||
141 | { |
||
142 | $this->eventDispatcher->dispatch(ConstEventsNames::XID, (new XidEvent($eventInfo, $binaryDataReader))->makeXidDTO()); |
||
143 | } |
||
144 | elseif (ConstEventType::ROTATE_EVENT === $eventInfo->getType()) |
||
145 | { |
||
146 | $this->eventDispatcher->dispatch(ConstEventsNames::ROTATE, (new RotateEvent($eventInfo, $binaryDataReader))->makeRotateEventDTO()); |
||
147 | } |
||
148 | elseif (ConstEventType::GTID_LOG_EVENT === $eventInfo->getType()) |
||
149 | { |
||
150 | $this->eventDispatcher->dispatch(ConstEventsNames::GTID, (new GtidEvent($eventInfo, $binaryDataReader))->makeGTIDLogDTO()); |
||
151 | } |
||
152 | elseif (ConstEventType::QUERY_EVENT === $eventInfo->getType()) |
||
153 | { |
||
154 | $this->eventDispatcher->dispatch(ConstEventsNames::QUERY, (new QueryEvent($eventInfo, $binaryDataReader))->makeQueryDTO()); |
||
155 | } |
||
156 | elseif (ConstEventType::MARIA_GTID_EVENT === $eventInfo->getType()) |
||
157 | { |
||
158 | $this->eventDispatcher->dispatch(ConstEventsNames::MARIADB_GTID, (new MariaDbGtidEvent($eventInfo, $binaryDataReader))->makeMariaDbGTIDLogDTO()); |
||
159 | } |
||
160 | } |
||
161 | } |
||
162 | } |
||
163 |