Passed
Push — main ( b2c2ea...1a254f )
by Miaad
01:42
created
src/logger.php 1 patch
Braces   +2 added lines, -4 removed lines patch added patch discarded remove patch
@@ -23,8 +23,7 @@  discard block
 block discarded – undo
23 23
         if (file_exists($log_file) && !(filesize($log_file) > self::$log_size * 1024 * 1024)) {
24 24
             $mode = 'a';
25 25
             $write = false;
26
-        }
27
-        else {
26
+        } else {
28 27
             $mode = 'w';
29 28
             $write = true;
30 29
         }
@@ -55,8 +54,7 @@  discard block
 block discarded – undo
55 54
         $text = date('Y/m/d H:i:s') . ( $type === loggerTypes::NONE ? " : $data\n\n" : " : ⤵\n$type : $data\n\n" );
56 55
         if (!is_null(self::$handler)) {
57 56
             fwrite(self::$handler, $text);
58
-        }
59
-        else {
57
+        } else {
60 58
             self::$waited_logs[] = $text;
61 59
         }
62 60
     }
Please login to merge, or discard this patch.
src/database/mysql.php 1 patch
Braces   +18 added lines, -23 removed lines patch added patch discarded remove patch
@@ -69,17 +69,13 @@  discard block
 block discarded – undo
69 69
         if (self::$auto_process) {
70 70
             if (isset(BPT::$update->message)) {
71 71
                 self::processMessage(BPT::$update->message);
72
-            }
73
-            elseif (isset(BPT::$update->edited_message)) {
72
+            } elseif (isset(BPT::$update->edited_message)) {
74 73
                 self::processMessage(BPT::$update->edited_message);
75
-            }
76
-            elseif (isset(BPT::$update->callback_query)) {
74
+            } elseif (isset(BPT::$update->callback_query)) {
77 75
                 self::processCallbackQuery(BPT::$update->callback_query);
78
-            }
79
-            elseif (isset(BPT::$update->inline_query)) {
76
+            } elseif (isset(BPT::$update->inline_query)) {
80 77
                 self::processInlineQuery(BPT::$update->inline_query);
81
-            }
82
-            elseif (isset(BPT::$update->my_chat_member)) {
78
+            } elseif (isset(BPT::$update->my_chat_member)) {
83 79
                 self::processMyChatMember(BPT::$update->my_chat_member);
84 80
             }
85 81
         }
@@ -136,8 +132,7 @@  discard block
 block discarded – undo
136 132
         if ($type === chatType::PRIVATE) {
137 133
             if ($update->new_chat_member->status === chatMemberStatus::MEMBER) {
138 134
                 self::update('users', ['blocked' => false], ['id' => $update->from->id], 1);
139
-            }
140
-            else {
135
+            } else {
141 136
                 self::update('users', ['blocked' => true], ['id' => $update->from->id], 1);
142 137
             }
143 138
         }
@@ -217,11 +212,9 @@  discard block
 block discarded – undo
217 212
         foreach ($vars as $var) {
218 213
             if (is_int($var)) {
219 214
                 $types .= 'i';
220
-            }
221
-            elseif (is_double($var)) {
215
+            } elseif (is_double($var)) {
222 216
                 $types .= 'd';
223
-            }
224
-            else {
217
+            } else {
225 218
                 $types .= 's';
226 219
             }
227 220
         }
@@ -239,8 +232,7 @@  discard block
 block discarded – undo
239 232
         foreach ($array as $name => $value) {
240 233
             if ($first) {
241 234
                 $first = false;
242
-            }
243
-            else {
235
+            } else {
244 236
                 $query .= $operator;
245 237
             }
246 238
             $query .= " `$name` = ?";
@@ -257,8 +249,7 @@  discard block
 block discarded – undo
257 249
         }
258 250
         if (!empty($count)) {
259 251
             $query .= !empty($offset) ? " LIMIT $offset,$count" : " LIMIT $count";
260
-        }
261
-        elseif (!empty($offset)) {
252
+        } elseif (!empty($offset)) {
262 253
             $query .= " OFFSET $offset";
263 254
         }
264 255
         return $values;
@@ -316,7 +307,9 @@  discard block
 block discarded – undo
