@@ -11,8 +11,7 @@ discard block |
||
11 | 11 | |
12 | 12 | if (file_exists('vendor/autoload.php')) { |
13 | 13 | require 'vendor/autoload.php'; |
14 | -} |
|
15 | -else { |
|
14 | +} else { |
|
16 | 15 | if (!file_exists('BPT.phar')) { |
17 | 16 | copy('https://dl.bptlib.ir/BPT.phar', 'BPT.phar'); |
18 | 17 | } |
@@ -174,14 +173,12 @@ discard block |
||
174 | 173 | } |
175 | 174 | if (isset($update->user_shared)) { |
176 | 175 | $target_id = $update->user_shared->user_id; |
177 | - } |
|
178 | - elseif (isset($update->forward_date)) { |
|
176 | + } elseif (isset($update->forward_date)) { |
|
179 | 177 | if (!isset($update->forward_from)) { |
180 | 178 | return $this->sendMessage(texts::USER_FORWARD_CLOSED, answer: true); |
181 | 179 | } |
182 | 180 | $target_id = $update->forward_from->id; |
183 | - } |
|
184 | - else { |
|
181 | + } else { |
|
185 | 182 | if (!is_numeric($text) || $text != floor($text)) { |
186 | 183 | return $this->sendMessage(texts::ONLY_INT, answer: true); |
187 | 184 | } |
@@ -21,8 +21,7 @@ |
||
21 | 21 | public static function init () { |
22 | 22 | if (settings::$multi) { |
23 | 23 | multi::init(); |
24 | - } |
|
25 | - else { |
|
24 | + } else { |
|
26 | 25 | if (!lock::exist('BPT-HOOK')) { |
27 | 26 | self::processSetWebhook(); |
28 | 27 | } |
@@ -46,8 +46,7 @@ |
||
46 | 46 | $text = date('Y/m/d H:i:s') . ($type !== loggerTypes::NONE ? " : ⤵\n$type" : '') . " : $data\n\n"; |
47 | 47 | if (!is_null(self::$handler)) { |
48 | 48 | fwrite(self::$handler, $text); |
49 | - } |
|
50 | - else { |
|
49 | + } else { |
|
51 | 50 | self::$waited_logs[] = $text; |
52 | 51 | } |
53 | 52 | } |
@@ -43,8 +43,7 @@ discard block |
||
43 | 43 | $curl_handler = curl_init(settings::$base_url."/bot$token/"); |
44 | 44 | curl_setopt($curl_handler, CURLOPT_RETURNTRANSFER, true); |
45 | 45 | curl_setopt($curl_handler, CURLOPT_SSL_VERIFYPEER, false); |
46 | - } |
|
47 | - else{ |
|
46 | + } else{ |
|
48 | 47 | $token = settings::$token; |
49 | 48 | if (!isset(self::$curl_handler)){ |
50 | 49 | self::$curl_handler = curl_init(settings::$base_url."/bot$token/"); |
@@ -66,11 +65,9 @@ discard block |
||
66 | 65 | if (isset($data['forgot'])) { |
67 | 66 | curl_setopt($curl_handler, CURLOPT_TIMEOUT_MS, settings::$forgot_time); |
68 | 67 | unset($data['forgot']); |
69 | - } |
|
70 | - elseif ($method === 'getUpdates' || $method === 'setWebhook'){ |
|
68 | + } elseif ($method === 'getUpdates' || $method === 'setWebhook'){ |
|
71 | 69 | curl_setopt($curl_handler, CURLOPT_TIMEOUT_MS, 5000); |
72 | - } |
|
73 | - elseif (settings::$base_timeout > 0) { |
|
70 | + } elseif (settings::$base_timeout > 0) { |
|
74 | 71 | curl_setopt($curl_handler, CURLOPT_TIMEOUT_MS, settings::$base_timeout); |
75 | 72 | } |
76 | 73 | } |
@@ -89,7 +89,10 @@ discard block |
||
89 | 89 | foreach ($allowed_file_names as $allowed_file_name) { |
90 | 90 | if (file_exists($allowed_file_name)) { |
91 | 91 | $mysqli->multi_query(file_get_contents($allowed_file_name)); |
92 | - while ($mysqli->next_result()){if (!$mysqli->more_results()) break;} |
|
92 | + while ($mysqli->next_result()){if (!$mysqli->more_results()) { |
|
93 | + break; |
|
94 | + } |
|
95 | + } |
|
93 | 96 | $loaded = true; |
94 | 97 | } |
95 | 98 | } |
@@ -107,17 +110,13 @@ discard block |
||
107 | 110 | if (self::$auto_process) { |
108 | 111 | if (isset(BPT::$update->message)) { |
109 | 112 | self::processMessage(BPT::$update->message); |
110 | - } |
|
111 | - elseif (isset(BPT::$update->edited_message)) { |
|
113 | + } elseif (isset(BPT::$update->edited_message)) { |
|
112 | 114 | self::processMessage(BPT::$update->edited_message); |
113 | - } |
|
114 | - elseif (isset(BPT::$update->callback_query)) { |
|
115 | + } elseif (isset(BPT::$update->callback_query)) { |
|
115 | 116 | self::processCallbackQuery(BPT::$update->callback_query); |
116 | - } |
|
117 | - elseif (isset(BPT::$update->inline_query)) { |
|
117 | + } elseif (isset(BPT::$update->inline_query)) { |
|
118 | 118 | self::processInlineQuery(BPT::$update->inline_query); |
119 | - } |
|
120 | - elseif (isset(BPT::$update->my_chat_member)) { |
|
119 | + } elseif (isset(BPT::$update->my_chat_member)) { |
|
121 | 120 | self::processMyChatMember(BPT::$update->my_chat_member); |
122 | 121 | } |
123 | 122 | } |
@@ -174,8 +173,7 @@ discard block |
||
174 | 173 | if ($type === chatType::PRIVATE) { |
175 | 174 | if ($update->new_chat_member->status === chatMemberStatus::MEMBER) { |
176 | 175 | self::update('users', ['blocked' => false], ['id' => $update->from->id], 1); |
177 | - } |
|
178 | - else { |
|
176 | + } else { |
|
179 | 177 | self::update('users', ['blocked' => true], ['id' => $update->from->id], 1); |
180 | 178 | } |
181 | 179 | } |
@@ -195,8 +193,7 @@ discard block |
||
195 | 193 | public static function addDefaultWhere (array $where): bool { |
196 | 194 | if (empty(self::$default_where)) { |
197 | 195 | self::$default_where = $where; |
198 | - } |
|
199 | - else { |
|
196 | + } else { |
|
200 | 197 | self::$default_where = array_merge(self::$default_where, $where); |
201 | 198 | } |
202 | 199 | return true; |
@@ -336,11 +333,9 @@ discard block |
||
336 | 333 | foreach ($vars as $var) { |
337 | 334 | if (is_int($var)) { |
338 | 335 | $types .= 'i'; |
339 | - } |
|
340 | - elseif (is_double($var)) { |
|
336 | + } elseif (is_double($var)) { |
|
341 | 337 | $types .= 'd'; |
342 | - } |
|
343 | - else { |
|
338 | + } else { |
|
344 | 339 | $types .= 's'; |
345 | 340 | } |
346 | 341 | } |
@@ -368,8 +363,7 @@ discard block |
||
368 | 363 | foreach ($where as $name => $value) { |
369 | 364 | if ($first) { |
370 | 365 | $first = false; |
371 | - } |
|
372 | - else { |
|
366 | + } else { |
|
373 | 367 | $query .= ' AND'; |
374 | 368 | } |
375 | 369 | |
@@ -387,8 +381,7 @@ discard block |
||
387 | 381 | foreach ($value as $sub_value) { |
388 | 382 | if ($sub_first) { |
389 | 383 | $sub_first = false; |
390 | - } |
|
391 | - else { |
|
384 | + } else { |
|
392 | 385 | $query .= ' AND'; |
393 | 386 | } |
394 | 387 | $operator = substr($sub_value,0,2); |
@@ -468,8 +461,7 @@ discard block |
||
468 | 461 | foreach ($order_by as $key => $mode) { |
469 | 462 | if ($first) { |
470 | 463 | $first = false; |
471 | - } |
|
472 | - else { |
|
464 | + } else { |
|
473 | 465 | $query .= ', '; |
474 | 466 | } |
475 | 467 | if (is_numeric($key)) { |
@@ -483,8 +475,7 @@ discard block |
||
483 | 475 | private static function countBuilder(string &$query, int $count = null, int $offset = null): void { |
484 | 476 | if (!empty($count)) { |
485 | 477 | $query .= !empty($offset) ? " LIMIT $offset, $count" : " LIMIT $count"; |
486 | - } |
|
487 | - elseif (!empty($offset)) { |
|
478 | + } elseif (!empty($offset)) { |
|
488 | 479 | $query .= " OFFSET $offset"; |
489 | 480 | } |
490 | 481 | } |
@@ -496,8 +487,7 @@ discard block |
||
496 | 487 | foreach ($modify as $name => $value) { |
497 | 488 | if ($first) { |
498 | 489 | $first = false; |
499 | - } |
|
500 | - else { |
|
490 | + } else { |
|
501 | 491 | $query .= ','; |
502 | 492 | } |
503 | 493 | |
@@ -543,7 +533,9 @@ discard block |
||
543 | 533 | |
544 | 534 | private static function insertBuilder(string &$query, string|array $columns, array|string $values): array { |
545 | 535 | $query .= '(`' . (is_string($columns) ? $columns : implode('`, `', $columns)) . '`) VALUES ('; |
546 | - if (is_string($values)) $values = [$values]; |
|
536 | + if (is_string($values)) { |
|
537 | + $values = [$values]; |
|
538 | + } |
|
547 | 539 | $query .= '?' . str_repeat(', ?', count($values) - 1) . ')'; |
548 | 540 | return $values; |
549 | 541 | } |
@@ -568,8 +560,7 @@ discard block |
||
568 | 560 | $column = 'all'; |
569 | 561 | } |
570 | 562 | $query .= strtoupper($function) . "($formatted) as `{$function}_$column`"; |
571 | - } |
|
572 | - else { |
|
563 | + } else { |
|
573 | 564 | $query .= "`$column`"; |
574 | 565 | } |
575 | 566 | |
@@ -757,9 +748,12 @@ discard block |
||
757 | 748 | public static function selectEach (string $table, array|string $columns = '*', array $where = [], int $count = null, int $offset = null, array|string $group_by = [], array|string $order_by = [], bool $ignore_default_where = false): bool|Generator { |
758 | 749 | $res = self::select($table, $columns, $where, $count, $offset, $group_by, $order_by, ignore_default_where: $ignore_default_where); |
759 | 750 | if ($res) { |
760 | - while ($row = $res->fetch_assoc()) yield $row; |
|
751 | + while ($row = $res->fetch_assoc()) { |
|
752 | + yield $row; |
|
753 | + } |
|
754 | + } else { |
|
755 | + return $res; |
|
761 | 756 | } |
762 | - else return $res; |
|
763 | 757 | } |
764 | 758 | |
765 | 759 | /** |