Complex classes like Request 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. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
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 Request, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 19 | class Request |
||
| 20 | { |
||
| 21 | /** |
||
| 22 | * Telegram object |
||
| 23 | * |
||
| 24 | * @var \Longman\TelegramBot\Telegram |
||
| 25 | */ |
||
| 26 | private static $telegram; |
||
| 27 | |||
| 28 | /** |
||
| 29 | * URI of the Telegram API |
||
| 30 | * |
||
| 31 | * @var string |
||
| 32 | */ |
||
| 33 | private static $api_base_uri = 'https://api.telegram.org'; |
||
| 34 | |||
| 35 | /** |
||
| 36 | * Guzzle Client object |
||
| 37 | * |
||
| 38 | * @var \GuzzleHttp\Client |
||
| 39 | */ |
||
| 40 | private static $client; |
||
| 41 | |||
| 42 | /** |
||
| 43 | * Input value of the request |
||
| 44 | * |
||
| 45 | * @var string |
||
| 46 | */ |
||
| 47 | private static $input; |
||
| 48 | |||
| 49 | /** |
||
| 50 | * Available actions to send |
||
| 51 | * |
||
| 52 | * @var array |
||
| 53 | */ |
||
| 54 | private static $actions = [ |
||
| 55 | 'getUpdates', |
||
| 56 | 'setWebhook', |
||
| 57 | 'getMe', |
||
| 58 | 'sendMessage', |
||
| 59 | 'forwardMessage', |
||
| 60 | 'sendPhoto', |
||
| 61 | 'sendAudio', |
||
| 62 | 'sendDocument', |
||
| 63 | 'sendSticker', |
||
| 64 | 'sendVideo', |
||
| 65 | 'sendVoice', |
||
| 66 | 'sendLocation', |
||
| 67 | 'sendVenue', |
||
| 68 | 'sendContact', |
||
| 69 | 'sendChatAction', |
||
| 70 | 'getUserProfilePhotos', |
||
| 71 | 'getFile', |
||
| 72 | 'kickChatMember', |
||
| 73 | 'leaveChat', |
||
| 74 | 'unbanChatMember', |
||
| 75 | 'getChat', |
||
| 76 | 'getChatAdministrators', |
||
| 77 | 'getChatMember', |
||
| 78 | 'getChatMembersCount', |
||
| 79 | 'answerCallbackQuery', |
||
| 80 | 'answerInlineQuery', |
||
| 81 | 'editMessageText', |
||
| 82 | 'editMessageCaption', |
||
| 83 | 'editMessageReplyMarkup', |
||
| 84 | 'getWebhookInfo', |
||
| 85 | ]; |
||
| 86 | |||
| 87 | /** |
||
| 88 | * Initialize |
||
| 89 | * |
||
| 90 | * @param \Longman\TelegramBot\Telegram $telegram |
||
| 91 | * |
||
| 92 | * @throws \Longman\TelegramBot\Exception\TelegramException |
||
| 93 | */ |
||
| 94 | 39 | public static function initialize(Telegram $telegram) |
|
| 103 | |||
| 104 | /** |
||
| 105 | * Set input from custom input or stdin and return it |
||
| 106 | * |
||
| 107 | * @return string |
||
| 108 | * @throws \Longman\TelegramBot\Exception\TelegramException |
||
| 109 | */ |
||
| 110 | public static function getInput() |
||
| 128 | |||
| 129 | /** |
||
| 130 | * Generate general fake server response |
||
| 131 | * |
||
| 132 | * @param array $data Data to add to fake response |
||
| 133 | * |
||
| 134 | * @return array Fake response data |
||
| 135 | */ |
||
| 136 | 6 | public static function generateGeneralFakeServerResponse(array $data = []) |
|
| 166 | |||
| 167 | /** |
||
| 168 | * Properly set up the request params |
||
| 169 | * |
||
| 170 | * If any item of the array is a resource, reformat it to a multipart request. |
||
| 171 | * Else, just return the passed data as form params. |
||
| 172 | * |
||
| 173 | * @param array $data |
||
| 174 | * |
||
| 175 | * @return array |
||
| 176 | */ |
||
| 177 | private static function setUpRequestParams(array $data) |
||
| 193 | |||
| 194 | /** |
||
| 195 | * Execute HTTP Request |
||
| 196 | * |
||
| 197 | * @param string $action Action to execute |
||
| 198 | * @param array $data Data to attach to the execution |
||
| 199 | * |
||
| 200 | * @return string Result of the HTTP Request |
||
| 201 | * @throws \Longman\TelegramBot\Exception\TelegramException |
||
| 202 | */ |
||
| 203 | public static function execute($action, array $data = []) |
||
| 204 | { |
||
| 205 | //Fix so that the keyboard markup is a string, not an object |
||
| 206 | if (isset($data['reply_markup'])) { |
||
| 207 | $data['reply_markup'] = (string)$data['reply_markup']; |
||
| 208 | } |
||
| 209 | |||
| 210 | $request_params = self::setUpRequestParams($data); |
||
| 211 | |||
| 212 | $debug_handle = TelegramLog::getDebugLogTempStream(); |
||
| 213 | $request_params['debug'] = $debug_handle; |
||
| 214 | |||
| 215 | try { |
||
| 216 | $response = self::$client->post( |
||
| 217 | '/bot' . self::$telegram->getApiKey() . '/' . $action, |
||
| 218 | $request_params |
||
| 219 | ); |
||
| 220 | $result = (string)$response->getBody(); |
||
| 221 | |||
| 222 | //Logging getUpdates Update |
||
| 223 | if ($action === 'getUpdates') { |
||
| 224 | TelegramLog::update($result); |
||
| 225 | } |
||
| 226 | } catch (RequestException $e) { |
||
| 227 | $result = (string)$e->getResponse()->getBody(); |
||
| 228 | } finally { |
||
| 229 | //Logging verbose debug output |
||
| 230 | TelegramLog::endDebugLogTempStream("Verbose HTTP Request output:\n%s\n"); |
||
| 231 | } |
||
| 232 | |||
| 233 | return $result; |
||
|
|
|||
| 234 | } |
||
| 235 | |||
| 236 | /** |
||
| 237 | * Download file |
||
| 238 | * |
||
| 239 | * @param \Longman\TelegramBot\Entities\File $file |
||
| 240 | * |
||
| 241 | * @return boolean |
||
| 242 | * @throws \Longman\TelegramBot\Exception\TelegramException |
||
| 243 | */ |
||
| 244 | public static function downloadFile(File $file) |
||
| 245 | { |
||
| 246 | $tg_file_path = $file->getFilePath(); |
||
| 247 | $file_path = self::$telegram->getDownloadPath() . '/' . $tg_file_path; |
||
| 248 | |||
| 249 | $file_dir = dirname($file_path); |
||
| 250 | //For safety reasons, first try to create the directory, then check that it exists. |
||
| 251 | //This is in case some other process has created the folder in the meantime. |
||
| 252 | if (!@mkdir($file_dir, 0755, true) && !is_dir($file_dir)) { |
||
| 253 | throw new TelegramException('Directory ' . $file_dir . ' can\'t be created'); |
||
| 254 | } |
||
| 255 | |||
| 256 | $debug_handle = TelegramLog::getDebugLogTempStream(); |
||
| 257 | |||
| 258 | try { |
||
| 259 | self::$client->get( |
||
| 260 | '/file/bot' . self::$telegram->getApiKey() . '/' . $tg_file_path, |
||
| 261 | ['debug' => $debug_handle, 'sink' => $file_path] |
||
| 262 | ); |
||
| 263 | |||
| 264 | return filesize($file_path) > 0; |
||
| 265 | } catch (RequestException $e) { |
||
| 266 | return (string)$e->getResponse()->getBody(); |
||
| 267 | } finally { |
||
| 268 | //Logging verbose debug output |
||
| 269 | TelegramLog::endDebugLogTempStream("Verbose HTTP File Download Request output:\n%s\n"); |
||
| 270 | } |
||
| 271 | } |
||
| 272 | |||
| 273 | /** |
||
| 274 | * Encode file |
||
| 275 | * |
||
| 276 | * @param string $file |
||
| 277 | * |
||
| 278 | * @return resource |
||
| 279 | * @throws \Longman\TelegramBot\Exception\TelegramException |
||
| 280 | */ |
||
| 281 | protected static function encodeFile($file) |
||
| 290 | |||
| 291 | /** |
||
| 292 | * Send command |
||
| 293 | * |
||
| 294 | * @todo Fake response doesn't need json encoding? |
||
| 295 | * |
||
| 296 | * @param string $action |
||
| 297 | * @param array $data |
||
| 298 | * |
||
| 299 | * @return \Longman\TelegramBot\Entities\ServerResponse |
||
| 300 | * @throws \Longman\TelegramBot\Exception\TelegramException |
||
| 301 | */ |
||
| 302 | 5 | public static function send($action, array $data = []) |
|
| 324 | |||
| 325 | /** |
||
| 326 | * Make sure the data isn't empty, else throw an exception |
||
| 327 | * |
||
| 328 | * @param array $data |
||
| 329 | * |
||
| 330 | * @throws \Longman\TelegramBot\Exception\TelegramException |
||
| 331 | */ |
||
| 332 | private static function ensureNonEmptyData(array $data) |
||
| 338 | |||
| 339 | /** |
||
| 340 | * Make sure the action is valid, else throw an exception |
||
| 341 | * |
||
| 342 | * @param string $action |
||
| 343 | * |
||
| 344 | * @throws \Longman\TelegramBot\Exception\TelegramException |
||
| 345 | */ |
||
| 346 | 5 | private static function ensureValidAction($action) |
|
| 352 | |||
| 353 | /** |
||
| 354 | * Assign an encoded file to a data array |
||
| 355 | * |
||
| 356 | * @param array $data |
||
| 357 | * @param string $field |
||
| 358 | * @param string $file |
||
| 359 | * |
||
| 360 | * @throws \Longman\TelegramBot\Exception\TelegramException |
||
| 361 | */ |
||
| 362 | private static function assignEncodedFile(&$data, $field, $file) |
||
| 368 | |||
| 369 | /** |
||
| 370 | * Returns basic information about the bot in form of a User object |
||
| 371 | * |
||
| 372 | * @link https://core.telegram.org/bots/api#getme |
||
| 373 | * |
||
| 374 | * @return \Longman\TelegramBot\Entities\ServerResponse |
||
| 375 | * @throws \Longman\TelegramBot\Exception\TelegramException |
||
| 376 | */ |
||
| 377 | public static function getMe() |
||
| 383 | |||
| 384 | /** |
||
| 385 | * Use this method to send text messages. On success, the sent Message is returned |
||
| 386 | * |
||
| 387 | * @link https://core.telegram.org/bots/api#sendmessage |
||
| 388 | * |
||
| 389 | * @param array $data |
||
| 390 | * |
||
| 391 | * @return \Longman\TelegramBot\Entities\ServerResponse |
||
| 392 | * @throws \Longman\TelegramBot\Exception\TelegramException |
||
| 393 | */ |
||
| 394 | 5 | public static function sendMessage(array $data) |
|
| 409 | |||
| 410 | /** |
||
| 411 | * Use this method to forward messages of any kind. On success, the sent Message is returned |
||
| 412 | * |
||
| 413 | * @link https://core.telegram.org/bots/api#forwardmessage |
||
| 414 | * |
||
| 415 | * @param array $data |
||
| 416 | * |
||
| 417 | * @return \Longman\TelegramBot\Entities\ServerResponse |
||
| 418 | * @throws \Longman\TelegramBot\Exception\TelegramException |
||
| 419 | */ |
||
| 420 | public static function forwardMessage(array $data) |
||
| 424 | |||
| 425 | /** |
||
| 426 | * Use this method to send photos. On success, the sent Message is returned |
||
| 427 | * |
||
| 428 | * @link https://core.telegram.org/bots/api#sendphoto |
||
| 429 | * |
||
| 430 | * @param array $data |
||
| 431 | * @param string $file |
||
| 432 | * |
||
| 433 | * @return \Longman\TelegramBot\Entities\ServerResponse |
||
| 434 | * @throws \Longman\TelegramBot\Exception\TelegramException |
||
| 435 | */ |
||
| 436 | public static function sendPhoto(array $data, $file = null) |
||
| 442 | |||
| 443 | /** |
||
| 444 | * Use this method to send audio files |
||
| 445 | * |
||
| 446 | * Your audio must be in the .mp3 format. On success, the sent Message is returned. |
||
| 447 | * Bots can currently send audio files of up to 50 MB in size, this limit may be changed in the future. |
||
| 448 | * For sending voice messages, use the sendVoice method instead. |
||
| 449 | * |
||
| 450 | * @link https://core.telegram.org/bots/api#sendaudio |
||
| 451 | * |
||
| 452 | * @param array $data |
||
| 453 | * @param string $file |
||
| 454 | * |
||
| 455 | * @return \Longman\TelegramBot\Entities\ServerResponse |
||
| 456 | * @throws \Longman\TelegramBot\Exception\TelegramException |
||
| 457 | */ |
||
| 458 | public static function sendAudio(array $data, $file = null) |
||
| 464 | |||
| 465 | /** |
||
| 466 | * Use this method to send general files. On success, the sent Message is returned. |
||
| 467 | * |
||
| 468 | * Bots can currently send files of any type of up to 50 MB in size, this limit may be changed in the future. |
||
| 469 | * |
||
| 470 | * @link https://core.telegram.org/bots/api#senddocument |
||
| 471 | * |
||
| 472 | * @param array $data |
||
| 473 | * @param string $file |
||
| 474 | * |
||
| 475 | * @return \Longman\TelegramBot\Entities\ServerResponse |
||
| 476 | * @throws \Longman\TelegramBot\Exception\TelegramException |
||
| 477 | */ |
||
| 478 | public static function sendDocument(array $data, $file = null) |
||
| 484 | |||
| 485 | /** |
||
| 486 | * Use this method to send .webp stickers. On success, the sent Message is returned. |
||
| 487 | * |
||
| 488 | * @link https://core.telegram.org/bots/api#sendsticker |
||
| 489 | * |
||
| 490 | * @param array $data |
||
| 491 | * @param string $file |
||
| 492 | * |
||
| 493 | * @return \Longman\TelegramBot\Entities\ServerResponse |
||
| 494 | * @throws \Longman\TelegramBot\Exception\TelegramException |
||
| 495 | */ |
||
| 496 | public static function sendSticker(array $data, $file = null) |
||
| 502 | |||
| 503 | /** |
||
| 504 | * Use this method to send video files. On success, the sent Message is returned. |
||
| 505 | * |
||
| 506 | * Telegram clients support mp4 videos (other formats may be sent as Document). |
||
| 507 | * Bots can currently send video files of up to 50 MB in size, this limit may be changed in the future. |
||
| 508 | * |
||
| 509 | * @link https://core.telegram.org/bots/api#sendvideo |
||
| 510 | * |
||
| 511 | * @param array $data |
||
| 512 | * @param string $file |
||
| 513 | * |
||
| 514 | * @return \Longman\TelegramBot\Entities\ServerResponse |
||
| 515 | * @throws \Longman\TelegramBot\Exception\TelegramException |
||
| 516 | */ |
||
| 517 | public static function sendVideo(array $data, $file = null) |
||
| 523 | |||
| 524 | /** |
||
| 525 | * Use this method to send audio files. On success, the sent Message is returned. |
||
| 526 | * |
||
| 527 | * Telegram clients will display the file as a playable voice message. |
||
| 528 | * For this to work, your audio must be in an .ogg file encoded with OPUS (other formats may be sent as Audio or Document). |
||
| 529 | * Bots can currently send voice messages of up to 50 MB in size, this limit may be changed in the future. |
||
| 530 | * |
||
| 531 | * @link https://core.telegram.org/bots/api#sendvoice |
||
| 532 | * |
||
| 533 | * @param array $data |
||
| 534 | * @param string $file |
||
| 535 | * |
||
| 536 | * @return \Longman\TelegramBot\Entities\ServerResponse |
||
| 537 | * @throws \Longman\TelegramBot\Exception\TelegramException |
||
| 538 | */ |
||
| 539 | public static function sendVoice(array $data, $file = null) |
||
| 545 | |||
| 546 | /** |
||
| 547 | * Use this method to send point on the map. On success, the sent Message is returned. |
||
| 548 | * |
||
| 549 | * @link https://core.telegram.org/bots/api#sendlocation |
||
| 550 | * |
||
| 551 | * @param array $data |
||
| 552 | * |
||
| 553 | * @return \Longman\TelegramBot\Entities\ServerResponse |
||
| 554 | * @throws \Longman\TelegramBot\Exception\TelegramException |
||
| 555 | */ |
||
| 556 | public static function sendLocation(array $data) |
||
| 560 | |||
| 561 | /** |
||
| 562 | * Use this method to send information about a venue. On success, the sent Message is returned. |
||
| 563 | * |
||
| 564 | * @link https://core.telegram.org/bots/api#sendvenue |
||
| 565 | * |
||
| 566 | * @param array $data |
||
| 567 | * |
||
| 568 | * @return \Longman\TelegramBot\Entities\ServerResponse |
||
| 569 | * @throws \Longman\TelegramBot\Exception\TelegramException |
||
| 570 | */ |
||
| 571 | public static function sendVenue(array $data) |
||
| 575 | |||
| 576 | /** |
||
| 577 | * Use this method to send phone contacts. On success, the sent Message is returned. |
||
| 578 | * |
||
| 579 | * @link https://core.telegram.org/bots/api#sendcontact |
||
| 580 | * |
||
| 581 | * @param array $data |
||
| 582 | * |
||
| 583 | * @return \Longman\TelegramBot\Entities\ServerResponse |
||
| 584 | * @throws \Longman\TelegramBot\Exception\TelegramException |
||
| 585 | */ |
||
| 586 | public static function sendContact(array $data) |
||
| 590 | |||
| 591 | /** |
||
| 592 | * Use this method when you need to tell the user that something is happening on the bot's side. |
||
| 593 | * |
||
| 594 | * The status is set for 5 seconds or less. |
||
| 595 | * (when a message arrives from your bot, Telegram clients clear its typing status) |
||
| 596 | * |
||
| 597 | * @link https://core.telegram.org/bots/api#sendchataction |
||
| 598 | * |
||
| 599 | * @param array $data |
||
| 600 | * |
||
| 601 | * @return \Longman\TelegramBot\Entities\ServerResponse |
||
| 602 | * @throws \Longman\TelegramBot\Exception\TelegramException |
||
| 603 | */ |
||
| 604 | public static function sendChatAction(array $data) |
||
| 608 | |||
| 609 | /** |
||
| 610 | * Use this method to get a list of profile pictures for a user. Returns a UserProfilePhotos object. |
||
| 611 | * |
||
| 612 | * @param array $data |
||
| 613 | * |
||
| 614 | * @return \Longman\TelegramBot\Entities\ServerResponse |
||
| 615 | * @throws \Longman\TelegramBot\Exception\TelegramException |
||
| 616 | */ |
||
| 617 | public static function getUserProfilePhotos(array $data) |
||
| 621 | |||
| 622 | /** |
||
| 623 | * Use this method to get basic info about a file and prepare it for downloading. On success, a File object is returned. |
||
| 624 | * |
||
| 625 | * For the moment, bots can download files of up to 20MB in size. |
||
| 626 | * The file can then be downloaded via the link https://api.telegram.org/file/bot<token>/<file_path>, |
||
| 627 | * where <file_path> is taken from the response. |
||
| 628 | * It is guaranteed that the link will be valid for at least 1 hour. |
||
| 629 | * When the link expires, a new one can be requested by calling getFile again. |
||
| 630 | * |
||
| 631 | * @link https://core.telegram.org/bots/api#getfile |
||
| 632 | * |
||
| 633 | * @param array $data |
||
| 634 | * |
||
| 635 | * @return \Longman\TelegramBot\Entities\ServerResponse |
||
| 636 | * @throws \Longman\TelegramBot\Exception\TelegramException |
||
| 637 | */ |
||
| 638 | public static function getFile(array $data) |
||
| 642 | |||
| 643 | /** |
||
| 644 | * Use this method to kick a user from a group or a supergroup. Returns True on success. |
||
| 645 | * |
||
| 646 | * In the case of supergroups, the user will not be able to return to the group on their own using invite links, etc., unless unbanned first. |
||
| 647 | * The bot must be an administrator in the group for this to work. |
||
| 648 | * |
||
| 649 | * @link https://core.telegram.org/bots/api#kickchatmember |
||
| 650 | * |
||
| 651 | * @param array $data |
||
| 652 | * |
||
| 653 | * @return \Longman\TelegramBot\Entities\ServerResponse |
||
| 654 | * @throws \Longman\TelegramBot\Exception\TelegramException |
||
| 655 | */ |
||
| 656 | public static function kickChatMember(array $data) |
||
| 660 | |||
| 661 | /** |
||
| 662 | * Use this method for your bot to leave a group, supergroup or channel. Returns True on success. |
||
| 663 | * |
||
| 664 | * @link https://core.telegram.org/bots/api#leavechat |
||
| 665 | * |
||
| 666 | * @param array $data |
||
| 667 | * |
||
| 668 | * @return \Longman\TelegramBot\Entities\ServerResponse |
||
| 669 | * @throws \Longman\TelegramBot\Exception\TelegramException |
||
| 670 | */ |
||
| 671 | public static function leaveChat(array $data) |
||
| 675 | |||
| 676 | /** |
||
| 677 | * Use this method to unban a previously kicked user in a supergroup. Returns True on success. |
||
| 678 | * |
||
| 679 | * The user will not return to the group automatically, but will be able to join via link, etc. |
||
| 680 | * The bot must be an administrator in the group for this to work. |
||
| 681 | * |
||
| 682 | * @link https://core.telegram.org/bots/api#unbanchatmember |
||
| 683 | * |
||
| 684 | * @param array $data |
||
| 685 | * |
||
| 686 | * @return \Longman\TelegramBot\Entities\ServerResponse |
||
| 687 | * @throws \Longman\TelegramBot\Exception\TelegramException |
||
| 688 | */ |
||
| 689 | public static function unbanChatMember(array $data) |
||
| 693 | |||
| 694 | /** |
||
| 695 | * Use this method to get up to date information about the chat (current name of the user for one-on-one conversations, current username of a user, group or channel, etc.). Returns a Chat object on success. |
||
| 696 | * |
||
| 697 | * @todo add get response in ServerResponse.php? |
||
| 698 | * |
||
| 699 | * @link https://core.telegram.org/bots/api#getchat |
||
| 700 | * |
||
| 701 | * @param array $data |
||
| 702 | * |
||
| 703 | * @return \Longman\TelegramBot\Entities\ServerResponse |
||
| 704 | * @throws \Longman\TelegramBot\Exception\TelegramException |
||
| 705 | */ |
||
| 706 | public static function getChat(array $data) |
||
| 710 | |||
| 711 | /** |
||
| 712 | * Use this method to get a list of administrators in a chat. |
||
| 713 | * |
||
| 714 | * On success, returns an Array of ChatMember objects that contains information about all chat administrators except other bots. |
||
| 715 | * If the chat is a group or a supergroup and no administrators were appointed, only the creator will be returned. |
||
| 716 | * |
||
| 717 | * @todo add get response in ServerResponse.php? |
||
| 718 | * |
||
| 719 | * @link https://core.telegram.org/bots/api#getchatadministrators |
||
| 720 | * |
||
| 721 | * @param array $data |
||
| 722 | * |
||
| 723 | * @return \Longman\TelegramBot\Entities\ServerResponse |
||
| 724 | * @throws \Longman\TelegramBot\Exception\TelegramException |
||
| 725 | */ |
||
| 726 | public static function getChatAdministrators(array $data) |
||
| 730 | |||
| 731 | /** |
||
| 732 | * Use this method to get the number of members in a chat. Returns Int on success. |
||
| 733 | * |
||
| 734 | * @todo add get response in ServerResponse.php? |
||
| 735 | * |
||
| 736 | * @link https://core.telegram.org/bots/api#getchatmemberscount |
||
| 737 | * |
||
| 738 | * @param array $data |
||
| 739 | * |
||
| 740 | * @return \Longman\TelegramBot\Entities\ServerResponse |
||
| 741 | * @throws \Longman\TelegramBot\Exception\TelegramException |
||
| 742 | */ |
||
| 743 | public static function getChatMembersCount(array $data) |
||
| 747 | |||
| 748 | /** |
||
| 749 | * Use this method to get information about a member of a chat. Returns a ChatMember object on success. |
||
| 750 | * |
||
| 751 | * @todo add get response in ServerResponse.php? |
||
| 752 | * |
||
| 753 | * @link https://core.telegram.org/bots/api#getchatmember |
||
| 754 | * |
||
| 755 | * @param array $data |
||
| 756 | * |
||
| 757 | * @return \Longman\TelegramBot\Entities\ServerResponse |
||
| 758 | * @throws \Longman\TelegramBot\Exception\TelegramException |
||
| 759 | */ |
||
| 760 | public static function getChatMember(array $data) |
||
| 764 | |||
| 765 | /** |
||
| 766 | * Use this method to send answers to callback queries sent from inline keyboards. On success, True is returned. |
||
| 767 | * |
||
| 768 | * The answer will be displayed to the user as a notification at the top of the chat screen or as an alert. |
||
| 769 | * |
||
| 770 | * @link https://core.telegram.org/bots/api#answercallbackquery |
||
| 771 | * |
||
| 772 | * @param array $data |
||
| 773 | * |
||
| 774 | * @return \Longman\TelegramBot\Entities\ServerResponse |
||
| 775 | * @throws \Longman\TelegramBot\Exception\TelegramException |
||
| 776 | */ |
||
| 777 | public static function answerCallbackQuery(array $data) |
||
| 781 | |||
| 782 | /** |
||
| 783 | * Get updates |
||
| 784 | * |
||
| 785 | * @link https://core.telegram.org/bots/api#getupdates |
||
| 786 | * |
||
| 787 | * @param array $data |
||
| 788 | * |
||
| 789 | * @return \Longman\TelegramBot\Entities\ServerResponse |
||
| 790 | * @throws \Longman\TelegramBot\Exception\TelegramException |
||
| 791 | */ |
||
| 792 | public static function getUpdates(array $data) |
||
| 796 | |||
| 797 | /** |
||
| 798 | * Set webhook |
||
| 799 | * |
||
| 800 | * @link https://core.telegram.org/bots/api#setwebhook |
||
| 801 | * |
||
| 802 | * @param string $url |
||
| 803 | * @param string $file |
||
| 804 | * |
||
| 805 | * @return \Longman\TelegramBot\Entities\ServerResponse |
||
| 806 | * @throws \Longman\TelegramBot\Exception\TelegramException |
||
| 807 | */ |
||
| 808 | public static function setWebhook($url = '', $file = null) |
||
| 816 | |||
| 817 | /** |
||
| 818 | * Use this method to edit text and game messages sent by the bot or via the bot (for inline bots). |
||
| 819 | * |
||
| 820 | * On success, if edited message is sent by the bot, the edited Message is returned, otherwise True is returned. |
||
| 821 | * |
||
| 822 | * @link https://core.telegram.org/bots/api#editmessagetext |
||
| 823 | * |
||
| 824 | * @param array $data |
||
| 825 | * |
||
| 826 | * @return \Longman\TelegramBot\Entities\ServerResponse |
||
| 827 | * @throws \Longman\TelegramBot\Exception\TelegramException |
||
| 828 | */ |
||
| 829 | public static function editMessageText(array $data) |
||
| 833 | |||
| 834 | /** |
||
| 835 | * Use this method to edit captions of messages sent by the bot or via the bot (for inline bots). |
||
| 836 | * |
||
| 837 | * On success, if edited message is sent by the bot, the edited Message is returned, otherwise True is returned. |
||
| 838 | * |
||
| 839 | * @link https://core.telegram.org/bots/api#editmessagecaption |
||
| 840 | * |
||
| 841 | * @param array $data |
||
| 842 | * |
||
| 843 | * @return \Longman\TelegramBot\Entities\ServerResponse |
||
| 844 | * @throws \Longman\TelegramBot\Exception\TelegramException |
||
| 845 | */ |
||
| 846 | public static function editMessageCaption(array $data) |
||
| 850 | |||
| 851 | /** |
||
| 852 | * Use this method to edit only the reply markup of messages sent by the bot or via the bot (for inline bots). |
||
| 853 | * |
||
| 854 | * On success, if edited message is sent by the bot, the edited Message is returned, otherwise True is returned. |
||
| 855 | * |
||
| 856 | * @link https://core.telegram.org/bots/api#editmessagereplymarkup |
||
| 857 | * |
||
| 858 | * @param array $data |
||
| 859 | * |
||
| 860 | * @return \Longman\TelegramBot\Entities\ServerResponse |
||
| 861 | * @throws \Longman\TelegramBot\Exception\TelegramException |
||
| 862 | */ |
||
| 863 | public static function editMessageReplyMarkup(array $data) |
||
| 867 | |||
| 868 | /** |
||
| 869 | * Use this method to send answers to an inline query. On success, True is returned. |
||
| 870 | * |
||
| 871 | * No more than 50 results per query are allowed. |
||
| 872 | * |
||
| 873 | * @link https://core.telegram.org/bots/api#answerinlinequery |
||
| 874 | * |
||
| 875 | * @param array $data |
||
| 876 | * |
||
| 877 | * @return \Longman\TelegramBot\Entities\ServerResponse |
||
| 878 | * @throws \Longman\TelegramBot\Exception\TelegramException |
||
| 879 | */ |
||
| 880 | public static function answerInlineQuery(array $data) |
||
| 884 | |||
| 885 | /** |
||
| 886 | * Return an empty Server Response |
||
| 887 | * |
||
| 888 | * No request to telegram are sent, this function is used in commands that |
||
| 889 | * don't need to fire a message after execution |
||
| 890 | * |
||
| 891 | * @return \Longman\TelegramBot\Entities\ServerResponse |
||
| 892 | * @throws \Longman\TelegramBot\Exception\TelegramException |
||
| 893 | */ |
||
| 894 | public static function emptyResponse() |
||
| 898 | |||
| 899 | /** |
||
| 900 | * Send message to all active chats |
||
| 901 | * |
||
| 902 | * @param string $callback_function |
||
| 903 | * @param array $data |
||
| 904 | * @param boolean $send_groups |
||
| 905 | * @param boolean $send_super_groups |
||
| 906 | * @param boolean $send_users |
||
| 907 | * @param string $date_from |
||
| 908 | * @param string $date_to |
||
| 909 | * |
||
| 910 | * @return array |
||
| 911 | * @throws \Longman\TelegramBot\Exception\TelegramException |
||
| 912 | */ |
||
| 913 | public static function sendToActiveChats( |
||
| 939 | |||
| 940 | /** |
||
| 941 | * Use this method to get current webhook status. |
||
| 942 | * |
||
| 943 | * @link https://core.telegram.org/bots/api#getwebhookinfo |
||
| 944 | * |
||
| 945 | * @return Entities\ServerResponse |
||
| 946 | * @throws \Longman\TelegramBot\Exception\TelegramException |
||
| 947 | */ |
||
| 948 | public static function getWebhookInfo() |
||
| 953 | } |
||
| 954 |
If you define a variable conditionally, it can happen that it is not defined for all execution paths.
Let’s take a look at an example:
In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.
Available Fixes
Check for existence of the variable explicitly:
Define a default value for the variable:
Add a value for the missing path: