Passed
Push — main ( e1a2dc...e011f6 )
by Miaad
02:06
created
receiver/getUpdates.php 2 patches
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -9,19 +9,19 @@  discard block
 block discarded – undo
9 9
 use stdClass;
10 10
 
11 11
 class getUpdates extends receiver {
12
-    public static function init () {
12
+    public static function init() {
13 13
         $last_update_id = self::loadData();
14
-        while(true) {
14
+        while (true) {
15 15
             if (!lock::exist('getUpdate')) {
16
-                $updates = telegram::getUpdates($last_update_id,allowed_updates: settings::$allowed_updates)->result;
16
+                $updates = telegram::getUpdates($last_update_id, allowed_updates: settings::$allowed_updates)->result;
17 17
                 self::handleUpdates($updates);
18
-                lock::save('getUpdate',BPT::$update->update_id+1);
19
-                $last_update_id = BPT::$update->update_id+1;
18
+                lock::save('getUpdate', BPT::$update->update_id + 1);
19
+                $last_update_id = BPT::$update->update_id + 1;
20 20
             }
21 21
         }
22 22
     }
23 23
 
24
-    private static function loadData(): bool|int|string {
24
+    private static function loadData(): bool | int | string {
25 25
         if (lock::exist('getUpdate')) {
26 26
             $last_update_id = lock::read('getUpdate');
27 27
         }
@@ -29,7 +29,7 @@  discard block
 block discarded – undo
29 29
             self::deleteOldLocks();
30 30
             telegram::deleteWebhook();
31 31
             $last_update_id = 0;
32
-            lock::save('getUpdate',0);
32
+            lock::save('getUpdate', 0);
33 33
         }
34 34
         return $last_update_id;
35 35
     }
Please login to merge, or discard this patch.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -24,8 +24,7 @@
 block discarded – undo
24 24
     private static function loadData(): bool|int|string {
25 25
         if (lock::exist('getUpdate')) {
26 26
             $last_update_id = lock::read('getUpdate');
27
-        }
28
-        else {
27
+        } else {
29 28
             self::deleteOldLocks();
30 29
             telegram::deleteWebhook();
31 30
             $last_update_id = 0;
Please login to merge, or discard this patch.
receiver/multi/curl.php 2 patches
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -10,12 +10,12 @@  discard block
 block discarded – undo
10 10
 use BPT\settings;
11 11
 
12 12
 class curl extends webhook {
13
-    public static function init (): string|null {
13
+    public static function init(): string | null {
14 14
         if (self::checkIP()) {
15 15
             return self::getUpdate();
16 16
         }
17 17
         else {
18
-            logger::write('not authorized access denied. IP : '. $_SERVER['REMOTE_ADDR'] ?? 'unknown',loggerTypes::ERROR);
18
+            logger::write('not authorized access denied. IP : '.$_SERVER['REMOTE_ADDR'] ?? 'unknown', loggerTypes::ERROR);
19 19
             BPT::exit();
20 20
         }
21 21
     }
@@ -24,7 +24,7 @@  discard block
 block discarded – undo
24 24
         return $_SERVER['REMOTE_ADDR'] === $_SERVER['SERVER_ADDR'];
25 25
     }
26 26
 
27
-    private static function getUpdate (): string {
27
+    private static function getUpdate(): string {
28 28
         $input = json_decode(file_get_contents("php://input"), true);
29 29
         webhook::telegramVerify($input['ip']);
30 30
         return $input['update'];
@@ -34,14 +34,14 @@  discard block
 block discarded – undo
34 34
         $urls = self::setURLS();
35 35
         $file = $urls['file'];
36 36
         $timeout = self::getTimeout($file);
37
-        self::create($file,$timeout);
37
+        self::create($file, $timeout);
38 38
         self::setWebhook($urls['url']);
39 39
         lock::set('BPT-MULTI-CURL');
40 40
     }
41 41
 
42
-    private static function getTimeout($url): float|int {
42
+    private static function getTimeout($url): float | int {
43 43
         $times = [];
44
-        for ($i = 0; $i < 10; $i ++) {
44
+        for ($i = 0; $i < 10; $i++) {
45 45
             $ch = curl_init($url);
46 46
             curl_setopt_array($ch, [CURLOPT_POSTFIELDS => json_encode([]), CURLOPT_TIMEOUT_MS => 100, CURLOPT_NOBODY => true, CURLOPT_RETURNTRANSFER => true, CURLOPT_SSL_VERIFYPEER => false, CURLOPT_SSL_VERIFYHOST => false, CURLOPT_CONNECTTIMEOUT_MS => 100, CURLOPT_HTTPHEADER => ['accept: application/json', 'content-type: application/json']]);
47 47
             $start = microtime(true);
@@ -52,12 +52,12 @@  discard block
 block discarded – undo
52 52
         return $timeout > 50 ? $timeout + 10 : 50;
53 53
     }
54 54
 
55
-    private static function create($file,$timeout) {
56
-        file_put_contents('receiver.php', '<?php http_response_code(200);ignore_user_abort();$ch = curl_init(\'' . $file . '\');curl_setopt_array($ch, [CURLOPT_POSTFIELDS => json_encode([\'update\'=>file_get_contents(\'php://input\'),\'ip\'=>$_SERVER[\'REMOTE_ADDR\']]), CURLOPT_TIMEOUT_MS => ' . $timeout . ', CURLOPT_RETURNTRANSFER => true, CURLOPT_SSL_VERIFYPEER => false, CURLOPT_SSL_VERIFYHOST => false, CURLOPT_CONNECTTIMEOUT_MS => ' . $timeout . ', CURLOPT_HTTPHEADER => [\'accept: application/json\', \'content-type: application/json\']]);curl_exec($ch);curl_close($ch);?>');
55
+    private static function create($file, $timeout) {
56
+        file_put_contents('receiver.php', '<?php http_response_code(200);ignore_user_abort();$ch = curl_init(\''.$file.'\');curl_setopt_array($ch, [CURLOPT_POSTFIELDS => json_encode([\'update\'=>file_get_contents(\'php://input\'),\'ip\'=>$_SERVER[\'REMOTE_ADDR\']]), CURLOPT_TIMEOUT_MS => '.$timeout.', CURLOPT_RETURNTRANSFER => true, CURLOPT_SSL_VERIFYPEER => false, CURLOPT_SSL_VERIFYHOST => false, CURLOPT_CONNECTTIMEOUT_MS => '.$timeout.', CURLOPT_HTTPHEADER => [\'accept: application/json\', \'content-type: application/json\']]);curl_exec($ch);curl_close($ch);?>');
57 57
     }
58 58
 
59 59
     private static function setURLS(): array {
60
-        $base_url = (isset(settings::$certificate) ? 'http://' : 'https://') . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
60
+        $base_url = (isset(settings::$certificate) ? 'http://' : 'https://').$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];
61 61
         $file = basename($_SERVER['REQUEST_URI']);
62 62
         return [
63 63
             'url'=>str_replace($file, 'receiver.php', $base_url),
Please login to merge, or discard this patch.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -13,8 +13,7 @@
 block discarded – undo
13 13
     public static function init (): string|null {
14 14
         if (self::checkIP()) {
15 15
             return self::getUpdate();
16
-        }
17
-        else {
16
+        } else {
18 17
             logger::write('not authorized access denied. IP : '. $_SERVER['REMOTE_ADDR'] ?? 'unknown',loggerTypes::ERROR);
19 18
             BPT::exit();
20 19
         }
Please login to merge, or discard this patch.
receiver/multi/exec.php 2 patches
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -10,11 +10,11 @@  discard block
 block discarded – undo
10 10
 use BPT\settings;
11 11
 
12 12
 class exec extends webhook {
13
-    public static function init(): string|null {
13
+    public static function init(): string | null {
14 14
         return self::getUpdate();
15 15
     }
16 16
 
17
-    private static function getUpdate (): string|null {
17
+    private static function getUpdate(): string | null {
18 18
         $up = glob('*.update');
19 19
         if (isset($up[0])) {
20 20
             $up = end($up);
@@ -25,7 +25,7 @@  discard block
 block discarded – undo
25 25
             return $update;
26 26
         }
27 27
         else {
28
-            logger::write('not authorized access denied. IP : '. $_SERVER['REMOTE_ADDR'] ?? 'unknown',loggerTypes::ERROR);
28
+            logger::write('not authorized access denied. IP : '.$_SERVER['REMOTE_ADDR'] ?? 'unknown', loggerTypes::ERROR);
29 29
             BPT::exit();
30 30
         }
31 31
     }
@@ -45,11 +45,11 @@  discard block
 block discarded – undo
45 45
     }
46 46
 
47 47
     private static function create($file) {
48
-        file_put_contents('receiver.php', '<?php $BPT = file_get_contents("php://input");$id = json_decode($BPT, true)[\'update_id\'];file_put_contents("{$_SERVER[\'REMOTE_ADDR\']}-$id.update",$BPT);exec("php ' . $file . ' > /dev/null &");');
48
+        file_put_contents('receiver.php', '<?php $BPT = file_get_contents("php://input");$id = json_decode($BPT, true)[\'update_id\'];file_put_contents("{$_SERVER[\'REMOTE_ADDR\']}-$id.update",$BPT);exec("php '.$file.' > /dev/null &");');
49 49
     }
50 50
 
51 51
     private static function setURLS(): array {
52
-        $base_url = (isset(settings::$certificate) ? 'http://' : 'https://') . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
52
+        $base_url = (isset(settings::$certificate) ? 'http://' : 'https://').$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];
53 53
         $file = basename($_SERVER['REQUEST_URI']);
54 54
         return [
55 55
             'url'=>str_replace($file, 'receiver.php', $base_url),
Please login to merge, or discard this patch.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -23,8 +23,7 @@
 block discarded – undo
23 23
             $update = file_get_contents($up);
24 24
             unlink($up);
25 25
             return $update;
26
-        }
27
-        else {
26
+        } else {
28 27
             logger::write('not authorized access denied. IP : '. $_SERVER['REMOTE_ADDR'] ?? 'unknown',loggerTypes::ERROR);
29 28
             BPT::exit();
30 29
         }
Please login to merge, or discard this patch.
receiver/webhook.php 2 patches
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -11,7 +11,7 @@  discard block
 block discarded – undo
11 11
 use CURLFile;
12 12
 
13 13
 class webhook extends receiver {
14
-    public static function init () {
14
+    public static function init() {
15 15
         if (settings::$multi) {
16 16
             multi::init();
17 17
         }
@@ -48,23 +48,23 @@  discard block
 block discarded – undo
48 48
     protected static function setWebhook(string $url) {
49 49
         $res = telegram::setWebhook($url, settings::$certificate, max_connections:settings::$max_connection, allowed_updates : settings::$allowed_updates);
50 50
         if ($res->ok) {
51
-            logger::write('Webhook was set successfully',loggerTypes::INFO);
51
+            logger::write('Webhook was set successfully', loggerTypes::INFO);
52 52
         }
53 53
         else {
54
-            logger::write("There is some problem happened , telegram response : \n".json_encode($res),loggerTypes::ERROR);
55
-            BPT::exit(print_r($res,true));
54
+            logger::write("There is some problem happened , telegram response : \n".json_encode($res), loggerTypes::ERROR);
55
+            BPT::exit(print_r($res, true));
56 56
         }
57 57
     }
58 58
 
59 59
     protected static function checkURL() {
60 60
         if (!(isset($_SERVER['SERVER_NAME']) && isset($_SERVER['REQUEST_URI']))) {
61
-            logger::write('For using webhook receiver , you should open this file in your webserver(by domain)',loggerTypes::ERROR);
61
+            logger::write('For using webhook receiver , you should open this file in your webserver(by domain)', loggerTypes::ERROR);
62 62
             BPT::exit();
63 63
         }
64 64
     }
65 65
 
66 66
     private static function setURL(): string {
67
-        return (isset(settings::$certificate) ? 'http://' : 'https://') . $_SERVER['SERVER_NAME'] . $_SERVER['SCRIPT_NAME'];
67
+        return (isset(settings::$certificate) ? 'http://' : 'https://').$_SERVER['SERVER_NAME'].$_SERVER['SCRIPT_NAME'];
68 68
     }
69 69
 
70 70
     protected static function setCertificate() {
Please login to merge, or discard this patch.
Braces   +4 added lines, -8 removed lines patch added patch discarded remove patch
@@ -14,14 +14,12 @@  discard block
 block discarded – undo
14 14
     public static function init () {
15 15
         if (settings::$multi) {
16 16
             multi::init();
17
-        }
18
-        else {
17
+        } else {
19 18
             if (lock::exist('BPT-HOOK')) {
20 19
                 receiver::telegramVerify();
21 20
                 receiver::processUpdate();
22 21
                 logger::write('Update received , lets process it ;)');
23
-            }
24
-            else {
22
+            } else {
25 23
                 self::deleteOldLocks();
26 24
                 self::checkURL();
27 25
                 self::setCertificate();
@@ -49,8 +47,7 @@  discard block
 block discarded – undo
49 47
         $res = telegram::setWebhook($url, settings::$certificate, max_connections:settings::$max_connection, allowed_updates : settings::$allowed_updates);
50 48
         if ($res->ok) {
51 49
             logger::write('Webhook was set successfully',loggerTypes::INFO);
52
-        }
53
-        else {
50
+        } else {
54 51
             logger::write("There is some problem happened , telegram response : \n".json_encode($res),loggerTypes::ERROR);
55 52
             BPT::exit(print_r($res,true));
56 53
         }
@@ -72,8 +69,7 @@  discard block
 block discarded – undo
72 69
             if (is_string(settings::$certificate)) {
73 70
                 if (file_exists(settings::$certificate)) {
74 71
                     settings::$certificate = new CURLFile(settings::$certificate);
75
-                }
76
-                else {
72
+                } else {
77 73
                     settings::$certificate = null;
78 74
                 }
79 75
             }
Please login to merge, or discard this patch.
receiver/receiver.php 2 patches
Spacing   +4 added lines, -4 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::ERROR);
25
+                logger::write('not authorized access denied. IP : '.$ip ?? $_SERVER['REMOTE_ADDR'] ?? 'unknown', loggerTypes::ERROR);
26 26
                 BPT::exit();
27 27
             }
28 28
         }
29 29
     }
30 30
 
31
-    protected static function processUpdate(string|stdClass $update = null) {
31
+    protected static function processUpdate(string | stdClass $update = null) {
32 32
         if (!is_object($update)) {
33 33
             $update = json_decode($update ?? file_get_contents("php://input"));
34 34
             if (!$update) {
@@ -41,7 +41,7 @@  discard block
 block discarded – undo
41 41
         self::processHandler();
42 42
     }
43 43
 
44
-    protected static function setMessageExtra (update &$update) {
44
+    protected static function setMessageExtra(update & $update) {
45 45
         if ((isset($update->message) && isset($update->message->text)) || (isset($update->edited_message) && isset($update->edited_message->text))) {
46 46
             $type = isset($update->message) ? 'message' : 'edited_message';
47 47
             $text = &$update->$type->text;
@@ -83,7 +83,7 @@  discard block
 block discarded – undo
83 83
                 BPT::$handler->something_else(BPT::$update);
84 84
             }
85 85
             else {
86
-                logger::write('Update received but handlers does not set',loggerTypes::WARNING);
86
+                logger::write('Update received but handlers does not set', loggerTypes::WARNING);
87 87
             }
88 88
         }
89 89
     }
Please login to merge, or discard this patch.
Braces   +5 added lines, -10 removed lines patch added patch discarded remove patch
@@ -63,26 +63,21 @@
 block discarded – undo
63 63
                 if (self::handlerExist('message')) {
64 64
                     BPT::$handler->message(BPT::$update->message);
65 65
                 }
66
-            }
67
-            elseif (isset(BPT::$update->callback_query)) {
66
+            } elseif (isset(BPT::$update->callback_query)) {
68 67
                 if (self::handlerExist('callback_query')) {
69 68
                     BPT::$handler->callback_query(BPT::$update->callback_query);
70 69
                 }
71
-            }
72
-            elseif (isset(BPT::$update->inline_query)) {
70
+            } elseif (isset(BPT::$update->inline_query)) {
73 71
                 if (self::handlerExist('inline_query')) {
74 72
                     BPT::$handler->inline_query(BPT::$update->inline_query);
75 73
                 }
76
-            }
77
-            elseif (isset(BPT::$update->edited_message)) {
74
+            } elseif (isset(BPT::$update->edited_message)) {
78 75
                 if (self::handlerExist('edited_message')) {
79 76
                     BPT::$handler->edited_message(BPT::$update->edited_message);
80 77
                 }
81
-            }
82
-            elseif (self::handlerExist('something_else')) {
78
+            } elseif (self::handlerExist('something_else')) {
83 79
                 BPT::$handler->something_else(BPT::$update);
84
-            }
85
-            else {
80
+            } else {
86 81
                 logger::write('Update received but handlers does not set',loggerTypes::WARNING);
87 82
             }
88 83
         }
Please login to merge, or discard this patch.
tools.php 2 patches
Spacing   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -22,7 +22,7 @@  discard block
 block discarded – undo
22 22
      * @param string $username Your text to be check is username or not e.g. : 'BPT_CH' | '@BPT_CH'
23 23
      * @return bool
24 24
      */
25
-    public static function isUsername (string $username): bool {
25
+    public static function isUsername(string $username): bool {
26 26
         $length = strlen($username);
27 27
         return strpos($username, '__') === false && $length >= 5 && $length <= 33 && preg_match('/^@?([a-zA-Z])(\w{4,31})$/', $username);
28 28
     }
@@ -38,7 +38,7 @@  discard block
 block discarded – undo
38 38
      * @param string $range Your range ip for check , if you didn't specify the block , it will be 32
39 39
      * @return bool
40 40
      */
41
-    public static function ipInRange (string $ip, string $range): bool {
41
+    public static function ipInRange(string $ip, string $range): bool {
42 42
         if (!str_contains($range, '/')) {
43 43
             $range .= '/32';
44 44
         }
@@ -57,7 +57,7 @@  discard block
 block discarded – undo
57 57
      * @param string $ip     Your ip to be check is telegram or not e.g. '192.168.1.1'
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 self::ipInRange($ip, '149.154.160.0/20') || self::ipInRange($ip, '91.108.4.0/22');
62 62
     }
63 63
 
@@ -71,10 +71,10 @@  discard block
 block discarded – undo
71 71
      * @param string $ip Your ip to be check is CloudFlare or not e.g. '192.168.1.1'
72 72
      * @return bool
73 73
      */
74
-    public static function isCloudFlare (string $ip): bool {
74
+    public static function isCloudFlare(string $ip): bool {
75 75
         $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'];
76 76
         foreach ($cf_ips as $cf_ip) {
77
-            if (self::ipInRange($ip,$cf_ip)) {
77
+            if (self::ipInRange($ip, $cf_ip)) {
78 78
                 return true;
79 79
             }
80 80
         }
@@ -95,9 +95,9 @@  discard block
 block discarded – undo
95 95
      * @param bool $verify check token with telegram or not
96 96
      * @return bool|array 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|array {
98
+    public static function isToken(string $token, bool $verify = false): bool | array {
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 ($res['ok']) {
103 103
                     return $res['result'];
@@ -130,14 +130,14 @@  discard block
 block discarded – undo
130 130
      * @param int|null $user_id e.g. => '442109602'
131 131
      * @return bool
132 132
      */
133
-    public static function isJoined (array|string|int $ids , int|null $user_id = null): bool {
133
+    public static function isJoined(array | string | int $ids, int | null $user_id = null): bool {
134 134
         if (!is_array($ids)) {
135 135
             $ids = [$ids];
136 136
         }
137 137
         //$user_id = $user_id ?? $this->catchFields(['field' => 'user_id']);
138 138
 
139 139
         foreach ($ids as $id) {
140
-            $check = telegram::getChatMember($id,$user_id);
140
+            $check = telegram::getChatMember($id, $user_id);
141 141
             if (isset($check['result'])) {
142 142
                 $check = $check['result']['status'];
143 143
                 return !($check === chatMemberStatus::LEFT || $check === chatMemberStatus::KICKED);
@@ -165,10 +165,10 @@  discard block
 block discarded – undo
165 165
      * @param string $characters e.g. => 'abcdefg'
166 166
      * @return string
167 167
      */
168
-    public static function randomString (int $length = 16, string $characters = 'aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ'): string {
168
+    public static function randomString(int $length = 16, string $characters = 'aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ'): string {
169 169
         $rand_string = '';
170 170
         $char_len = strlen($characters) - 1;
171
-        for ($i = 0; $i < $length; $i ++) {
171
+        for ($i = 0; $i < $length; $i++) {
172 172
             $rand_string .= $characters[rand(0, $char_len)];
173 173
         }
174 174
         return $rand_string;
@@ -187,10 +187,10 @@  discard block
 block discarded – undo
187 187
      * @param string $mode Your selected mode e.g. => `parseMode::HTML` | `HTML`
188 188
      * @return string|false return false when mode is incorrect
189 189
      */
190
-    public static function modeEscape (string $text, string $mode = parseMode::HTML): string|false {
190
+    public static function modeEscape(string $text, string $mode = parseMode::HTML): string | false {
191 191
         return match ($mode) {
192
-            parseMode::HTML => str_replace(['&', '<', '>',], ["&amp;", "&lt;", "&gt;",], $text),
193
-            parseMode::MARKDOWN => str_replace(['\\', '_', '*', '`', '['], ['\\\\', '\_', '\*', '\`', '\[',], $text),
192
+            parseMode::HTML => str_replace(['&', '<', '>', ], ["&amp;", "&lt;", "&gt;", ], $text),
193
+            parseMode::MARKDOWN => str_replace(['\\', '_', '*', '`', '['], ['\\\\', '\_', '\*', '\`', '\[', ], $text),
194 194
             parseMode::MARKDOWNV2 => str_replace(
195 195
                 ['_', '*', '[', ']', '(', ')', '~', '`', '>', '#', '+', '-', '=', '|', '{', '}', '.', '!', '\\'],
196 196
                 ['\_', '\*', '\[', '\]', '\(', '\)', '\~', '\`', '\>', '\#', '\+', '\-', '\=', '\|', '\{', '\}', '\.', '\!', '\\\\'],
@@ -216,10 +216,10 @@  discard block
 block discarded – undo
216 216
      * @param int $precision e.g. => 2
217 217
      * @return string
218 218
      */
219
-    public static function byteFormat (int $byte, int $precision = 2): string {
219
+    public static function byteFormat(int $byte, int $precision = 2): string {
220 220
         $rate_counter = 0;
221 221
 
222
-        while ($byte > 1024){
222
+        while ($byte > 1024) {
223 223
             $byte /= 1024;
224 224
             $rate_counter++;
225 225
         }
@@ -228,7 +228,7 @@  discard block
 block discarded – undo
228 228
             $byte = round($byte, $precision);
229 229
         }
230 230
 
231
-        return $byte . ' ' . ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB'][$rate_counter];
231
+        return $byte.' '.['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB'][$rate_counter];
232 232
     }
233 233
 
234 234
     /**
@@ -248,7 +248,7 @@  discard block
 block discarded – undo
248 248
      * @param bool $format if you set this true , you will receive symbolic string like 2.76MB
249 249
      * @return string|int|false string for formatted data , int for normal data , false when size can not be found(file not found or ...)
250 250
      */
251
-    public static function size (string $path, bool $format = true): string|int|false {
251
+    public static function size(string $path, bool $format = true): string | int | false {
252 252
         if (filter_var($path, FILTER_VALIDATE_URL)) {
253 253
             $ch = curl_init($path);
254 254
             curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
@@ -283,7 +283,7 @@  discard block
 block discarded – undo
283 283
      * @param array $array e.g. => ['path'=>'xfolder/yfolder','sub'=>true]
284 284
      * @return bool
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
         if (is_dir($path)) {
288 288
             if (count(scandir($path)) > 2) {
289 289
                 if ($sub) {
@@ -295,7 +295,7 @@  discard block
 block discarded – undo
295 295
                     rmdir($path);
296 296
                 }
297 297
                 else {
298
-                    logger::write("BPT delete function used\ndelete function cannot delete folder because its have subFiles and sub parameter haven't true value",loggerTypes::ERROR);
298
+                    logger::write("BPT delete function used\ndelete function cannot delete folder because its have subFiles and sub parameter haven't true value", loggerTypes::ERROR);
299 299
                     return false;
300 300
                 }
301 301
             }
@@ -318,9 +318,9 @@  discard block
 block discarded – undo
318 318
      * @return array
319 319
      * @throws Exception
320 320
      */
321
-    public static function time2string (int $datetime): array {
321
+    public static function time2string(int $datetime): array {
322 322
         $now = new DateTime;
323
-        $input = new DateTime('@' . $datetime);
323
+        $input = new DateTime('@'.$datetime);
324 324
         $status = $now < $input ? 'later' : 'ago';
325 325
         $diff = $now->diff($input);
326 326
         $diff->w = floor($diff->d / 7);
Please login to merge, or discard this patch.
Braces   +14 added lines, -12 removed lines patch added patch discarded remove patch
@@ -257,15 +257,15 @@  discard block
 block discarded – undo
257 257
             curl_exec($ch);
258 258
             $size = curl_getinfo($ch, CURLINFO_CONTENT_LENGTH_DOWNLOAD);
259 259
             curl_close($ch);
260
-        }
261
-        else {
260
+        } else {
262 261
             $size = file_exists($path) ? filesize($path) : false;
263 262
         }
264 263
 
265 264
         if (isset($size) && is_numeric($size)) {
266 265
             return $format ? tools::byteFormat($size) : $size;
267
-        }
268
-        else return false;
266
+        } else {
267
+            return false;
268
+        }
269 269
     }
270 270
 
271 271
     //fix methods after here comments
@@ -293,15 +293,16 @@  discard block
 block discarded – undo
293 293
                         $file->isDir() ? rmdir($file->getRealPath()) : unlink($file->getRealPath());
294 294
                     }
295 295
                     rmdir($path);
296
-                }
297
-                else {
296
+                } else {
298 297
                     logger::write("BPT delete function used\ndelete function cannot delete folder because its have subFiles and sub parameter haven't true value",loggerTypes::ERROR);
299 298
                     return false;
300 299
                 }
301
-            }
302
-            else rmdir($path);
303
-        }
304
-        else unlink($path);
300
+            } else {
301
+                rmdir($path);
302
+            }
303
+        } else {
304
+            unlink($path);
305
+        }
305 306
 
306 307
         return true;
307 308
     }
@@ -328,8 +329,9 @@  discard block
 block discarded – undo
328 329
         foreach ($string as $k => &$v) {
329 330
             if ($diff->$v) {
330 331
                 $v = $diff->$v;
331
-            }
332
-            else unset($string[$k]);
332
+            } else {
333
+                unset($string[$k]);
334
+            }
333 335
         }
334 336
         $string['status'] = $status;
335 337
         return count($string) > 1 ? $string : ['status' => 'now'];
Please login to merge, or discard this patch.
logger.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -10,7 +10,7 @@  discard block
 block discarded – undo
10 10
     private static $handler;
11 11
 
12 12
 
13
-    public static function init (int $log_size = 10) {
13
+    public static function init(int $log_size = 10) {
14 14
         self::$log_size = $log_size;
15 15
         if (file_exists('BPT.log') && !(filesize('BPT.log') > self::$log_size * 1024 * 1024)) {
16 16
             $mode = 'a';
@@ -24,13 +24,13 @@  discard block
 block discarded – undo
24 24
         self::$handler = fopen('BPT.log', $mode);
25 25
 
26 26
         if ($write) {
27
-            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");
27
+            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 28
         }
29 29
     }
30 30
 
31 31
     public static function write(string $data, string $type = loggerTypes::NONE) {
32 32
         if (!is_null(self::$handler)) {
33
-            $text = date('Y/m/d H:i:s') . ( $type === loggerTypes::NONE ? " : $data\n\n" : " : ⤵\n$type : $data\n\n" );
33
+            $text = date('Y/m/d H:i:s').($type === loggerTypes::NONE ? " : $data\n\n" : " : ⤵\n$type : $data\n\n");
34 34
             fwrite(self::$handler, $text);
35 35
         }
36 36
     }
Please login to merge, or discard this patch.
api/request/answer.php 1 patch
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -11,33 +11,33 @@  discard block
 block discarded – undo
11 11
 class answer {
12 12
     private static bool $is_answered = false;
13 13
 
14
-    public static function init(string $method,array $data) {
14
+    public static function init(string $method, array $data) {
15 15
         self::checkAnswered();
16 16
         self::checkWebhook();
17 17
         self::deleteAdditionalData($data);
18 18
         self::$is_answered = true;
19 19
         $data['method'] = $method;
20 20
         $payload = json_encode($data);
21
-        header('Content-Type: application/json;Content-Length: ' . strlen($payload));
21
+        header('Content-Type: application/json;Content-Length: '.strlen($payload));
22 22
         echo $payload;
23 23
         return true;
24 24
     }
25 25
 
26 26
     private static function checkAnswered() {
27 27
         if (self::$is_answered) {
28
-            logger::write('You can use answer mode only once for each webhook update , You already did it!',loggerTypes::ERROR);
28
+            logger::write('You can use answer mode only once for each webhook update , You already did it!', loggerTypes::ERROR);
29 29
             BPT::exit();
30 30
         }
31 31
     }
32 32
 
33 33
     private static function checkWebhook() {
34
-        if(settings::$receiver === receiver::GETUPDATES) {
35
-            logger::write('Answer mode only work when receiver is webhook',loggerTypes::ERROR);
34
+        if (settings::$receiver === receiver::GETUPDATES) {
35
+            logger::write('Answer mode only work when receiver is webhook', loggerTypes::ERROR);
36 36
             BPT::exit();
37 37
         }
38 38
 
39
-        if(settings::$multi) {
40
-            logger::write('You can not use answer mode when multi setting is on',loggerTypes::ERROR);
39
+        if (settings::$multi) {
40
+            logger::write('You can not use answer mode when multi setting is on', loggerTypes::ERROR);
41 41
             BPT::exit();
42 42
         }
43 43
     }
@@ -52,12 +52,12 @@  discard block
 block discarded – undo
52 52
         if (isset($data['return_array'])) {
53 53
             unset($data['return_array']);
54 54
         }
55
-        foreach ($data as $key=>&$value){
56
-            if (!isset($value)){
55
+        foreach ($data as $key=>&$value) {
56
+            if (!isset($value)) {
57 57
                 unset($data[$key]);
58 58
                 continue;
59 59
             }
60
-            if (is_array($value) || (is_object($value) && !is_a($value,'CURLFile'))){
60
+            if (is_array($value) || (is_object($value) && !is_a($value, 'CURLFile'))) {
61 61
                 $value = json_encode($value);
62 62
             }
63 63
         }
Please login to merge, or discard this patch.
api/request/curl.php 2 patches
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -10,18 +10,18 @@  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
         $token = $info['token'];
17 17
         $handler = $info['handler'];
18
-        self::setTimeout($data,$handler,$method);
18
+        self::setTimeout($data, $handler, $method);
19 19
         self::setData($data);
20 20
         $data['method'] = $method;
21 21
         curl_setopt($handler, CURLOPT_POSTFIELDS, $data);
22 22
         $result = curl_exec($handler);
23 23
         if (curl_errno($handler)) {
24
-            logger::write(curl_error($handler),loggerTypes::WARNING);
24
+            logger::write(curl_error($handler), loggerTypes::WARNING);
25 25
         }
26 26
         if ($token != settings::$token) {
27 27
             curl_close($handler);
@@ -37,9 +37,9 @@  discard block
 block discarded – undo
37 37
             curl_setopt($curl_handler, CURLOPT_RETURNTRANSFER, true);
38 38
             curl_setopt($curl_handler, CURLOPT_SSL_VERIFYPEER, false);
39 39
         }
40
-        else{
40
+        else {
41 41
             $token = settings::$token;
42
-            if (!isset(self::$curl_handler)){
42
+            if (!isset(self::$curl_handler)) {
43 43
                 self::$curl_handler = curl_init(settings::$base_url."$token/");
44 44
                 curl_setopt(self::$curl_handler, CURLOPT_RETURNTRANSFER, true);
45 45
                 curl_setopt(self::$curl_handler, CURLOPT_SSL_VERIFYPEER, false);
@@ -55,22 +55,22 @@  discard block
 block discarded – undo
55 55
         ];
56 56
     }
57 57
 
58
-    private static function setTimeout(array &$data , CurlHandle $curl_handler,string $method) {
58
+    private static function setTimeout(array &$data, CurlHandle $curl_handler, string $method) {
59 59
         if (isset($data['forgot'])) {
60 60
             curl_setopt($curl_handler, CURLOPT_TIMEOUT_MS, settings::$forgot_time);
61 61
             unset($data['forgot']);
62 62
         }
63
-        elseif ($method === 'getUpdates'){
63
+        elseif ($method === 'getUpdates') {
64 64
             curl_setopt($curl_handler, CURLOPT_TIMEOUT_MS, 5000);
65 65
         }
66
-        else{
66
+        else {
67 67
             curl_setopt($curl_handler, CURLOPT_TIMEOUT_MS, 300);
68 68
         }
69 69
     }
70 70
 
71 71
     private static function setData(array &$data) {
72
-        foreach ($data as &$value){
73
-            if (is_array($value) || (is_object($value) && !is_a($value,'CURLFile'))){
72
+        foreach ($data as &$value) {
73
+            if (is_array($value) || (is_object($value) && !is_a($value, 'CURLFile'))) {
74 74
                 $value = json_encode($value);
75 75
             }
76 76
         }
Please login to merge, or discard this patch.
Braces   +3 added lines, -6 removed lines patch added patch discarded remove patch
@@ -36,8 +36,7 @@  discard block
 block discarded – undo
36 36
             $curl_handler = curl_init(settings::$base_url."$token/");
37 37
             curl_setopt($curl_handler, CURLOPT_RETURNTRANSFER, true);
38 38
             curl_setopt($curl_handler, CURLOPT_SSL_VERIFYPEER, false);
39
-        }
40
-        else{
39
+        } else{
41 40
             $token = settings::$token;
42 41
             if (!isset(self::$curl_handler)){
43 42
                 self::$curl_handler = curl_init(settings::$base_url."$token/");
@@ -59,11 +58,9 @@  discard block
 block discarded – undo
59 58
         if (isset($data['forgot'])) {
60 59
             curl_setopt($curl_handler, CURLOPT_TIMEOUT_MS, settings::$forgot_time);
61 60
             unset($data['forgot']);
62
-        }
63
-        elseif ($method === 'getUpdates'){
61
+        } elseif ($method === 'getUpdates'){
64 62
             curl_setopt($curl_handler, CURLOPT_TIMEOUT_MS, 5000);
65
-        }
66
-        else{
63
+        } else{
67 64
             curl_setopt($curl_handler, CURLOPT_TIMEOUT_MS, 300);
68 65
         }
69 66
     }
Please login to merge, or discard this patch.