| Total Complexity | 41 |
| Total Lines | 135 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 1 | Features | 0 |
Complex classes like receiver often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use receiver, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 19 | class receiver { |
||
| 20 | private static array $handlers = [ |
||
| 21 | 'message' => null, |
||
| 22 | 'edited_message' => null, |
||
| 23 | 'channel_post' => null, |
||
| 24 | 'edited_channel_post' => null, |
||
| 25 | 'inline_query' => null, |
||
| 26 | 'callback_query' => null, |
||
| 27 | 'my_chat_member' => null, |
||
| 28 | 'chat_member' => null, |
||
| 29 | 'chat_join_request' => null, |
||
| 30 | 'something_else' => null |
||
| 31 | ]; |
||
| 32 | |||
| 33 | protected static function telegramVerify(string $ip = null): void { |
||
| 34 | if (settings::$telegram_verify) { |
||
| 35 | $ip = $ip ?? tools::remoteIP(); |
||
| 36 | if (!tools::isTelegram($ip)) { |
||
| 37 | logger::write('not authorized access denied. IP : '. $ip ?? 'unknown',loggerTypes::WARNING); |
||
| 38 | BPT::exit(); |
||
| 39 | } |
||
| 40 | } |
||
| 41 | } |
||
| 42 | |||
| 43 | protected static function processUpdate(string|stdClass|update $update = null): void { |
||
| 67 | } |
||
| 68 | |||
| 69 | protected static function setMessageExtra (update &$update): void { |
||
| 70 | if (!isset($update->message->text) && !isset($update->edited_message->text)) { |
||
| 71 | return; |
||
| 72 | } |
||
| 73 | $type = isset($update->message) ? 'message' : 'edited_message'; |
||
| 74 | $text = &$update->$type->text; |
||
| 75 | if (settings::$security) { |
||
| 76 | $text = tools::clearText($text); |
||
| 77 | } |
||
| 78 | if (str_starts_with($text, '/')) { |
||
| 79 | preg_match('/\/([a-zA-Z_0-9]{1,64})(@[a-zA-Z]\w{1,28}bot)?( [\S]{1,64})?/', $text, $result); |
||
| 80 | if (isset($result[1])) { |
||
| 81 | $update->$type->command = $result[1]; |
||
| 82 | } |
||
| 83 | if (isset($result[2])) { |
||
| 84 | $update->$type->command_username = $result[2]; |
||
| 85 | } |
||
| 86 | if (isset($result[3])) { |
||
| 87 | $update->$type->command_payload = trim($result[3]); |
||
| 88 | } |
||
| 89 | } |
||
| 90 | } |
||
| 91 | |||
| 92 | private static function processHandler(): void { |
||
| 146 | } |
||
| 147 | } |
||
| 148 | |||
| 149 | private static function handlerExist(string $handler): bool { |
||
| 154 | } |
||
| 155 | } |