316 307
     public static function insert (string $table, string|array $columns, array|string $values): mysqli_result|bool {
317 308
         $query = "INSERT INTO `$table`(";
318 309
         $query .= '`' . (is_string($columns) ? $columns : implode('`,`', $columns)) . '`) VALUES (';
319
-        if (is_string($values)) $values = [$values];
310
+        if (is_string($values)) {
311
+            $values = [$values];
312
+        }
320 313
         $query .= '?' . str_repeat(',?', count($values) - 1) . ')';
321 314
         return self::query($query, $values, false);
322 315
     }
@@ -340,8 +333,7 @@  discard block
 block discarded – undo
340 333
         $query = "SELECT ";
341 334
         if ($columns == '*') {
342 335
             $query .= "* ";
343
-        }
344
-        else {
336
+        } else {
345 337
             $query .= '`' . (is_string($columns) ? $columns : implode('`,`', $columns)) . '` ';
346 338
         }
347 339
         $query .= "FROM `$table`";
@@ -402,8 +394,11 @@  discard block
 block discarded – undo
402 394
     public static function selectEach (string $table, array|string $columns = '*', array $where = null, int $count = null, int $offset = null): bool|Generator {
403 395
         $res = self::select($table, $columns, $where, $count, $offset);
404 396
         if ($res) {
405
-            while ($row = $res->fetch_assoc()) yield $row;
397
+            while ($row = $res->fetch_assoc()) {
398
+                yield $row;
399
+            }
400
+        } else {
401
+            return $res;
406 402
         }
407
-        else return $res;
408 403
     }
409 404
 }
410 405
\ No newline at end of file
Please login to merge, or discard this patch.
examples/messenger/bot.php 1 patch
Braces   +16 added lines, -32 removed lines patch added patch discarded remove patch
@@ -7,8 +7,7 @@  discard block
 block discarded – undo
7 7
 
