Passed
Push — main ( 006c6c...060baa )
by Miaad
02:32
created
src/receiver/webhook.php 2 patches
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -13,7 +13,7 @@  discard block
 block discarded – undo
13 13
 use CURLFile;
14 14
 
15 15
 class webhook extends receiver {
16
-    public static function init () {
16
+    public static function init() {
17 17
         if (settings::$multi) {
18 18
             multi::init();
19 19
         }
@@ -42,26 +42,26 @@  discard block
 block discarded – undo
42 42
         }
43 43
     }
44 44
 
45
-    protected static function setWebhook(string $url,string $secret = '') {
45
+    protected static function setWebhook(string $url, string $secret = '') {
46 46
         $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);
47 47
         if (telegram::$status) {
48
-            logger::write('Webhook was set successfully',loggerTypes::INFO);
48
+            logger::write('Webhook was set successfully', loggerTypes::INFO);
49 49
         }
50 50
         else {
51
-            logger::write("There is some problem happened , telegram response : \n".json_encode($res),loggerTypes::ERROR);
52
-            BPT::exit(print_r($res,true));
51
+            logger::write("There is some problem happened , telegram response : \n".json_encode($res), loggerTypes::ERROR);
52
+            BPT::exit(print_r($res, true));
53 53
         }
54 54
     }
55 55
 
56 56
     protected static function checkURL() {
57 57
         if (!(isset($_SERVER['SERVER_NAME']) && isset($_SERVER['REQUEST_URI']))) {
58
-            logger::write('For using webhook receiver , you should open this file in your webserver(by domain)',loggerTypes::ERROR);
58
+            logger::write('For using webhook receiver , you should open this file in your webserver(by domain)', loggerTypes::ERROR);
59 59
             throw new bptException('WEBHOOK_NEED_URL');
60 60
         }
61 61
     }
62 62
 
63 63
     private static function setURL(): string {
64
-        return (isset(settings::$certificate) ? 'http://' : 'https://') . $_SERVER['SERVER_NAME'] . $_SERVER['SCRIPT_NAME'];
64
+        return (isset(settings::$certificate) ? 'http://' : 'https://').$_SERVER['SERVER_NAME'].$_SERVER['SCRIPT_NAME'];
65 65
     }
66 66
 
67 67
     protected static function setCertificate() {
@@ -83,15 +83,15 @@  discard block
 block discarded – undo
83 83
         self::setCertificate();
84 84
         $url = self::setURL();
85 85
         $secret = settings::$secret ?? tools::randomString(64);
86
-        self::setWebhook($url,$secret);
87
-        lock::save('BPT-HOOK',$secret);
86
+        self::setWebhook($url, $secret);
87
+        lock::save('BPT-HOOK', $secret);
88 88
         BPT::exit('Done');
89 89
     }
90 90
 
91 91
     private static function checkSecret() {
92 92
         $secret = lock::read('BPT-HOOK');
93 93
         if ($secret !== self::getSecret()) {
94
-            logger::write('This is not webhook set by BPT, webhook will reset',loggerTypes::WARNING);
94
+            logger::write('This is not webhook set by BPT, webhook will reset', loggerTypes::WARNING);
95 95
             self::processSetWebhook();
96 96
         }
97 97
     }
Please login to merge, or discard this patch.
Braces   +4 added lines, -8 removed lines patch added patch discarded remove patch
@@ -16,15 +16,13 @@  discard block
 block discarded – undo
16 16
     public static function init () {
17 17
         if (settings::$multi) {
18 18
             multi::init();
19
-        }
20
-        else {
19
+        } else {
21 20
             if (lock::exist('BPT-HOOK')) {
22 21
                 receiver::telegramVerify();
23 22
                 self::checkSecret();
24 23
                 receiver::processUpdate();
25 24
                 logger::write('Update received , lets process it ;)');
26
-            }
27
-            else {
25
+            } else {
28 26
                 self::processSetWebhook();
29 27
             }
30 28
         }
@@ -46,8 +44,7 @@  discard block
 block discarded – undo
46 44
         $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);
47 45
         if (telegram::$status) {
48 46
             logger::write('Webhook was set successfully',loggerTypes::INFO);
49
-        }
50
-        else {
47
+        } else {
51 48
             logger::write("There is some problem happened , telegram response : \n".json_encode($res),loggerTypes::ERROR);
52 49
             BPT::exit(print_r($res,true));
53 50
         }
@@ -69,8 +66,7 @@  discard block
 block discarded – undo
69 66
             if (is_string(settings::$certificate)) {
70 67
                 if (file_exists(settings::$certificate)) {
71 68
                     settings::$certificate = new CURLFile(settings::$certificate);
72
-                }
73
-                else {
69
+                } else {
74 70
                     settings::$certificate = null;
75 71
                 }
76 72
             }
Please login to merge, or discard this patch.
src/receiver/receiver.php 2 patches
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -22,13 +22,13 @@  discard block
 block discarded – undo
22 22
     protected static function telegramVerify(string $ip = null) {
23 23
         if (settings::$telegram_verify) {
24 24
             if (!tools::isTelegram($ip ?? $_SERVER['REMOTE_ADDR'] ?? '')) {
25
-                logger::write('not authorized access denied. IP : '. $ip ?? $_SERVER['REMOTE_ADDR'] ?? 'unknown',loggerTypes::WARNING);
25
+                logger::write('not authorized access denied. IP : '.$ip ?? $_SERVER['REMOTE_ADDR'] ?? 'unknown', loggerTypes::WARNING);
26 26
                 BPT::exit();
27 27
             }
28 28
         }
29 29
     }
30 30
 
31
-    protected static function processUpdate(string|stdClass|update $update = null) {
31
+    protected static function processUpdate(string | stdClass | update $update = null) {
32 32
         if (!is_object($update)) {
33 33
             $update = json_decode($update ?? file_get_contents("php://input"));
34 34
             if (!$update) {
@@ -36,7 +36,7 @@  discard block
 block discarded – undo
36 36
             }
37 37
         }
38 38
 
39
-        if (!is_a($update,'update')) {
39
+        if (!is_a($update, 'update')) {
40 40
             $update = new update($update);
41 41
         }
42 42
 
@@ -45,7 +45,7 @@  discard block
 block discarded – undo
45 45
         self::processHandler();
46 46
     }
47 47
 
48
-    protected static function setMessageExtra (update &$update) {
48
+    protected static function setMessageExtra(update & $update) {
49 49
         if ((isset($update->message) && isset($update->message->text)) || (isset($update->edited_message) && isset($update->edited_message->text))) {
50 50
             $type = isset($update->message) ? 'message' : 'edited_message';
51 51
             $text = &$update->$type->text;
@@ -93,7 +93,7 @@  discard block
 block discarded – undo
93 93
                 BPT::$handler->something_else(BPT::$update);
94 94
             }
95 95
             else {
96
-                logger::write('Update received but handlers does not set',loggerTypes::WARNING);
96
+                logger::write('Update received but handlers does not set', loggerTypes::WARNING);
97 97
             }
98 98
         }
99 99
     }
Please login to merge, or discard this patch.
Braces   +5 added lines, -10 removed lines patch added patch discarded remove patch
@@ -73,26 +73,21 @@
 block discarded – undo
73 73
                 if (self::handlerExist('message')) {
74 74
                     BPT::$handler->message(BPT::$update->message);
75 75
                 }
76
-            }
77
-            elseif (isset(BPT::$update->callback_query)) {
76
+            } elseif (isset(BPT::$update->callback_query)) {
78 77
                 if (self::handlerExist('callback_query')) {
79 78
                     BPT::$handler->callback_query(BPT::$update->callback_query);
80 79
                 }
81
-            }
82
-            elseif (isset(BPT::$update->inline_query)) {
80
+            } elseif (isset(BPT::$update->inline_query)) {
83 81
                 if (self::handlerExist('inline_query')) {
84 82
                     BPT::$handler->inline_query(BPT::$update->inline_query);
85 83
                 }
86
-            }
87
-            elseif (isset(BPT::$update->edited_message)) {
84
+            } elseif (isset(BPT::$update->edited_message)) {
88 85
                 if (self::handlerExist('edited_message')) {
89 86
                     BPT::$handler->edited_message(BPT::$update->edited_message);
90 87
                 }
91
-            }
92
-            elseif (self::handlerExist('something_else')) {
88
+            } elseif (self::handlerExist('something_else')) {
93 89
                 BPT::$handler->something_else(BPT::$update);
94
-            }
95
-            else {
90
+            } else {
96 91
                 logger::write('Update received but handlers does not set',loggerTypes::WARNING);
97 92
             }
98 93
         }
Please login to merge, or discard this patch.
src/tools/is.php 1 patch
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -20,7 +20,7 @@  discard block
 block discarded – undo
20 20
      *
21 21
      * @return bool
22 22
      */
23
-    public static function isUsername (string $username): bool {
23
+    public static function isUsername(string $username): bool {
24 24
         $length = strlen($username);
25 25
         return !str_contains($username, '__') && $length >= 5 && $length <= 33 && preg_match('/^@?([a-zA-Z])(\w{4,31})$/', $username);
26 26
     }
@@ -37,7 +37,7 @@  discard block
 block discarded – undo
37 37
      *
38 38
      * @return bool
39 39
      */
40
-    public static function ipInRange (string $ip, string $range): bool {
40
+    public static function ipInRange(string $ip, string $range): bool {
41 41
         if (!str_contains($range, '/')) {
42 42
             $range .= '/32';
43 43
         }
@@ -57,7 +57,7 @@  discard block
 block discarded – undo
57 57
      *
58 58
      * @return bool
59 59
      */
60
-    public static function isTelegram (string $ip): bool {
60
+    public static function isTelegram(string $ip): bool {
61 61
         return tools::ipInRange($ip, '149.154.160.0/20') || tools::ipInRange($ip, '91.108.4.0/22');
62 62
     }
63 63
 
@@ -72,10 +72,10 @@  discard block
 block discarded – undo
72 72
      *
73 73
      * @return bool
74 74
      */
75
-    public static function isCloudFlare (string $ip): bool {
75
+    public static function isCloudFlare(string $ip): bool {
76 76
         $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'];
77 77
         foreach ($cf_ips as $cf_ip) {
78
-            if (self::ipInRange($ip,$cf_ip)) {
78
+            if (self::ipInRange($ip, $cf_ip)) {
79 79
                 return true;
80 80
             }
81 81
         }
@@ -95,9 +95,9 @@  discard block
 block discarded – undo
95 95
      *
96 96
      * @return bool|user return array when verify is active and token is true array of telegram getMe result
97 97
      */
98
-    public static function isToken (string $token, bool $verify = false): bool|user {
98
+    public static function isToken(string $token, bool $verify = false): bool | user {
99 99
         if (preg_match('/^(\d{8,10}):[\w\-]{35}$/', $token)) {
100
-            if ($verify){
100
+            if ($verify) {
101 101
                 $res = telegram::me($token);
102 102
                 if (telegram::$status) {
103 103
                     return $res;
@@ -129,14 +129,14 @@  discard block
 block discarded – undo
129 129
      *
130 130
      * @return bool
131 131
      */
132
-    public static function isJoined (array|string|int $ids , int|null $user_id = null): bool {
132
+    public static function isJoined(array | string | int $ids, int | null $user_id = null): bool {
133 133
         if (!is_array($ids)) {
134 134
             $ids = [$ids];
135 135
         }
136 136
         $user_id = $user_id ?? request::catchFields('user_id');
137 137
 
138 138
         foreach ($ids as $id) {
139
-            $check = telegram::getChatMember($id,$user_id);
139
+            $check = telegram::getChatMember($id, $user_id);
140 140
             if (telegram::$status) {
141 141
                 $check = $check->status;
142 142
                 if ($check === chatMemberStatus::LEFT || $check === chatMemberStatus::KICKED) {
@@ -163,7 +163,7 @@  discard block
 block discarded – undo
163 163
      *
164 164
      * @return array keys will be id and values will be bool(null for not founded ids)
165 165
      */
166
-    public static function joinChecker (array|string|int $ids , int|null $user_id = null): array {
166
+    public static function joinChecker(array | string | int $ids, int | null $user_id = null): array {
167 167
         if (!is_array($ids)) {
168 168
             $ids = [$ids];
169 169
         }
@@ -171,7 +171,7 @@  discard block
 block discarded – undo
171 171
 
172 172
         $result = [];
173 173
         foreach ($ids as $id) {
174
-            $check = telegram::getChatMember($id,$user_id);
174
+            $check = telegram::getChatMember($id, $user_id);
175 175
             if (telegram::$status) {
176 176
                 $check = $check->status;
177 177
                 $result[$id] = $check !== chatMemberStatus::LEFT && $check !== chatMemberStatus::KICKED;
@@ -191,6 +191,6 @@  discard block
 block discarded – undo
191 191
      * @return bool
192 192
      */
193 193
     public static function isShorted(string $text): bool{
194
-        return preg_match('/^[a-zA-Z0-9]+$/',$text);
194
+        return preg_match('/^[a-zA-Z0-9]+$/', $text);
195 195
     }
196 196
 }
197 197
\ No newline at end of file
Please login to merge, or discard this patch.
src/tools/encrypt.php 2 patches
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -29,7 +29,7 @@  discard block
 block discarded – undo
29 29
      * @return string|bool|array{hash:string, key:string, iv:string}
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
         if (extension_loaded('openssl')) {
34 34
             if ($action === cryptoAction::ENCRYPT) {
35 35
                 $key = self::randomString(64);
@@ -39,22 +39,22 @@  discard block
 block discarded – undo
39 39
             }
40 40
             elseif ($action === cryptoAction::DECRYPT) {
41 41
                 if (empty($key)) {
42
-                    logger::write("tools::crypto function used\nkey parameter is not set",loggerTypes::ERROR);
42
+                    logger::write("tools::crypto function used\nkey parameter is not set", loggerTypes::ERROR);
43 43
                     throw new bptException('ARGUMENT_NOT_FOUND_KEY');
44 44
                 }
45 45
                 elseif (empty($iv)) {
46
-                    logger::write("tools::crypto function used\niv parameter is not set",loggerTypes::ERROR);
46
+                    logger::write("tools::crypto function used\niv parameter is not set", loggerTypes::ERROR);
47 47
                     throw new bptException('ARGUMENT_NOT_FOUND_IV');
48 48
                 }
49 49
                 return openssl_decrypt(base64_decode($text), 'AES-256-CBC', $key, 1, $iv);
50 50
             }
51 51
             else {
52
-                logger::write("tools::crypto function used\naction is not right, its must be `encode` or `decode`",loggerTypes::WARNING);
52
+                logger::write("tools::crypto function used\naction is not right, its must be `encode` or `decode`", loggerTypes::WARNING);
53 53
                 return false;
54 54
             }
55 55
         }
56 56
         else {
57
-            logger::write("tools::crypto function used\nopenssl extension is not found , It may not be installed or enabled",loggerTypes::ERROR);
57
+            logger::write("tools::crypto function used\nopenssl extension is not found , It may not be installed or enabled", loggerTypes::ERROR);
58 58
             throw new bptException('OPENSSL_EXTENSION_MISSING');
59 59
         }
60 60
     }
@@ -71,7 +71,7 @@  discard block
 block discarded – undo
71 71
     public static function shortEncode(int $num): string {
72 72
         $codes = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
73 73
         $array = [];
74
-        while ($num > 0){
74
+        while ($num > 0) {
75 75
             $array[] = $num % 62;
76 76
             $num = floor($num / 62);
77 77
         }
@@ -79,7 +79,7 @@  discard block
 block discarded – undo
79 79
         foreach ($array as &$value) {
80 80
             $value = $codes[$value];
81 81
         }
82
-        return strrev(implode('',$array));
82
+        return strrev(implode('', $array));
83 83
     }
84 84
 
85 85
     /**
@@ -96,7 +96,7 @@  discard block
 block discarded – undo
96 96
         $num = 0;
97 97
         $text = str_split(strrev($text));
98 98
         foreach ($text as $key=>$value) {
99
-            $num += strpos($codes,$value) * pow(62,$key);
99
+            $num += strpos($codes, $value) * pow(62, $key);
100 100
         }
101 101
         return $num;
102 102
     }
Please login to merge, or discard this patch.
Braces   +7 added lines, -9 removed lines patch added patch discarded remove patch
@@ -36,24 +36,20 @@  discard block
 block discarded – undo
36 36
                 $iv = self::randomString();
37 37
                 $output = base64_encode(openssl_encrypt($text, 'AES-256-CBC', $key, 1, $iv));
38 38
                 return ['hash' => $output, 'key' => $key, 'iv' => $iv];
39
-            }
40
-            elseif ($action === cryptoAction::DECRYPT) {
39
+            } elseif ($action === cryptoAction::DECRYPT) {
41 40
                 if (empty($key)) {
42 41
                     logger::write("tools::crypto function used\nkey parameter is not set",loggerTypes::ERROR);
43 42
                     throw new bptException('ARGUMENT_NOT_FOUND_KEY');
44
-                }
45
-                elseif (empty($iv)) {
43
+                } elseif (empty($iv)) {
46 44
                     logger::write("tools::crypto function used\niv parameter is not set",loggerTypes::ERROR);
47 45
                     throw new bptException('ARGUMENT_NOT_FOUND_IV');
48 46
                 }
49 47
                 return openssl_decrypt(base64_decode($text), 'AES-256-CBC', $key, 1, $iv);
50
-            }
51
-            else {
48
+            } else {
52 49
                 logger::write("tools::crypto function used\naction is not right, its must be `encode` or `decode`",loggerTypes::WARNING);
53 50
                 return false;
54 51
             }
55
-        }
56
-        else {
52
+        } else {
57 53
             logger::write("tools::crypto function used\nopenssl extension is not found , It may not be installed or enabled",loggerTypes::ERROR);
58 54
             throw new bptException('OPENSSL_EXTENSION_MISSING');
59 55
         }
@@ -75,7 +71,9 @@  discard block
 block discarded – undo
75 71
             $array[] = $num % 62;
76 72
             $num = floor($num / 62);
77 73
         }
78
-        if (count($array) < 1) $array = [0];
74
+        if (count($array) < 1) {
75
+            $array = [0];
76
+        }
79 77
         foreach ($array as &$value) {
80 78
             $value = $codes[$value];
81 79
         }
Please login to merge, or discard this patch.
src/tools/convert.php 1 patch
Spacing   +12 added lines, -12 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 (!isset($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
         $diff = $base_time->diff($target_time);
103 103
 
@@ -124,12 +124,12 @@  discard block
 block discarded – undo
124 124
      *
125 125
      * @return string[]|string
126 126
      */
127
-    public static function realEscapeString(string|array $input): string|array {
128
-        if(is_array($input)) {
127
+    public static function realEscapeString(string | array $input): string | array {
128
+        if (is_array($input)) {
129 129
             return array_map(__METHOD__, $input);
130 130
         }
131 131
 
132
-        if(!empty($input) && is_string($input)) {
132
+        if (!empty($input) && is_string($input)) {
133 133
             return str_replace(array('\\', "\0", "\n", "\r", "'", '"', "\x1a"), array('\\\\', '\\0', '\\n', '\\r', "\\'", '\\"', '\\Z'), $input);
134 134
         }
135 135
 
@@ -147,7 +147,7 @@  discard block
 block discarded – undo
147 147
      *
148 148
      * @return string[]|string
149 149
      */
150
-    public static function strReplaceFirst(string|array $search, string|array $replace, string|array $subject): string|array {
150
+    public static function strReplaceFirst(string | array $search, string | array $replace, string | array $subject): string | array {
151 151
         $pos = strpos($subject, $search);
152 152
         if ($pos !== false) {
153 153
             return substr_replace($subject, $replace, $pos, strlen($search));
Please login to merge, or discard this patch.
src/logger.php 2 patches
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -12,7 +12,7 @@  discard block
 block discarded – undo
12 12
     private static $handler;
13 13
 
14 14
 
15
-    public static function init (int $log_size = 10): void {
15
+    public static function init(int $log_size = 10): void {
16 16
         self::$log_size = $log_size;
17 17
         if (file_exists(settings::$name.'BPT.log') && !(filesize(settings::$name.'BPT.log') > self::$log_size * 1024 * 1024)) {
18 18
             $mode = 'a';
@@ -25,7 +25,7 @@  discard block
 block discarded – undo
25 25
         self::$handler = fopen(settings::$name.'BPT.log', $mode);
26 26
 
27 27
         if ($write) {
28
-            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");
28
+            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");
29 29
         }
30 30
 
31 31
         if (self::$waited_logs != []) {
@@ -36,7 +36,7 @@  discard block
 block discarded – undo
36 36
     }
37 37
 
38 38
     public static function write(string $data, string $type = loggerTypes::NONE): void {
39
-        $text = date('Y/m/d H:i:s') . ( $type === loggerTypes::NONE ? " : $data\n\n" : " : ⤵\n$type : $data\n\n" );
39
+        $text = date('Y/m/d H:i:s').($type === loggerTypes::NONE ? " : $data\n\n" : " : ⤵\n$type : $data\n\n");
40 40
         if (!is_null(self::$handler)) {
41 41
             fwrite(self::$handler, $text);
42 42
         }
Please login to merge, or discard this patch.
Braces   +2 added lines, -4 removed lines patch added patch discarded remove patch
@@ -17,8 +17,7 @@  discard block
 block discarded – undo
17 17
         if (file_exists(settings::$name.'BPT.log') && !(filesize(settings::$name.'BPT.log') > self::$log_size * 1024 * 1024)) {
18 18
             $mode = 'a';
19 19
             $write = false;
20
-        }
21
-        else {
20
+        } else {
22 21
             $mode = 'w';
23 22
             $write = true;
24 23
         }
@@ -39,8 +38,7 @@  discard block
 block discarded – undo
39 38
         $text = date('Y/m/d H:i:s') . ( $type === loggerTypes::NONE ? " : $data\n\n" : " : ⤵\n$type : $data\n\n" );
40 39
         if (!is_null(self::$handler)) {
41 40
             fwrite(self::$handler, $text);
42
-        }
43
-        else {
41
+        } else {
44 42
             self::$waited_logs[] = $text;
45 43
         }
46 44
     }
Please login to merge, or discard this patch.
src/api/request/curl.php 2 patches
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -10,17 +10,17 @@  discard block
 block discarded – undo
10 10
 class curl {
11 11
     private static CurlHandle $curl_handler;
12 12
 
13
-    public static function init(string $method,array $data) {
13
+    public static function init(string $method, array $data) {
14 14
         $info = self::getInfo($data);
15 15
         $data = $info['data'];
16 16
         $handler = $info['handler'];
17
-        self::setTimeout($data,$handler,$method);
17
+        self::setTimeout($data, $handler, $method);
18 18
         self::setData($data);
19 19
         $data['method'] = $method;
20 20
         curl_setopt($handler, CURLOPT_POSTFIELDS, $data);
21 21
         $result = curl_exec($handler);
22 22
         if (curl_errno($handler)) {
23
-            logger::write(curl_error($handler),loggerTypes::WARNING);
23
+            logger::write(curl_error($handler), loggerTypes::WARNING);
24 24
         }
25 25
         if ($info['token'] != settings::$token) {
26 26
             curl_close($handler);
@@ -36,9 +36,9 @@  discard block
 block discarded – undo
36 36
             curl_setopt($curl_handler, CURLOPT_RETURNTRANSFER, true);
37 37
             curl_setopt($curl_handler, CURLOPT_SSL_VERIFYPEER, false);
38 38
         }
39
-        else{
39
+        else {
40 40
             $token = settings::$token;
41
-            if (!isset(self::$curl_handler)){
41
+            if (!isset(self::$curl_handler)) {
42 42
                 self::$curl_handler = curl_init(settings::$base_url."/bot$token/");
43 43
                 curl_setopt(self::$curl_handler, CURLOPT_RETURNTRANSFER, true);
44 44
                 curl_setopt(self::$curl_handler, CURLOPT_SSL_VERIFYPEER, false);
@@ -54,22 +54,22 @@  discard block
 block discarded – undo
54 54
         ];
55 55
     }
56 56
 
57
-    private static function setTimeout(array &$data , CurlHandle $curl_handler,string $method): void {
57
+    private static function setTimeout(array &$data, CurlHandle $curl_handler, string $method): void {
58 58
         if (isset($data['forgot'])) {
59 59
             curl_setopt($curl_handler, CURLOPT_TIMEOUT_MS, settings::$forgot_time);
60 60
             unset($data['forgot']);
61 61
         }
62
-        elseif ($method === 'getUpdates'){
62
+        elseif ($method === 'getUpdates') {
63 63
             curl_setopt($curl_handler, CURLOPT_TIMEOUT_MS, 5000);
64 64
         }
65
-        else{
65
+        else {
66 66
             curl_setopt($curl_handler, CURLOPT_TIMEOUT_MS, 300);
67 67
         }
68 68
     }
69 69
 
70 70
     private static function setData(array &$data): void {
71
-        foreach ($data as &$value){
72
-            if (is_array($value) || (is_object($value) && !is_a($value,'CURLFile'))){
71
+        foreach ($data as &$value) {
72
+            if (is_array($value) || (is_object($value) && !is_a($value, 'CURLFile'))) {
73 73
                 $value = json_encode($value);
74 74
             }
75 75
         }
Please login to merge, or discard this patch.
Braces   +3 added lines, -6 removed lines patch added patch discarded remove patch
@@ -35,8 +35,7 @@  discard block
 block discarded – undo
35 35
             $curl_handler = curl_init(settings::$base_url."/bot$token/");
36 36
             curl_setopt($curl_handler, CURLOPT_RETURNTRANSFER, true);
37 37
             curl_setopt($curl_handler, CURLOPT_SSL_VERIFYPEER, false);
38
-        }
39
-        else{
38
+        } else{
40 39
             $token = settings::$token;
41 40
             if (!isset(self::$curl_handler)){
42 41
                 self::$curl_handler = curl_init(settings::$base_url."/bot$token/");
@@ -58,11 +57,9 @@  discard block
 block discarded – undo
58 57
         if (isset($data['forgot'])) {
59 58
             curl_setopt($curl_handler, CURLOPT_TIMEOUT_MS, settings::$forgot_time);
60 59
             unset($data['forgot']);
61
-        }
62
-        elseif ($method === 'getUpdates'){
60
+        } elseif ($method === 'getUpdates'){
63 61
             curl_setopt($curl_handler, CURLOPT_TIMEOUT_MS, 5000);
64
-        }
65
-        else{
62
+        } else{
66 63
             curl_setopt($curl_handler, CURLOPT_TIMEOUT_MS, 300);
67 64
         }
68 65
     }
Please login to merge, or discard this patch.
src/lock.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -11,15 +11,15 @@
 block discarded – undo
11 11
         return touch(settings::$name."$name.lock");
12 12
     }
13 13
 
14
-    public static function save(string $name, string $data): bool|int {
15
-        return file_put_contents(settings::$name."$name.lock", $data) && chmod(settings::$name."$name.lock",0640);
14
+    public static function save(string $name, string $data): bool | int {
15
+        return file_put_contents(settings::$name."$name.lock", $data) && chmod(settings::$name."$name.lock", 0640);
16 16
     }
17 17
 
18
-    public static function read(string $name): bool|string {
18
+    public static function read(string $name): bool | string {
19 19
         return file_get_contents(settings::$name."$name.lock");
20 20
     }
21 21
 
22
-    public static function mtime(string $name): bool|int {
22
+    public static function mtime(string $name): bool | int {
23 23
         return filemtime(settings::$name."$name.lock");
24 24
     }
25 25
 
Please login to merge, or discard this patch.
src/settings.php 2 patches
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -23,7 +23,7 @@  discard block
 block discarded – undo
23 23
 
24 24
     public static int $log_size = 10;
25 25
 
26
-    public static string|CURLFile|null $certificate = null;
26
+    public static string | CURLFile | null $certificate = null;
27 27
 
28 28
     public static bool $handler = true;
29 29
 
@@ -51,14 +51,14 @@  discard block
 block discarded – undo
51 51
 
52 52
     public static array $allowed_updates = ['message', 'edited_channel_post', 'callback_query', 'inline_query'];
53 53
 
54
-    public static array|mysqli|null $db = ['type' => 'json', 'file_name' => 'BPT-DB.json'];
54
+    public static array | mysqli | null $db = ['type' => 'json', 'file_name' => 'BPT-DB.json'];
55 55
 
56 56
 
57
-    public static function init (array|stdClass $settings): void {
57
+    public static function init(array | stdClass $settings): void {
58 58
         $settings = (array) $settings;
59 59
 
60 60
         foreach ($settings as $setting => $value) {
61
-            try{
61
+            try {
62 62
                 if ($setting === 'name') {
63 63
                     if (!is_dir('bots_files')) {
64 64
                         mkdir('bots_files');
@@ -70,11 +70,11 @@  discard block
 block discarded – undo
70 70
                 }
71 71
                 self::$$setting = $value;
72 72
             }
73
-            catch (TypeError){
74
-                logger::write("$setting setting has wrong type , its set to default value",loggerTypes::WARNING);
73
+            catch (TypeError) {
74
+                logger::write("$setting setting has wrong type , its set to default value", loggerTypes::WARNING);
75 75
             }
76
-            catch (Error){
77
-                logger::write("$setting setting is not one of library settings",loggerTypes::WARNING);
76
+            catch (Error) {
77
+                logger::write("$setting setting is not one of library settings", loggerTypes::WARNING);
78 78
             }
79 79
         }
80 80
 
@@ -92,19 +92,19 @@  discard block
 block discarded – undo
92 92
                 }
93 93
             }
94 94
             else {
95
-                logger::write('token format is not right, check it and try again',loggerTypes::ERROR);
95
+                logger::write('token format is not right, check it and try again', loggerTypes::ERROR);
96 96
                 throw new bptException('TOKEN_NOT_TRUE');
97 97
             }
98 98
         }
99 99
         else {
100
-            logger::write('You must specify token parameter in settings',loggerTypes::ERROR);
100
+            logger::write('You must specify token parameter in settings', loggerTypes::ERROR);
101 101
             throw new bptException('TOKEN_NOT_FOUND');
102 102
         }
103 103
     }
104 104
 
105 105
     public static function done(): void {
106 106
         if (self::$logger) {
107
-            $estimated = round((microtime(true)-$_SERVER['REQUEST_TIME_FLOAT'])*1000,2);
107
+            $estimated = round((microtime(true) - $_SERVER['REQUEST_TIME_FLOAT']) * 1000, 2);
108 108
             $status_message = match (true) {
109 109
                 $estimated < 100 => 'Excellent',
110 110
                 $estimated < 500 => 'Very good',
@@ -136,7 +136,7 @@  discard block
 block discarded – undo
136 136
         if (self::$secure_folder) {
137 137
             $address = explode('/', $_SERVER['REQUEST_URI']);
138 138
             unset($address[count($address) - 1]);
139
-            $address = implode('/', $address) . '/BPT.php';
139
+            $address = implode('/', $address).'/BPT.php';
140 140
             $text = "ErrorDocument 404 $address\nErrorDocument 403 $address\n Options -Indexes\n  Order Deny,Allow\nDeny from all\nAllow from 127.0.0.1\n<Files *.php>\n    Order Allow,Deny\n    Allow from all\n</Files>";
141 141
             if (!file_exists('.htaccess') || filesize('.htaccess') != strlen($text)) {
142 142
                 file_put_contents('.htaccess', $text);
@@ -155,7 +155,7 @@  discard block
 block discarded – undo
155 155
             getUpdates::init();
156 156
         }
157 157
         else {
158
-            logger::write('You can\'t use getUpdates receiver when handler is off , use webhook or use handler',loggerTypes::ERROR);
158
+            logger::write('You can\'t use getUpdates receiver when handler is off , use webhook or use handler', loggerTypes::ERROR);
159 159
             throw new bptException('GETUPDATE_NEED_HANDLER');
160 160
         }
161 161
     }
Please login to merge, or discard this patch.
Braces   +5 added lines, -10 removed lines patch added patch discarded remove patch
@@ -69,11 +69,9 @@  discard block
 block discarded – undo
69 69
                     $value = 'bots_files/'.$value.'/';
70 70
                 }
71 71
                 self::$$setting = $value;
72
-            }
73
-            catch (TypeError){
72
+            } catch (TypeError){
74 73
                 logger::write("$setting setting has wrong type , its set to default value",loggerTypes::WARNING);
75
-            }
76
-            catch (Error){
74
+            } catch (Error){
77 75
                 logger::write("$setting setting is not one of library settings",loggerTypes::WARNING);
78 76
             }
79 77
         }
@@ -90,13 +88,11 @@  discard block
 block discarded – undo
90 88
                 if (!empty(self::$receiver)) {
91 89
                     self::$receiver !== receiver::GETUPDATES ? self::webhook() : self::getUpdates();
92 90
                 }
93
-            }
94
-            else {
91
+            } else {
95 92
                 logger::write('token format is not right, check it and try again',loggerTypes::ERROR);
96 93
                 throw new bptException('TOKEN_NOT_TRUE');
97 94
             }
98
-        }
99
-        else {
95
+        } else {
100 96
             logger::write('You must specify token parameter in settings',loggerTypes::ERROR);
101 97
             throw new bptException('TOKEN_NOT_FOUND');
102 98
         }
@@ -153,8 +149,7 @@  discard block
 block discarded – undo
153 149
     private static function getUpdates(): void {
154 150
         if (self::$handler) {
155 151
             getUpdates::init();
156
-        }
157
-        else {
152
+        } else {
158 153
             logger::write('You can\'t use getUpdates receiver when handler is off , use webhook or use handler',loggerTypes::ERROR);
159 154
             throw new bptException('GETUPDATE_NEED_HANDLER');
160 155
         }
Please login to merge, or discard this patch.