@@ -43,8 +43,7 @@ |
||
43 | 43 | private static function getUrl (string $endpoint, bool $pay = false): string { |
44 | 44 | if ($pay) { |
45 | 45 | $url = self::$sandbox ? self::SANDBOX_PAY_BASE : self::PAY_BASE; |
46 | - } |
|
47 | - else { |
|
46 | + } else { |
|
48 | 47 | $url = self::$sandbox ? self::SANDBOX_API_BASE : self::API_BASE; |
49 | 48 | } |
50 | 49 | $url .= $endpoint; |
@@ -217,8 +217,9 @@ discard block |
||
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 | } |
@@ -260,8 +261,7 @@ discard block |
||
260 | 261 | curl_exec($ch); |
261 | 262 | $size = curl_getinfo($ch, CURLINFO_CONTENT_LENGTH_DOWNLOAD); |
262 | 263 | curl_close($ch); |
263 | - } |
|
264 | - else { |
|
264 | + } else { |
|
265 | 265 | $path = realpath($path); |
266 | 266 | $size = file_exists($path) ? filesize($path) : false; |
267 | 267 | } |
@@ -332,8 +332,7 @@ discard block |
||
332 | 332 | $zip->addFile($filePath, substr($filePath, $root_len)); |
333 | 333 | } |
334 | 334 | } |
335 | - } |
|
336 | - else { |
|
335 | + } else { |
|
337 | 336 | $zip->addFile($path, basename($path)); |
338 | 337 | } |
339 | 338 | return $zip->close(); |
@@ -352,9 +351,13 @@ discard block |
||
352 | 351 | */ |
353 | 352 | public static function downloadFile (string $url, string $path, int $chunk_size = 512): bool { |
354 | 353 | $file = fopen($url, 'rb'); |
355 | - if (!$file) return false; |
|
354 | + if (!$file) { |
|
355 | + return false; |
|
356 | + } |
|
356 | 357 | $path = fopen($path, 'wb'); |
357 | - if (!$path) return false; |
|
358 | + if (!$path) { |
|
359 | + return false; |
|
360 | + } |
|
358 | 361 | |
359 | 362 | $length = $chunk_size * 1024; |
360 | 363 | while (!feof($file)){ |
@@ -461,8 +464,9 @@ discard block |
||
461 | 464 | foreach ($string as $k => &$v) { |
462 | 465 | if ($diff->$v) { |
463 | 466 | $v = $diff->$v; |
467 | + } else { |
|
468 | + unset($string[$k]); |
|
464 | 469 | } |
465 | - else unset($string[$k]); |
|
466 | 470 | } |
467 | 471 | $string['status'] = $base_time < $target_time ? 'later' : 'ago'; |
468 | 472 | |
@@ -528,8 +532,7 @@ discard block |
||
528 | 532 | if ($last === "\0") { |
529 | 533 | $new .= str_repeat($last, ord($char)); |
530 | 534 | $last = ''; |
531 | - } |
|
532 | - else { |
|
535 | + } else { |
|
533 | 536 | $new .= $last; |
534 | 537 | $last = $char; |
535 | 538 | } |
@@ -613,7 +616,9 @@ discard block |
||
613 | 616 | } |
614 | 617 | $rows = []; |
615 | 618 | foreach ($keyboard as $row) { |
616 | - if (!is_array($row)) continue; |
|
619 | + if (!is_array($row)) { |
|
620 | + continue; |
|
621 | + } |
|
617 | 622 | $buttons = []; |
618 | 623 | foreach ($row as $base_button) { |
619 | 624 | $button_info = explode('||', $base_button); |
@@ -622,15 +627,12 @@ discard block |
||
622 | 627 | if (count($button_info) > 1) { |
623 | 628 | if ($button_info[1] === 'con') { |
624 | 629 | $button->setRequest_contact(true); |
625 | - } |
|
626 | - elseif ($button_info[1] === 'loc') { |
|
630 | + } elseif ($button_info[1] === 'loc') { |
|
627 | 631 | $button->setRequest_location(true); |
628 | - } |
|
629 | - elseif ($button_info[1] === 'poll') { |
|
632 | + } elseif ($button_info[1] === 'poll') { |
|
630 | 633 | $type = $button_info[2] === pollType::QUIZ ? pollType::QUIZ : pollType::REGULAR; |
631 | 634 | $button->setRequest_poll((new keyboardButtonPollType())->setType($type)); |
632 | - } |
|
633 | - elseif ($button_info[1] === 'web' && isset($button_info[2])) { |
|
635 | + } elseif ($button_info[1] === 'web' && isset($button_info[2])) { |
|
634 | 636 | $url = $button_info[2]; |
635 | 637 | $button->setWeb_app((new webAppInfo())->setUrl($url)); |
636 | 638 | } |
@@ -641,8 +643,7 @@ discard block |
||
641 | 643 | } |
642 | 644 | $keyboard_object->setKeyboard($rows); |
643 | 645 | return $keyboard_object; |
644 | - } |
|
645 | - elseif (!empty($inline)) { |
|
646 | + } elseif (!empty($inline)) { |
|
646 | 647 | $keyboard_object = new inlineKeyboardMarkup(); |
647 | 648 | $rows = []; |
648 | 649 | foreach ($inline as $row) { |
@@ -652,12 +653,10 @@ discard block |
||
652 | 653 | if (isset($button_info[1])) { |
653 | 654 | if (filter_var($button_info[1], FILTER_VALIDATE_URL) && str_starts_with($button_info[1], 'http')) { |
654 | 655 | $button->setText($button_info[0])->setUrl($button_info[1]); |
655 | - } |
|
656 | - else { |
|
656 | + } else { |
|
657 | 657 | $button->setText($button_info[0])->setCallback_data($button_info[1]); |
658 | 658 | } |
659 | - } |
|
660 | - else { |
|
659 | + } else { |
|
661 | 660 | $button->setText($button_info[0])->setUrl('https://t.me/BPT_CH'); |
662 | 661 | } |
663 | 662 | $buttons[] = $button; |
@@ -666,8 +665,7 @@ discard block |
||
666 | 665 | } |
667 | 666 | $keyboard_object->setInline_keyboard($rows); |
668 | 667 | return $keyboard_object; |
669 | - } |
|
670 | - else { |
|
668 | + } else { |
|
671 | 669 | logger::write("tools::eKey function used\nkeyboard or inline parameter must be set",loggerTypes::ERROR); |
672 | 670 | throw new bptException('ARGUMENT_NOT_FOUND_KEYBOARD_INLINE'); |
673 | 671 | } |
@@ -686,8 +684,12 @@ discard block |
||
686 | 684 | * @return string |
687 | 685 | */ |
688 | 686 | public static function inviteLink (int $user_id = null, string $bot_username = null): string { |
689 | - if (empty($user_id)) $user_id = telegram::catchFields(fields::USER_ID); |
|
690 | - if (empty($bot_username)) $bot_username = telegram::getMe()->username; |
|
687 | + if (empty($user_id)) { |
|
688 | + $user_id = telegram::catchFields(fields::USER_ID); |
|
689 | + } |
|
690 | + if (empty($bot_username)) { |
|
691 | + $bot_username = telegram::getMe()->username; |
|
692 | + } |
|
691 | 693 | return 'https://t.me/' . str_replace('@', '', $bot_username) . '?start=ref_' . tools::shortEncode($user_id); |
692 | 694 | } |
693 | 695 | |
@@ -722,8 +724,7 @@ discard block |
||
722 | 724 | $iv = self::randomString(); |
723 | 725 | $output = base64_encode(openssl_encrypt($text, 'AES-256-CBC', $key, 1, $iv)); |
724 | 726 | return ['hash' => $output, 'key' => $key, 'iv' => $iv]; |
725 | - } |
|
726 | - elseif ($action === codecAction::DECRYPT) { |
|
727 | + } elseif ($action === codecAction::DECRYPT) { |
|
727 | 728 | if (empty($key)) { |
728 | 729 | logger::write("tools::codec function used\nkey parameter is not set",loggerTypes::ERROR); |
729 | 730 | throw new bptException('ARGUMENT_NOT_FOUND_KEY'); |
@@ -733,8 +734,7 @@ discard block |
||
733 | 734 | throw new bptException('ARGUMENT_NOT_FOUND_IV'); |
734 | 735 | } |
735 | 736 | return openssl_decrypt(base64_decode($text), 'AES-256-CBC', $key, 1, $iv); |
736 | - } |
|
737 | - else { |
|
737 | + } else { |
|
738 | 738 | logger::write("tools::codec function used\naction is not right, its must be `encode` or `decode`",loggerTypes::WARNING); |
739 | 739 | return false; |
740 | 740 | } |
@@ -756,7 +756,9 @@ discard block |
||
756 | 756 | $array[] = $num % 62; |
757 | 757 | $num = floor($num / 62); |
758 | 758 | } |
759 | - if (count($array) < 1) $array = [0]; |
|
759 | + if (count($array) < 1) { |
|
760 | + $array = [0]; |
|
761 | + } |
|
760 | 762 | foreach ($array as &$value) { |
761 | 763 | $value = $codes[$value]; |
762 | 764 | } |
@@ -862,20 +862,17 @@ discard block |
||
862 | 862 | foreach ($arguments['media'] as $key => $media) { |
863 | 863 | if ($media['media'] instanceof CURLFile) { |
864 | 864 | $remove_answer = true; |
865 | - } |
|
866 | - elseif (is_string($media['media']) && file_exists(realpath($media['media']))) { |
|
865 | + } elseif (is_string($media['media']) && file_exists(realpath($media['media']))) { |
|
867 | 866 | $arguments['media'][$key]['media'] = new CURLFile($media['media']); |
868 | 867 | $remove_answer = true; |
869 | 868 | } |
870 | 869 | } |
871 | - } |
|
872 | - elseif ($file_params = self::methodFile($name)) { |
|
870 | + } elseif ($file_params = self::methodFile($name)) { |
|
873 | 871 | foreach ($file_params as $param) { |
874 | 872 | if (isset($arguments[$param])) { |
875 | 873 | if ($arguments[$param] instanceof CURLFile) { |
876 | 874 | $remove_answer = true; |
877 | - } |
|
878 | - elseif (is_string($arguments[$param]) && file_exists(realpath($arguments[$param]))) { |
|
875 | + } elseif (is_string($arguments[$param]) && file_exists(realpath($arguments[$param]))) { |
|
879 | 876 | $arguments[$param] = new CURLFile($arguments[$param]); |
880 | 877 | $remove_answer = true; |
881 | 878 | } |
@@ -915,8 +912,7 @@ discard block |
||
915 | 912 | if (!isset($arguments[$default])){ |
916 | 913 | $arguments[$default] = self::catchFields($default); |
917 | 914 | } |
918 | - } |
|
919 | - elseif (isset(BPT::$update->$key) || $key === 'other') { |
|
915 | + } elseif (isset(BPT::$update->$key) || $key === 'other') { |
|
920 | 916 | foreach ($default as $def) { |
921 | 917 | if (!isset($arguments[$def])){ |
922 | 918 | $arguments[$def] = self::catchFields($def); |
@@ -987,9 +983,13 @@ discard block |
||
987 | 983 | default => false |
988 | 984 | }; |
989 | 985 | case fields::FILE_ID : |
990 | - if (isset(BPT::$update->message)) $type = 'message'; |
|
991 | - elseif (isset(BPT::$update->edited_message)) $type = 'edited_message'; |
|
992 | - else return false; |
|
986 | + if (isset(BPT::$update->message)) { |
|
987 | + $type = 'message'; |
|
988 | + } elseif (isset(BPT::$update->edited_message)) { |
|
989 | + $type = 'edited_message'; |
|
990 | + } else { |
|
991 | + return false; |
|
992 | + } |
|
993 | 993 | |
994 | 994 | return match(true) { |
995 | 995 | isset(BPT::$update->$type->animation) => BPT::$update->$type->animation->file_id, |
@@ -156,12 +156,13 @@ discard block |
||
156 | 156 | break; |
157 | 157 | case 'W': |
158 | 158 | $avs = ($date[7] == 6 ? 0 : $date[7] + 1) - $doy % 7; |
159 | - if ($avs < 0) $avs += 7; |
|
159 | + if ($avs < 0) { |
|
160 | + $avs += 7; |
|
161 | + } |
|
160 | 162 | $num = (int) (($doy + $avs) / 7); |
161 | 163 | if ($avs < 4) { |
162 | 164 | $num++; |
163 | - } |
|
164 | - elseif ($num < 1) { |
|
165 | + } elseif ($num < 1) { |
|
165 | 166 | $num = ($avs == 4 or $avs == ($jalali_year % 33 % 4 - 2 == (int) ($jalali_year % 33 * 0.05) ? 5 : 4)) ? 53 : 52; |
166 | 167 | } |
167 | 168 | $aks = $avs + $leap_year; |
@@ -187,7 +188,9 @@ discard block |
||
187 | 188 | } |
188 | 189 | public static function jstrftime ($format, $timestamp = '', $none = '', $time_zone = 'Asia/Tehran', $tr_num = 'fa') { |
189 | 190 | $T_sec = 0;/* <= رفع خطاي زمان سرور ، با اعداد '+' و '-' بر حسب ثانيه */ |
190 | - if ($time_zone != 'local') date_default_timezone_set(($time_zone === '') ? 'Asia/Tehran' : $time_zone); |
|
191 | + if ($time_zone != 'local') { |
|
192 | + date_default_timezone_set(($time_zone === '') ? 'Asia/Tehran' : $time_zone); |
|
193 | + } |
|
191 | 194 | $timestamp = $T_sec + (($timestamp === '') ? time() : self::tr_num($timestamp)); |
192 | 195 | $date = explode('_', date('h_H_i_j_n_s_w_Y', $timestamp)); |
193 | 196 | [$jalali_year, $jalali_month, $jalali_day] = self::gregorian_to_jalali($date[7], $date[4], $date[3]); |
@@ -199,8 +202,7 @@ discard block |
||
199 | 202 | $sub = substr($format, $i, 1); |
200 | 203 | if ($sub == '%') { |
201 | 204 | $sub = substr($format, ++$i, 1); |
202 | - } |
|
203 | - else { |
|
205 | + } else { |
|
204 | 206 | $output .= $sub; |
205 | 207 | continue; |
206 | 208 | } |
@@ -229,30 +231,41 @@ discard block |
||
229 | 231 | break; |
230 | 232 | /* Week */ case 'U': |
231 | 233 | $avs = (($date[6] < 5) ? $date[6] + 2 : $date[6] - 5) - ($doy % 7); |
232 | - if ($avs < 0) $avs += 7; |
|
234 | + if ($avs < 0) { |
|
235 | + $avs += 7; |
|
236 | + } |
|
233 | 237 | $num = (int) (($doy + $avs) / 7) + 1; |
234 | - if ($avs > 3 or $avs == 1) $num--; |
|
238 | + if ($avs > 3 or $avs == 1) { |
|
239 | + $num--; |
|
240 | + } |
|
235 | 241 | $output .= ($num < 10) ? '0' . $num : $num; |
236 | 242 | break; |
237 | 243 | case 'V': |
238 | 244 | $avs = (($date[6] == 6) ? 0 : $date[6] + 1) - ($doy % 7); |
239 | - if ($avs < 0) $avs += 7; |
|
245 | + if ($avs < 0) { |
|
246 | + $avs += 7; |
|
247 | + } |
|
240 | 248 | $num = (int) (($doy + $avs) / 7); |
241 | 249 | if ($avs < 4) { |
242 | 250 | $num++; |
243 | - } |
|
244 | - elseif ($num < 1) { |
|
251 | + } elseif ($num < 1) { |
|
245 | 252 | $num = ($avs == 4 or $avs == ((((($jalali_year % 33) % 4) - 2) == ((int) (($jalali_year % 33) * 0.05))) ? 5 : 4)) ? 53 : 52; |
246 | 253 | } |
247 | 254 | $aks = $avs + $leap_year; |
248 | - if ($aks == 7) $aks = 0; |
|
255 | + if ($aks == 7) { |
|
256 | + $aks = 0; |
|
257 | + } |
|
249 | 258 | $output .= (($leap_year + 363 - $doy) < $aks and $aks < 3) ? '01' : (($num < 10) ? '0' . $num : $num); |
250 | 259 | break; |
251 | 260 | case 'W': |
252 | 261 | $avs = (($date[6] == 6) ? 0 : $date[6] + 1) - ($doy % 7); |
253 | - if ($avs < 0) $avs += 7; |
|
262 | + if ($avs < 0) { |
|
263 | + $avs += 7; |
|
264 | + } |
|
254 | 265 | $num = (int) (($doy + $avs) / 7) + 1; |
255 | - if ($avs > 3) $num--; |
|
266 | + if ($avs > 3) { |
|
267 | + $num--; |
|
268 | + } |
|
256 | 269 | $output .= ($num < 10) ? '0' . $num : $num; |
257 | 270 | break; |
258 | 271 | /* Month */ case 'b': |
@@ -356,11 +369,12 @@ discard block |
||
356 | 369 | return ($tr_num != 'en') ? self::tr_num($output, 'fa', '.') : $output; |
357 | 370 | } |
358 | 371 | public static function jmktime ($hour = '', $minute = '', $second = '', $jalali_month = '', $jalali_day = '', $jalali_year = '', $none = '', $timezone = 'Asia/Tehran'): bool|int { |
359 | - if ($timezone != 'local') date_default_timezone_set($timezone); |
|
372 | + if ($timezone != 'local') { |
|
373 | + date_default_timezone_set($timezone); |
|
374 | + } |
|
360 | 375 | if ($hour === '') { |
361 | 376 | return time(); |
362 | - } |
|
363 | - else { |
|
377 | + } else { |
|
364 | 378 | [ |
365 | 379 | $hour, |
366 | 380 | $minute, |
@@ -371,16 +385,13 @@ discard block |
||
371 | 385 | ] = explode('_', self::tr_num($hour . '_' . $minute . '_' . $second . '_' . $jalali_month . '_' . $jalali_day . '_' . $jalali_year)); |
372 | 386 | if ($minute === '') { |
373 | 387 | return mktime($hour); |
374 | - } |
|
375 | - else { |
|
388 | + } else { |
|
376 | 389 | if ($second === '') { |
377 | 390 | return mktime($hour, $minute); |
378 | - } |
|
379 | - else { |
|
391 | + } else { |
|
380 | 392 | if ($jalali_month === '') { |
381 | 393 | return mktime($hour, $minute, $second); |
382 | - } |
|
383 | - else { |
|
394 | + } else { |
|
384 | 395 | $jdate = explode('_', self::jdate('Y_j', '', '', $timezone, 'en')); |
385 | 396 | if ($jalali_day === '') { |
386 | 397 | [ |
@@ -389,8 +400,7 @@ discard block |
||
389 | 400 | $gregorian_day |
390 | 401 | ] = self::jalali_to_gregorian($jdate[0], $jalali_month, $jdate[1]); |
391 | 402 | return mktime($hour, $minute, $second, $gregorian_month); |
392 | - } |
|
393 | - else { |
|
403 | + } else { |
|
394 | 404 | if ($jalali_year === '') { |
395 | 405 | [ |
396 | 406 | $gregorian_year, |
@@ -398,8 +408,7 @@ discard block |
||
398 | 408 | $gregorian_day |
399 | 409 | ] = self::jalali_to_gregorian($jdate[0], $jalali_month, $jalali_day); |
400 | 410 | return mktime($hour, $minute, $second, $gregorian_month, $gregorian_day); |
401 | - } |
|
402 | - else { |
|
411 | + } else { |
|
403 | 412 | [ |
404 | 413 | $gregorian_year, |
405 | 414 | $gregorian_month, |
@@ -463,8 +472,7 @@ discard block |
||
463 | 472 | 'نوزده' |
464 | 473 | ]; |
465 | 474 | $h34 = $k34[substr($num, 2 - $length, 2) - 10]; |
466 | - } |
|
467 | - else { |
|
475 | + } else { |
|
468 | 476 | $xy4 = substr($num, 3 - $length, 1); |
469 | 477 | $p34 = ($xy3 == 0 or $xy4 == 0) ? '' : ' و '; |
470 | 478 | $k3 = ['', '', 'بیست', 'سی', 'چهل', 'پنجاه', 'شصت', 'هفتاد', 'هشتاد', 'نود']; |
@@ -610,8 +618,7 @@ discard block |
||
610 | 618 | if ($days < 186) { |
611 | 619 | $jalali_month = 1 + (int) ($days / 31); |
612 | 620 | $jalali_day = 1 + ($days % 31); |
613 | - } |
|
614 | - else { |
|
621 | + } else { |
|
615 | 622 | $jalali_month = 7 + (int) (($days - 186) / 30); |
616 | 623 | $jalali_day = 1 + (($days - 186) % 30); |
617 | 624 | } |
@@ -7,8 +7,7 @@ discard block |
||
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 | } |
@@ -79,8 +78,7 @@ discard block |
||
79 | 78 | $data = $check_message->fetch_object(); |
80 | 79 | $receiver_id = $data->receiver_id; |
81 | 80 | $result = $this->copyMessage($receiver_id, reply_to_message_id: $data->receiver_message_id); |
82 | - } |
|
83 | - else { |
|
81 | + } else { |
|
84 | 82 | $check_message = mysql::select('messages', ['sender_message_id','sender_id'], [ |
85 | 83 | 'receiver_message_id' => $reply_message_id, |
86 | 84 | 'receiver_id' => $user_id |
@@ -95,8 +93,7 @@ discard block |
||
95 | 93 | if ($value === 'reply_on') { |
96 | 94 | mysql::update('users',['value'=>''],['id'=>$user_id]); |
97 | 95 | $result = $this->copyMessage($receiver_id, reply_to_message_id: $data->sender_message_id); |
98 | - } |
|
99 | - else { |
|
96 | + } else { |
|
100 | 97 | $result = $this->copyMessage($receiver_id); |
101 | 98 | } |
102 | 99 | } |
@@ -138,8 +135,7 @@ discard block |
||
138 | 135 | ] |
139 | 136 | ] |
140 | 137 | ]; |
141 | - } |
|
142 | - else { |
|
138 | + } else { |
|
143 | 139 | $keyboard = [ |
144 | 140 | 'inline_keyboard' => [ |
145 | 141 | [ |
@@ -162,25 +158,21 @@ discard block |
||
162 | 158 | ],1); |
163 | 159 | if ($check_message->num_rows > 0) { |
164 | 160 | $result = $this->copyMessage(self::ADMIN, reply_to_message_id: $check_message->fetch_object()->receiver_message_id,reply_markup: $keyboard); |
165 | - } |
|
166 | - else { |
|
161 | + } else { |
|
167 | 162 | $result = $this->copyMessage(self::ADMIN,reply_markup: $keyboard); |
168 | 163 | } |
169 | - } |
|
170 | - else { |
|
164 | + } else { |
|
171 | 165 | $check_message = mysql::select('messages', 'sender_message_id', [ |
172 | 166 | 'receiver_message_id' => $reply_message_id, |
173 | 167 | 'receiver_id' => $user_id |
174 | 168 | ],1); |
175 | 169 | if ($check_message->num_rows > 0) { |
176 | 170 | $result = $this->copyMessage(self::ADMIN, reply_to_message_id: $check_message->fetch_object()->sender_message_id,reply_markup: $keyboard); |
177 | - } |
|
178 | - else { |
|
171 | + } else { |
|
179 | 172 | $result = $this->copyMessage(self::ADMIN,reply_markup: $keyboard); |
180 | 173 | } |
181 | 174 | } |
182 | - } |
|
183 | - else { |
|
175 | + } else { |
|
184 | 176 | $result = $this->copyMessage(self::ADMIN,reply_markup: $keyboard); |
185 | 177 | } |
186 | 178 |
@@ -74,17 +74,13 @@ discard block |
||
74 | 74 | if (self::$auto_process) { |
75 | 75 | if (isset(BPT::$update->message)) { |
76 | 76 | self::processMessage(BPT::$update->message); |
77 | - } |
|
78 | - elseif (isset(BPT::$update->edited_message)) { |
|
77 | + } elseif (isset(BPT::$update->edited_message)) { |
|
79 | 78 | self::processMessage(BPT::$update->edited_message); |
80 | - } |
|
81 | - elseif (isset(BPT::$update->callback_query)) { |
|
79 | + } elseif (isset(BPT::$update->callback_query)) { |
|
82 | 80 | self::processCallbackQuery(BPT::$update->callback_query); |
83 | - } |
|
84 | - elseif (isset(BPT::$update->inline_query)) { |
|
81 | + } elseif (isset(BPT::$update->inline_query)) { |
|
85 | 82 | self::processInlineQuery(BPT::$update->inline_query); |
86 | - } |
|
87 | - elseif (isset(BPT::$update->my_chat_member)) { |
|
83 | + } elseif (isset(BPT::$update->my_chat_member)) { |
|
88 | 84 | self::processMyChatMember(BPT::$update->my_chat_member); |
89 | 85 | } |
90 | 86 | } |
@@ -141,8 +137,7 @@ discard block |
||
141 | 137 | if ($type === chatType::PRIVATE) { |
142 | 138 | if ($update->new_chat_member->status === chatMemberStatus::MEMBER) { |
143 | 139 | self::update('users', ['blocked' => false], ['id' => $update->from->id], 1); |
144 | - } |
|
145 | - else { |
|
140 | + } else { |
|
146 | 141 | self::update('users', ['blocked' => true], ['id' => $update->from->id], 1); |
147 | 142 | } |
148 | 143 | } |
@@ -162,8 +157,7 @@ discard block |
||
162 | 157 | public static function addDefaultWhere (array $where): bool { |
163 | 158 | if (empty(self::$default_where)) { |
164 | 159 | self::$default_where = $where; |
165 | - } |
|
166 | - else { |
|
160 | + } else { |
|
167 | 161 | self::$default_where = array_merge(self::$default_where, $where); |
168 | 162 | } |
169 | 163 | return true; |
@@ -303,11 +297,9 @@ discard block |
||
303 | 297 | foreach ($vars as $var) { |
304 | 298 | if (is_int($var)) { |
305 | 299 | $types .= 'i'; |
306 | - } |
|
307 | - elseif (is_double($var)) { |
|
300 | + } elseif (is_double($var)) { |
|
308 | 301 | $types .= 'd'; |
309 | - } |
|
310 | - else { |
|
302 | + } else { |
|
311 | 303 | $types .= 's'; |
312 | 304 | } |
313 | 305 | } |
@@ -335,8 +327,7 @@ discard block |
||
335 | 327 | foreach ($where as $name => $value) { |
336 | 328 | if ($first) { |
337 | 329 | $first = false; |
338 | - } |
|
339 | - else { |
|
330 | + } else { |
|
340 | 331 | $query .= ' AND'; |
341 | 332 | } |
342 | 333 | |
@@ -354,8 +345,7 @@ discard block |
||
354 | 345 | foreach ($value as $sub_value) { |
355 | 346 | if ($sub_first) { |
356 | 347 | $sub_first = false; |
357 | - } |
|
358 | - else { |
|
348 | + } else { |
|
359 | 349 | $query .= ' AND'; |
360 | 350 | } |
361 | 351 | $operator = substr($sub_value,0,2); |
@@ -435,8 +425,7 @@ discard block |
||
435 | 425 | foreach ($order_by as $key => $mode) { |
436 | 426 | if ($first) { |
437 | 427 | $first = false; |
438 | - } |
|
439 | - else { |
|
428 | + } else { |
|
440 | 429 | $query .= ', '; |
441 | 430 | } |
442 | 431 | if (is_numeric($key)) { |
@@ -450,8 +439,7 @@ discard block |
||
450 | 439 | private static function countBuilder(string &$query, int $count = null, int $offset = null): void { |
451 | 440 | if (!empty($count)) { |
452 | 441 | $query .= !empty($offset) ? " LIMIT $offset, $count" : " LIMIT $count"; |
453 | - } |
|
454 | - elseif (!empty($offset)) { |
|
442 | + } elseif (!empty($offset)) { |
|
455 | 443 | $query .= " OFFSET $offset"; |
456 | 444 | } |
457 | 445 | } |
@@ -463,8 +451,7 @@ discard block |
||
463 | 451 | foreach ($modify as $name => $value) { |
464 | 452 | if ($first) { |
465 | 453 | $first = false; |
466 | - } |
|
467 | - else { |
|
454 | + } else { |
|
468 | 455 | $query .= ','; |
469 | 456 | } |
470 | 457 | |
@@ -510,7 +497,9 @@ discard block |
||
510 | 497 | |
511 | 498 | private static function insertBuilder(string &$query, string|array $columns, array|string $values): array { |
512 | 499 | $query .= '(`' . (is_string($columns) ? $columns : implode('`, `', $columns)) . '`) VALUES ('; |
513 | - if (is_string($values)) $values = [$values]; |
|
500 | + if (is_string($values)) { |
|
501 | + $values = [$values]; |
|
502 | + } |
|
514 | 503 | $query .= '?' . str_repeat(', ?', count($values) - 1) . ')'; |
515 | 504 | return $values; |
516 | 505 | } |
@@ -535,8 +524,7 @@ discard block |
||
535 | 524 | $column = 'all'; |
536 | 525 | } |
537 | 526 | $query .= strtoupper($function) . "($formatted) as `{$function}_$column`"; |
538 | - } |
|
539 | - else { |
|
527 | + } else { |
|
540 | 528 | $query .= "`$column`"; |
541 | 529 | } |
542 | 530 | |
@@ -716,9 +704,12 @@ discard block |
||
716 | 704 | public static function selectEach (string $table, array|string $columns = '*', array $where = null, int $count = null, int $offset = null, array|string $group_by = [], array|string $order_by = [], bool $ignore_default_where = false): bool|Generator { |
717 | 705 | $res = self::select($table, $columns, $where, $count, $offset, $group_by, $order_by, ignore_default_where: $ignore_default_where); |
718 | 706 | if ($res) { |
719 | - while ($row = $res->fetch_assoc()) yield $row; |
|
707 | + while ($row = $res->fetch_assoc()) { |
|
708 | + yield $row; |
|
709 | + } |
|
710 | + } else { |
|
711 | + return $res; |
|
720 | 712 | } |
721 | - else return $res; |
|
722 | 713 | } |
723 | 714 | |
724 | 715 | /** |