Passed
Push — main ( 0084f7...f34b86 )
by Miaad
12:18
created
src/telegram/request.php 1 patch
Spacing   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -831,30 +831,30 @@  discard block
 block discarded – undo
831 831
         'getGameHighScores'               => ['BPT\types\gameHighScore']
832 832
     ];
833 833
 
834
-    public static function __callStatic (string $name, array $arguments) {
834
+    public static function __callStatic(string $name, array $arguments) {
835 835
         if (!$action = self::methodAction($name)) {
836
-            logger::write("$name method is not supported",loggerTypes::ERROR);
836
+            logger::write("$name method is not supported", loggerTypes::ERROR);
837 837
             throw new bptException('METHOD_NOT_FOUND');
838 838
         }
839 839
         self::checkArguments($arguments);
840
-        self::keysName($action,$arguments);
841
-        self::readyFile($action,$arguments);
840
+        self::keysName($action, $arguments);
841
+        self::readyFile($action, $arguments);
842 842
         self::cleanArguments($arguments);
843
-        self::setDefaults($action,$arguments);
843
+        self::setDefaults($action, $arguments);
844 844
 
845 845
         if (isset($arguments['answer']) && $arguments['answer'] === true) {
846 846
             unset($arguments['answer']);
847 847
             if (!answer::isAnswered()) {
848
-                return answer::init($action,$arguments);
848
+                return answer::init($action, $arguments);
849 849
             }
850
-            logger::write('you can use answer mode only once for each webhook update, Others will be called like normal',loggerTypes::WARNING);
850
+            logger::write('you can use answer mode only once for each webhook update, Others will be called like normal', loggerTypes::WARNING);
851 851
         }
852
-        $result = curl::init($action,$arguments);
852
+        $result = curl::init($action, $arguments);
853 853
         if (!is_object($result)) {
854
-            logger::write("Telegram $action method failed : " . $result, loggerTypes::WARNING);
854
+            logger::write("Telegram $action method failed : ".$result, loggerTypes::WARNING);
855 855
             return false;
856 856
         }
857
-        return self::processResponse($action,$result);
857
+        return self::processResponse($action, $result);
858 858
     }
859 859
 
860 860
     private static function checkArguments(array &$arguments): void {
@@ -863,7 +863,7 @@  discard block
 block discarded – undo
863 863
         }
864 864
     }
865 865
 