8 8
 if (file_exists('vendor/autoload.php')){
9 9
     require 'vendor/autoload.php';
10
-}
11
-else{
10
+} else{
12 11
     if(!file_exists('BPT.phar')) {
13 12
         copy('https://dl.bptlib.ir/BPT.phar', 'BPT.phar');
14 13
     }
@@ -45,8 +44,7 @@  discard block
 block discarded – undo
45 44
 
46 45
         if ($text === '/start') {
47 46
             $this->sendMessage(self::START_TEXT,answer: true);
48
-        }
49
-        else {
47
+        } else {
50 48
             /** You could use both style */
51 49
             $message_id = $update->message_id;
52 50
             #$message_id = $update->id;
@@ -54,16 +52,13 @@  discard block
 block discarded – undo
54 52
             if (self::ADMIN === $user_id) {
55 53
                 if ($text === '/help') {
56 54
                     $this->sendMessage(self::HELP, answer: true);
57
-                }
58
-                elseif ($text === '/reply_on') {
55
+                } elseif ($text === '/reply_on') {
59 56
                     mysql::update('users',['value'=>'reply_on'],['id'=>$user_id],1);
60 57
                     $this->sendMessage(self::REPLY_ON, answer: true);
61
-                }
62
-                elseif ($text === '/reply_off') {
58
+                } elseif ($text === '/reply_off') {
63 59
                     mysql::update('users',['value'=>'reply_off'],['id'=>$user_id],1);
64 60
                     $this->sendMessage(self::REPLY_OFF, answer: true);
65
-                }
66
-                elseif (isset($update->reply_to_message)) {
61
+                } elseif (isset($update->reply_to_message)) {
67 62
                     $reply_message_id = $update->reply_to_message->message_id;
68 63
 
69 64
                     if ($update->reply_to_message->from->id === $user_id) {
@@ -76,13 +71,11 @@  discard block
 block discarded – undo
76 71
                             $data = $check_message->fetch_object();
77 72
                             $receiver_id = $data->receiver_id;
78 73
                             $result = $this->copyMessage($receiver_id, reply_to_message_id: $data->receiver_message_id);
79
-                        }
80
-                        else {
74
+                        } else {
81 75
                             $this->sendMessage(self::NOT_FOUND, answer: true);
82 76
                             return;
83 77
                         }
84
-                    }
85
-                    else {
78
+                    } else {
86 79
                         $data = mysql::select('messages', ['sender_message_id','sender_id'], [
87 80
                             'receiver_message_id' => $reply_message_id,
88 81
                             'receiver_id'         => $user_id
@@ -93,8 +86,7 @@  discard block
 block discarded – undo
93 86
                         if ($value === 'reply_on') {
94 87
                             mysql::update('users',['value'=>''],['id'=>$user_id]);
95 88
                             $result = $this->copyMessage($receiver_id, reply_to_message_id: $data->sender_message_id);
96
-                        }
97
-                        else {
89
+                        } else {
98 90
                             $result = $this->copyMessage($receiver_id);
99 91
                         }
100 92
                     }
@@ -107,13 +99,11 @@  discard block
 block discarded – undo
107 99
                         if (self::SHOW_STATUS) {
108 100
                             $this->sendMessage(self::SEND_SUCCESSFUL, answer: true);
109 101
                         }
110
-                    }
111
-                    else {
102
+                    } else {
112 103
                         $this->sendMessage(self::SEND_FAILED, answer: true);
113 104
                     }
114 105
                 }
115
-            }
116
-            else {
106
+            } else {
117 107
                 $username = $update->from->username;
118 108
                 if (empty($username)) {
119 109
                     $name = $update->from->first_name . (!empty($update->from->last_name) ? (' ' . $update->from->last_name) : '');
@@ -137,8 +127,7 @@  discard block
 block discarded – undo
137 127
                             ]
138 128
                         ]
139 129
                     ];
140
-                }
141
-                else {
130
+                } else {
142 131
                     $keyboard = [
143 132
                         'inline_keyboard' => [
144 133
                             [
@@ -161,25 +150,21 @@  discard block
 block discarded – undo
161 150
                         ],1);
162 151
                         if ($check_message->num_rows > 0) {
163 152
                             $result = $this->copyMessage(self::ADMIN, reply_to_message_id: $check_message->fetch_object()->receiver_message_id,reply_markup: $keyboard);
164
-                        }
165
-                        else {
153
+                        } else {
166 154
                             $result = $this->copyMessage(self::ADMIN,reply_markup: $keyboard);
167 155
                         }
168
-                    }
169
-                    else {
156
+                    } else {
170 157
                         $check_message = mysql::select('messages', 'sender_message_id', [
171 158
                             'receiver_message_id' => $reply_message_id,
172 159
                             'receiver_id'         => $user_id
173 160
                         ],1);
174 161
                         if ($check_message->num_rows > 0) {
175 162
                             $result = $this->copyMessage(self::ADMIN, reply_to_message_id: $check_message->fetch_object()->sender_message_id,reply_markup: $keyboard);
176
-                        }
177
-                        else {
163
+                        } else {
178 164
                             $result = $this->copyMessage(self::ADMIN,reply_markup: $keyboard);
179 165
                         }
180 166
                     }
181
-                }
182
-                else {
167
+                } else {
183 168
                     $result = $this->copyMessage(self::ADMIN,reply_markup: $keyboard);
184 169
                 }
185 170
 
@@ -195,8 +180,7 @@  discard block
 block discarded – undo
195 180
                     if (self::SHOW_STATUS) {
196 181
                         $this->sendMessage(self::SEND_SUCCESSFUL, answer: true);
197 182
                     }
198
-                }
199
-                else {
183
+                } else {
200 184
                     $this->sendMessage(self::SEND_FAILED, answer: true);
201 185
                 }
202 186
             }
Please login to merge, or discard this patch.
src/receiver/webhook.php 1 patch
Braces   +5 added lines, -10 removed lines patch added patch discarded remove patch
@@ -23,15 +23,13 @@  discard block
 block discarded – undo
