Passed
Push — main ( 7044f1...4122b8 )
by Miaad
01:31
created
tools/generator.php 2 patches
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -28,10 +28,10 @@  discard block
 block discarded – undo
28 28
      *
29 29
      * @return string
30 30
      */
31
-    public static function randomString (int $length = 16, string $characters = 'aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ'): string {
31
+    public static function randomString(int $length = 16, string $characters = 'aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ'): string {
32 32
         $rand_string = '';
33 33
         $char_len = strlen($characters) - 1;
34
-        for ($i = 0; $i < $length; $i ++) {
34
+        for ($i = 0; $i < $length; $i++) {
35 35
             $rand_string .= $characters[rand(0, $char_len)];
36 36
         }
37 37
         return $rand_string;
@@ -60,12 +60,12 @@  discard block
 block discarded – undo
60 60
      * @return inlineKeyboardMarkup|replyKeyboardMarkup replyKeyboardMarkup for keyboard and inlineKeyboardMarkup for inline
61 61
      * @throws bptException
62 62
      */
63
-    public static function easyKey(array $keyboard = [], array $inline = []): inlineKeyboardMarkup|replyKeyboardMarkup {
63
+    public static function easyKey(array $keyboard = [], array $inline = []): inlineKeyboardMarkup | replyKeyboardMarkup {
64 64
         if (!empty($keyboard)) {
65 65
             $keyboard_object = new replyKeyboardMarkup();
66 66
             $keyboard_object->setResize_keyboard($keyboard['resize'] ?? true);
67 67
             if (isset($keyboard['one_time'])) {
68
-                $keyboard_object->setOne_time_keyboard($keyboard['one_time']) ;
68
+                $keyboard_object->setOne_time_keyboard($keyboard['one_time']);
69 69
             }
70 70
             foreach ($keyboard as $row) {
71 71
                 $buttons = [];
@@ -118,7 +118,7 @@  discard block
 block discarded – undo
118 118
             return $keyboard_object;
119 119
         }
120 120
         else {
121
-            logger::write("tools::eKey function used\nkeyboard or inline parameter must be set",loggerTypes::ERROR);
121
+            logger::write("tools::eKey function used\nkeyboard or inline parameter must be set", loggerTypes::ERROR);
122 122
             throw new bptException('ARGUMENT_NOT_FOUND_KEYBOARD_INLINE');
123 123
         }
124 124
     }
Please login to merge, or discard this patch.
Braces   +7 added lines, -14 removed lines patch added patch discarded remove patch
@@ -76,15 +76,12 @@  discard block
 block discarded – undo
76 76
                     if (count($button_info) > 1) {
77 77
                         if ($button_info[1] === 'con') {
78 78
                             $button->setRequest_contact(true);
79
-                        }
80
-                        elseif ($button_info[1] === 'loc') {
79
+                        } elseif ($button_info[1] === 'loc') {
81 80
                             $button->setRequest_location(true);
82
-                        }
83
-                        elseif ($button_info[1] === 'poll') {
81
+                        } elseif ($button_info[1] === 'poll') {
84 82
                             $type = $button_info[2] === pollType::QUIZ ? pollType::QUIZ : pollType::REGULAR;
85 83
                             $button->setRequest_poll((new keyboardButtonPollType())->setType($type));
86
-                        }
87
-                        elseif ($button_info[1] === 'web' && isset($button_info[2])) {
84
+                        } elseif ($button_info[1] === 'web' && isset($button_info[2])) {
88 85
                             $url = $button_info[2];
89 86
                             $button->setWeb_app((new webAppInfo())->setUrl($url));
90 87
                         }
@@ -94,8 +91,7 @@  discard block
 block discarded – undo
94 91
                 $keyboard_object->setKeyboard([$buttons]);
95 92
             }
96 93
             return $keyboard_object;
97
-        }
98
-        elseif (!empty($inline)) {
94
+        } elseif (!empty($inline)) {
99 95
             $keyboard_object = new inlineKeyboardMarkup();
100 96
             foreach ($inline as $row) {
101 97
                 $buttons = [];
@@ -104,20 +100,17 @@  discard block
 block discarded – undo
104 100
                     if (isset($button_info[1])) {
105 101
                         if (filter_var($button_info[1], FILTER_VALIDATE_URL) && str_starts_with($button_info[1], 'http')) {
106 102
                             $button->setText($button_info[0])->setUrl($button_info[1]);
107
-                        }
108
-                        else {
103
+                        } else {
109 104
                             $button->setText($button_info[0])->setCallback_data($button_info[1]);
110 105
                         }
111
-                    }
112
-                    else {
106
+                    } else {
113 107
                         $button->setText($button_info[0])->setUrl('https://t.me/BPT_CH');
114 108
                     }
115 109
                 }
116 110
                 $keyboard_object->setInline_keyboard([$buttons]);
117 111
             }
118 112
             return $keyboard_object;
119
-        }
120
-        else {
113
+        } else {
121 114
             logger::write("tools::eKey function used\nkeyboard or inline parameter must be set",loggerTypes::ERROR);
122 115
             throw new bptException('ARGUMENT_NOT_FOUND_KEYBOARD_INLINE');
123 116
         }
Please login to merge, or discard this patch.
tools/encrypt.php 2 patches
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -29,7 +29,7 @@  discard block
 block discarded – undo
29 29
      * @return array|string|bool
30 30
      * @throws bptException
31 31
      */
32
-    public static function crypto (string $action, string $text, string $key = null, string $iv = null): bool|array|string {
32
+    public static function crypto(string $action, string $text, string $key = null, string $iv = null): bool | array | string {
33 33
 
34 34
         if (extension_loaded('openssl')) {
35 35
             if ($action === cryptoAction::ENCRYPT) {
@@ -40,11 +40,11 @@  discard block
 block discarded – undo
40 40
             }
41 41
             elseif ($action === cryptoAction::DECRYPT) {
42 42
                 if (empty($key)) {
43
-                    logger::write("tools::crypto function used\nkey parameter is not set",loggerTypes::ERROR);
43
+                    logger::write("tools::crypto function used\nkey parameter is not set", loggerTypes::ERROR);
44 44
                     throw new bptException('ARGUMENT_NOT_FOUND_KEY');
45 45
                 }
46 46
                 if (empty($iv)) {
47
-                    logger::write("tools::crypto function used\niv parameter is not set",loggerTypes::ERROR);
47
+                    logger::write("tools::crypto function used\niv parameter is not set", loggerTypes::ERROR);
48 48
                     throw new bptException('ARGUMENT_NOT_FOUND_IV');
49 49
                 }
50 50
                 return openssl_decrypt(base64_decode($text), 'AES-256-CBC', $key, 1, $iv);
@@ -55,7 +55,7 @@  discard block
 block discarded – undo
55 55
             }
56 56
         }
57 57
         else {
58
-            logger::write("tools::crypto function used\nopenssl extension is not found , It may not be installed or enabled",loggerTypes::ERROR);
58
+            logger::write("tools::crypto function used\nopenssl extension is not found , It may not be installed or enabled", loggerTypes::ERROR);
59 59
             throw new bptException('OPENSSL_EXTENSION_MISSING');
60 60
         }
61 61
     }
Please login to merge, or discard this patch.
Braces   +3 added lines, -6 removed lines patch added patch discarded remove patch
@@ -37,8 +37,7 @@  discard block
 block discarded – undo
37 37
                 $iv = self::randomString();
38 38
                 $output = base64_encode(openssl_encrypt($text, 'AES-256-CBC', $key, 1, $iv));
39 39
                 return ['hash' => $output, 'key' => $key, 'iv' => $iv];
40
-            }
41
-            elseif ($action === cryptoAction::DECRYPT) {
40
+            } elseif ($action === cryptoAction::DECRYPT) {
42 41
                 if (empty($key)) {
43 42
                     logger::write("tools::crypto function used\nkey parameter is not set",loggerTypes::ERROR);
44 43
                     throw new bptException('ARGUMENT_NOT_FOUND_KEY');
@@ -48,13 +47,11 @@  discard block
 block discarded – undo
48 47
                     throw new bptException('ARGUMENT_NOT_FOUND_IV');
49 48
                 }
50 49
                 return openssl_decrypt(base64_decode($text), 'AES-256-CBC', $key, 1, $iv);
51
-            }
52
-            else {
50
+            } else {
53 51
                 logger::write("tools::crypto function used\naction is not right, its must be `encode` or `decode`");
54 52
                 return false;
55 53
             }
56
-        }
57
-        else {
54
+        } else {
58 55
             logger::write("tools::crypto function used\nopenssl extension is not found , It may not be installed or enabled",loggerTypes::ERROR);
59 56
             throw new bptException('OPENSSL_EXTENSION_MISSING');
60 57
         }
Please login to merge, or discard this patch.
tools/convert.php 2 patches
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -21,10 +21,10 @@  discard block
 block discarded – undo
21 21
      *
22 22
      * @return string
23 23
      */
24
-    public static function byteFormat (int $byte, int $precision = 2): string {
24
+    public static function byteFormat(int $byte, int $precision = 2): string {
25 25
         $rate_counter = 0;
26 26
 
27
-        while ($byte > 1024){
27
+        while ($byte > 1024) {
28 28
             $byte /= 1024;
29 29
             $rate_counter++;
30 30
         }
@@ -33,7 +33,7 @@  discard block
 block discarded – undo
33 33
             $byte = round($byte, $precision);
34 34
         }
35 35
 
36
-        return $byte . ' ' . ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB'][$rate_counter];
36
+        return $byte.' '.['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB'][$rate_counter];
37 37
     }
38 38
 
39 39
     /**
@@ -50,10 +50,10 @@  discard block
 block discarded – undo
50 50
      *
51 51
      * @return string|false return false when mode is incorrect
52 52
      */
53
-    public static function modeEscape (string $text, string $mode = parseMode::HTML): string|false {
53
+    public static function modeEscape(string $text, string $mode = parseMode::HTML): string | false {
54 54
         return match ($mode) {
55
-            parseMode::HTML => str_replace(['&', '<', '>',], ["&amp;", "&lt;", "&gt;",], $text),
56
-            parseMode::MARKDOWN => str_replace(['\\', '_', '*', '`', '['], ['\\\\', '\_', '\*', '\`', '\[',], $text),
55
+            parseMode::HTML => str_replace(['&', '<', '>', ], ["&amp;", "&lt;", "&gt;", ], $text),
56
+            parseMode::MARKDOWN => str_replace(['\\', '_', '*', '`', '['], ['\\\\', '\_', '\*', '\`', '\[', ], $text),
57 57
             parseMode::MARKDOWNV2 => str_replace(
58 58
                 ['_', '*', '[', ']', '(', ')', '~', '`', '>', '#', '+', '-', '=', '|', '{', '}', '.', '!', '\\'],
59 59
                 ['\_', '\*', '\[', '\]', '\(', '\)', '\~', '\`', '\>', '\#', '\+', '\-', '\=', '\|', '\{', '\}', '\.', '\!', '\\\\'],
@@ -92,12 +92,12 @@  discard block
 block discarded – undo
92 92
      * @return array{status: string,year: string,month: string,day: string,hour: string,minute: string,second: string}
93 93
      * @throws Exception
94 94
      */
95
-    public static function timeDiff (int|string $target_time, int|string|null $base_time = null): array {
95
+    public static function timeDiff(int | string $target_time, int | string | null $base_time = null): array {
96 96
         if (empty($base_time)) {
97 97
             $base_time = '@'.time();
98 98
         }
99 99
         $base_time = new DateTime($base_time);
100
-        $target_time = new DateTime(is_numeric($target_time) ? '@' . $target_time : $target_time . ' +00:00');
100
+        $target_time = new DateTime(is_numeric($target_time) ? '@'.$target_time : $target_time.' +00:00');
101 101
 
102 102
         $status = $base_time < $target_time ? 'later' : 'ago';
103 103
         $diff = $base_time->diff($target_time);
Please login to merge, or discard this patch.
Braces   +2 added lines, -1 removed lines patch added patch discarded remove patch
@@ -106,8 +106,9 @@
 block discarded – undo
106 106
         foreach ($string as $k => &$v) {
107 107
             if ($diff->$v) {
108 108
                 $v = $diff->$v;
109
+            } else {
110
+                unset($string[$k]);
109 111
             }
110
-            else unset($string[$k]);
111 112
         }
112 113
         $string['status'] = $status;
113 114
 
Please login to merge, or discard this patch.