Conditions | 14 |
Paths | 49 |
Total Lines | 50 |
Code Lines | 32 |
Lines | 0 |
Ratio | 0 % |
Changes | 4 | ||
Bugs | 2 | 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 |
||
65 | public function consume(): void |
||
66 | { |
||
67 | $binLogServerInfo = $this->binLogSocketConnect->getBinLogServerInfo(); |
||
68 | $binaryDataReader = new BinaryDataReader($this->binLogSocketConnect->getResponse()); |
||
69 | |||
70 | // check EOF_Packet -> https://dev.mysql.com/doc/internals/en/packet-EOF_Packet.html |
||
71 | if (self::EOF_HEADER_VALUE === $binaryDataReader->readUInt8()) { |
||
72 | return; |
||
73 | } |
||
74 | |||
75 | // decode all events data |
||
76 | $eventInfo = $this->createEventInfo($binaryDataReader); |
||
77 | |||
78 | $eventDTO = null; |
||
79 | |||
80 | // we always need this events to clean table maps and for BinLogCurrent class to keep track of binlog position |
||
81 | // always parse table map event but propagate when needed (we need this for creating table cache) |
||
82 | if (ConstEventType::TABLE_MAP_EVENT === $eventInfo->getType()) { |
||
83 | $eventDTO = $this->rowEventFactory->makeRowEvent($binaryDataReader, $eventInfo)->makeTableMapDTO(); |
||
84 | } else if (ConstEventType::ROTATE_EVENT === $eventInfo->getType()) { |
||
85 | $this->cache->clear(); |
||
86 | $eventDTO = (new RotateEvent($binLogServerInfo, $eventInfo, $binaryDataReader))->makeRotateEventDTO(); |
||
87 | } else if (ConstEventType::GTID_LOG_EVENT === $eventInfo->getType()) { |
||
88 | $eventDTO = (new GtidEvent($eventInfo, $binaryDataReader))->makeGTIDLogDTO(); |
||
89 | } else if (ConstEventType::HEARTBEAT_LOG_EVENT === $eventInfo->getType()) { |
||
90 | $eventDTO = new HeartbeatDTO($eventInfo); |
||
91 | } else if (ConstEventType::MARIA_GTID_EVENT === $eventInfo->getType()) { |
||
92 | $eventDTO = (new MariaDbGtidEvent($eventInfo, $binaryDataReader))->makeMariaDbGTIDLogDTO(); |
||
93 | } |
||
94 | |||
95 | // check for ignore and permitted events |
||
96 | if (!$this->config->checkEvent($eventInfo->getType())) { |
||
97 | return; |
||
98 | } |
||
99 | |||
100 | if (in_array($eventInfo->getType(), [ConstEventType::UPDATE_ROWS_EVENT_V1, ConstEventType::UPDATE_ROWS_EVENT_V2], true)) { |
||
101 | $eventDTO = $this->rowEventFactory->makeRowEvent($binaryDataReader, $eventInfo)->makeUpdateRowsDTO(); |
||
102 | } else if (in_array($eventInfo->getType(), [ConstEventType::WRITE_ROWS_EVENT_V1, ConstEventType::WRITE_ROWS_EVENT_V2], true)) { |
||
103 | $eventDTO = $this->rowEventFactory->makeRowEvent($binaryDataReader, $eventInfo)->makeWriteRowsDTO(); |
||
104 | } else if (in_array($eventInfo->getType(), [ConstEventType::DELETE_ROWS_EVENT_V1, ConstEventType::DELETE_ROWS_EVENT_V2], true)) { |
||
105 | $eventDTO = $this->rowEventFactory->makeRowEvent($binaryDataReader, $eventInfo)->makeDeleteRowsDTO(); |
||
106 | } else if (ConstEventType::XID_EVENT === $eventInfo->getType()) { |
||
107 | $eventDTO = (new XidEvent($eventInfo, $binaryDataReader))->makeXidDTO(); |
||
108 | } else if (ConstEventType::QUERY_EVENT === $eventInfo->getType()) { |
||
109 | $eventDTO = $this->filterDummyMariaDbEvents((new QueryEvent($eventInfo, $binaryDataReader))->makeQueryDTO()); |
||
110 | } else if (ConstEventType::FORMAT_DESCRIPTION_EVENT === $eventInfo->getType()) { |
||
111 | $eventDTO = new FormatDescriptionEventDTO($eventInfo); |
||
112 | } |
||
113 | |||
114 | $this->dispatch($eventDTO); |
||
115 | } |
||
148 |