23 23
     public static function init () {
24 24
         if (settings::$multi) {
25 25
             multi::init();
26
-        }
27
-        else {
26
+        } else {
28 27
             if (lock::exist('BPT-HOOK')) {
29 28
                 receiver::telegramVerify();
30 29
                 self::checkSecret();
31 30
                 logger::write('Update received , lets process it ;)');
32 31
                 receiver::processUpdate();
33
-            }
34
-            else {
32
+            } else {
35 33
                 self::processSetWebhook();
36 34
             }
37 35
         }
@@ -74,8 +72,7 @@  discard block
 block discarded – undo
74 72
             if (is_string(settings::$certificate)) {
75 73
                 if (file_exists(realpath(settings::$certificate))) {
76 74
                     settings::$certificate = new CURLFile(settings::$certificate);
77
-                }
78
-                else {
75
+                } else {
79 76
                     settings::$certificate = null;
80 77
                 }
81 78
             }
@@ -125,11 +122,9 @@  discard block
 block discarded – undo
125 122
         ignore_user_abort(true);
126 123
         if (function_exists('fastcgi_finish_request')) {
127 124
             fastcgi_finish_request();
128
-        }
129
-        elseif (function_exists('litespeed_finish_request')) {
125
+        } elseif (function_exists('litespeed_finish_request')) {
130 126
             litespeed_finish_request();
131
-        }
132
-        else {
127
+        } else {
133 128
             return false;
134 129
         }
135 130
 
Please login to merge, or discard this patch.
src/tools.php 1 patch
Braces   +34 added lines, -32 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)){
@@ -463,8 +466,9 @@  discard block
 block discarded – undo
463 466
         foreach ($string as $k => &$v) {
464 467
             if ($diff->$v) {
465 468
                 $v = $diff->$v;
469
+            } else {
470
+                unset($string[$k]);
466 471
             }
467
-            else unset($string[$k]);
468 472
         }
469 473
         $string['status'] = $base_time < $target_time ? 'later' : 'ago';
470 474
 
@@ -530,8 +534,7 @@  discard block
 block discarded – undo
530 534
             if ($last === "\0") {
531 535
                 $new .= str_repeat($last, ord($char));
532 536
                 $last = '';
533
-            }
534
-            else {
537
+            } else {
535 538
                 $new .= $last;
536 539
                 $last = $char;
537 540
             }
@@ -615,7 +618,9 @@  discard block
 block discarded – undo
615 618
             }
616 619
             $rows = [];