866
-    private static function keysName (string $name, array &$arguments): void {
866
+    private static function keysName(string $name, array &$arguments): void {
867 867
         foreach ($arguments as $key => $argument) {
868 868
             if (is_numeric($key) && isset(self::METHODS_KEYS[$name][$key])) {
869 869
                 $arguments[self::METHODS_KEYS[$name][$key]] = $argument;
@@ -872,7 +872,7 @@  discard block
 block discarded – undo
872 872
         }
873 873
     }
874 874
 
875
-    private static function methodAction(string $name): string|false {
875
+    private static function methodAction(string $name): string | false {
876 876
         return self::METHODS_ACTION[str_replace('_', '', strtolower($name))] ?? false;
877 877
     }
878 878
 
@@ -908,11 +908,11 @@  discard block
 block discarded – undo
908 908
         }
909 909
     }
910 910
 
911
-    private static function methodFile(string $name): array|false {
911
+    private static function methodFile(string $name): array | false {
912 912
         return self::METHODS_WITH_FILE[$name] ?? false;
913 913
     }
914 914
 
915
-    private static function methodReturn(string $name,stdClass $response) {
915
+    private static function methodReturn(string $name, stdClass $response) {
916 916
         if (!settings::$use_types_classes) {
917 917
             return $response;
918 918
         }
@@ -934,13 +934,13 @@  discard block
 block discarded – undo
934 934
         $defaults = self::METHODS_EXTRA_DEFAULTS[$name] ?? [];
935 935
         foreach ($defaults as $key => $default) {
936 936
             if (is_numeric($key)) {
937
-                if (!isset($arguments[$default])){
937
+                if (!isset($arguments[$default])) {
938 938
                     $arguments[$default] = self::catchFields($default);
939 939
                 }
940 940
             }
941 941
             elseif (isset(BPT::$update->{$key}) || $key === 'other') {
942 942
                 foreach ($default as $def) {
943
-                    if (!isset($arguments[$def])){
943
+                    if (!isset($arguments[$def])) {
944 944
                         $arguments[$def] = self::catchFields($def);
945 945
                     }
946 946
                 }
@@ -959,14 +959,14 @@  discard block
 block discarded – undo
959 959
         self::$status = $response->ok;
960 960
         self::$pure_response = $response;
961 961
         if (!$response->ok) {
962
-            logger::write("Telegram $name method failed : " . json_encode($response), loggerTypes::WARNING);
962
+            logger::write("Telegram $name method failed : ".json_encode($response), loggerTypes::WARNING);
963 963
             unset($response->ok);
964 964
             return new responseError($response);
965 965
         }
966
-        return self::methodReturn($name,$response);
966
+        return self::methodReturn($name, $response);
967 967
     }
968 968
 
969
-    private static function cleanArguments (array &$arguments): void {
969
+    private static function cleanArguments(array &$arguments): void {
970 970
         foreach ($arguments as $key => $argument) {
971 971
             if ($argument == [] || $argument === null) {
972 972
                 unset($arguments[$key]);
@@ -981,7 +981,7 @@  discard block
 block discarded – undo
981 981
      *
982 982
      * @return int|string|bool
983 983
      */
984
-    public static function catchFields (string $field): int|string|bool {
984
+    public static function catchFields(string $field): int | string | bool {
985 985
         switch ($field) {
986 986
             case fields::CHAT_ID :
987 987
             case fields::FROM_CHAT_ID :
@@ -1128,13 +1128,13 @@  discard block
 block discarded – undo
1128 1128
                     default => false
1129 1129
                 };
1130 1130
             case fields::URL :
1131
-                return 'https://' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
1131
+                return 'https://'.$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];
1132 1132
             default:
1133 1133
                 return false;
1134 1134
         }
1135 1135
     }
1136 1136
 
1137
-    public static function fileLink (string|null $file_id = null): bool|string {
1137
+    public static function fileLink(string | null $file_id = null): bool | string {
1138 1138
         $file = request::getFile($file_id);
1139 1139
         if (!isset($file->file_path)) {
1140 1140
             return false;
@@ -1156,7 +1156,7 @@  discard block
 block discarded – undo
1156 1156
      *
1157 1157
      * @return bool
1158 1158
      */
1159
-    public static function downloadFile (string $destination, string|null $file_id = null): bool {
1159
+    public static function downloadFile(string $destination, string | null $file_id = null): bool {
1160 1160
         return tools::downloadFile(self::fileLink($file_id), $destination);
1161 1161
     }
1162 1162
 
@@ -1174,10 +1174,10 @@  discard block
 block discarded – undo
1174 1174
      *
1175 1175
      * @return message|bool|responseError
1176 1176
      */
1177
-    public static function sendFile (string $file_id, int|string $chat_id = null, int $message_thread_id = null, string $caption = null, string $parse_mode = null, array $caption_entities = null, bool $disable_notification = null, bool $protect_content = null, int $reply_to_message_id = null, bool $allow_sending_without_reply = null, inlineKeyboardMarkup|replyKeyboardMarkup|replyKeyboardRemove|forceReply|stdClass|array $reply_markup = null, string $token = null, bool $forgot = null, bool $answer = null): message|bool|responseError {
1177
+    public static function sendFile(string $file_id, int | string $chat_id = null, int $message_thread_id = null, string $caption = null, string $parse_mode = null, array $caption_entities = null, bool $disable_notification = null, bool $protect_content = null, int $reply_to_message_id = null, bool $allow_sending_without_reply = null, inlineKeyboardMarkup | replyKeyboardMarkup | replyKeyboardRemove | forceReply | stdClass | array $reply_markup = null, string $token = null, bool $forgot = null, bool $answer = null): message | bool | responseError {
1178 1178
         $type = tools::fileType($file_id);
1179 1179
         return match ($type) {
1180
-            fileTypes::VIDEO => request::sendVideo($file_id, $chat_id, $message_thread_id, null, null, null, null, $caption, $parse_mode, $caption_entities, false,null, $disable_notification, $protect_content, $reply_to_message_id, $allow_sending_without_reply, $reply_markup, $token, $forgot, $answer),
1180
+            fileTypes::VIDEO => request::sendVideo($file_id, $chat_id, $message_thread_id, null, null, null, null, $caption, $parse_mode, $caption_entities, false, null, $disable_notification, $protect_content, $reply_to_message_id, $allow_sending_without_reply, $reply_markup, $token, $forgot, $answer),
1181 1181
             fileTypes::VIDEO_NOTE => request::sendVideoNote($file_id, $chat_id, $message_thread_id, null, null, null, $disable_notification, $protect_content, $reply_to_message_id, $allow_sending_without_reply, $reply_markup, $token, $forgot, $answer),
1182 1182
             fileTypes::ANIMATION => request::sendAnimation($file_id, $chat_id, $message_thread_id, null, null, null, null, $caption, $parse_mode, $caption_entities, false, $disable_notification, $protect_content, $reply_to_message_id, $allow_sending_without_reply, $reply_markup, $token, $forgot, $answer),
1183 1183
             fileTypes::AUDIO => request::sendAudio($file_id, $chat_id, $message_thread_id, $caption, $parse_mode, $caption_entities, null, null, null, null, $disable_notification, $protect_content, $reply_to_message_id, $allow_sending_without_reply, $reply_markup, $token, $forgot, $answer),
Please login to merge, or discard this patch.
src/receiver/multi/exec.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -16,14 +16,14 @@  discard block
 block discarded – undo
16 16
     /**
17 17
      * @internal Only for BPT self usage , Don't use it in your source!
18 18
      */
19
-    public static function init(): string|null {
19
+    public static function init(): string | null {
20 20
         return self::getUpdate();
21 21
     }
22 22
 
23
-    private static function getUpdate (): string|null {
23
+    private static function getUpdate(): string | null {
24 24
         $up = glob('*.update');
25 25
         if (!isset($up[0])) {
26
-            logger::write('not authorized access denied. IP : '. $_SERVER['REMOTE_ADDR'] ?? 'unknown',loggerTypes::WARNING);
26
+            logger::write('not authorized access denied. IP : '.$_SERVER['REMOTE_ADDR'] ?? 'unknown', loggerTypes::WARNING);
27 27
             BPT::exit();
28 28
         }
29 29
         $up = end($up);
@@ -53,7 +53,7 @@  discard block
 block discarded – undo
53 53
     }
54 54
 
55 55
     private static function create($file) {
56
-        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 &");');
56
+        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 &");');
57 57
     }
58 58
 
59 59
     #[ArrayShape(['url' => 'array|string|string[]', 'file' => 'string'])]
Please login to merge, or discard this patch.
src/receiver/multi/curl.php 1 patch
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -13,9 +13,9 @@  discard block
 block discarded – undo
13 13
  * curl class , for multiprocessing with curl tricks
14 14
  */
15 15
 class curl extends webhook {
16
-    public static function init (): string|null {
16
+    public static function init(): string | null {
17 17
         if (!self::checkIP()) {
18
-            logger::write('not authorized access denied. IP : '. $_SERVER['REMOTE_ADDR'] ?? 'unknown',loggerTypes::WARNING);
18
+            logger::write('not authorized access denied. IP : '.$_SERVER['REMOTE_ADDR'] ?? 'unknown', loggerTypes::WARNING);
19 19
             BPT::exit();
20 20
         }
21 21
         return self::getUpdate();
@@ -25,7 +25,7 @@  discard block
 block discarded – undo
25 25
         return $_SERVER['REMOTE_ADDR'] === $_SERVER['SERVER_ADDR'];
26 26
     }
27 27
 
28
-    private static function getUpdate (): string {
28
+    private static function getUpdate(): string {
29 29
         $input = json_decode(file_get_contents('php://input'), true);
30 30
         webhook::telegramVerify($input['ip']);
31 31
         return $input['update'];
@@ -42,9 +42,9 @@  discard block
 block discarded – undo
42 42
         lock::set('BPT-MULTI-CURL');
43 43
     }
44 44
 
45
-    private static function getTimeout($url): float|int {
45
+    private static function getTimeout($url): float | int {
46 46
         $times = [];
47
-        for ($i = 0; $i < 10; $i ++) {
47
+        for ($i = 0; $i < 10; $i++) {
48 48
             $ch = curl_init($url);
49 49
             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']]);
50 50
             $start = microtime(true);
@@ -55,8 +55,8 @@  discard block
 block discarded – undo
55 55
         return $timeout > 50 ? $timeout + 10 : 50;
56 56
     }
57 57
 
58
-    private static function create($file,$timeout) {
59
-        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);?>');
58
+    private static function create($file, $timeout) {
59
+        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);?>');
60 60
     }
61 61
 
62 62
     #[ArrayShape(['url' => 'array|string|string[]', 'file' => 'array|string|string[]'])]
Please login to merge, or discard this patch.
src/receiver/webhook.php 1 patch
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -18,7 +18,7 @@  discard block
 block discarded – undo
18 18
     /**
19 19
      * @internal Only for BPT self usage , Don't use it in your source!
20 20
      */
21
-    public static function init () {
21
+    public static function init() {
22 22
         if (settings::$multi) {
23 23
             multi::init();
24 24
         }
@@ -38,28 +38,28 @@  discard block
 block discarded – undo
38 38
         lock::deleteIfExist(['BPT-MULTI-EXEC', 'BPT-MULTI-CURL', 'getUpdate', 'getUpdateHook']);
39 39
     }
40 40
 
41
-    protected static function setWebhook(string $url,string $secret = '') {
41
+    protected static function setWebhook(string $url, string $secret = '') {
42 42
         $res = BPT::setWebhook($url, settings::$certificate, max_connections: settings::$max_connection, allowed_updates: settings::$allowed_updates, drop_pending_updates: settings::$skip_old_updates, secret_token: $secret);
43 43
         if (!BPT::$status) {
44
-            logger::write("There is some problem happened , telegram response : \n".json_encode($res),loggerTypes::ERROR);
45
-            BPT::exit(print_r($res,true));
44
+            logger::write("There is some problem happened , telegram response : \n".json_encode($res), loggerTypes::ERROR);
45
+            BPT::exit(print_r($res, true));
46 46
         }
47
-        logger::write('Webhook was set successfully',loggerTypes::INFO);
47
+        logger::write('Webhook was set successfully', loggerTypes::INFO);
48 48
     }
49 49
 
50 50
     protected static function checkURL() {
51 51
         if (!(isset($_SERVER['SERVER_NAME']) && isset($_SERVER['REQUEST_URI']))) {
52
-            logger::write('For using webhook receiver , you should open this file in your webserver(by domain)',loggerTypes::ERROR);
52
+            logger::write('For using webhook receiver , you should open this file in your webserver(by domain)', loggerTypes::ERROR);
53 53
             throw new bptException('WEBHOOK_NEED_URL');
54 54
         }
55 55
     }
56 56
 
57 57
     protected static function setURL(): string {
58 58
         if (isset($_GET['token'])) {
59
-            logger::write('You can not specify token in url',loggerTypes::ERROR);
59
+            logger::write('You can not specify token in url', loggerTypes::ERROR);
60 60
             BPT::exit('You can not specify token in url');
61 61
         }
62
-        return (isset(settings::$certificate) ? 'http://' : 'https://') . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
62
+        return (isset(settings::$certificate) ? 'http://' : 'https://').$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];
63 63
     }
64 64
 
65 65
     protected static function setCertificate() {
@@ -74,8 +74,8 @@  discard block
 block discarded – undo
74 74
         self::checkURL();
75 75
         self::setCertificate();
76 76
         $url = self::setURL();
77
-        $secret = !empty(settings::$secret) ? settings::$secret : str_replace(':','---',settings::$token);
78
-        self::setWebhook($url,$secret);
77
+        $secret = !empty(settings::$secret) ? settings::$secret : str_replace(':', '---', settings::$token);
78
+        self::setWebhook($url, $secret);
79 79
         lock::save('BPT-HOOK', md5($secret));
80 80
         BPT::exit('Done');
81 81
     }
@@ -88,7 +88,7 @@  discard block
 block discarded – undo
88 88
                 BPT::exit();
89 89
             }
90 90
             if (settings::$telegram_verify) {
91
-                logger::write('This is not webhook set by BPT, webhook will reset',loggerTypes::WARNING);
91
+                logger::write('This is not webhook set by BPT, webhook will reset', loggerTypes::WARNING);
92 92
                 self::processSetWebhook();
93 93
             }
94 94
         }
@@ -110,7 +110,7 @@  discard block
 block discarded – undo
110 110
      *
111 111
      * @return bool
112 112
      */
113
-    public static function fastClose (int $timeout = 86400): bool {
113
+    public static function fastClose(int $timeout = 86400): bool {
114 114
         if (settings::$multi || !lock::exist('BPT-HOOK') || settings::$receiver !== \BPT\constants\receiver::WEBHOOK) {
115 115
             return false;
116 116
         }
Please login to merge, or discard this patch.
src/receiver/callback.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -9,18 +9,18 @@  discard block
 block discarded – undo
9 9
 use BPT\tools\tools;
10 10
 
11 11
 class callback {
12
-    public static function encodeData (array $data): string {
12
+    public static function encodeData(array $data): string {
13 13
         return tools::codec(codecAction::ENCRYPT, json_encode($data), md5(settings::$token), 'SguQgUvvKRLvmCyq')['hash'];
14 14
     }
15 15
 
16
-    public static function decodeData (string $data): array {
16
+    public static function decodeData(string $data): array {
17 17
         return json_decode(tools::codec(codecAction::DECRYPT, $data, md5(settings::$token), 'SguQgUvvKRLvmCyq'), true);
18 18
     }
19 19
 
20 20
     /**
21 21
      * @internal Only for BPT self usage , Don't use it in your source!
22 22
      */
23
-    public static function process () {
23
+    public static function process() {
24 24
         if (!settings::$handler || settings::$receiver != \BPT\constants\receiver::WEBHOOK || settings::$multi || !(isset($_GET['data']) || isset($_POST['data']))) {
25 25
             return false;
26 26
         }
@@ -45,7 +45,7 @@  discard block
 block discarded – undo
45 45
     /**
46 46
      * @internal Only for BPT self usage , Don't use it in your source!
47 47
      */
48
-    public static function callHandler (string $handler_name, $input) {
48
+    public static function callHandler(string $handler_name, $input) {
49 49
         if (method_exists(BPT::$handler, $handler_name)) {
50 50
             BPT::$handler->$handler_name($input);
51 51
         }
Please login to merge, or discard this patch.
src/BPT.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -299,13 +299,13 @@  discard block
 block discarded – undo
299 299
  * @method gameHighScore[]|responseError getGameHighScores (int|array|null $user_id = null, int|null $chat_id = null, int|null $message_id = null, string|null $inline_message_id = null, string|null $token = null, bool|null $forgot = null, bool|null $answer = null) Use this method to get data for high score tables. Will return the score of the specified user and several of their neighbors in a game. Returns an Array of GameHighScore objects.
300 300
  * @method gameHighScore[]|responseError getGameHigh (int|array|null $user_id = null, int|null $chat_id = null, int|null $message_id = null, string|null $inline_message_id = null, string|null $token = null, bool|null $forgot = null, bool|null $answer = null) Use this method to get data for high score tables. Will return the score of the specified user and several of their neighbors in a game. Returns an Array of GameHighScore objects.
301 301
  */
302
-class BPT extends telegram{
303
-    public static stdClass|update $update;
302
+class BPT extends telegram {
303
+    public static stdClass | update $update;
304 304
 
305 305
     public static BPT $handler;
306 306
 
307 307
 
308
-    public function __construct (array|easySettings $settings) {
308
+    public function __construct(array | easySettings $settings) {
309 309
         static::$handler = &$this;
310 310
         settings::init($settings);
311 311
     }
@@ -315,7 +315,7 @@  discard block
 block discarded – undo
315 315
     }
316 316
 
317 317
     #[NoReturn]
318
-    public static function exit (string|null $message = null): void {
318
+    public static function exit (string | null $message = null): void {
319 319
         die($message ?? "<div style='width:98vw;height:98vh;display:flex;justify-content:center;align-items:center;font-size:25vw'>BPT</div>");
320 320
     }
321 321
 }
Please login to merge, or discard this patch.