| Total Complexity | 45 |
| Total Lines | 126 |
| 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 |
||
| 14 | class receiver { |
||
| 15 | private static array $handlers = [ |
||
| 16 | 'message' => null, |
||
| 17 | 'callback_query' => null, |
||
| 18 | 'inline_query' => null, |
||
| 19 | 'edited_message' => null, |
||
| 20 | 'something_else' => null |
||
| 21 | ]; |
||
| 22 | |||
| 23 | protected static function telegramVerify(string $ip = null): void { |
||
| 24 | if (settings::$telegram_verify) { |
||
| 25 | $ip = $ip ?? $_SERVER['REMOTE_ADDR']; |
||
| 26 | if (settings::$cloadflare_verify) { |
||
| 27 | if (isset($_SERVER['HTTP_CF_CONNECTING_IP']) && tools::isCloudFlare($ip)) { |
||
| 28 | $ip = $_SERVER['HTTP_CF_CONNECTING_IP']; |
||
| 29 | } |
||
| 30 | } |
||
| 31 | elseif (settings::$arvancloud_verify) { |
||
| 32 | if (isset($_SERVER['HTTP_AR_REAL_IP']) && tools::isArvanCloud($ip)) { |
||
| 33 | $ip = $_SERVER['HTTP_AR_REAL_IP']; |
||
| 34 | } |
||
| 35 | } |
||
| 36 | |||
| 37 | if (!tools::isTelegram($ip ?? '')) { |
||
| 38 | logger::write('not authorized access denied. IP : '. $ip ?? 'unknown',loggerTypes::WARNING); |
||
| 39 | BPT::exit(); |
||
| 40 | } |
||
| 41 | } |
||
| 42 | } |
||
| 43 | |||
| 44 | protected static function processUpdate(string|stdClass|update $update = null): void { |
||
| 45 | if (!is_object($update)) { |
||
| 46 | $update = json_decode($update ?? file_get_contents("php://input")); |
||
| 47 | if (!$update) { |
||
| 48 | BPT::exit(); |
||
| 49 | } |
||
| 50 | } |
||
| 51 | |||
| 52 | if (!is_a($update,'update')) { |
||
| 53 | $update = new update($update); |
||
| 54 | } |
||
| 55 | |||
| 56 | self::setMessageExtra($update); |
||
| 57 | BPT::$update = $update; |
||
| 58 | db::process(); |
||
| 59 | self::processHandler(); |
||
| 60 | } |
||
| 61 | |||
| 62 | protected static function setMessageExtra (update &$update): void { |
||
| 63 | if ((isset($update->message) && isset($update->message->text)) || (isset($update->edited_message) && isset($update->edited_message->text))) { |
||
| 64 | $type = isset($update->message) ? 'message' : 'edited_message'; |
||
| 65 | $text = &$update->$type->text; |
||
| 66 | if (settings::$security) { |
||
| 67 | $text = tools::clearText($text); |
||
| 68 | } |
||
| 69 | if (str_starts_with($text, '/')) { |
||
| 70 | preg_match('/\/([a-zA-Z_0-9]{1,64})(@[a-zA-Z]\w{1,28}bot)?( [\S]{1,64})?/', $text, $result); |
||
| 71 | if (isset($result[1])) { |
||
| 72 | $update->$type->commend = $result[1]; |
||
| 73 | } |
||
| 74 | if (isset($result[2])) { |
||
| 75 | $update->$type->commend_username = $result[2]; |
||
| 76 | } |
||
| 77 | if (isset($result[3])) { |
||
| 78 | $update->$type->commend_payload = $result[3]; |
||
| 79 | } |
||
| 80 | } |
||
| 81 | } |
||
| 82 | } |
||
| 83 | |||
| 84 | private static function processHandler(): void { |
||
| 131 | } |
||
| 132 | } |
||
| 133 | } |
||
| 134 | |||
| 135 | private static function handlerExist(string $handler): bool { |
||
| 140 | } |
||
| 141 | } |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths