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 | 'deleteWebhook', |
||
58 | 'getMe', |
||
59 | 'sendMessage', |
||
60 | 'forwardMessage', |
||
61 | 'sendPhoto', |
||
62 | 'sendAudio', |
||
63 | 'sendDocument', |
||
64 | 'sendSticker', |
||
65 | 'sendVideo', |
||
66 | 'sendVoice', |
||
67 | 'sendLocation', |
||
68 | 'sendVenue', |
||
69 | 'sendContact', |
||
70 | 'sendChatAction', |
||
71 | 'getUserProfilePhotos', |
||
72 | 'getFile', |
||
73 | 'kickChatMember', |
||
74 | 'leaveChat', |
||
75 | 'unbanChatMember', |
||
76 | 'getChat', |
||
77 | 'getChatAdministrators', |
||
78 | 'getChatMember', |
||
79 | 'getChatMembersCount', |
||
80 | 'answerCallbackQuery', |
||
81 | 'answerInlineQuery', |
||
82 | 'editMessageText', |
||
83 | 'editMessageCaption', |
||
84 | 'editMessageReplyMarkup', |
||
85 | 'getWebhookInfo', |
||
86 | ]; |
||
87 | |||
88 | /** |
||
89 | * Initialize |
||
90 | * |
||
91 | * @param \Longman\TelegramBot\Telegram $telegram |
||
92 | * |
||
93 | * @throws \Longman\TelegramBot\Exception\TelegramException |
||
94 | */ |
||
95 | 39 | public static function initialize(Telegram $telegram) |
|
104 | |||
105 | /** |
||
106 | * Set input from custom input or stdin and return it |
||
107 | * |
||
108 | * @return string |
||
109 | * @throws \Longman\TelegramBot\Exception\TelegramException |
||
110 | */ |
||
111 | public static function getInput() |
||
129 | |||
130 | /** |
||
131 | * Generate general fake server response |
||
132 | * |
||
133 | * @param array $data Data to add to fake response |
||
134 | * |
||
135 | * @return array Fake response data |
||
136 | */ |
||
137 | 6 | public static function generateGeneralFakeServerResponse(array $data = []) |
|
167 | |||
168 | /** |
||
169 | * Properly set up the request params |
||
170 | * |
||
171 | * If any item of the array is a resource, reformat it to a multipart request. |
||
172 | * Else, just return the passed data as form params. |
||
173 | * |
||
174 | * @param array $data |
||
175 | * |
||
176 | * @return array |
||
177 | */ |
||
178 | private static function setUpRequestParams(array $data) |
||
194 | |||
195 | /** |
||
196 | * Execute HTTP Request |
||
197 | * |
||
198 | * @param string $action Action to execute |
||
199 | * @param array $data Data to attach to the execution |
||
200 | * |
||
201 | * @return string Result of the HTTP Request |
||
202 | * @throws \Longman\TelegramBot\Exception\TelegramException |
||
203 | */ |
||
204 | public static function execute($action, array $data = []) |
||
236 | |||
237 | /** |
||
238 | * Download file |
||
239 | * |
||
240 | * @param \Longman\TelegramBot\Entities\File $file |
||
241 | * |
||
242 | * @return boolean |
||
243 | * @throws \Longman\TelegramBot\Exception\TelegramException |
||
244 | */ |
||
245 | public static function downloadFile(File $file) |
||
273 | |||
274 | /** |
||
275 | * Encode file |
||
276 | * |
||
277 | * @param string $file |
||
278 | * |
||
279 | * @return resource |
||
280 | * @throws \Longman\TelegramBot\Exception\TelegramException |
||
281 | */ |
||
282 | protected static function encodeFile($file) |
||
291 | |||
292 | /** |
||
293 | * Send command |
||
294 | * |
||
295 | * @todo Fake response doesn't need json encoding? |
||
296 | * |
||
297 | * @param string $action |
||
298 | * @param array $data |
||
299 | * |
||
300 | * @return \Longman\TelegramBot\Entities\ServerResponse |
||
301 | * @throws \Longman\TelegramBot\Exception\TelegramException |
||
302 | */ |
||
303 | 5 | public static function send($action, array $data = []) |
|
325 | |||
326 | /** |
||
327 | * Make sure the data isn't empty, else throw an exception |
||
328 | * |
||
329 | * @param array $data |
||
330 | * |
||
331 | * @throws \Longman\TelegramBot\Exception\TelegramException |
||
332 | */ |
||
333 | private static function ensureNonEmptyData(array $data) |
||
339 | |||
340 | /** |
||
341 | * Make sure the action is valid, else throw an exception |
||
342 | * |
||
343 | * @param string $action |
||
344 | * |
||
345 | * @throws \Longman\TelegramBot\Exception\TelegramException |
||
346 | */ |
||
347 | 5 | private static function ensureValidAction($action) |
|
353 | |||
354 | /** |
||
355 | * Assign an encoded file to a data array |
||
356 | * |
||
357 | * @param array $data |
||
358 | * @param string $field |
||
359 | * @param string $file |
||
360 | * |
||
361 | * @throws \Longman\TelegramBot\Exception\TelegramException |
||
362 | */ |
||
363 | private static function assignEncodedFile(&$data, $field, $file) |
||
369 | |||
370 | /** |
||
371 | * Returns basic information about the bot in form of a User object |
||
372 | * |
||
373 | * @link https://core.telegram.org/bots/api#getme |
||
374 | * |
||
375 | * @return \Longman\TelegramBot\Entities\ServerResponse |
||
376 | * @throws \Longman\TelegramBot\Exception\TelegramException |
||
377 | */ |
||
378 | public static function getMe() |
||
384 | |||
385 | /** |
||
386 | * Use this method to send text messages. On success, the sent Message is returned |
||
387 | * |
||
388 | * @link https://core.telegram.org/bots/api#sendmessage |
||
389 | * |
||
390 | * @param array $data |
||
391 | * |
||
392 | * @return \Longman\TelegramBot\Entities\ServerResponse |
||
393 | * @throws \Longman\TelegramBot\Exception\TelegramException |
||
394 | */ |
||
395 | 5 | public static function sendMessage(array $data) |
|
410 | |||
411 | /** |
||
412 | * Use this method to forward messages of any kind. On success, the sent Message is returned |
||
413 | * |
||
414 | * @link https://core.telegram.org/bots/api#forwardmessage |
||
415 | * |
||
416 | * @param array $data |
||
417 | * |
||
418 | * @return \Longman\TelegramBot\Entities\ServerResponse |
||
419 | * @throws \Longman\TelegramBot\Exception\TelegramException |
||
420 | */ |
||
421 | public static function forwardMessage(array $data) |
||
425 | |||
426 | /** |
||
427 | * Use this method to send photos. On success, the sent Message is returned |
||
428 | * |
||
429 | * @link https://core.telegram.org/bots/api#sendphoto |
||
430 | * |
||
431 | * @param array $data |
||
432 | * @param string $file |
||
433 | * |
||
434 | * @return \Longman\TelegramBot\Entities\ServerResponse |
||
435 | * @throws \Longman\TelegramBot\Exception\TelegramException |
||
436 | */ |
||
437 | public static function sendPhoto(array $data, $file = null) |
||
443 | |||
444 | /** |
||
445 | * Use this method to send audio files |
||
446 | * |
||
447 | * Your audio must be in the .mp3 format. On success, the sent Message is returned. |
||
448 | * Bots can currently send audio files of up to 50 MB in size, this limit may be changed in the future. |
||
449 | * For sending voice messages, use the sendVoice method instead. |
||
450 | * |
||
451 | * @link https://core.telegram.org/bots/api#sendaudio |
||
452 | * |
||
453 | * @param array $data |
||
454 | * @param string $file |
||
455 | * |
||
456 | * @return \Longman\TelegramBot\Entities\ServerResponse |
||
457 | * @throws \Longman\TelegramBot\Exception\TelegramException |
||
458 | */ |
||
459 | public static function sendAudio(array $data, $file = null) |
||
465 | |||
466 | /** |
||
467 | * Use this method to send general files. On success, the sent Message is returned. |
||
468 | * |
||
469 | * Bots can currently send files of any type of up to 50 MB in size, this limit may be changed in the future. |
||
470 | * |
||
471 | * @link https://core.telegram.org/bots/api#senddocument |
||
472 | * |
||
473 | * @param array $data |
||
474 | * @param string $file |
||
475 | * |
||
476 | * @return \Longman\TelegramBot\Entities\ServerResponse |
||
477 | * @throws \Longman\TelegramBot\Exception\TelegramException |
||
478 | */ |
||
479 | public static function sendDocument(array $data, $file = null) |
||
485 | |||
486 | /** |
||
487 | * Use this method to send .webp stickers. On success, the sent Message is returned. |
||
488 | * |
||
489 | * @link https://core.telegram.org/bots/api#sendsticker |
||
490 | * |
||
491 | * @param array $data |
||
492 | * @param string $file |
||
493 | * |
||
494 | * @return \Longman\TelegramBot\Entities\ServerResponse |
||
495 | * @throws \Longman\TelegramBot\Exception\TelegramException |
||
496 | */ |
||
497 | public static function sendSticker(array $data, $file = null) |
||
503 | |||
504 | /** |
||
505 | * Use this method to send video files. On success, the sent Message is returned. |
||
506 | * |
||
507 | * Telegram clients support mp4 videos (other formats may be sent as Document). |
||
508 | * Bots can currently send video files of up to 50 MB in size, this limit may be changed in the future. |
||
509 | * |
||
510 | * @link https://core.telegram.org/bots/api#sendvideo |
||
511 | * |
||
512 | * @param array $data |
||
513 | * @param string $file |
||
514 | * |
||
515 | * @return \Longman\TelegramBot\Entities\ServerResponse |
||
516 | * @throws \Longman\TelegramBot\Exception\TelegramException |
||
517 | */ |
||
518 | public static function sendVideo(array $data, $file = null) |
||
524 | |||
525 | /** |
||
526 | * Use this method to send audio files. On success, the sent Message is returned. |
||
527 | * |
||
528 | * Telegram clients will display the file as a playable voice message. |
||
529 | * For this to work, your audio must be in an .ogg file encoded with OPUS (other formats may be sent as Audio or Document). |
||
530 | * Bots can currently send voice messages of up to 50 MB in size, this limit may be changed in the future. |
||
531 | * |
||
532 | * @link https://core.telegram.org/bots/api#sendvoice |
||
533 | * |
||
534 | * @param array $data |
||
535 | * @param string $file |
||
536 | * |
||
537 | * @return \Longman\TelegramBot\Entities\ServerResponse |
||
538 | * @throws \Longman\TelegramBot\Exception\TelegramException |
||
539 | */ |
||
540 | public static function sendVoice(array $data, $file = null) |
||
546 | |||
547 | /** |
||
548 | * Use this method to send point on the map. On success, the sent Message is returned. |
||
549 | * |
||
550 | * @link https://core.telegram.org/bots/api#sendlocation |
||
551 | * |
||
552 | * @param array $data |
||
553 | * |
||
554 | * @return \Longman\TelegramBot\Entities\ServerResponse |
||
555 | * @throws \Longman\TelegramBot\Exception\TelegramException |
||
556 | */ |
||
557 | public static function sendLocation(array $data) |
||
561 | |||
562 | /** |
||
563 | * Use this method to send information about a venue. On success, the sent Message is returned. |
||
564 | * |
||
565 | * @link https://core.telegram.org/bots/api#sendvenue |
||
566 | * |
||
567 | * @param array $data |
||
568 | * |
||
569 | * @return \Longman\TelegramBot\Entities\ServerResponse |
||
570 | * @throws \Longman\TelegramBot\Exception\TelegramException |
||
571 | */ |
||
572 | public static function sendVenue(array $data) |
||
576 | |||
577 | /** |
||
578 | * Use this method to send phone contacts. On success, the sent Message is returned. |
||
579 | * |
||
580 | * @link https://core.telegram.org/bots/api#sendcontact |
||
581 | * |
||
582 | * @param array $data |
||
583 | * |
||
584 | * @return \Longman\TelegramBot\Entities\ServerResponse |
||
585 | * @throws \Longman\TelegramBot\Exception\TelegramException |
||
586 | */ |
||
587 | public static function sendContact(array $data) |
||
591 | |||
592 | /** |
||
593 | * Use this method when you need to tell the user that something is happening on the bot's side. |
||
594 | * |
||
595 | * The status is set for 5 seconds or less. |
||
596 | * (when a message arrives from your bot, Telegram clients clear its typing status) |
||
597 | * |
||
598 | * @link https://core.telegram.org/bots/api#sendchataction |
||
599 | * |
||
600 | * @param array $data |
||
601 | * |
||
602 | * @return \Longman\TelegramBot\Entities\ServerResponse |
||
603 | * @throws \Longman\TelegramBot\Exception\TelegramException |
||
604 | */ |
||
605 | public static function sendChatAction(array $data) |
||
609 | |||
610 | /** |
||
611 | * Use this method to get a list of profile pictures for a user. Returns a UserProfilePhotos object. |
||
612 | * |
||
613 | * @param array $data |
||
614 | * |
||
615 | * @return \Longman\TelegramBot\Entities\ServerResponse |
||
616 | * @throws \Longman\TelegramBot\Exception\TelegramException |
||
617 | */ |
||
618 | public static function getUserProfilePhotos(array $data) |
||
622 | |||
623 | /** |
||
624 | * Use this method to get basic info about a file and prepare it for downloading. On success, a File object is returned. |
||
625 | * |
||
626 | * For the moment, bots can download files of up to 20MB in size. |
||
627 | * The file can then be downloaded via the link https://api.telegram.org/file/bot<token>/<file_path>, |
||
628 | * where <file_path> is taken from the response. |
||
629 | * It is guaranteed that the link will be valid for at least 1 hour. |
||
630 | * When the link expires, a new one can be requested by calling getFile again. |
||
631 | * |
||
632 | * @link https://core.telegram.org/bots/api#getfile |
||
633 | * |
||
634 | * @param array $data |
||
635 | * |
||
636 | * @return \Longman\TelegramBot\Entities\ServerResponse |
||
637 | * @throws \Longman\TelegramBot\Exception\TelegramException |
||
638 | */ |
||
639 | public static function getFile(array $data) |
||
643 | |||
644 | /** |
||
645 | * Use this method to kick a user from a group or a supergroup. Returns True on success. |
||
646 | * |
||
647 | * 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. |
||
648 | * The bot must be an administrator in the group for this to work. |
||
649 | * |
||
650 | * @link https://core.telegram.org/bots/api#kickchatmember |
||
651 | * |
||
652 | * @param array $data |
||
653 | * |
||
654 | * @return \Longman\TelegramBot\Entities\ServerResponse |
||
655 | * @throws \Longman\TelegramBot\Exception\TelegramException |
||
656 | */ |
||
657 | public static function kickChatMember(array $data) |
||
661 | |||
662 | /** |
||
663 | * Use this method for your bot to leave a group, supergroup or channel. Returns True on success. |
||
664 | * |
||
665 | * @link https://core.telegram.org/bots/api#leavechat |
||
666 | * |
||
667 | * @param array $data |
||
668 | * |
||
669 | * @return \Longman\TelegramBot\Entities\ServerResponse |
||
670 | * @throws \Longman\TelegramBot\Exception\TelegramException |
||
671 | */ |
||
672 | public static function leaveChat(array $data) |
||
676 | |||
677 | /** |
||
678 | * Use this method to unban a previously kicked user in a supergroup. Returns True on success. |
||
679 | * |
||
680 | * The user will not return to the group automatically, but will be able to join via link, etc. |
||
681 | * The bot must be an administrator in the group for this to work. |
||
682 | * |
||
683 | * @link https://core.telegram.org/bots/api#unbanchatmember |
||
684 | * |
||
685 | * @param array $data |
||
686 | * |
||
687 | * @return \Longman\TelegramBot\Entities\ServerResponse |
||
688 | * @throws \Longman\TelegramBot\Exception\TelegramException |
||
689 | */ |
||
690 | public static function unbanChatMember(array $data) |
||
694 | |||
695 | /** |
||
696 | * 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. |
||
697 | * |
||
698 | * @todo add get response in ServerResponse.php? |
||
699 | * |
||
700 | * @link https://core.telegram.org/bots/api#getchat |
||
701 | * |
||
702 | * @param array $data |
||
703 | * |
||
704 | * @return \Longman\TelegramBot\Entities\ServerResponse |
||
705 | * @throws \Longman\TelegramBot\Exception\TelegramException |
||
706 | */ |
||
707 | public static function getChat(array $data) |
||
711 | |||
712 | /** |
||
713 | * Use this method to get a list of administrators in a chat. |
||
714 | * |
||
715 | * On success, returns an Array of ChatMember objects that contains information about all chat administrators except other bots. |
||
716 | * If the chat is a group or a supergroup and no administrators were appointed, only the creator will be returned. |
||
717 | * |
||
718 | * @todo add get response in ServerResponse.php? |
||
719 | * |
||
720 | * @link https://core.telegram.org/bots/api#getchatadministrators |
||
721 | * |
||
722 | * @param array $data |
||
723 | * |
||
724 | * @return \Longman\TelegramBot\Entities\ServerResponse |
||
725 | * @throws \Longman\TelegramBot\Exception\TelegramException |
||
726 | */ |
||
727 | public static function getChatAdministrators(array $data) |
||
731 | |||
732 | /** |
||
733 | * Use this method to get the number of members in a chat. Returns Int on success. |
||
734 | * |
||
735 | * @todo add get response in ServerResponse.php? |
||
736 | * |
||
737 | * @link https://core.telegram.org/bots/api#getchatmemberscount |
||
738 | * |
||
739 | * @param array $data |
||
740 | * |
||
741 | * @return \Longman\TelegramBot\Entities\ServerResponse |
||
742 | * @throws \Longman\TelegramBot\Exception\TelegramException |
||
743 | */ |
||
744 | public static function getChatMembersCount(array $data) |
||
748 | |||
749 | /** |
||
750 | * Use this method to get information about a member of a chat. Returns a ChatMember object on success. |
||
751 | * |
||
752 | * @todo add get response in ServerResponse.php? |
||
753 | * |
||
754 | * @link https://core.telegram.org/bots/api#getchatmember |
||
755 | * |
||
756 | * @param array $data |
||
757 | * |
||
758 | * @return \Longman\TelegramBot\Entities\ServerResponse |
||
759 | * @throws \Longman\TelegramBot\Exception\TelegramException |
||
760 | */ |
||
761 | public static function getChatMember(array $data) |
||
765 | |||
766 | /** |
||
767 | * Use this method to send answers to callback queries sent from inline keyboards. On success, True is returned. |
||
768 | * |
||
769 | * The answer will be displayed to the user as a notification at the top of the chat screen or as an alert. |
||
770 | * |
||
771 | * @link https://core.telegram.org/bots/api#answercallbackquery |
||
772 | * |
||
773 | * @param array $data |
||
774 | * |
||
775 | * @return \Longman\TelegramBot\Entities\ServerResponse |
||
776 | * @throws \Longman\TelegramBot\Exception\TelegramException |
||
777 | */ |
||
778 | public static function answerCallbackQuery(array $data) |
||
782 | |||
783 | /** |
||
784 | * Get updates |
||
785 | * |
||
786 | * @link https://core.telegram.org/bots/api#getupdates |
||
787 | * |
||
788 | * @param array $data |
||
789 | * |
||
790 | * @return \Longman\TelegramBot\Entities\ServerResponse |
||
791 | * @throws \Longman\TelegramBot\Exception\TelegramException |
||
792 | */ |
||
793 | public static function getUpdates(array $data) |
||
797 | |||
798 | /** |
||
799 | * Set webhook |
||
800 | * |
||
801 | * @link https://core.telegram.org/bots/api#setwebhook |
||
802 | * |
||
803 | * @param string $url |
||
804 | * @param array $data Optional parameters. |
||
805 | * |
||
806 | * @return \Longman\TelegramBot\Entities\ServerResponse |
||
807 | * @throws \Longman\TelegramBot\Exception\TelegramException |
||
808 | */ |
||
809 | public static function setWebhook($url = '', array $data = []) |
||
824 | |||
825 | /** |
||
826 | * Delete webhook |
||
827 | * |
||
828 | * @link https://core.telegram.org/bots/api#deletewebhook |
||
829 | * |
||
830 | * @return \Longman\TelegramBot\Entities\ServerResponse |
||
831 | * @throws \Longman\TelegramBot\Exception\TelegramException |
||
832 | */ |
||
833 | public static function deleteWebhook() |
||
838 | |||
839 | /** |
||
840 | * Use this method to edit text and game messages sent by the bot or via the bot (for inline bots). |
||
841 | * |
||
842 | * On success, if edited message is sent by the bot, the edited Message is returned, otherwise True is returned. |
||
843 | * |
||
844 | * @link https://core.telegram.org/bots/api#editmessagetext |
||
845 | * |
||
846 | * @param array $data |
||
847 | * |
||
848 | * @return \Longman\TelegramBot\Entities\ServerResponse |
||
849 | * @throws \Longman\TelegramBot\Exception\TelegramException |
||
850 | */ |
||
851 | public static function editMessageText(array $data) |
||
855 | |||
856 | /** |
||
857 | * Use this method to edit captions of messages sent by the bot or via the bot (for inline bots). |
||
858 | * |
||
859 | * On success, if edited message is sent by the bot, the edited Message is returned, otherwise True is returned. |
||
860 | * |
||
861 | * @link https://core.telegram.org/bots/api#editmessagecaption |
||
862 | * |
||
863 | * @param array $data |
||
864 | * |
||
865 | * @return \Longman\TelegramBot\Entities\ServerResponse |
||
866 | * @throws \Longman\TelegramBot\Exception\TelegramException |
||
867 | */ |
||
868 | public static function editMessageCaption(array $data) |
||
872 | |||
873 | /** |
||
874 | * Use this method to edit only the reply markup of messages sent by the bot or via the bot (for inline bots). |
||
875 | * |
||
876 | * On success, if edited message is sent by the bot, the edited Message is returned, otherwise True is returned. |
||
877 | * |
||
878 | * @link https://core.telegram.org/bots/api#editmessagereplymarkup |
||
879 | * |
||
880 | * @param array $data |
||
881 | * |
||
882 | * @return \Longman\TelegramBot\Entities\ServerResponse |
||
883 | * @throws \Longman\TelegramBot\Exception\TelegramException |
||
884 | */ |
||
885 | public static function editMessageReplyMarkup(array $data) |
||
889 | |||
890 | /** |
||
891 | * Use this method to send answers to an inline query. On success, True is returned. |
||
892 | * |
||
893 | * No more than 50 results per query are allowed. |
||
894 | * |
||
895 | * @link https://core.telegram.org/bots/api#answerinlinequery |
||
896 | * |
||
897 | * @param array $data |
||
898 | * |
||
899 | * @return \Longman\TelegramBot\Entities\ServerResponse |
||
900 | * @throws \Longman\TelegramBot\Exception\TelegramException |
||
901 | */ |
||
902 | public static function answerInlineQuery(array $data) |
||
906 | |||
907 | /** |
||
908 | * Return an empty Server Response |
||
909 | * |
||
910 | * No request to telegram are sent, this function is used in commands that |
||
911 | * don't need to fire a message after execution |
||
912 | * |
||
913 | * @return \Longman\TelegramBot\Entities\ServerResponse |
||
914 | * @throws \Longman\TelegramBot\Exception\TelegramException |
||
915 | */ |
||
916 | public static function emptyResponse() |
||
920 | |||
921 | /** |
||
922 | * Send message to all active chats |
||
923 | * |
||
924 | * @param string $callback_function |
||
925 | * @param array $data |
||
926 | * @param boolean $send_groups |
||
927 | * @param boolean $send_super_groups |
||
928 | * @param boolean $send_users |
||
929 | * @param string $date_from |
||
930 | * @param string $date_to |
||
931 | * |
||
932 | * @return array |
||
933 | * @throws \Longman\TelegramBot\Exception\TelegramException |
||
934 | */ |
||
935 | public static function sendToActiveChats( |
||
961 | |||
962 | /** |
||
963 | * Use this method to get current webhook status. |
||
964 | * |
||
965 | * @link https://core.telegram.org/bots/api#getwebhookinfo |
||
966 | * |
||
967 | * @return Entities\ServerResponse |
||
968 | * @throws \Longman\TelegramBot\Exception\TelegramException |
||
969 | */ |
||
970 | public static function getWebhookInfo() |
||
975 | } |
||
976 |
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: