Passed
Push — main ( 7834cc...51b09b )
by Miaad
01:43
created
src/receiver/getUpdates.php 1 patch
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -16,23 +16,23 @@  discard block
 block discarded – undo
16 16
  */
17 17
 class getUpdates extends receiver {
18 18
     #[NoReturn]
19
-    public static function init () {
19
+    public static function init() {
20 20
         $last_update_id = self::loadData();
21
-        while(true) {
21
+        while (true) {
22 22
             if (!lock::exist('getUpdate')) {
23
-                $updates = telegram::getUpdates($last_update_id,allowed_updates: settings::$allowed_updates);
23
+                $updates = telegram::getUpdates($last_update_id, allowed_updates: settings::$allowed_updates);
24 24
                 if (!telegram::$status) {
25
-                    logger::write("There is some problem happened , telegram response : \n".json_encode($updates),loggerTypes::ERROR);
26
-                    BPT::exit(print_r($updates,true));
25
+                    logger::write("There is some problem happened , telegram response : \n".json_encode($updates), loggerTypes::ERROR);
26
+                    BPT::exit(print_r($updates, true));
27 27
                 }
28 28
                 self::handleUpdates($updates);
29
-                lock::save('getUpdate',BPT::$update->update_id+1);
30
-                $last_update_id = BPT::$update->update_id+1;
29
+                lock::save('getUpdate', BPT::$update->update_id + 1);
30
+                $last_update_id = BPT::$update->update_id + 1;
31 31
             }
32 32
         }
33 33
     }
34 34
 
35
-    private static function loadData(): bool|int|string {
35
+    private static function loadData(): bool | int | string {
36 36
         if (lock::exist('getUpdate')) {
37 37
             $last_update_id = lock::read('getUpdate');
38 38
         }
@@ -40,7 +40,7 @@  discard block
 block discarded – undo
40 40
             self::deleteOldLocks();
41 41
             telegram::deleteWebhook();
42 42
             $last_update_id = 0;
43
-            lock::save('getUpdate',0);
43
+            lock::save('getUpdate', 0);
44 44
         }
45 45
         return $last_update_id;
46 46
     }
Please login to merge, or discard this patch.
src/receiver/webhook.php 1 patch
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -20,7 +20,7 @@  discard block
 block discarded – undo
20 20
     /**
21 21
      * @internal Only for BPT self usage , Don't use it in your source!
22 22
      */
23
-    public static function init () {
23
+    public static function init() {
24 24
         if (settings::$multi) {
25 25
             multi::init();
26 26
         }
@@ -49,24 +49,24 @@  discard block
 block discarded – undo
49 49
         }
50 50
     }
51 51
 
52
-    protected static function setWebhook(string $url,string $secret = '') {
52
+    protected static function setWebhook(string $url, string $secret = '') {
53 53
         $res = telegram::setWebhook($url, settings::$certificate, max_connections: settings::$max_connection, allowed_updates: settings::$allowed_updates, drop_pending_updates: settings::$skip_old_updates, secret_token: $secret);
54 54
         if (!telegram::$status) {
55
-            logger::write("There is some problem happened , telegram response : \n".json_encode($res),loggerTypes::ERROR);
56
-            BPT::exit(print_r($res,true));
55
+            logger::write("There is some problem happened , telegram response : \n".json_encode($res), loggerTypes::ERROR);
56
+            BPT::exit(print_r($res, true));
57 57
         }
58
-        logger::write('Webhook was set successfully',loggerTypes::INFO);
58
+        logger::write('Webhook was set successfully', loggerTypes::INFO);
59 59
     }
60 60
 
61 61
     protected static function checkURL() {
62 62
         if (!(isset($_SERVER['SERVER_NAME']) && isset($_SERVER['REQUEST_URI']))) {
63
-            logger::write('For using webhook receiver , you should open this file in your webserver(by domain)',loggerTypes::ERROR);
63
+            logger::write('For using webhook receiver , you should open this file in your webserver(by domain)', loggerTypes::ERROR);
64 64
             throw new bptException('WEBHOOK_NEED_URL');
65 65
         }
66 66
     }
67 67
 
68 68
     private static function setURL(): string {
69
-        return (isset(settings::$certificate) ? 'http://' : 'https://') . $_SERVER['SERVER_NAME'] . $_SERVER['SCRIPT_NAME'];
69
+        return (isset(settings::$certificate) ? 'http://' : 'https://').$_SERVER['SERVER_NAME'].$_SERVER['SCRIPT_NAME'];
70 70
     }
71 71
 
72 72
     protected static function setCertificate() {
@@ -89,15 +89,15 @@  discard block
 block discarded – undo
89 89
         self::setCertificate();
90 90
         $url = self::setURL();
91 91
         $secret = !empty(settings::$secret) ? settings::$secret : tools::randomString(64);
92
-        self::setWebhook($url,$secret);
93
-        lock::save('BPT-HOOK',$secret);
92
+        self::setWebhook($url, $secret);
93
+        lock::save('BPT-HOOK', $secret);
94 94
         BPT::exit('Done');
95 95
     }
96 96
 
97 97
     private static function checkSecret() {
98 98
         $secret = lock::read('BPT-HOOK');
99 99
         if ($secret !== self::getSecret()) {
100
-            logger::write('This is not webhook set by BPT, webhook will reset',loggerTypes::WARNING);
100
+            logger::write('This is not webhook set by BPT, webhook will reset', loggerTypes::WARNING);
101 101
             self::processSetWebhook();
102 102
         }
103 103
     }
Please login to merge, or discard this patch.
src/tools.php 1 patch
Spacing   +49 added lines, -49 removed lines patch added patch discarded remove patch
@@ -29,7 +29,7 @@  discard block
 block discarded – undo
29 29
 /**
30 30
  * tools class , gather what ever you need
31 31
  */
32
-class tools{
32
+class tools {
33 33
     /**
34 34
      * Check the given username format
35 35
      *
@@ -41,7 +41,7 @@  discard block
 block discarded – undo
41 41
      *
42 42
      * @return bool
43 43
      */
44
-    public static function isUsername (string $username): bool {
44
+    public static function isUsername(string $username): bool {
45 45
         $length = strlen($username);
46 46
         return !str_contains($username, '__') && $length >= 5 && $length <= 33 && preg_match('/^@?([a-zA-Z])(\w{4,31})$/', $username);
47 47
     }
@@ -58,7 +58,7 @@  discard block
 block discarded – undo
58 58
      *
59 59
      * @return bool
60 60
      */
61
-    public static function ipInRange (string $ip, string $range): bool {
61
+    public static function ipInRange(string $ip, string $range): bool {
62 62
         if (!str_contains($range, '/')) {
63 63
             $range .= '/32';
64 64
         }
@@ -78,7 +78,7 @@  discard block
 block discarded – undo
78 78
      *
79 79
      * @return bool
80 80
      */
81
-    public static function isTelegram (string $ip): bool {
81
+    public static function isTelegram(string $ip): bool {
82 82
         return tools::ipInRange($ip, '149.154.160.0/20') || tools::ipInRange($ip, '91.108.4.0/22');
83 83
     }
84 84
 
@@ -93,10 +93,10 @@  discard block
 block discarded – undo
93 93
      *
94 94
      * @return bool
95 95
      */
96
-    public static function isCloudFlare (string $ip): bool {
96
+    public static function isCloudFlare(string $ip): bool {
97 97
         $cf_ips = ['173.245.48.0/20', '103.21.244.0/22', '103.22.200.0/22', '103.31.4.0/22', '141.101.64.0/18', '108.162.192.0/18', '190.93.240.0/20', '188.114.96.0/20', '197.234.240.0/22', '198.41.128.0/17', '162.158.0.0/15', '104.16.0.0/12', '104.24.0.0/14', '172.64.0.0/13', '131.0.72.0/22'];
98 98
         foreach ($cf_ips as $cf_ip) {
99
-            if (self::ipInRange($ip,$cf_ip)) {
99
+            if (self::ipInRange($ip, $cf_ip)) {
100 100
                 return true;
101 101
             }
102 102
         }
@@ -114,10 +114,10 @@  discard block
 block discarded – undo
114 114
      *
115 115
      * @return bool
116 116
      */
117
-    public static function isArvanCloud (string $ip): bool {
117
+    public static function isArvanCloud(string $ip): bool {
118 118
         $ar_ips = ['185.143.232.0/22', '92.114.16.80/28', '2.146.0.0/28', '46.224.2.32/29', '89.187.178.96/29', '195.181.173.128/29', '89.187.169.88/29', '188.229.116.16/29', '83.123.255.56/31', '164.138.128.28/31', '94.182.182.28/30', '185.17.115.176/30', '5.213.255.36/31', '138.128.139.144/29', '5.200.14.8/29', '188.122.68.224/29', '188.122.83.176/29', '213.179.217.16/29', '185.179.201.192/29', '43.239.139.192/29', '213.179.197.16/29', '213.179.201.192/29', '109.200.214.248/29', '138.128.141.16/29', '188.122.78.136/29', '213.179.211.32/29', '103.194.164.24/29', '185.50.105.136/29', '213.179.213.16/29', '162.244.52.120/29', '188.122.80.240/29', '109.200.195.64/29', '109.200.199.224/29', '185.228.238.0/28', '94.182.153.24/29', '94.101.182.0/27', '37.152.184.208/28', '78.39.156.192/28', '158.255.77.238/31', '81.12.28.16/29', '176.65.192.202/31', '2.144.3.128/28', '89.45.48.64/28', '37.32.16.0/27', '37.32.17.0/27', '37.32.18.0/27'];
119 119
         foreach ($ar_ips as $ar_ip) {
120
-            if (self::ipInRange($ip,$ar_ip)) {
120
+            if (self::ipInRange($ip, $ar_ip)) {
121 121
                 return true;
122 122
             }
123 123
         }
@@ -137,11 +137,11 @@  discard block
 block discarded – undo
137 137
      *
138 138
      * @return bool|user return array when verify is active and token is true array of telegram getMe result
139 139
      */
140
-    public static function isToken (string $token, bool $verify = false): bool|user {
140
+    public static function isToken(string $token, bool $verify = false): bool | user {
141 141
         if (!preg_match('/^(\d{8,10}):[\w\-]{35}$/', $token)) {
142 142
             return false;
143 143
         }
144
-        if (!$verify){
144
+        if (!$verify) {
145 145
             return true;
146 146
         }
147 147
         $res = telegram::me($token);
@@ -171,14 +171,14 @@  discard block
 block discarded – undo
171 171
      *
172 172
      * @return bool
173 173
      */
174
-    public static function isJoined (array|string|int $ids , int|null $user_id = null): bool {
174
+    public static function isJoined(array | string | int $ids, int | null $user_id = null): bool {
175 175
         if (!is_array($ids)) {
176 176
             $ids = [$ids];
177 177
         }
178 178
         $user_id = $user_id ?? request::catchFields('user_id');
179 179
 
180 180
         foreach ($ids as $id) {
181
-            $check = telegram::getChatMember($id,$user_id);
181
+            $check = telegram::getChatMember($id, $user_id);
182 182
             if (telegram::$status) {
183 183
                 $check = $check->status;
184 184
                 if ($check === chatMemberStatus::LEFT || $check === chatMemberStatus::KICKED) {
@@ -205,7 +205,7 @@  discard block
 block discarded – undo
205 205
      *
206 206
      * @return array keys will be id and values will be bool(null for not founded ids)
207 207
      */
208
-    public static function joinChecker (array|string|int $ids , int|null $user_id = null): array {
208
+    public static function joinChecker(array | string | int $ids, int | null $user_id = null): array {
209 209
         if (!is_array($ids)) {
210 210
             $ids = [$ids];
211 211
         }
@@ -213,7 +213,7 @@  discard block
 block discarded – undo
213 213
 
214 214
         $result = [];
215 215
         foreach ($ids as $id) {
216
-            $check = telegram::getChatMember($id,$user_id);
216
+            $check = telegram::getChatMember($id, $user_id);
217 217
             if (telegram::$status) {
218 218
                 $check = $check->status;
219 219
                 $result[$id] = $check !== chatMemberStatus::LEFT && $check !== chatMemberStatus::KICKED;
@@ -233,7 +233,7 @@  discard block
 block discarded – undo
233 233
      * @return bool
234 234
      */
235 235
     public static function isShorted(string $text): bool{
236
-        return preg_match('/^[a-zA-Z0-9]+$/',$text);
236
+        return preg_match('/^[a-zA-Z0-9]+$/', $text);
237 237
     }
238 238
 
239 239
     /**
@@ -250,7 +250,7 @@  discard block
 block discarded – undo
250 250
      *
251 251
      * @return string|int|false string for formatted data , int for normal data , false when size can not be found(file not found or ...)
252 252
      */
253
-    public static function size (string $path, bool $format = true): string|int|false {
253
+    public static function size(string $path, bool $format = true): string | int | false {
254 254
         if (filter_var($path, FILTER_VALIDATE_URL)) {
255 255
             $ch = curl_init($path);
256 256
             curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
@@ -282,7 +282,7 @@  discard block
 block discarded – undo
282 282
      * @return bool
283 283
      * @throws bptException
284 284
      */
285
-    public static function delete (string $path, bool $sub = true): bool {
285
+    public static function delete(string $path, bool $sub = true): bool {
286 286
         if (!is_dir($path)) {
287 287
             return unlink($path);
288 288
         }
@@ -290,7 +290,7 @@  discard block
 block discarded – undo
290 290
             return rmdir($path);
291 291
         }
292 292
         if (!$sub) {
293
-            logger::write("tools::delete function used\ndelete function cannot delete folder because its have subFiles and sub parameter haven't true value",loggerTypes::ERROR);
293
+            logger::write("tools::delete function used\ndelete function cannot delete folder because its have subFiles and sub parameter haven't true value", loggerTypes::ERROR);
294 294
             throw new bptException('DELETE_FOLDER_HAS_SUB');
295 295
         }
296 296
         $it = new RecursiveDirectoryIterator($path, FilesystemIterator::SKIP_DOTS);
@@ -312,7 +312,7 @@  discard block
 block discarded – undo
312 312
      * @return bool
313 313
      * @throws bptException when zip extension not found
314 314
      */
315
-    public static function zip (string $path, string $destination): bool {
315
+    public static function zip(string $path, string $destination): bool {
316 316
         if (!extension_loaded('zip')) {
317 317
             logger::write("tools::zip function used\nzip extension is not found , It may not be installed or enabled", loggerTypes::ERROR);
318 318
             throw new bptException('ZIP_EXTENSION_MISSING');
@@ -347,14 +347,14 @@  discard block
 block discarded – undo
347 347
      *
348 348
      * @return bool true on success and false in failure
349 349
      */
350
-    public static function downloadFile (string $url, string $path,int $chunk_size = 512): bool {
350
+    public static function downloadFile(string $url, string $path, int $chunk_size = 512): bool {
351 351
         $file = fopen($url, 'rb');
352 352
         if (!$file) return false;
353 353
         $path = fopen($path, 'wb');
354 354
         if (!$path) return false;
355 355
 
356 356
         $length = $chunk_size * 1024;
357
-        while (!feof($file)){
357
+        while (!feof($file)) {
358 358
             fwrite($path, fread($file, $length), $length);
359 359
         }
360 360
         fclose($path);
@@ -376,10 +376,10 @@  discard block
 block discarded – undo
376 376
      *
377 377
      * @return string
378 378
      */
379
-    public static function byteFormat (int $byte, int $precision = 2): string {
379
+    public static function byteFormat(int $byte, int $precision = 2): string {
380 380
         $rate_counter = 0;
381 381
 
382
-        while ($byte > 1024){
382
+        while ($byte > 1024) {
383 383
             $byte /= 1024;
384 384
             $rate_counter++;
385 385
         }
@@ -388,7 +388,7 @@  discard block
 block discarded – undo
388 388
             $byte = round($byte, $precision);
389 389
         }
390 390
 
391
-        return $byte . ' ' . ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB'][$rate_counter];
391
+        return $byte.' '.['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB'][$rate_counter];
392 392
     }
393 393
 
394 394
     /**
@@ -405,10 +405,10 @@  discard block
 block discarded – undo
405 405
      *
406 406
      * @return string|false return false when mode is incorrect
407 407
      */
408
-    public static function modeEscape (string $text, string $mode = parseMode::HTML): string|false {
408
+    public static function modeEscape(string $text, string $mode = parseMode::HTML): string | false {
409 409
         return match ($mode) {
410
-            parseMode::HTML => str_replace(['&', '<', '>',], ["&amp;", "&lt;", "&gt;",], $text),
411
-            parseMode::MARKDOWN => str_replace(['\\', '_', '*', '`', '['], ['\\\\', '\_', '\*', '\`', '\[',], $text),
410
+            parseMode::HTML => str_replace(['&', '<', '>', ], ["&amp;", "&lt;", "&gt;", ], $text),
411
+            parseMode::MARKDOWN => str_replace(['\\', '_', '*', '`', '['], ['\\\\', '\_', '\*', '\`', '\[', ], $text),
412 412
             parseMode::MARKDOWNV2 => str_replace(
413 413
                 ['_', '*', '[', ']', '(', ')', '~', '`', '>', '#', '+', '-', '=', '|', '{', '}', '.', '!', '\\'],
414 414
                 ['\_', '\*', '\[', '\]', '\(', '\)', '\~', '\`', '\>', '\#', '\+', '\-', '\=', '\|', '\{', '\}', '\.', '\!', '\\\\'],
@@ -447,12 +447,12 @@  discard block
 block discarded – undo
447 447
      * @return array{status: string,year: string,month: string,day: string,hour: string,minute: string,second: string}
448 448
      * @throws Exception
449 449
      */
450
-    public static function timeDiff (int|string $target_time, int|string|null $base_time = null): array {
450
+    public static function timeDiff(int | string $target_time, int | string | null $base_time = null): array {
451 451
         if (!isset($base_time)) {
452 452
             $base_time = '@'.time();
453 453
         }
454 454
         $base_time = new DateTime($base_time);
455
-        $target_time = new DateTime(is_numeric($target_time) ? '@' . $target_time : $target_time . ' +00:00');
455
+        $target_time = new DateTime(is_numeric($target_time) ? '@'.$target_time : $target_time.' +00:00');
456 456
 
457 457
         $diff = $base_time->diff($target_time);
458 458
 
@@ -479,12 +479,12 @@  discard block
 block discarded – undo
479 479
      *
480 480
      * @return string[]|string
481 481
      */
482
-    public static function realEscapeString(string|array $input): string|array {
483
-        if(is_array($input)) {
482
+    public static function realEscapeString(string | array $input): string | array {
483
+        if (is_array($input)) {
484 484
             return array_map(__METHOD__, $input);
485 485
         }
486 486
 
487
-        if(!empty($input) && is_string($input)) {
487
+        if (!empty($input) && is_string($input)) {
488 488
             return str_replace(['\\', "\0", "\n", "\r", "'", '"', "\x1a"], ['\\\\', '\\0', '\\n', '\\r', "\\'", '\\"', '\\Z'], $input);
489 489
         }
490 490
 
@@ -502,7 +502,7 @@  discard block
 block discarded – undo
502 502
      *
503 503
      * @return string[]|string
504 504
      */
505
-    public static function strReplaceFirst(string|array $search, string|array $replace, string|array $subject): string|array {
505
+    public static function strReplaceFirst(string | array $search, string | array $replace, string | array $subject): string | array {
506 506
         $pos = strpos($subject, $search);
507 507
         if ($pos !== false) {
508 508
             return substr_replace($subject, $replace, $pos, strlen($search));
@@ -519,7 +519,7 @@  discard block
 block discarded – undo
519 519
      *
520 520
      * @return string see possible values in fileType class
521 521
      */
522
-    public static function fileType (string $file_id): string {
522
+    public static function fileType(string $file_id): string {
523 523
         $data = base64_decode(str_pad(strtr($file_id, '-_', '+/'), strlen($file_id) % 4, '='));
524 524
         $new = '';
525 525
         $last = '';
@@ -533,7 +533,7 @@  discard block
 block discarded – undo
533 533
                 $last = $char;
534 534
             }
535 535
         }
536
-        $data = unpack('VtypeId/Vdc_id', $new . $last);
536
+        $data = unpack('VtypeId/Vdc_id', $new.$last);
537 537
         $data['typeId'] = $data['typeId'] & ~33554432 & ~16777216;
538 538
         return [
539 539
             fileTypes::THUMBNAIL,
@@ -571,10 +571,10 @@  discard block
 block discarded – undo
571 571
      *
572 572
      * @return string
573 573
      */
574
-    public static function randomString (int $length = 16, string $characters = 'aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ'): string {
574
+    public static function randomString(int $length = 16, string $characters = 'aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ'): string {
575 575
         $rand_string = '';
576 576
         $char_len = strlen($characters) - 1;
577
-        for ($i = 0; $i < $length; $i ++) {
577
+        for ($i = 0; $i < $length; $i++) {
578 578
             $rand_string .= $characters[rand(0, $char_len)];
579 579
         }
580 580
         return $rand_string;
@@ -603,7 +603,7 @@  discard block
 block discarded – undo
603 603
      * @return inlineKeyboardMarkup|replyKeyboardMarkup replyKeyboardMarkup for keyboard and inlineKeyboardMarkup for inline
604 604
      * @throws bptException
605 605
      */
606
-    public static function easyKey(array $keyboard = [], array $inline = []): inlineKeyboardMarkup|replyKeyboardMarkup {
606
+    public static function easyKey(array $keyboard = [], array $inline = []): inlineKeyboardMarkup | replyKeyboardMarkup {
607 607
         if (!empty($keyboard)) {
608 608
             $keyboard_object = new replyKeyboardMarkup();
609 609
             $keyboard_object->setResize_keyboard($keyboard['resize'] ?? true);
@@ -667,7 +667,7 @@  discard block
 block discarded – undo
667 667
             return $keyboard_object;
668 668
         }
669 669
         else {
670
-            logger::write("tools::eKey function used\nkeyboard or inline parameter must be set",loggerTypes::ERROR);
670
+            logger::write("tools::eKey function used\nkeyboard or inline parameter must be set", loggerTypes::ERROR);
671 671
             throw new bptException('ARGUMENT_NOT_FOUND_KEYBOARD_INLINE');
672 672
         }
673 673
     }
@@ -684,10 +684,10 @@  discard block
 block discarded – undo
684 684
      *
685 685
      * @return string
686 686
      */
687
-    public static function inviteLink (int $user_id = null, string $bot_username = null): string {
687
+    public static function inviteLink(int $user_id = null, string $bot_username = null): string {
688 688
         if (empty($user_id)) $user_id = telegram::catchFields(fields::USER_ID);
689 689
         if (empty($bot_username)) $bot_username = telegram::getMe()->username;
690
-        return 'https://t.me/' . str_replace('@', '', $bot_username) . '?start=ref_' . tools::shortEncode($user_id);
690
+        return 'https://t.me/'.str_replace('@', '', $bot_username).'?start=ref_'.tools::shortEncode($user_id);
691 691
     }
692 692
 
693 693
     /**
@@ -711,9 +711,9 @@  discard block
 block discarded – undo
711 711
      * @return string|bool|array{hash:string, key:string, iv:string}
712 712
      * @throws bptException
713 713
      */
714
-    public static function crypto (string $action, string $text, string $key = null, string $iv = null): bool|array|string {
714
+    public static function crypto(string $action, string $text, string $key = null, string $iv = null): bool | array | string {
715 715
         if (!extension_loaded('openssl')) {
716
-            logger::write("tools::crypto function used\nopenssl extension is not found , It may not be installed or enabled",loggerTypes::ERROR);
716
+            logger::write("tools::crypto function used\nopenssl extension is not found , It may not be installed or enabled", loggerTypes::ERROR);
717 717
             throw new bptException('OPENSSL_EXTENSION_MISSING');
718 718
         }
719 719
         if ($action === cryptoAction::ENCRYPT) {
@@ -724,17 +724,17 @@  discard block
 block discarded – undo
724 724
         }
725 725
         elseif ($action === cryptoAction::DECRYPT) {
726 726
             if (empty($key)) {
727
-                logger::write("tools::crypto function used\nkey parameter is not set",loggerTypes::ERROR);
727
+                logger::write("tools::crypto function used\nkey parameter is not set", loggerTypes::ERROR);
728 728
                 throw new bptException('ARGUMENT_NOT_FOUND_KEY');
729 729
             }
730 730
             if (empty($iv)) {
731
-                logger::write("tools::crypto function used\niv parameter is not set",loggerTypes::ERROR);
731
+                logger::write("tools::crypto function used\niv parameter is not set", loggerTypes::ERROR);
732 732
                 throw new bptException('ARGUMENT_NOT_FOUND_IV');
733 733
             }
734 734
             return openssl_decrypt(base64_decode($text), 'AES-256-CBC', $key, 1, $iv);
735 735
         }
736 736
         else {
737
-            logger::write("tools::crypto function used\naction is not right, its must be `encode` or `decode`",loggerTypes::WARNING);
737
+            logger::write("tools::crypto function used\naction is not right, its must be `encode` or `decode`", loggerTypes::WARNING);
738 738
             return false;
739 739
         }
740 740
     }
@@ -751,7 +751,7 @@  discard block
 block discarded – undo
751 751
     public static function shortEncode(int $num): string {
752 752
         $codes = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
753 753
         $array = [];
754
-        while ($num > 0){
754
+        while ($num > 0) {
755 755
             $array[] = $num % 62;
756 756
             $num = floor($num / 62);
757 757
         }
@@ -759,7 +759,7 @@  discard block
 block discarded – undo
759 759
         foreach ($array as &$value) {
760 760
             $value = $codes[$value];
761 761
         }
762
-        return strrev(implode('',$array));
762
+        return strrev(implode('', $array));
763 763
     }
764 764
 
765 765
     /**
@@ -776,7 +776,7 @@  discard block
 block discarded – undo
776 776
         $num = 0;
777 777
         $text = str_split(strrev($text));
778 778
         foreach ($text as $key=>$value) {
779
-            $num += strpos($codes,$value) * pow(62,$key);
779
+            $num += strpos($codes, $value) * pow(62, $key);
780 780
         }
781 781
         return $num;
782 782
     }
Please login to merge, or discard this patch.
src/database/mysql.php 1 patch
Spacing   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -25,7 +25,7 @@  discard block
 block discarded – undo
25 25
     /**
26 26
      * @internal Only for BPT self usage , Don't use it in your source!
27 27
      */
28
-    public static function init (): void {
28
+    public static function init(): void {
29 29
         $host = settings::$db['host'] ?? 'localhost';
30 30
         $port = settings::$db['port'] ?? 3306;
31 31
         $user = settings::$db['user'] ?? settings::$db['username'] ?? 'unknown';
@@ -33,7 +33,7 @@  discard block
 block discarded – undo
33 33
         $dbname = settings::$db['dbname'];
34 34
         self::$connection = new mysqli($host, $user, $pass, $dbname, $port);
35 35
         if (self::$connection->connect_errno) {
36
-            logger::write('SQL connection has problem : ' . self::$connection->connect_error, loggerTypes::ERROR);
36
+            logger::write('SQL connection has problem : '.self::$connection->connect_error, loggerTypes::ERROR);
37 37
             throw new bptException('SQL_CONNECTION_PROBLEM');
38 38
         }
39 39
         if (!lock::exist('BPT-MYSQL')) {
@@ -41,7 +41,7 @@  discard block
 block discarded – undo
41 41
         }
42 42
     }
43 43
 
44
-    private static function install (): void {
44
+    private static function install(): void {
45 45
         self::pureQuery("
46 46
 CREATE TABLE `users`
47 47
 (
@@ -62,7 +62,7 @@  discard block
 block discarded – undo
62 62
     /**
63 63
      * @internal Only for BPT self usage , Don't use it in your source!
64 64
      */
65
-    public static function process (): void {
65
+    public static function process(): void {
66 66
         if (isset(BPT::$update->message)) {
67 67
             self::processMessage(BPT::$update->message);
68 68
         }
@@ -80,7 +80,7 @@  discard block
 block discarded – undo
80 80
         }
81 81
     }
82 82
 
83
-    private static function processMessage (message $update): void {
83
+    private static function processMessage(message $update): void {
84 84
         $type = $update->chat->type;
85 85
         if ($type === chatType::PRIVATE) {
86 86
             $user_id = $update->from->id;
@@ -106,7 +106,7 @@  discard block
 block discarded – undo
106 106
         }
107 107
     }
108 108
 
109
-    private static function processCallbackQuery (callbackQuery $update): void {
109
+    private static function processCallbackQuery(callbackQuery $update): void {
110 110
         $type = $update->message->chat->type;
111 111
         if ($type === chatType::PRIVATE) {
112 112
             $user_id = $update->from->id;
@@ -116,7 +116,7 @@  discard block
 block discarded – undo
116 116
         }
117 117
     }
118 118
 
119
-    private static function processInlineQuery (inlineQuery $update): void {
119
+    private static function processInlineQuery(inlineQuery $update): void {
120 120
         $type = $update->chat_type;
121 121
         if ($type === chatType::PRIVATE || $type === chatType::SENDER) {
122 122
             $user_id = $update->from->id;
@@ -126,7 +126,7 @@  discard block
 block discarded – undo
126 126
         }
127 127
     }
128 128
 
129
-    private static function processMyChatMember (chatMemberUpdated $update): void {
129
+    private static function processMyChatMember(chatMemberUpdated $update): void {
130 130
         $type = $update->chat->type;
131 131
         if ($type === chatType::PRIVATE) {
132 132
             if ($update->new_chat_member->status === chatMemberStatus::MEMBER) {
@@ -143,7 +143,7 @@  discard block
 block discarded – undo
143 143
      *
144 144
      * @return mysqli
145 145
      */
146
-    public static function getMysqli (): mysqli {
146
+    public static function getMysqli(): mysqli {
147 147
         return self::$connection;
148 148
     }
149 149
 
@@ -152,7 +152,7 @@  discard block
 block discarded – undo
152 152
      *
153 153
      * @return int|string
154 154
      */
155
-    public static function affected_rows (): int|string {
155
+    public static function affected_rows(): int | string {
156 156
         return self::$connection->affected_rows;
157 157
     }
158 158
 
@@ -161,7 +161,7 @@  discard block
 block discarded – undo
161 161
      *
162 162
      * @return int|string
163 163
      */
164
-    public static function insert_id (): int|string {
164
+    public static function insert_id(): int | string {
165 165
         return self::$connection->insert_id;
166 166
     }
167 167
 
@@ -172,7 +172,7 @@  discard block
 block discarded – undo
172 172
      *
173 173
      * @return string
174 174
      */
175
-    public static function escapeString (string $text): string {
175
+    public static function escapeString(string $text): string {
176 176
         return self::$connection->real_escape_string($text);
177 177
     }
178 178
 
@@ -187,7 +187,7 @@  discard block
 block discarded – undo
187 187
      *
188 188
      * @return mysqli_result|bool
189 189
      */
190
-    public static function pureQuery (string $query): mysqli_result|bool {
190
+    public static function pureQuery(string $query): mysqli_result | bool {
191 191
         return self::$connection->query($query);
192 192
     }
193 193
 
@@ -204,7 +204,7 @@  discard block
 block discarded – undo
204 204
      *
205 205
      * @return mysqli_result|bool
206 206
      */
207
-    public static function query (string $query, array $vars = [], bool $need_result = true): mysqli_result|bool {
207
+    public static function query(string $query, array $vars = [], bool $need_result = true): mysqli_result | bool {
208 208
         $prepare = self::$connection->prepare($query);
209 209
         if (!$prepare->execute($vars)) {
210 210
             logger::write(loggerTypes::WARNING, $prepare->error);
@@ -213,7 +213,7 @@  discard block
 block discarded – undo
213 213
         return $need_result ? $prepare->get_result() : true;
214 214
     }
215 215
 
216
-    private static function makeArrayReady (string &$query, array $array, string $operator = ' AND '): array {
216
+    private static function makeArrayReady(string &$query, array $array, string $operator = ' AND '): array {
217 217
         $first = true;
218 218
         $values = [];
219 219
         foreach ($array as $name => $value) {
@@ -229,7 +229,7 @@  discard block
 block discarded – undo
229 229
         return $values;
230 230
     }
231 231
 
232
-    private static function makeQueryReady (string &$query, array $where = null, int $count = null, int $offset = null): array {
232
+    private static function makeQueryReady(string &$query, array $where = null, int $count = null, int $offset = null): array {
233 233
         $values = [];
234 234
         if (!empty($where)) {
235 235
             $query .= " WHERE";
@@ -256,7 +256,7 @@  discard block
 block discarded – undo
256 256
      *
257 257
      * @return mysqli_result|bool
258 258
      */
259
-    public static function delete (string $table, array $where = null, int $count = null, int $offset = null): mysqli_result|bool {
259
+    public static function delete(string $table, array $where = null, int $count = null, int $offset = null): mysqli_result | bool {
260 260
         $query = "DELETE FROM `$table`";
261 261
         $res = self::makeQueryReady($query, $where, $count, $offset);
262 262
         return self::query($query, $res, false);
@@ -275,7 +275,7 @@  discard block
 block discarded – undo
275 275
      *
276 276
      * @return mysqli_result|bool
277 277
      */
278
-    public static function update (string $table, array $modify, array $where = null, int $count = null, int $offset = null): mysqli_result|bool {
278
+    public static function update(string $table, array $modify, array $where = null, int $count = null, int $offset = null): mysqli_result | bool {
279 279
         $query = "UPDATE `$table` SET";
280 280
         $values = self::makeArrayReady($query, $modify, ', ');
281 281
         $res = self::makeQueryReady($query, $where, $count, $offset);
@@ -293,11 +293,11 @@  discard block
 block discarded – undo
293 293
      *
294 294
      * @return mysqli_result|bool
295 295
      */
296
-    public static function insert (string $table, string|array $columns, array|string $values): mysqli_result|bool {
296
+    public static function insert(string $table, string | array $columns, array | string $values): mysqli_result | bool {
297 297
         $query = "INSERT INTO `$table`(";
298
-        $query .= '`' . (is_string($columns) ? $columns : implode('`,`', $columns)) . '`) VALUES (';
298
+        $query .= '`'.(is_string($columns) ? $columns : implode('`,`', $columns)).'`) VALUES (';
299 299
         if (is_string($values)) $values = [$values];
300
-        $query .= '?' . str_repeat(',?', count($values) - 1) . ')';
300
+        $query .= '?'.str_repeat(',?', count($values) - 1).')';
301 301
         return self::query($query, $values, false);
302 302
     }
303 303
 
@@ -315,13 +315,13 @@  discard block
 block discarded – undo
315 315
      *
316 316
      * @return mysqli_result|bool
317 317
      */
318
-    public static function select (string $table, array|string $columns = '*', array $where = null, int $count = null, int $offset = null): mysqli_result|bool {
318
+    public static function select(string $table, array | string $columns = '*', array $where = null, int $count = null, int $offset = null): mysqli_result | bool {
319 319
         $query = "SELECT ";
320 320
         if ($columns == '*') {
321 321
             $query .= "* ";
322 322
         }
323 323
         else {
324
-            $query .= '`' . (is_string($columns) ? $columns : implode('`,`', $columns)) . '` ';
324
+            $query .= '`'.(is_string($columns) ? $columns : implode('`,`', $columns)).'` ';
325 325
         }
326 326
         $query .= "FROM `$table`";
327 327
         $res = self::makeQueryReady($query, $where, $count, $offset);
@@ -339,7 +339,7 @@  discard block
 block discarded – undo
339 339
      *
340 340
      * @return null|bool|array
341 341
      */
342
-    public static function selectArray (string $table, array|string $columns = '*', array $where = null): bool|array|null {
342
+    public static function selectArray(string $table, array | string $columns = '*', array $where = null): bool | array | null {
343 343
         $res = self::select($table, $columns, $where, 1);
344 344
         if ($res) {
345 345
             return $res->fetch_assoc();
@@ -356,7 +356,7 @@  discard block
 block discarded – undo
356 356
      * @param array|string $columns sets column that you want to retrieve , set '*' to retrieve all , default : '*'
357 357
      * @param array|null   $where   Set your ifs default : null
358 358
      */
359
-    public static function selectObject (string $table, array|string $columns = '*', array $where = null) {
359
+    public static function selectObject(string $table, array | string $columns = '*', array $where = null) {
360 360
         $res = self::select($table, $columns, $where, 1);
361 361
         if ($res) {
362 362
             return $res->fetch_object();
@@ -378,7 +378,7 @@  discard block
 block discarded – undo
378 378
      *
379 379
      * @return bool|Generator
380 380
      */
381
-    public static function selectEach (string $table, array|string $columns = '*', array $where = null, int $count = null, int $offset = null): bool|Generator {
381
+    public static function selectEach(string $table, array | string $columns = '*', array $where = null, int $count = null, int $offset = null): bool | Generator {
382 382
         $res = self::select($table, $columns, $where, $count, $offset);
383 383
         if ($res) {
384 384
             while ($row = $res->fetch_assoc()) yield $row;
Please login to merge, or discard this patch.
src/database/json.php 1 patch
Spacing   +79 added lines, -79 removed lines patch added patch discarded remove patch
@@ -103,7 +103,7 @@  discard block
 block discarded – undo
103 103
     /**
104 104
      * @internal Only for BPT self usage , Don't use it in your source!
105 105
      */
106
-    public static function init (): void {
106
+    public static function init(): void {
107 107
         self::$folder = settings::$name.'database';
108 108
         self::$global_default_data = settings::$db['global'] ?? self::$global_default_data;
109 109
         self::setUserDefaultData();
@@ -115,7 +115,7 @@  discard block
 block discarded – undo
115 115
         self::load();
116 116
     }
117 117
 
118
-    private static function setUserDefaultData (): void {
118
+    private static function setUserDefaultData(): void {
119 119
         self::$user_default_data = settings::$db['user'] ?? self::$user_default_data;
120 120
         if (!isset(self::$user_default_data['step'])) {
121 121
             self::$user_default_data['step'] = 'none';
@@ -134,7 +134,7 @@  discard block
 block discarded – undo
134 134
         }
135 135
     }
136 136
 
137
-    private static function setGroupUserDefaultData (): void {
137
+    private static function setGroupUserDefaultData(): void {
138 138
         self::$group_user_default_data = settings::$db['group_user'] ?? self::$group_user_default_data;
139 139
         if (!isset(self::$group_user_default_data['step'])) {
140 140
             self::$group_user_default_data['step'] = 'none';
@@ -162,10 +162,10 @@  discard block
 block discarded – undo
162 162
         }
163 163
 
164 164
         if (!file_exists(self::$folder.'/global.json')) {
165
-            file_put_contents(self::$folder.'/global.json',self::$global_default_data);
165
+            file_put_contents(self::$folder.'/global.json', self::$global_default_data);
166 166
         }
167 167
         if (!file_exists(self::$folder.'/ids.json')) {
168
-            file_put_contents(self::$folder.'/ids.json',json_encode([
168
+            file_put_contents(self::$folder.'/ids.json', json_encode([
169 169
                 'privates' => [],
170 170
                 'groups' => [],
171 171
                 'supergroups' => [],
@@ -174,25 +174,25 @@  discard block
 block discarded – undo
174 174
         }
175 175
     }
176 176
 
177
-    private static function load (): void {
177
+    private static function load(): void {
178 178
         self::$global = json_decode(file_get_contents(self::$folder.'/global.json'));
179 179
         self::$old_global = clone self::$global;
180
-        self::$ids = json_decode(file_get_contents(self::$folder.'/ids.json'),true);
180
+        self::$ids = json_decode(file_get_contents(self::$folder.'/ids.json'), true);
181 181
         self::$old_ids = clone self::$ids;
182 182
     }
183 183
 
184
-    private static function read (string $address) {
184
+    private static function read(string $address) {
185 185
         return file_exists(self::$folder.'/'.$address.'.json') ? json_decode(file_get_contents(self::$folder.'/'.$address.'.json'), false) : null;
186 186
     }
187 187
 
188
-    private static function write (string $address,string $data): void {
189
-        file_put_contents(self::$folder.'/'.$address.'.json',$data);
188
+    private static function write(string $address, string $data): void {
189
+        file_put_contents(self::$folder.'/'.$address.'.json', $data);
190 190
     }
191 191
 
192 192
     /**
193 193
      * @internal Only for BPT self usage , Don't use it in your source!
194 194
      */
195
-    public static function process (): void {
195
+    public static function process(): void {
196 196
         if (isset(BPT::$update->message)) {
197 197
             self::processMessage(BPT::$update->message);
198 198
         }
@@ -215,16 +215,16 @@  discard block
 block discarded – undo
215 215
      */
216 216
     public static function save(): void {
217 217
         if (self::$user !== self::$old_user && !empty(self::$user_id)) {
218
-            self::write('privates/' . self::$user_id,json_encode(self::$user));
218
+            self::write('privates/'.self::$user_id, json_encode(self::$user));
219 219
         }
220 220
         if (self::$group !== self::$old_group && !empty(self::$group_id)) {
221
-            self::write('groups/' . self::$group_id,json_encode(self::$group));
221
+            self::write('groups/'.self::$group_id, json_encode(self::$group));
222 222
         }
223 223
         if (self::$supergroup !== self::$old_supergroup && !empty(self::$supergroup_id)) {
224
-            self::write('supergroups/' . self::$supergroup_id,json_encode(self::$supergroup));
224
+            self::write('supergroups/'.self::$supergroup_id, json_encode(self::$supergroup));
225 225
         }
226 226
         if (self::$channel !== self::$old_channel && !empty(self::$channel_id)) {
227
-            self::write('channels/' . self::$channel_id,json_encode(self::$channel));
227
+            self::write('channels/'.self::$channel_id, json_encode(self::$channel));
228 228
         }
229 229
         if (self::$group_user !== self::$old_group_user && !empty(self::$group_user_id)) {
230 230
             if (empty(self::$group)) {
@@ -235,13 +235,13 @@  discard block
 block discarded – undo
235 235
                 $category = 'groups';
236 236
                 $group_id = self::$group_id;
237 237
             }
238
-            self::write($category . '/' . $group_id . '/' . self::$group_user_id,json_encode(self::$group_user));
238
+            self::write($category.'/'.$group_id.'/'.self::$group_user_id, json_encode(self::$group_user));
239 239
         }
240 240
         if (self::$ids !== self::$old_ids) {
241
-            self::write('ids',json_encode(self::$ids));
241
+            self::write('ids', json_encode(self::$ids));
242 242
         }
243 243
         if (self::$global !== self::$old_global) {
244
-            self::write('global',json_encode(self::$global));
244
+            self::write('global', json_encode(self::$global));
245 245
         }
246 246
         if (self::$group_ids !== self::$old_group_ids) {
247 247
             if (empty(self::$group)) {
@@ -252,17 +252,17 @@  discard block
 block discarded – undo
252 252
                 $category = 'groups';
253 253
                 $group_id = self::$group_id;
254 254
             }
255
-            self::write($category . '/' . $group_id . '/users',json_encode(self::$group_user));
255
+            self::write($category.'/'.$group_id.'/users', json_encode(self::$group_user));
256 256
         }
257 257
     }
258 258
 
259 259
     private static function processMessage(message $update): void {
260 260
         $type = $update->chat->type;
261
-        $category = $type . 's';
261
+        $category = $type.'s';
262 262
         if ($type === chatType::PRIVATE) {
263 263
             self::$user_id = $update->from->id;
264
-            if (in_array(self::$user_id,self::$ids[$category])) {
265
-                self::$user = self::read($category . '/' . self::$user_id);
264
+            if (in_array(self::$user_id, self::$ids[$category])) {
265
+                self::$user = self::read($category.'/'.self::$user_id);
266 266
                 self::$old_user = clone self::$user;
267 267
                 self::$user->last_active = time();
268 268
             }
@@ -270,10 +270,10 @@  discard block
 block discarded – undo
270 270
                 self::$ids[$category][] = self::$user_id;
271 271
                 self::$user = (object) self::$user_default_data;
272 272
                 self::$user->first_active = self::$user->last_active = time();
273
-                if (isset($update->commend) && isset($update->commend_payload) && $update->commend === 'start' && str_starts_with($update->commend_payload,'ref_')) {
274
-                    if (tools::isShorted(substr($update->commend_payload,4))) {
275
-                        $referral = tools::shortDecode(substr($update->commend_payload,4));
276
-                        if (in_array($referral,self::$ids[$category])) {
273
+                if (isset($update->commend) && isset($update->commend_payload) && $update->commend === 'start' && str_starts_with($update->commend_payload, 'ref_')) {
274
+                    if (tools::isShorted(substr($update->commend_payload, 4))) {
275
+                        $referral = tools::shortDecode(substr($update->commend_payload, 4));
276
+                        if (in_array($referral, self::$ids[$category])) {
277 277
                             self::$user->referral = $referral;
278 278
                         }
279 279
                     }
@@ -282,8 +282,8 @@  discard block
 block discarded – undo
282 282
         }
283 283
         elseif ($type === chatType::CHANNEL) {
284 284
             self::$channel_id = $update->chat->id;
285
-            if (in_array(self::$channel_id,self::$ids[$category])) {
286
-                self::$channel = self::read($category . '/' . self::$channel_id);
285
+            if (in_array(self::$channel_id, self::$ids[$category])) {
286
+                self::$channel = self::read($category.'/'.self::$channel_id);
287 287
                 self::$old_channel = clone self::$channel;
288 288
             }
289 289
             else {
@@ -297,10 +297,10 @@  discard block
 block discarded – undo
297 297
             $chat_id = $update->chat->id;
298 298
             if ($type === chatType::SUPERGROUP) {
299 299
                 self::$supergroup_id = $update->chat->id;
300
-                if (in_array($chat_id,self::$ids[$category])) {
301
-                    self::$supergroup = self::read($category . '/' . $chat_id);
300
+                if (in_array($chat_id, self::$ids[$category])) {
301
+                    self::$supergroup = self::read($category.'/'.$chat_id);
302 302
                     self::$old_supergroup = clone self::$supergroup;
303
-                    self::$group_ids = self::read($category . '/' . $chat_id . '/users');
303
+                    self::$group_ids = self::read($category.'/'.$chat_id.'/users');
304 304
                     self::$old_group_ids = clone self::$group_ids;
305 305
                 }
306 306
                 else {
@@ -311,10 +311,10 @@  discard block
 block discarded – undo
311 311
             }
312 312
             else {
313 313
                 self::$group_id = $update->chat->id;
314
-                if (in_array($chat_id,self::$ids[$category])) {
315
-                    self::$group = self::read($category . '/' . $chat_id);
314
+                if (in_array($chat_id, self::$ids[$category])) {
315
+                    self::$group = self::read($category.'/'.$chat_id);
316 316
                     self::$old_group = clone self::$group;
317
-                    self::$group_ids = self::read($category . '/' . $chat_id . '/users');
317
+                    self::$group_ids = self::read($category.'/'.$chat_id.'/users');
318 318
                     self::$old_group_ids = clone self::$group_ids;
319 319
                 }
320 320
                 else {
@@ -324,8 +324,8 @@  discard block
 block discarded – undo
324 324
                 }
325 325
             }
326 326
 
327
-            if (in_array(self::$user_id,self::$group_ids)) {
328
-                self::$group_user = self::read($category . '/' . $chat_id . '/' . self::$user_id);
327
+            if (in_array(self::$user_id, self::$group_ids)) {
328
+                self::$group_user = self::read($category.'/'.$chat_id.'/'.self::$user_id);
329 329
                 self::$old_group_user = clone self::$group_user;
330 330
             }
331 331
             else {
@@ -341,42 +341,42 @@  discard block
 block discarded – undo
341 341
 
342 342
     private static function processCallbackQuery(callbackQuery $update): void {
343 343
         $type = $update->message->chat->type;
344
-        $category = $type . 's';
344
+        $category = $type.'s';
345 345
         if ($type === chatType::PRIVATE) {
346 346
             self::$user_id = $update->from->id;
347
-            if (in_array(self::$user_id,self::$ids[$category])) {
348
-                self::$user = self::read($category . '/' . self::$user_id);
347
+            if (in_array(self::$user_id, self::$ids[$category])) {
348
+                self::$user = self::read($category.'/'.self::$user_id);
349 349
                 self::$old_user = clone self::$user;
350 350
                 self::$user->last_active = time();
351 351
             }
352 352
         }
353 353
         elseif ($type === chatType::CHANNEL) {
354 354
             self::$channel_id = $update->message->chat->id;
355
-            if (in_array(self::$channel_id,self::$ids[$category])) {
356
-                self::$channel = self::read($category . '/' . self::$channel_id);
355
+            if (in_array(self::$channel_id, self::$ids[$category])) {
356
+                self::$channel = self::read($category.'/'.self::$channel_id);
357 357
                 self::$old_channel = clone self::$channel;
358 358
             }
359 359
         }
360 360
         else {
361 361
             self::$user_id = $update->from->id;
362 362
             $chat_id = $update->message->chat->id;
363
-            if (in_array($chat_id,self::$ids[$category])) {
363
+            if (in_array($chat_id, self::$ids[$category])) {
364 364
                 if ($type === chatType::SUPERGROUP) {
365 365
                     self::$supergroup_id = $update->message->chat->id;
366
-                    self::$supergroup = self::read($category . '/' . $chat_id);
366
+                    self::$supergroup = self::read($category.'/'.$chat_id);
367 367
                     self::$old_supergroup = clone self::$supergroup;
368 368
                 }
369 369
                 else {
370 370
                     self::$group_id = $update->message->chat->id;
371
-                    self::$group = self::read($category . '/' . $chat_id);
371
+                    self::$group = self::read($category.'/'.$chat_id);
372 372
                     self::$old_group = clone self::$group;
373 373
                 }
374
-                self::$group_ids = self::read($category . '/' . $chat_id . '/users');
374
+                self::$group_ids = self::read($category.'/'.$chat_id.'/users');
375 375
                 self::$old_group_ids = clone self::$group_ids;
376 376
             }
377 377
 
378
-            if (in_array(self::$user_id,self::$group_ids)) {
379
-                self::$group_user = self::read($category . '/' . $chat_id . '/' . self::$user_id);
378
+            if (in_array(self::$user_id, self::$group_ids)) {
379
+                self::$group_user = self::read($category.'/'.$chat_id.'/'.self::$user_id);
380 380
                 self::$group_user_id = self::$user_id;
381 381
                 self::$old_group_user = clone self::$group_user;
382 382
             }
@@ -390,10 +390,10 @@  discard block
 block discarded – undo
390 390
     private static function processInlineQuery(inlineQuery $update): void {
391 391
         $type = $update->chat_type;
392 392
         if ($type === chatType::PRIVATE || $type === chatType::SENDER) {
393
-            $category = chatType::PRIVATE . 's';
393
+            $category = chatType::PRIVATE.'s';
394 394
             self::$user_id = $update->from->id;
395
-            if (in_array(self::$user_id,self::$ids[$category])) {
396
-                self::$user = self::read($category . '/' . self::$user_id);
395
+            if (in_array(self::$user_id, self::$ids[$category])) {
396
+                self::$user = self::read($category.'/'.self::$user_id);
397 397
                 self::$old_user = clone self::$user;
398 398
                 self::$user->last_active = time();
399 399
             }
@@ -403,11 +403,11 @@  discard block
 block discarded – undo
403 403
     private static function processChatMember(chatMemberUpdated $update): void {
404 404
         $type = $update->chat->type;
405 405
 
406
-        $category = $type . 's';
406
+        $category = $type.'s';
407 407
         if ($type === chatType::CHANNEL) {
408 408
             self::$channel_id = $update->chat->id;
409
-            if (in_array(self::$channel_id,self::$ids[$category])) {
410
-                self::$channel = self::read($category . '/' . self::$channel_id);
409
+            if (in_array(self::$channel_id, self::$ids[$category])) {
410
+                self::$channel = self::read($category.'/'.self::$channel_id);
411 411
                 self::$old_channel = clone self::$channel;
412 412
             }
413 413
             else {
@@ -426,10 +426,10 @@  discard block
 block discarded – undo
426 426
 
427 427
             if ($type === chatType::SUPERGROUP) {
428 428
                 self::$supergroup_id = $chat_id;
429
-                if (in_array($chat_id,self::$ids[$category])) {
430
-                    self::$supergroup = self::read($category . '/' . $chat_id);
429
+                if (in_array($chat_id, self::$ids[$category])) {
430
+                    self::$supergroup = self::read($category.'/'.$chat_id);
431 431
                     self::$old_supergroup = clone self::$supergroup;
432
-                    self::$group_ids = self::read($category . '/' . $chat_id . '/users');
432
+                    self::$group_ids = self::read($category.'/'.$chat_id.'/users');
433 433
                     self::$old_group_ids = clone self::$group_ids;
434 434
                 }
435 435
                 else {
@@ -440,10 +440,10 @@  discard block
 block discarded – undo
440 440
             }
441 441
             elseif ($type === chatType::GROUP) {
442 442
                 self::$group_id = $chat_id;
443
-                if (in_array($chat_id,self::$ids[$category])) {
444
-                    self::$group = self::read($category . '/' . $chat_id);
443
+                if (in_array($chat_id, self::$ids[$category])) {
444
+                    self::$group = self::read($category.'/'.$chat_id);
445 445
                     self::$old_group = clone self::$group;
446
-                    self::$group_ids = self::read($category . '/' . $chat_id . '/users');
446
+                    self::$group_ids = self::read($category.'/'.$chat_id.'/users');
447 447
                     self::$old_group_ids = clone self::$group_ids;
448 448
                 }
449 449
                 else {
@@ -453,13 +453,13 @@  discard block
 block discarded – undo
453 453
                 }
454 454
             }
455 455
 
456
-            if (!in_array($user_id,self::$group_ids)) {
456
+            if (!in_array($user_id, self::$group_ids)) {
457 457
                 self::$group_ids[] = $user_id;
458 458
                 self::$group_user = (object) self::$group_user_default_data;
459 459
             }
460 460
             else {
461 461
                 self::$group_user_id = $by_id == $user_id ? $user_id : $by_id;
462
-                self::$group_user = self::read($category . '/' . $chat_id . '/' . self::$group_user_id);
462
+                self::$group_user = self::read($category.'/'.$chat_id.'/'.self::$group_user_id);
463 463
             }
464 464
 
465 465
             if ($new_user->status === chatMemberStatus::LEFT || $new_user->status === chatMemberStatus::KICKED) {
@@ -500,9 +500,9 @@  discard block
 block discarded – undo
500 500
      * @return bool
501 501
      * @throws bptException
502 502
      */
503
-    public static function deleteUser (int $user_id = null): bool {
503
+    public static function deleteUser(int $user_id = null): bool {
504 504
         if (empty($user_id)) $user_id = telegram::catchFields(fields::USER_ID);
505
-        if (!file_exists(self::$folder . '/privates/' . $user_id . '.json')) {
505
+        if (!file_exists(self::$folder.'/privates/'.$user_id.'.json')) {
506 506
             return false;
507 507
         }
508 508
         unset(self::$ids['privates'][array_search($user_id, self::$ids['privates'])]);
@@ -510,7 +510,7 @@  discard block
 block discarded – undo
510 510
         if ($user_id === self::$user_id) {
511 511
             self::$user = self::$old_user = null;
512 512
         }
513
-        return tools::delete(self::$folder . '/privates/' . $user_id . '.json');
513
+        return tools::delete(self::$folder.'/privates/'.$user_id.'.json');
514 514
     }
515 515
 
516 516
     /**
@@ -521,18 +521,18 @@  discard block
 block discarded – undo
521 521
      * @return bool
522 522
      * @throws bptException
523 523
      */
524
-    public static function deleteGroup (int $group_id = null): bool {
524
+    public static function deleteGroup(int $group_id = null): bool {
525 525
         if (empty($group_id)) $group_id = telegram::catchFields(fields::CHAT_ID);
526
-        if (!file_exists(self::$folder . '/groups/' . $group_id . '.json')) {
526
+        if (!file_exists(self::$folder.'/groups/'.$group_id.'.json')) {
527 527
             return false;
528 528
         }
529 529
         unset(self::$ids['groups'][array_search($group_id, self::$ids['groups'])]);
530 530
         sort(self::$ids['groups']);
531
-        tools::delete(self::$folder . '/groups/' . $group_id);
531
+        tools::delete(self::$folder.'/groups/'.$group_id);
532 532
         if ($group_id === self::$group_id) {
533 533
             self::$group = self::$old_group = null;
534 534
         }
535
-        return tools::delete(self::$folder . '/groups/' . $group_id . '.json');
535
+        return tools::delete(self::$folder.'/groups/'.$group_id.'.json');
536 536
     }
537 537
 
538 538
     /**
@@ -543,18 +543,18 @@  discard block
 block discarded – undo
543 543
      * @return bool
544 544
      * @throws bptException
545 545
      */
546
-    public static function deleteSuperGroup (int $group_id = null): bool {
546
+    public static function deleteSuperGroup(int $group_id = null): bool {
547 547
         if (empty($group_id)) $group_id = telegram::catchFields(fields::CHAT_ID);
548
-        if (!file_exists(self::$folder . '/supergroups/' . $group_id . '.json')) {
548
+        if (!file_exists(self::$folder.'/supergroups/'.$group_id.'.json')) {
549 549
             return false;
550 550
         }
551 551
         unset(self::$ids['supergroups'][array_search($group_id, self::$ids['supergroups'])]);
552 552
         sort(self::$ids['supergroups']);
553
-        tools::delete(self::$folder . '/supergroups/' . $group_id);
553
+        tools::delete(self::$folder.'/supergroups/'.$group_id);
554 554
         if ($group_id === self::$supergroup_id) {
555 555
             self::$supergroup = self::$old_supergroup = null;
556 556
         }
557
-        return tools::delete(self::$folder . '/supergroups/' . $group_id . '.json');
557
+        return tools::delete(self::$folder.'/supergroups/'.$group_id.'.json');
558 558
     }
559 559
 
560 560
     /**
@@ -565,9 +565,9 @@  discard block
 block discarded – undo
565 565
      * @return bool
566 566
      * @throws bptException
567 567
      */
568
-    public static function deleteChannel (int $channel_id = null): bool {
568
+    public static function deleteChannel(int $channel_id = null): bool {
569 569
         if (empty($channel_id)) $channel_id = telegram::catchFields(fields::CHAT_ID);
570
-        if (!file_exists(self::$folder . '/channels/' . $channel_id . '.json')) {
570
+        if (!file_exists(self::$folder.'/channels/'.$channel_id.'.json')) {
571 571
             return false;
572 572
         }
573 573
         unset(self::$ids['channels'][array_search($channel_id, self::$ids['channels'])]);
@@ -575,7 +575,7 @@  discard block
 block discarded – undo
575 575
         if ($channel_id === self::$channel_id) {
576 576
             self::$channel = self::$old_channel = null;
577 577
         }
578
-        return tools::delete(self::$folder . '/channels/' . $channel_id . '.json');
578
+        return tools::delete(self::$folder.'/channels/'.$channel_id.'.json');
579 579
     }
580 580
 
581 581
     /**
@@ -583,7 +583,7 @@  discard block
 block discarded – undo
583 583
      *
584 584
      * @return int[]
585 585
      */
586
-    public static function getUsers (): array {
586
+    public static function getUsers(): array {
587 587
         return self::$ids['privates'] ?? [];
588 588
     }
589 589
 
@@ -592,7 +592,7 @@  discard block
 block discarded – undo
592 592
      *
593 593
      * @return int[]
594 594
      */
595
-    public static function getGroups (): array {
595
+    public static function getGroups(): array {
596 596
         return self::$ids['groups'] ?? [];
597 597
     }
598 598
 
@@ -601,7 +601,7 @@  discard block
 block discarded – undo
601 601
      *
602 602
      * @return int[]
603 603
      */
604
-    public static function getSuperGroups (): array {
604
+    public static function getSuperGroups(): array {
605 605
         return self::$ids['supergroups'] ?? [];
606 606
     }
607 607
 
@@ -610,7 +610,7 @@  discard block
 block discarded – undo
610 610
      *
611 611
      * @return int[]
612 612
      */
613
-    public static function getChannels (): array {
613
+    public static function getChannels(): array {
614 614
         return self::$ids['channels'] ?? [];
615 615
     }
616 616
 }
Please login to merge, or discard this patch.
src/BPT.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -257,13 +257,13 @@  discard block
 block discarded – undo
257 257
  * @method bool|responseError unpinAllForumTopicMessages (int|string|array $chat_id, int $message_thread_id, string|null $token = null, bool|null $forgot = null, bool|null $answer = null) Use this method to clear the list of pinned messages in a forum topic. The bot must be an administrator in the chat for this to work and must have the can_pin_messages administrator right in the supergroup. Returns True on success.
258 258
  * @method bool|responseError unpinTopicMessages (int|string|array $chat_id, int $message_thread_id, string|null $token = null, bool|null $forgot = null, bool|null $answer = null) Use this method to clear the list of pinned messages in a forum topic. The bot must be an administrator in the chat for this to work and must have the can_pin_messages administrator right in the supergroup. Returns True on success.
259 259
  */
260
-class BPT extends telegram{
260
+class BPT extends telegram {
261 261
     public static update $update;
262 262
 
263 263
     public static BPT $handler;
264 264
 
265 265
 
266
-    public function __construct (array|stdClass $settings) {
266
+    public function __construct(array | stdClass $settings) {
267 267
         static::$handler = &$this;
268 268
         settings::init($settings);
269 269
     }
@@ -273,7 +273,7 @@  discard block
 block discarded – undo
273 273
     }
274 274
 
275 275
     #[NoReturn]
276
-    public static function exit (string|null $message = null) {
276
+    public static function exit (string | null $message = null) {
277 277
         die($message ?? "<div style='width:98vw;height:98vh;display:flex;justify-content:center;align-items:center;font-size:25vw'>BPT</div>");
278 278
     }
279 279
 }
Please login to merge, or discard this patch.