Passed
Push — main ( a1dfd6...7044f1 )
by Miaad
01:36
created
tools.php 1 patch
Spacing   +45 added lines, -45 removed lines patch added patch discarded remove patch
@@ -35,7 +35,7 @@  discard block
 block discarded – undo
35 35
      *
36 36
      * @return bool
37 37
      */
38
-    public static function isUsername (string $username): bool {
38
+    public static function isUsername(string $username): bool {
39 39
         $length = strlen($username);
40 40
         return !str_contains($username, '__') && $length >= 5 && $length <= 33 && preg_match('/^@?([a-zA-Z])(\w{4,31})$/', $username);
41 41
     }
@@ -52,7 +52,7 @@  discard block
 block discarded – undo
52 52
      *
53 53
      * @return bool
54 54
      */
55
-    public static function ipInRange (string $ip, string $range): bool {
55
+    public static function ipInRange(string $ip, string $range): bool {
56 56
         if (!str_contains($range, '/')) {
57 57
             $range .= '/32';
58 58
         }
@@ -72,7 +72,7 @@  discard block
 block discarded – undo
72 72
      *
73 73
      * @return bool
74 74
      */
75
-    public static function isTelegram (string $ip): bool {
75
+    public static function isTelegram(string $ip): bool {
76 76
         return self::ipInRange($ip, '149.154.160.0/20') || self::ipInRange($ip, '91.108.4.0/22');
77 77
     }
78 78
 
@@ -87,10 +87,10 @@  discard block
 block discarded – undo
87 87
      *
88 88
      * @return bool
89 89
      */
90
-    public static function isCloudFlare (string $ip): bool {
90
+    public static function isCloudFlare(string $ip): bool {
91 91
         $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', '172.64.0.0/13', '131.0.72.0/22'];
92 92
         foreach ($cf_ips as $cf_ip) {
93
-            if (self::ipInRange($ip,$cf_ip)) {
93
+            if (self::ipInRange($ip, $cf_ip)) {
94 94
                 return true;
95 95
             }
96 96
         }
@@ -110,9 +110,9 @@  discard block
 block discarded – undo
110 110
      *
111 111
      * @return bool|types\user return array when verify is active and token is true array of telegram getMe result
112 112
      */
113
-    public static function isToken (string $token, bool $verify = false): bool|types\user {
113
+    public static function isToken(string $token, bool $verify = false): bool | types\user {
114 114
         if (preg_match('/^(\d{8,10}):[\w\-]{35}$/', $token)) {
115
-            if ($verify){
115
+            if ($verify) {
116 116
                 $res = telegram::me($token);
117 117
                 if (telegram::$status) {
118 118
                     return $res;
@@ -144,14 +144,14 @@  discard block
 block discarded – undo
144 144
      *
145 145
      * @return bool
146 146
      */
147
-    public static function isJoined (array|string|int $ids , int|null $user_id = null): bool {
147
+    public static function isJoined(array | string | int $ids, int | null $user_id = null): bool {
148 148
         if (!is_array($ids)) {
149 149
             $ids = [$ids];
150 150
         }
151 151
         $user_id = $user_id ?? request::catchFields('user_id');
152 152
 
153 153
         foreach ($ids as $id) {
154
-            $check = telegram::getChatMember($id,$user_id);
154
+            $check = telegram::getChatMember($id, $user_id);
155 155
             if (telegram::$status) {
156 156
                 $check = $check->status;
157 157
                 if ($check === chatMemberStatus::LEFT || $check === chatMemberStatus::KICKED) {
@@ -178,7 +178,7 @@  discard block
 block discarded – undo
178 178
      *
179 179
      * @return array keys will be id and values will be bool(null for not founded ids)
180 180
      */
181
-    public static function joinChecker (array|string|int $ids , int|null $user_id = null): array {
181
+    public static function joinChecker(array | string | int $ids, int | null $user_id = null): array {
182 182
         if (!is_array($ids)) {
183 183
             $ids = [$ids];
184 184
         }
@@ -186,7 +186,7 @@  discard block
 block discarded – undo
186 186
 
187 187
         $result = [];
188 188
         foreach ($ids as $id) {
189
-            $check = telegram::getChatMember($id,$user_id);
189
+            $check = telegram::getChatMember($id, $user_id);
190 190
             if (telegram::$status) {
191 191
                 $check = $check->status;
192 192
                 $result[$id] = $check !== chatMemberStatus::LEFT && $check !== chatMemberStatus::KICKED;
@@ -210,10 +210,10 @@  discard block
 block discarded – undo
210 210
      *
211 211
      * @return string
212 212
      */
213
-    public static function randomString (int $length = 16, string $characters = 'aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ'): string {
213
+    public static function randomString(int $length = 16, string $characters = 'aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ'): string {
214 214
         $rand_string = '';
215 215
         $char_len = strlen($characters) - 1;
216
-        for ($i = 0; $i < $length; $i ++) {
216
+        for ($i = 0; $i < $length; $i++) {
217 217
             $rand_string .= $characters[rand(0, $char_len)];
218 218
         }
219 219
         return $rand_string;
@@ -233,10 +233,10 @@  discard block
 block discarded – undo
233 233
      *
234 234
      * @return string|false return false when mode is incorrect
235 235
      */
236
-    public static function modeEscape (string $text, string $mode = parseMode::HTML): string|false {
236
+    public static function modeEscape(string $text, string $mode = parseMode::HTML): string | false {
237 237
         return match ($mode) {
238
-            parseMode::HTML => str_replace(['&', '<', '>',], ["&amp;", "&lt;", "&gt;",], $text),
239
-            parseMode::MARKDOWN => str_replace(['\\', '_', '*', '`', '['], ['\\\\', '\_', '\*', '\`', '\[',], $text),
238
+            parseMode::HTML => str_replace(['&', '<', '>', ], ["&amp;", "&lt;", "&gt;", ], $text),
239
+            parseMode::MARKDOWN => str_replace(['\\', '_', '*', '`', '['], ['\\\\', '\_', '\*', '\`', '\[', ], $text),
240 240
             parseMode::MARKDOWNV2 => str_replace(
241 241
                 ['_', '*', '[', ']', '(', ')', '~', '`', '>', '#', '+', '-', '=', '|', '{', '}', '.', '!', '\\'],
242 242
                 ['\_', '\*', '\[', '\]', '\(', '\)', '\~', '\`', '\>', '\#', '\+', '\-', '\=', '\|', '\{', '\}', '\.', '\!', '\\\\'],
@@ -259,10 +259,10 @@  discard block
 block discarded – undo
259 259
      *
260 260
      * @return string
261 261
      */
262
-    public static function byteFormat (int $byte, int $precision = 2): string {
262
+    public static function byteFormat(int $byte, int $precision = 2): string {
263 263
         $rate_counter = 0;
264 264
 
265
-        while ($byte > 1024){
265
+        while ($byte > 1024) {
266 266
             $byte /= 1024;
267 267
             $rate_counter++;
268 268
         }
@@ -271,7 +271,7 @@  discard block
 block discarded – undo
271 271
             $byte = round($byte, $precision);
272 272
         }
273 273
 
274
-        return $byte . ' ' . ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB'][$rate_counter];
274
+        return $byte.' '.['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB'][$rate_counter];
275 275
     }
276 276
 
277 277
     /**
@@ -288,7 +288,7 @@  discard block
 block discarded – undo
288 288
      *
289 289
      * @return string|int|false string for formatted data , int for normal data , false when size can not be found(file not found or ...)
290 290
      */
291
-    public static function size (string $path, bool $format = true): string|int|false {
291
+    public static function size(string $path, bool $format = true): string | int | false {
292 292
         if (filter_var($path, FILTER_VALIDATE_URL)) {
293 293
             $ch = curl_init($path);
294 294
             curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
@@ -321,7 +321,7 @@  discard block
 block discarded – undo
321 321
      * @return bool
322 322
      * @throws bptException
323 323
      */
324
-    public static function delete (string $path, bool $sub = true): bool {
324
+    public static function delete(string $path, bool $sub = true): bool {
325 325
         if (is_dir($path)) {
326 326
             if (count(scandir($path)) > 2) {
327 327
                 if ($sub) {
@@ -333,7 +333,7 @@  discard block
 block discarded – undo
333 333
                     return rmdir($path);
334 334
                 }
335 335
                 else {
336
-                    logger::write("tools::delete function used\ndelete function cannot delete folder because its have subFiles and sub parameter haven't true value",loggerTypes::ERROR);
336
+                    logger::write("tools::delete function used\ndelete function cannot delete folder because its have subFiles and sub parameter haven't true value", loggerTypes::ERROR);
337 337
                     throw new bptException('DELETE_FOLDER_HAS_SUB');
338 338
                 }
339 339
             }
@@ -357,12 +357,12 @@  discard block
 block discarded – undo
357 357
      * @return array{status: string,year: string,month: string,day: string,hour: string,minute: string,second: string}
358 358
      * @throws Exception
359 359
      */
360
-    public static function timeDiff (int|string $target_time, int|string|null $base_time = null): array {
360
+    public static function timeDiff(int | string $target_time, int | string | null $base_time = null): array {
361 361
         if (empty($base_time)) {
362 362
             $base_time = '@'.time();
363 363
         }
364 364
         $base_time = new DateTime($base_time);
365
-        $target_time = new DateTime(is_numeric($target_time) ? '@' . $target_time : $target_time . ' +00:00');
365
+        $target_time = new DateTime(is_numeric($target_time) ? '@'.$target_time : $target_time.' +00:00');
366 366
 
367 367
         $status = $base_time < $target_time ? 'later' : 'ago';
368 368
         $diff = $base_time->diff($target_time);
@@ -415,7 +415,7 @@  discard block
 block discarded – undo
415 415
      * @return array|string|bool
416 416
      * @throws bptException
417 417
      */
418
-    public static function crypto (string $action, string $text, string $key = null, string $iv = null): bool|array|string {
418
+    public static function crypto(string $action, string $text, string $key = null, string $iv = null): bool | array | string {
419 419
 
420 420
         if (extension_loaded('openssl')) {
421 421
             if ($action === cryptoAction::ENCRYPT) {
@@ -426,11 +426,11 @@  discard block
 block discarded – undo
426 426
             }
427 427
             elseif ($action === cryptoAction::DECRYPT) {
428 428
                 if (empty($key)) {
429
-                    logger::write("tools::crypto function used\nkey parameter is not set",loggerTypes::ERROR);
429
+                    logger::write("tools::crypto function used\nkey parameter is not set", loggerTypes::ERROR);
430 430
                     throw new bptException('ARGUMENT_NOT_FOUND_KEY');
431 431
                 }
432 432
                 if (empty($iv)) {
433
-                    logger::write("tools::crypto function used\niv parameter is not set",loggerTypes::ERROR);
433
+                    logger::write("tools::crypto function used\niv parameter is not set", loggerTypes::ERROR);
434 434
                     throw new bptException('ARGUMENT_NOT_FOUND_IV');
435 435
                 }
436 436
                 return openssl_decrypt(base64_decode($text), 'AES-256-CBC', $key, 1, $iv);
@@ -441,7 +441,7 @@  discard block
 block discarded – undo
441 441
             }
442 442
         }
443 443
         else {
444
-            logger::write("tools::crypto function used\nopenssl extension is not found , It may not be installed or enabled",loggerTypes::ERROR);
444
+            logger::write("tools::crypto function used\nopenssl extension is not found , It may not be installed or enabled", loggerTypes::ERROR);
445 445
             throw new bptException('OPENSSL_EXTENSION_MISSING');
446 446
         }
447 447
     }
@@ -459,7 +459,7 @@  discard block
 block discarded – undo
459 459
      * @return bool
460 460
      * @throws bptException when zip extension not found
461 461
      */
462
-    public static function zip (string $path, string $destination, bool $self = true, bool $sub_folder = true): bool {
462
+    public static function zip(string $path, string $destination, bool $self = true, bool $sub_folder = true): bool {
463 463
         if (extension_loaded('zip')) {
464 464
             if (file_exists($destination)) unlink($destination);
465 465
 
@@ -467,15 +467,15 @@  discard block
 block discarded – undo
467 467
             $zip = new ZipArchive();
468 468
             $zip->open($destination, ZipArchive::CREATE);
469 469
 
470
-            if (is_dir($path)){
471
-                if ($self){
472
-                    $dirs = explode('\\',$path);
470
+            if (is_dir($path)) {
471
+                if ($self) {
472
+                    $dirs = explode('\\', $path);
473 473
                     $dir_count = count($dirs);
474
-                    $main_dir = $dirs[$dir_count-1];
474
+                    $main_dir = $dirs[$dir_count - 1];
475 475
 
476 476
                     $path = '';
477
-                    for ($i=0; $i < $dir_count - 1; $i++) {
478
-                        $path .= '\\' . $dirs[$i];
477
+                    for ($i = 0; $i < $dir_count - 1; $i++) {
478
+                        $path .= '\\'.$dirs[$i];
479 479
                     }
480 480
                     $path = substr($path, 1);
481 481
                     $zip->addEmptyDir($main_dir);
@@ -484,27 +484,27 @@  discard block
 block discarded – undo
484 484
                 $it = new RecursiveDirectoryIterator($path, FilesystemIterator::SKIP_DOTS);
485 485
                 $files = new RecursiveIteratorIterator($it, RecursiveIteratorIterator::SELF_FIRST);
486 486
                 foreach ($files as $file) {
487
-                    if ($file->isFile()){
488
-                        if ($sub_folder){
489
-                            $zip->addFile($file, str_replace($path . '\\', '', $file));
487
+                    if ($file->isFile()) {
488
+                        if ($sub_folder) {
489
+                            $zip->addFile($file, str_replace($path.'\\', '', $file));
490 490
                         }
491
-                        else{
491
+                        else {
492 492
                             $zip->addFile($file, basename($file));
493 493
                         }
494 494
                     }
495 495
                     elseif ($file->isDir() && $sub_folder) {
496
-                        $zip->addEmptyDir(str_replace($path . '\\', '', $file . '\\'));
496
+                        $zip->addEmptyDir(str_replace($path.'\\', '', $file.'\\'));
497 497
                     }
498 498
                 }
499 499
             }
500
-            else{
500
+            else {
501 501
                 $zip->addFile($path, basename($path));
502 502
             }
503 503
 
504 504
             return $zip->close();
505 505
         }
506 506
         else {
507
-            logger::write("tools::zip function used\nzip extension is not found , It may not be installed or enabled",loggerTypes::ERROR);
507
+            logger::write("tools::zip function used\nzip extension is not found , It may not be installed or enabled", loggerTypes::ERROR);
508 508
             throw new bptException('ZIP_EXTENSION_MISSING');
509 509
         }
510 510
     }
@@ -532,12 +532,12 @@  discard block
 block discarded – undo
532 532
      * @return inlineKeyboardMarkup|replyKeyboardMarkup replyKeyboardMarkup for keyboard and inlineKeyboardMarkup for inline
533 533
      * @throws exception
534 534
      */
535
-    public static function easyKey(array $keyboard = [], array $inline = []): inlineKeyboardMarkup|replyKeyboardMarkup {
535
+    public static function easyKey(array $keyboard = [], array $inline = []): inlineKeyboardMarkup | replyKeyboardMarkup {
536 536
         if (!empty($keyboard)) {
537 537
             $keyboard_object = new replyKeyboardMarkup();
538 538
             $keyboard_object->setResize_keyboard($keyboard['resize'] ?? true);
539 539
             if (isset($keyboard['one_time'])) {
540
-                $keyboard_object->setOne_time_keyboard($keyboard['one_time']) ;
540
+                $keyboard_object->setOne_time_keyboard($keyboard['one_time']);
541 541
             }
542 542
             foreach ($keyboard as $row) {
543 543
                 $buttons = [];
@@ -590,7 +590,7 @@  discard block
 block discarded – undo
590 590
             return $keyboard_object;
591 591
         }
592 592
         else {
593
-            logger::write("tools::eKey function used\nkeyboard or inline parameter must be set",loggerTypes::ERROR);
593
+            logger::write("tools::eKey function used\nkeyboard or inline parameter must be set", loggerTypes::ERROR);
594 594
             throw new bptException('ARGUMENT_NOT_FOUND_KEYBOARD_INLINE');
595 595
         }
596 596
     }
Please login to merge, or discard this patch.