Passed
Push — main ( 723093...1f3d08 )
by Miaad
01:40
created
src/receiver/receiver.php 1 patch
Braces   +10 added lines, -20 removed lines patch added patch discarded remove patch
@@ -85,51 +85,41 @@
 block discarded – undo
85 85
                 if (self::handlerExist('message')) {
86 86
                     BPT::$handler->message(BPT::$update->message);
87 87
                 }
88
-            }
89
-            elseif (isset(BPT::$update->edited_message)) {
88
+            } elseif (isset(BPT::$update->edited_message)) {
90 89
                 if (self::handlerExist('edited_message')) {
91 90
                     BPT::$handler->edited_message(BPT::$update->edited_message);
92 91
                 }
93
-            }
94
-            elseif (isset(BPT::$update->channel_post)) {
92
+            } elseif (isset(BPT::$update->channel_post)) {
95 93
                 if (self::handlerExist('channel_post')) {
96 94
                     BPT::$handler->channel_post(BPT::$update->channel_post);
97 95
                 }
98
-            }
99
-            elseif (isset(BPT::$update->edited_channel_post)) {
96
+            } elseif (isset(BPT::$update->edited_channel_post)) {
100 97
                 if (self::handlerExist('edited_channel_post')) {
101 98
                     BPT::$handler->edited_channel_post(BPT::$update->edited_channel_post);
102 99
                 }
103
-            }
104
-            elseif (isset(BPT::$update->inline_query)) {
100
+            } elseif (isset(BPT::$update->inline_query)) {
105 101
                 if (self::handlerExist('inline_query')) {
106 102
                     BPT::$handler->inline_query(BPT::$update->inline_query);
107 103
                 }
108
-            }
109
-            elseif (isset(BPT::$update->callback_query)) {
104
+            } elseif (isset(BPT::$update->callback_query)) {
110 105
                 if (self::handlerExist('callback_query')) {
111 106
                     BPT::$handler->callback_query(BPT::$update->callback_query);
112 107
                 }
113
-            }
114
-            elseif (isset(BPT::$update->my_chat_member)) {
108
+            } elseif (isset(BPT::$update->my_chat_member)) {
115 109
                 if (self::handlerExist('my_chat_member')) {
116 110
                     BPT::$handler->my_chat_member(BPT::$update->my_chat_member);
117 111
                 }
118
-            }
119
-            elseif (isset(BPT::$update->chat_member)) {
112
+            } elseif (isset(BPT::$update->chat_member)) {
120 113
                 if (self::handlerExist('chat_member')) {
121 114
                     BPT::$handler->chat_member(BPT::$update->chat_member);
122 115
                 }
123
-            }
124
-            elseif (isset(BPT::$update->chat_join_request)) {
116
+            } elseif (isset(BPT::$update->chat_join_request)) {
125 117
                 if (self::handlerExist('chat_join_request')) {
126 118
                     BPT::$handler->chat_join_request(BPT::$update->chat_join_request);
127 119
                 }
128
-            }
129
-            elseif (self::handlerExist('something_else')) {
120
+            } elseif (self::handlerExist('something_else')) {
130 121
                 BPT::$handler->something_else(BPT::$update);
131
-            }
132
-            else {
122
+            } else {
133 123
                 logger::write('Update received but handlers are not set',loggerTypes::WARNING);
134 124
             }
135 125
         }
Please login to merge, or discard this patch.
src/tools.php 1 patch
Braces   +35 added lines, -34 removed lines patch added patch discarded remove patch
@@ -217,8 +217,9 @@  discard block
 block discarded – undo
217 217
             if (telegram::$status) {
218 218
                 $check = $check->status;
219 219
                 $result[$id] = $check !== chatMemberStatus::LEFT && $check !== chatMemberStatus::KICKED;
220
+            } else {
221
+                $result[$id] = null;
220 222
             }
221
-            else $result[$id] = null;
222 223
         }
223 224
         return $result;
224 225
     }
