Passed
Push — main ( bd6751...4aef09 )
by Miaad
10:17
created
src/telegram/telegram.php 1 patch
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -15,7 +15,7 @@  discard block
 block discarded – undo
15 15
  * telegram class , Adding normal method call to request class and a simple name for being easy to call
16 16
  */
17 17
 class telegram extends request {
18
-    public function __call (string $name, array $arguments) {
18
+    public function __call(string $name, array $arguments) {
19 19
         return request::$name(...$arguments);
20 20
     }
21 21
 
@@ -33,11 +33,11 @@  discard block
 block discarded – undo
33 33
      *
34 34
      * @return bool
35 35
      */
36
-    public static function downloadFile (string|null $destination = null, string|null $file_id = null): bool {
36
+    public static function downloadFile(string | null $destination = null, string | null $file_id = null): bool {
37 37
         return tools::downloadFile(self::fileLink($file_id), $destination);
38 38
     }
39 39
 
40
-    public static function fileLink(string|null $file_id = null): bool|string {
40
+    public static function fileLink(string | null $file_id = null): bool | string {
41 41
         $file = self::getFile($file_id);
42 42
         if (!isset($file->file_path)) {
43 43
             return false;
@@ -59,31 +59,31 @@  discard block
 block discarded – undo
59 59
      *
60 60
      * @return message|bool|responseError
61 61
      */
62
-    public static function sendFile (string $file_id, int|string $chat_id = null, int $message_thread_id = null, string $caption = null, string $parse_mode = null, array $caption_entities = null, bool $disable_notification = null, bool $protect_content = null, int $reply_to_message_id = null, bool $allow_sending_without_reply = null, inlineKeyboardMarkup|replyKeyboardMarkup|replyKeyboardRemove|forceReply|stdClass|array $reply_markup = null, string $token = null, bool $forgot = null, bool $answer = null): message|bool|responseError {
62
+    public static function sendFile(string $file_id, int | string $chat_id = null, int $message_thread_id = null, string $caption = null, string $parse_mode = null, array $caption_entities = null, bool $disable_notification = null, bool $protect_content = null, int $reply_to_message_id = null, bool $allow_sending_without_reply = null, inlineKeyboardMarkup | replyKeyboardMarkup | replyKeyboardRemove | forceReply | stdClass | array $reply_markup = null, string $token = null, bool $forgot = null, bool $answer = null): message | bool | responseError {
63 63
         $type = tools::fileType($file_id);
64 64
         if ($type === fileTypes::VIDEO) {
65
-            return self::sendVideo($file_id,$chat_id,$message_thread_id,null,null,null,null,$caption,$parse_mode,$caption_entities,null,$disable_notification,$protect_content,$reply_to_message_id,$allow_sending_without_reply,$reply_markup,$token,$forgot,$answer);
65
+            return self::sendVideo($file_id, $chat_id, $message_thread_id, null, null, null, null, $caption, $parse_mode, $caption_entities, null, $disable_notification, $protect_content, $reply_to_message_id, $allow_sending_without_reply, $reply_markup, $token, $forgot, $answer);
66 66
         }
67 67
         elseif ($type === fileTypes::VIDEO_NOTE) {
68
-            return self::sendVideoNote($file_id,$chat_id,$message_thread_id,null,null,null,$disable_notification,$protect_content,$reply_to_message_id,$allow_sending_without_reply,$reply_markup,$token,$forgot,$answer);
68
+            return self::sendVideoNote($file_id, $chat_id, $message_thread_id, null, null, null, $disable_notification, $protect_content, $reply_to_message_id, $allow_sending_without_reply, $reply_markup, $token, $forgot, $answer);
69 69
         }
70 70
         elseif ($type === fileTypes::ANIMATION) {
71
-            return self::sendAnimation($file_id,$chat_id,$message_thread_id,null,null,null,null,$caption,$parse_mode,$caption_entities,$disable_notification,$protect_content,$reply_to_message_id,$allow_sending_without_reply,$reply_markup,$token,$forgot,$answer);
71
+            return self::sendAnimation($file_id, $chat_id, $message_thread_id, null, null, null, null, $caption, $parse_mode, $caption_entities, $disable_notification, $protect_content, $reply_to_message_id, $allow_sending_without_reply, $reply_markup, $token, $forgot, $answer);
72 72
         }
73 73
         elseif ($type === fileTypes::AUDIO) {
74
-            return self::sendAudio($file_id,$chat_id,$message_thread_id,$caption,$parse_mode,$caption_entities,null,null,null,null,$disable_notification,$protect_content,$reply_to_message_id,$allow_sending_without_reply,$reply_markup,$token,$forgot,$answer);
74
+            return self::sendAudio($file_id, $chat_id, $message_thread_id, $caption, $parse_mode, $caption_entities, null, null, null, null, $disable_notification, $protect_content, $reply_to_message_id, $allow_sending_without_reply, $reply_markup, $token, $forgot, $answer);
75 75
         }
76 76
         elseif ($type === fileTypes::PHOTO || $type === fileTypes::PROFILE_PHOTO) {
77
-            return self::sendPhoto($file_id,$chat_id,$message_thread_id,$caption,$parse_mode,$caption_entities,$disable_notification,$protect_content,$reply_to_message_id,$allow_sending_without_reply,$reply_markup,$token,$forgot,$answer);
77
+            return self::sendPhoto($file_id, $chat_id, $message_thread_id, $caption, $parse_mode, $caption_entities, $disable_notification, $protect_content, $reply_to_message_id, $allow_sending_without_reply, $reply_markup, $token, $forgot, $answer);
78 78
         }
79 79
         elseif ($type === fileTypes::VOICE) {
80
-            return self::sendVoice($file_id,$chat_id,$message_thread_id,$caption,$parse_mode,$caption_entities,null,$disable_notification,$protect_content,$reply_to_message_id,$allow_sending_without_reply,$reply_markup,$token,$forgot,$answer);
80
+            return self::sendVoice($file_id, $chat_id, $message_thread_id, $caption, $parse_mode, $caption_entities, null, $disable_notification, $protect_content, $reply_to_message_id, $allow_sending_without_reply, $reply_markup, $token, $forgot, $answer);
81 81
         }
82 82
         elseif ($type === fileTypes::STICKER) {
83
-            return self::sendSticker($file_id,$chat_id,$message_thread_id,$disable_notification,$protect_content,$reply_to_message_id,$allow_sending_without_reply,$reply_markup,$token,$forgot,$answer);
83
+            return self::sendSticker($file_id, $chat_id, $message_thread_id, $disable_notification, $protect_content, $reply_to_message_id, $allow_sending_without_reply, $reply_markup, $token, $forgot, $answer);
84 84
         }
85 85
         elseif ($type === fileTypes::DOCUMENT) {
86
-            return self::sendDocument($file_id,$chat_id,$message_thread_id,null,$caption,$parse_mode,$caption_entities,null,$disable_notification,$protect_content,$reply_to_message_id,$allow_sending_without_reply,$reply_markup,$token,$forgot,$answer);
86
+            return self::sendDocument($file_id, $chat_id, $message_thread_id, null, $caption, $parse_mode, $caption_entities, null, $disable_notification, $protect_content, $reply_to_message_id, $allow_sending_without_reply, $reply_markup, $token, $forgot, $answer);
87 87
         }
88 88
         else return false;
89 89
     }
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);
@@ -283,7 +283,7 @@  discard block
 block discarded – undo
283 283
      * @return bool
284 284
      * @throws bptException
285 285
      */
286
-    public static function delete (string $path, bool $sub = true): bool {
286
+    public static function delete(string $path, bool $sub = true): bool {
287 287
         $path = realpath($path);
288 288
         if (!is_dir($path)) {
289 289
             return unlink($path);
@@ -292,7 +292,7 @@  discard block
 block discarded – undo
292 292
             return rmdir($path);
293 293
         }
294 294
         if (!$sub) {
295
-            logger::write("tools::delete function used\ndelete function cannot delete folder because its have subFiles and sub parameter haven't true value",loggerTypes::ERROR);
295
+            logger::write("tools::delete function used\ndelete function cannot delete folder because its have subFiles and sub parameter haven't true value", loggerTypes::ERROR);
296 296
             throw new bptException('DELETE_FOLDER_HAS_SUB');
297 297
         }
298 298
         $it = new RecursiveDirectoryIterator($path, FilesystemIterator::SKIP_DOTS);
@@ -314,7 +314,7 @@  discard block
 block discarded – undo
314 314
      * @return bool
315 315
      * @throws bptException when zip extension not found
316 316
      */
317
-    public static function zip (string $path, string $destination): bool {
317
+    public static function zip(string $path, string $destination): bool {
318 318
         if (!extension_loaded('zip')) {
319 319
             logger::write("tools::zip function used\nzip extension is not found , It may not be installed or enabled", loggerTypes::ERROR);
320 320
             throw new bptException('ZIP_EXTENSION_MISSING');
@@ -349,14 +349,14 @@  discard block
 block discarded – undo
349 349
      *
350 350
      * @return bool true on success and false in failure
351 351
      */
352
-    public static function downloadFile (string $url, string $path,int $chunk_size = 512): bool {
352
+    public static function downloadFile(string $url, string $path, int $chunk_size = 512): bool {
353 353
         $file = fopen($url, 'rb');
354 354
         if (!$file) return false;
355 355
         $path = fopen($path, 'wb');
356 356
         if (!$path) return false;
357 357
 
358 358
         $length = $chunk_size * 1024;
359
-        while (!feof($file)){
359
+        while (!feof($file)) {
360 360
             fwrite($path, fread($file, $length), $length);
361 361
         }
362 362
         fclose($path);
@@ -379,10 +379,10 @@  discard block
 block discarded – undo
379 379
      *
380 380
      * @return string
381 381
      */
382
-    public static function byteFormat (int $byte, int $precision = 2, bool $space_between = true): string {
382
+    public static function byteFormat(int $byte, int $precision = 2, bool $space_between = true): string {
383 383
         $rate_counter = 0;
384 384
 
385
-        while ($byte > 1024){
385
+        while ($byte > 1024) {
386 386
             $byte /= 1024;
387 387
             $rate_counter++;
388 388
         }
@@ -391,7 +391,7 @@  discard block
 block discarded – undo
391 391
             $byte = round($byte, $precision);
392 392
         }
393 393
 
394
-        return $byte . ($space_between ? ' ' : '') . ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB'][$rate_counter];
394
+        return $byte.($space_between ? ' ' : '').['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB'][$rate_counter];
395 395
     }
396 396
 
397 397
     /**
@@ -408,10 +408,10 @@  discard block
 block discarded – undo
408 408
      *
409 409
      * @return string|false return false when mode is incorrect
410 410
      */
411
-    public static function modeEscape (string $text, string $mode = parseMode::HTML): string|false {
411
+    public static function modeEscape(string $text, string $mode = parseMode::HTML): string | false {
412 412
         return match ($mode) {
413
-            parseMode::HTML => str_replace(['&', '<', '>',], ["&amp;", "&lt;", "&gt;",], $text),
414
-            parseMode::MARKDOWN => str_replace(['\\', '_', '*', '`', '['], ['\\\\', '\_', '\*', '\`', '\[',], $text),
413
+            parseMode::HTML => str_replace(['&', '<', '>', ], ["&amp;", "&lt;", "&gt;", ], $text),
414
+            parseMode::MARKDOWN => str_replace(['\\', '_', '*', '`', '['], ['\\\\', '\_', '\*', '\`', '\[', ], $text),
415 415
             parseMode::MARKDOWNV2 => str_replace(
416 416
                 ['_', '*', '[', ']', '(', ')', '~', '`', '>', '#', '+', '-', '=', '|', '{', '}', '.', '!', '\\'],
417 417
                 ['\_', '\*', '\[', '\]', '\(', '\)', '\~', '\`', '\>', '\#', '\+', '\-', '\=', '\|', '\{', '\}', '\.', '\!', '\\\\'],
@@ -450,12 +450,12 @@  discard block
 block discarded – undo
450 450
      * @return array{status: string,year: string,month: string,day: string,hour: string,minute: string,second: string}
451 451
      * @throws Exception
452 452
      */
453
-    public static function timeDiff (int|string $target_time, int|string|null $base_time = null): array {
453
+    public static function timeDiff(int | string $target_time, int | string | null $base_time = null): array {
454 454
         if (!isset($base_time)) {
455 455
             $base_time = '@'.time();
456 456
         }
457 457
         $base_time = new DateTime($base_time);
458
-        $target_time = new DateTime(is_numeric($target_time) ? '@' . $target_time : $target_time . ' +00:00');
458
+        $target_time = new DateTime(is_numeric($target_time) ? '@'.$target_time : $target_time.' +00:00');
459 459
 
460 460
         $diff = $base_time->diff($target_time);
461 461
 
@@ -482,12 +482,12 @@  discard block
 block discarded – undo
482 482
      *
483 483
      * @return string[]|string
484 484
      */
485
-    public static function realEscapeString(string|array $input): string|array {
486
-        if(is_array($input)) {
485
+    public static function realEscapeString(string | array $input): string | array {
486
+        if (is_array($input)) {
487 487
             return array_map(__METHOD__, $input);
488 488
         }
489 489
 
490
-        if(!empty($input) && is_string($input)) {
490
+        if (!empty($input) && is_string($input)) {
491 491
             return str_replace(['\\', "\0", "\n", "\r", "'", '"', "\x1a"], ['\\\\', '\\0', '\\n', '\\r', "\\'", '\\"', '\\Z'], $input);
492 492
         }
493 493
 
@@ -505,7 +505,7 @@  discard block
 block discarded – undo
505 505
      *
506 506
      * @return string[]|string
507 507
      */
508
-    public static function strReplaceFirst(string|array $search, string|array $replace, string|array $subject): string|array {
508
+    public static function strReplaceFirst(string | array $search, string | array $replace, string | array $subject): string | array {
509 509
         $pos = strpos($subject, $search);
510 510
         if ($pos !== false) {
511 511
             return substr_replace($subject, $replace, $pos, strlen($search));
@@ -522,7 +522,7 @@  discard block
 block discarded – undo
522 522
      *
523 523
      * @return string see possible values in fileType class
524 524
      */
525
-    public static function fileType (string $file_id): string {
525
+    public static function fileType(string $file_id): string {
526 526
         $data = base64_decode(str_pad(strtr($file_id, '-_', '+/'), strlen($file_id) % 4, '='));
527 527
         $new = '';
528 528
         $last = '';
@@ -536,7 +536,7 @@  discard block
 block discarded – undo
536 536
                 $last = $char;
537 537
             }
538 538
         }
539
-        $data = unpack('VtypeId/Vdc_id', $new . $last);
539
+        $data = unpack('VtypeId/Vdc_id', $new.$last);
540 540
         $data['typeId'] = $data['typeId'] & ~33554432 & ~16777216;
541 541
         return [
542 542
             fileTypes::THUMBNAIL,
@@ -574,10 +574,10 @@  discard block
 block discarded – undo
574 574
      *
575 575
      * @return string
576 576
      */
577
-    public static function randomString (int $length = 16, string $characters = 'aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ'): string {
577
+    public static function randomString(int $length = 16, string $characters = 'aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ'): string {
578 578
         $rand_string = '';
579 579
         $char_len = strlen($characters) - 1;
580
-        for ($i = 0; $i < $length; $i ++) {
580
+        for ($i = 0; $i < $length; $i++) {
581 581
             $rand_string .= $characters[rand(0, $char_len)];
582 582
         }
583 583
         return $rand_string;
@@ -606,7 +606,7 @@  discard block
 block discarded – undo
606 606
      * @return inlineKeyboardMarkup|replyKeyboardMarkup replyKeyboardMarkup for keyboard and inlineKeyboardMarkup for inline
607 607
      * @throws bptException
608 608
      */
609
-    public static function easyKey(array $keyboard = [], array $inline = []): inlineKeyboardMarkup|replyKeyboardMarkup {
609
+    public static function easyKey(array $keyboard = [], array $inline = []): inlineKeyboardMarkup | replyKeyboardMarkup {
610 610
         if (!empty($keyboard)) {
611 611
             $keyboard_object = new replyKeyboardMarkup();
612 612
             $keyboard_object->setResize_keyboard($keyboard['resize'] ?? true);
@@ -670,7 +670,7 @@  discard block
 block discarded – undo
670 670
             return $keyboard_object;
671 671
         }
672 672
         else {
673
-            logger::write("tools::eKey function used\nkeyboard or inline parameter must be set",loggerTypes::ERROR);
673
+            logger::write("tools::eKey function used\nkeyboard or inline parameter must be set", loggerTypes::ERROR);
674 674
             throw new bptException('ARGUMENT_NOT_FOUND_KEYBOARD_INLINE');
675 675
         }
676 676
     }
@@ -687,10 +687,10 @@  discard block
 block discarded – undo
687 687
      *
688 688
      * @return string
689 689
      */
690
-    public static function inviteLink (int $user_id = null, string $bot_username = null): string {
690
+    public static function inviteLink(int $user_id = null, string $bot_username = null): string {
691 691
         if (empty($user_id)) $user_id = telegram::catchFields(fields::USER_ID);
692 692
         if (empty($bot_username)) $bot_username = telegram::getMe()->username;
693
-        return 'https://t.me/' . str_replace('@', '', $bot_username) . '?start=ref_' . tools::shortEncode($user_id);
693
+        return 'https://t.me/'.str_replace('@', '', $bot_username).'?start=ref_'.tools::shortEncode($user_id);
694 694
     }
695 695
 
696 696
     /**
@@ -714,9 +714,9 @@  discard block
 block discarded – undo
714 714
      * @return string|bool|array{hash:string, key:string, iv:string}
715 715
      * @throws bptException
716 716
      */
717
-    public static function crypto (string $action, string $text, string $key = null, string $iv = null): bool|array|string {
717
+    public static function crypto(string $action, string $text, string $key = null, string $iv = null): bool | array | string {
718 718
         if (!extension_loaded('openssl')) {
719
-            logger::write("tools::crypto function used\nopenssl extension is not found , It may not be installed or enabled",loggerTypes::ERROR);
719
+            logger::write("tools::crypto function used\nopenssl extension is not found , It may not be installed or enabled", loggerTypes::ERROR);
720 720
             throw new bptException('OPENSSL_EXTENSION_MISSING');
721 721
         }
722 722
         if ($action === cryptoAction::ENCRYPT) {
@@ -727,17 +727,17 @@  discard block
 block discarded – undo
727 727
         }
728 728
         elseif ($action === cryptoAction::DECRYPT) {
729 729
             if (empty($key)) {
730
-                logger::write("tools::crypto function used\nkey parameter is not set",loggerTypes::ERROR);
730
+                logger::write("tools::crypto function used\nkey parameter is not set", loggerTypes::ERROR);
731 731
                 throw new bptException('ARGUMENT_NOT_FOUND_KEY');
732 732
             }
733 733
             if (empty($iv)) {
734
-                logger::write("tools::crypto function used\niv parameter is not set",loggerTypes::ERROR);
734
+                logger::write("tools::crypto function used\niv parameter is not set", loggerTypes::ERROR);
735 735
                 throw new bptException('ARGUMENT_NOT_FOUND_IV');
736 736
             }
737 737
             return openssl_decrypt(base64_decode($text), 'AES-256-CBC', $key, 1, $iv);
738 738
         }
739 739
         else {
740
-            logger::write("tools::crypto function used\naction is not right, its must be `encode` or `decode`",loggerTypes::WARNING);
740
+            logger::write("tools::crypto function used\naction is not right, its must be `encode` or `decode`", loggerTypes::WARNING);
741 741
             return false;
742 742
         }
743 743
     }
@@ -754,7 +754,7 @@  discard block
 block discarded – undo
754 754
     public static function shortEncode(int $num): string {
755 755
         $codes = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
756 756
         $array = [];
757
-        while ($num > 0){
757
+        while ($num > 0) {
758 758
             $array[] = $num % 62;
759 759
             $num = floor($num / 62);
760 760
         }
@@ -762,7 +762,7 @@  discard block
 block discarded – undo
762 762
         foreach ($array as &$value) {
763 763
             $value = $codes[$value];
764 764
         }
765
-        return strrev(implode('',$array));
765
+        return strrev(implode('', $array));
766 766
     }
767 767
 
768 768
     /**
@@ -779,7 +779,7 @@  discard block
 block discarded – undo
779 779
         $num = 0;
780 780
         $text = str_split(strrev($text));
781 781
         foreach ($text as $key=>$value) {
782
-            $num += strpos($codes,$value) * pow(62,$key);
782
+            $num += strpos($codes, $value) * pow(62, $key);
783 783
         }
784 784
         return $num;
785 785
     }
Please login to merge, or discard this patch.
src/logger.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -17,7 +17,7 @@  discard block
 block discarded – undo
17 17
     /**
18 18
      * @internal Only for BPT self usage , Don't use it in your source!
19 19
      */
20
-    public static function init (int $log_size = 10): void {
20
+    public static function init(int $log_size = 10): void {
21 21
         self::$log_size = $log_size;
22 22
         $log_file = realpath(settings::$name.'BPT.log');
23 23
         if (file_exists($log_file) && !(filesize($log_file) > self::$log_size * 1024 * 1024)) {
@@ -31,7 +31,7 @@  discard block
 block discarded – undo
31 31
         self::$handler = fopen($log_file, $mode);
32 32
 
33 33
         if ($write) {
34
-            fwrite(self::$handler,"♥♥♥♥♥♥♥♥♥♥♥♥♥♥ BPT Library  ♥♥♥♥♥♥♥♥♥♥♥♥♥♥\nTnx for using our library\nSome information about us :\nAuthor : @Im_Miaad\nHelper : @A_LiReza_ME\nChannel : @BPT_CH\nOur Website : https://bptlib.ir\n\nIf you have any problem with our library\nContact to our supports\n♥♥♥♥♥♥♥♥♥♥♥♥♥♥ BPT Library  ♥♥♥♥♥♥♥♥♥♥♥♥♥♥\nINFO : BPT Library LOG STARTED ...\nwarning : this file automatically deleted when its size reached log_size setting, do not delete it manually\n\n");
34
+            fwrite(self::$handler, "♥♥♥♥♥♥♥♥♥♥♥♥♥♥ BPT Library  ♥♥♥♥♥♥♥♥♥♥♥♥♥♥\nTnx for using our library\nSome information about us :\nAuthor : @Im_Miaad\nHelper : @A_LiReza_ME\nChannel : @BPT_CH\nOur Website : https://bptlib.ir\n\nIf you have any problem with our library\nContact to our supports\n♥♥♥♥♥♥♥♥♥♥♥♥♥♥ BPT Library  ♥♥♥♥♥♥♥♥♥♥♥♥♥♥\nINFO : BPT Library LOG STARTED ...\nwarning : this file automatically deleted when its size reached log_size setting, do not delete it manually\n\n");
35 35
         }
36 36
 
37 37
         if (self::$waited_logs != []) {
@@ -52,7 +52,7 @@  discard block
 block discarded – undo
52 52
      * @return void
53 53
      */
54 54
     public static function write(string $data, string $type = loggerTypes::NONE): void {
55
-        $text = date('Y/m/d H:i:s') . ( $type === loggerTypes::NONE ? " : $data\n\n" : " : ⤵\n$type : $data\n\n" );
55
+        $text = date('Y/m/d H:i:s').($type === loggerTypes::NONE ? " : $data\n\n" : " : ⤵\n$type : $data\n\n");
56 56
         if (!is_null(self::$handler)) {
57 57
             fwrite(self::$handler, $text);
58 58
         }
Please login to merge, or discard this patch.
src/receiver/webhook.php 1 patch
Spacing   +11 added lines, -11 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
     }
@@ -115,7 +115,7 @@  discard block
 block discarded – undo
115 115
      *
116 116
      * @return bool
117 117
      */
118
-    public static function fastClose (int $timeout = 86400): bool {
118
+    public static function fastClose(int $timeout = 86400): bool {
119 119
         if (settings::$multi || !lock::exist('BPT-HOOK')) {
120 120
             return false;
121 121
         }
Please login to merge, or discard this patch.