617 620
             foreach ($keyboard as $row) {
618
-                if (!is_array($row)) continue;
621
+                if (!is_array($row)) {
622
+                    continue;
623
+                }
619 624
                 $buttons = [];
620 625
                 foreach ($row as $base_button) {
621 626
                     $button_info = explode('||', $base_button);
@@ -624,15 +629,12 @@  discard block
 block discarded – undo
624 629
                     if (count($button_info) > 1) {
625 630
                         if ($button_info[1] === 'con') {
626 631
                             $button->setRequest_contact(true);
627
-                        }
628
-                        elseif ($button_info[1] === 'loc') {
632
+                        } elseif ($button_info[1] === 'loc') {
629 633
                             $button->setRequest_location(true);
630
-                        }
631
-                        elseif ($button_info[1] === 'poll') {
634
+                        } elseif ($button_info[1] === 'poll') {
632 635
                             $type = $button_info[2] === pollType::QUIZ ? pollType::QUIZ : pollType::REGULAR;
633 636
                             $button->setRequest_poll((new keyboardButtonPollType())->setType($type));
634
-                        }
635
-                        elseif ($button_info[1] === 'web' && isset($button_info[2])) {
637
+                        } elseif ($button_info[1] === 'web' && isset($button_info[2])) {
636 638
                             $url = $button_info[2];
637 639
                             $button->setWeb_app((new webAppInfo())->setUrl($url));
638 640
                         }
@@ -643,8 +645,7 @@  discard block
 block discarded – undo
643 645
             }
644 646
             $keyboard_object->setKeyboard($rows);
645 647
             return $keyboard_object;
646
-        }
647
-        elseif (!empty($inline)) {
648
+        } elseif (!empty($inline)) {
648 649
             $keyboard_object = new inlineKeyboardMarkup();
649 650
             $rows = [];
650 651
             foreach ($inline as $row) {
@@ -654,12 +655,10 @@  discard block
 block discarded – undo
654 655
                     if (isset($button_info[1])) {
655 656
                         if (filter_var($button_info[1], FILTER_VALIDATE_URL) && str_starts_with($button_info[1], 'http')) {
656 657
                             $button->setText($button_info[0])->setUrl($button_info[1]);
657
-                        }
658
-                        else {
658
+                        } else {
659 659
                             $button->setText($button_info[0])->setCallback_data($button_info[1]);
660 660
                         }
661
-                    }
662
-                    else {
661
+                    } else {
663 662
                         $button->setText($button_info[0])->setUrl('https://t.me/BPT_CH');
664 663
                     }
665 664
                     $buttons[] = $button;
@@ -668,8 +667,7 @@  discard block
 block discarded – undo
668 667
             }
669 668
             $keyboard_object->setInline_keyboard($rows);
670 669
             return $keyboard_object;
671
-        }
672
-        else {
670
+        } else {
673 671
             logger::write("tools::eKey function used\nkeyboard or inline parameter must be set",loggerTypes::ERROR);
674 672
             throw new bptException('ARGUMENT_NOT_FOUND_KEYBOARD_INLINE');
675 673
         }
@@ -688,8 +686,12 @@  discard block
 block discarded – undo
688 686
      * @return string
689 687
      */
690 688
     public static function inviteLink (int $user_id = null, string $bot_username = null): string {
691
-        if (empty($user_id)) $user_id = telegram::catchFields(fields::USER_ID);
692
-        if (empty($bot_username)) $bot_username = telegram::getMe()->username;
689
+        if (empty($user_id)) {
690
+            $user_id = telegram::catchFields(fields::USER_ID);
691
+        }
692
+        if (empty($bot_username)) {
693
+            $bot_username = telegram::getMe()->username;
694
+        }
693 695
         return 'https://t.me/' . str_replace('@', '', $bot_username) . '?start=ref_' . tools::shortEncode($user_id);
694 696
     }
695 697
 
@@ -724,8 +726,7 @@  discard block
 block discarded – undo
724 726
             $iv = self::randomString();
725 727
             $output = base64_encode(openssl_encrypt($text, 'AES-256-CBC', $key, 1, $iv));
726 728
             return ['hash' => $output, 'key' => $key, 'iv' => $iv];
727
-        }
728
-        elseif ($action === codecAction::DECRYPT) {
729
+        } elseif ($action === codecAction::DECRYPT) {
729 730
             if (empty($key)) {
730 731
                 logger::write("tools::codec function used\nkey parameter is not set",loggerTypes::ERROR);
731 732
                 throw new bptException('ARGUMENT_NOT_FOUND_KEY');
@@ -735,8 +736,7 @@  discard block
 block discarded – undo
735 736
                 throw new bptException('ARGUMENT_NOT_FOUND_IV');
736 737
             }
737 738
             return openssl_decrypt(base64_decode($text), 'AES-256-CBC', $key, 1, $iv);
738
-        }
739
-        else {
739
+        } else {
740 740
             logger::write("tools::codec function used\naction is not right, its must be `encode` or `decode`",loggerTypes::WARNING);
741 741
             return false;
742 742
         }
@@ -765,7 +765,9 @@  discard block
 block discarded – undo
765 765
             $array[] = $num % 62;
766 766
             $num = floor($num / 62);
767 767
         }
768
-        if (count($array) < 1) $array = [0];
768
+        if (count($array) < 1) {
769
+            $array = [0];
770
+        }
769 771
         foreach ($array as &$value) {
770 772
             $value = $codes[$value];
771 773
         }
Please login to merge, or discard this patch.
src/pay/crypto.php 1 patch
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -158,8 +158,7 @@
 block discarded – undo
158 158
             if (isset($_SERVER['HTTP_CF_CONNECTING_IP']) && tools::isCloudFlare($ip)) {
159 159
                 $ip = $_SERVER['HTTP_CF_CONNECTING_IP'];
160 160
             }
161
-        }
162
-        elseif (settings::$arvancloud_verify && isset($_SERVER['HTTP_AR_REAL_IP']) && tools::isArvanCloud($ip)) {
161
+        } elseif (settings::$arvancloud_verify && isset($_SERVER['HTTP_AR_REAL_IP']) && tools::isArvanCloud($ip)) {
163 162
             $ip = $_SERVER['HTTP_AR_REAL_IP'];
164 163
         }
165 164
 
Please login to merge, or discard this patch.