@@ -259,8 +260,7 @@  discard block
 block discarded – undo
259 260
             curl_exec($ch);
260 261
             $size = curl_getinfo($ch, CURLINFO_CONTENT_LENGTH_DOWNLOAD);
261 262
             curl_close($ch);
262
-        }
263
-        else {
263
+        } else {
264 264
             $path = realpath($path);
265 265
             $size = file_exists($path) ? filesize($path) : false;
266 266
         }
@@ -331,8 +331,7 @@  discard block
 block discarded – undo
331 331
                     $zip->addFile($filePath, substr($filePath, $root_len));
332 332
                 }
333 333
             }
334
-        }
335
-        else {
334
+        } else {
336 335
             $zip->addFile($path, basename($path));
337 336
         }
338 337
         return $zip->close();
@@ -351,9 +350,13 @@  discard block
 block discarded – undo
351 350
      */
352 351
     public static function downloadFile (string $url, string $path,int $chunk_size = 512): bool {
353 352
         $file = fopen($url, 'rb');
354
-        if (!$file) return false;
353
+        if (!$file) {
354
+            return false;
355
+        }
355 356
         $path = fopen($path, 'wb');
356
-        if (!$path) return false;
357
+        if (!$path) {
358
+            return false;
359
+        }
357 360
 
358 361
         $length = $chunk_size * 1024;
359 362
         while (!feof($file)){
@@ -460,8 +463,9 @@  discard block
 block discarded – undo
460 463
         foreach ($string as $k => &$v) {
461 464
             if ($diff->$v) {
462 465
                 $v = $diff->$v;
466
+            } else {
467
+                unset($string[$k]);
463 468
             }
464
-            else unset($string[$k]);
465 469
         }
466 470
         $string['status'] = $base_time < $target_time ? 'later' : 'ago';
467 471
 
@@ -527,8 +531,7 @@  discard block
 block discarded – undo
527 531
             if ($last === "\0") {
528 532
                 $new .= str_repeat($last, ord($char));
529 533
                 $last = '';
530
-            }
531
-            else {
534
+            } else {
532 535
                 $new .= $last;
533 536
                 $last = $char;
534 537
             }
@@ -612,7 +615,9 @@  discard block
 block discarded – undo
612 615
             }
613 616
             $rows = [];
614 617
             foreach ($keyboard as $row) {
615
-                if (!is_array($row)) continue;
618
+                if (!is_array($row)) {
619
+                    continue;
620
+                }
616 621
                 $buttons = [];
617 622
                 foreach ($row as $base_button) {
618 623
                     $button_info = explode('||', $base_button);
@@ -621,15 +626,12 @@  discard block
 block discarded – undo
621 626
                     if (count($button_info) > 1) {
622 627
                         if ($button_info[1] === 'con') {
623 628
                             $button->setRequest_contact(true);
624
-                        }
625
-                        elseif ($button_info[1] === 'loc') {
629
+                        } elseif ($button_info[1] === 'loc') {
626 630
                             $button->setRequest_location(true);
627
-                        }
628
-                        elseif ($button_info[1] === 'poll') {
631
+                        } elseif ($button_info[1] === 'poll') {
629 632
                             $type = $button_info[2] === pollType::QUIZ ? pollType::QUIZ : pollType::REGULAR;
630 633
                             $button->setRequest_poll((new keyboardButtonPollType())->setType($type));
631
-                        }
632
-                        elseif ($button_info[1] === 'web' && isset($button_info[2])) {
634
+                        } elseif ($button_info[1] === 'web' && isset($button_info[2])) {
633 635
                             $url = $button_info[2];
634 636
                             $button->setWeb_app((new webAppInfo())->setUrl($url));
635 637
                         }
@@ -640,8 +642,7 @@  discard block
 block discarded – undo
640 642
             }
641 643
             $keyboard_object->setKeyboard($rows);
642 644
             return $keyboard_object;
643
-        }
644
-        elseif (!empty($inline)) {
645
+        } elseif (!empty($inline)) {
645 646
             $keyboard_object = new inlineKeyboardMarkup();
646 647
             $rows = [];
647 648
             foreach ($inline as $row) {
@@ -651,12 +652,10 @@  discard block
 block discarded – undo
651 652
                     if (isset($button_info[1])) {
652 653
                         if (filter_var($button_info[1], FILTER_VALIDATE_URL) && str_starts_with($button_info[1], 'http')) {
653 654
                             $button->setText($button_info[0])->setUrl($button_info[1]);
654
-                        }
655
-                        else {
655
+                        } else {
656 656
                             $button->setText($button_info[0])->setCallback_data($button_info[1]);
657 657
                         }
658
-                    }
659
-                    else {
658
+                    } else {
660 659
                         $button->setText($button_info[0])->setUrl('https://t.me/BPT_CH');
661 660
                     }
662 661
                     $buttons[] = $button;
@@ -665,8 +664,7 @@  discard block
 block discarded – undo
665 664
             }
666 665
             $keyboard_object->setInline_keyboard($rows);
667 666
             return $keyboard_object;
668
-        }
669
-        else {
667
+        } else {
670 668
             logger::write("tools::eKey function used\nkeyboard or inline parameter must be set",loggerTypes::ERROR);
671 669
             throw new bptException('ARGUMENT_NOT_FOUND_KEYBOARD_INLINE');
672 670
         }
@@ -685,8 +683,12 @@  discard block
 block discarded – undo
685 683
      * @return string
686 684
      */
687 685
     public static function inviteLink (int $user_id = null, string $bot_username = null): string {
688
-        if (empty($user_id)) $user_id = telegram::catchFields(fields::USER_ID);
689
-        if (empty($bot_username)) $bot_username = telegram::getMe()->username;
686
+        if (empty($user_id)) {
687
+            $user_id = telegram::catchFields(fields::USER_ID);
688
+        }
689
+        if (empty($bot_username)) {
690
+            $bot_username = telegram::getMe()->username;
691
+        }
690 692
         return 'https://t.me/' . str_replace('@', '', $bot_username) . '?start=ref_' . tools::shortEncode($user_id);
691 693
     }
692 694
 
@@ -721,8 +723,7 @@  discard block
 block discarded – undo
721 723
             $iv = self::randomString();
722 724
             $output = base64_encode(openssl_encrypt($text, 'AES-256-CBC', $key, 1, $iv));
723 725
             return ['hash' => $output, 'key' => $key, 'iv' => $iv];
724
-        }
725
-        elseif ($action === codecAction::DECRYPT) {
726
+        } elseif ($action === codecAction::DECRYPT) {
726 727
             if (empty($key)) {
727 728
                 logger::write("tools::codec function used\nkey parameter is not set",loggerTypes::ERROR);
728 729
                 throw new bptException('ARGUMENT_NOT_FOUND_KEY');
@@ -732,8 +733,7 @@  discard block
 block discarded – undo
732 733
                 throw new bptException('ARGUMENT_NOT_FOUND_IV');
733 734
             }
734 735
             return openssl_decrypt(base64_decode($text), 'AES-256-CBC', $key, 1, $iv);
735
-        }
736
-        else {
736
+        } else {
737 737
             logger::write("tools::codec function used\naction is not right, its must be `encode` or `decode`",loggerTypes::WARNING);
738 738
             return false;
739 739
         }
@@ -762,7 +762,9 @@  discard block
 block discarded – undo
762 762
             $array[] = $num % 62;
763 763
             $num = floor($num / 62);
764 764
         }
765
-        if (count($array) < 1) $array = [0];
765
+        if (count($array) < 1) {
766
+            $array = [0];
767
+        }
766 768
         foreach ($array as &$value) {
767 769
             $value = $codes[$value];
768 770
         }
@@ -797,8 +799,7 @@  discard block
 block discarded – undo
797 799
         $ip = $_SERVER['REMOTE_ADDR'];
798 800
         if (settings::$cloudflare_verify && isset($_SERVER['HTTP_CF_CONNECTING_IP']) && tools::isCloudFlare($ip)) {
799 801
             $ip = $_SERVER['HTTP_CF_CONNECTING_IP'];
800
-        }
801
-        elseif (settings::$arvancloud_verify && isset($_SERVER['HTTP_AR_REAL_IP']) && tools::isArvanCloud($ip)) {
802
+        } elseif (settings::$arvancloud_verify && isset($_SERVER['HTTP_AR_REAL_IP']) && tools::isArvanCloud($ip)) {
802 803
             $ip = $_SERVER['HTTP_AR_REAL_IP'];
803 804
         }
804 805
         return $ip;
Please login to merge, or discard this patch.
src/telegram/request.php 1 patch
Braces   +13 added lines, -15 removed lines patch added patch discarded remove patch
@@ -775,8 +775,7 @@  discard block
 block discarded – undo
775 775
         self::setDefaults($action,$arguments);
776 776
         if (isset($arguments['answer'])) {
777 777
             return answer::init($action,$arguments);
778
-        }
779
-        else {
778
+        } else {
780 779
             $result = curl::init($action,$arguments);
781 780
             if (!is_object($result)) {
782 781
                 return false;
@@ -811,8 +810,7 @@  discard block
 block discarded – undo
811 810
                     $arguments['media'][$key]['media'] = new CURLFile($media['media']);
812 811
                 }
813 812
             }
814
-        }
815
-        elseif ($file_params = self::methodFile($name)) {
813
+        } elseif ($file_params = self::methodFile($name)) {
816 814
             foreach ($file_params as $param) {
817 815
                 if (isset($arguments[$param]) && is_string($arguments[$param]) && file_exists(realpath($arguments[$param]))) {
818 816
                     $arguments[$param] = new CURLFile($arguments[$param]);
@@ -834,12 +832,10 @@  discard block
 block discarded – undo
834 832
                     $value = new ($return[0]) ($value);
835 833
                 }
836 834
                 return $response;
837
-            }
838
-            else {
835
+            } else {
839 836
                 return new ($return) ($response->result);
840 837
             }
841
-        }
842
-        else {
838
+        } else {
843 839
             return $response->result;
844 840
         }
845 841
     }
@@ -851,8 +847,7 @@  discard block
 block discarded – undo
851 847
                 if (!isset($arguments[$default])){
852 848
                     $arguments[$default] = self::catchFields($default);
853 849
                 }
854
-            }
855
-            elseif (isset(BPT::$update->$key) || $key === 'other') {
850
+            } elseif (isset(BPT::$update->$key) || $key === 'other') {
856 851
                 foreach ($default as $def) {
857 852
                     if (!isset($arguments[$def])){
858 853
                         $arguments[$def] = self::catchFields($def);
@@ -868,8 +863,7 @@  discard block
 block discarded – undo
868 863
         self::$pure_response = $response;
869 864
         if ($response->ok) {
870 865
             return self::methodReturn($name,$response);
871
-        }
872
-        else {
866
+        } else {
873 867
             return new responseError($response);
874 868
         }
875 869
     }
@@ -910,9 +904,13 @@  discard block
 block discarded – undo
910 904
                     default => false
911 905
                 };
912 906
             case fields::FILE_ID :
913
-                if (isset(BPT::$update->message)) $type = 'message';
914
-                elseif (isset(BPT::$update->edited_message)) $type = 'edited_message';
915
-                else return false;
907
+                if (isset(BPT::$update->message)) {
908
+                    $type = 'message';
909
+                } elseif (isset(BPT::$update->edited_message)) {
910
+                    $type = 'edited_message';
911
+                } else {
912
+                    return false;
913
+                }
916 914
 
917 915
                 return match(true) {
918 916
                     isset(BPT::$update->$type->animation) => BPT::$update->$type->animation->file_id,
Please login to merge, or discard this patch.