Passed
Push — main ( 03f6f3...31e835 )
by Miaad
10:35
created
examples/messenger/bot.php 2 patches
Spacing   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -19,7 +19,7 @@  discard block
 block discarded – undo
19 19
     const ADMIN = 123456789;
20 20
     const SHOW_STATUS = true;
21 21
     const UNKNOWN = 'I didnt understand it, Please use commands or reply to a user message';
22
-    const HELP            = 'Hello dear admin 
22
+    const HELP = 'Hello dear admin 
23 23
 This is a simple messenger bot which also support reply for users and admin itself
24 24
 For answering an user message , You must reply on it
25 25
 If you want to reply , You must first use /reply_on command and this will apply on your next message
@@ -34,11 +34,11 @@  discard block
 block discarded – undo
34 34
     const SEND_FAILED     = 'Failed!';
35 35
     const SEND_SUCCESSFUL = 'Done!';
36 36
 
37
-    public function __construct (array $settings) {
37
+    public function __construct(array $settings) {
38 38
         parent::__construct($settings);
39 39
     }
40 40
 
41
-    public function message (message $update) {
41
+    public function message(message $update) {
42 42
         $text = $update->text ?? '';
43 43
         $user_id = $update->from->id;
44 44
 
@@ -54,11 +54,11 @@  discard block
 block discarded – undo
54 54
                 return $this->sendMessage(self::HELP, answer: true);
55 55
             }
56 56
             if ($text === '/reply_on') {
57
-                mysql::update('users',['value'=>'reply_on'],['id'=>$user_id],1);
57
+                mysql::update('users', ['value'=>'reply_on'], ['id'=>$user_id], 1);
58 58
                 return $this->sendMessage(self::REPLY_ON, answer: true);
59 59
             }
60 60
             if ($text === '/reply_off') {
61
-                mysql::update('users',['value'=>'reply_off'],['id'=>$user_id],1);
61
+                mysql::update('users', ['value'=>'reply_off'], ['id'=>$user_id], 1);
62 62
                 return $this->sendMessage(self::REPLY_OFF, answer: true);
63 63
             }
64 64
             if (!isset($update->reply_to_message)) {
@@ -68,10 +68,10 @@  discard block
 block discarded – undo
68 68
             $reply_message_id = $update->reply_to_message->message_id;
69 69
 
70 70
             if ($update->reply_to_message->from->id === $user_id) {
71
-                $check_message = mysql::select('messages', ['receiver_message_id','receiver_id'], [
71
+                $check_message = mysql::select('messages', ['receiver_message_id', 'receiver_id'], [
72 72
                     'sender_message_id' => $reply_message_id,
73 73
                     'sender_id'         => $user_id
74
-                ],1);
74
+                ], 1);
75 75
 
76 76
                 if ($check_message->num_rows < 1) {
77 77
                     return $this->sendMessage(self::NOT_FOUND, answer: true);
@@ -81,19 +81,19 @@  discard block
 block discarded – undo
81 81
                 $result = $this->copyMessage($receiver_id, reply_to_message_id: $data->receiver_message_id);
82 82
             }
83 83
             else {
84
-                $check_message = mysql::select('messages', ['sender_message_id','sender_id'], [
84
+                $check_message = mysql::select('messages', ['sender_message_id', 'sender_id'], [
85 85
                     'receiver_message_id' => $reply_message_id,
86 86
                     'receiver_id'         => $user_id
87
-                ],1);
87
+                ], 1);
88 88
 
89 89
                 if ($check_message->num_rows < 1) {
90 90
                     return $this->sendMessage(self::NOT_FOUND, answer: true);
91 91
                 }
92 92
                 $data = $check_message->fetch_object();
93
-                $value = mysql::select('users','value',['id'=>$user_id])->fetch_object()->value;
93
+                $value = mysql::select('users', 'value', ['id'=>$user_id])->fetch_object()->value;
94 94
                 $receiver_id = $data->sender_id;
95 95
                 if ($value === 'reply_on') {
96
-                    mysql::update('users',['value'=>''],['id'=>$user_id]);
96
+                    mysql::update('users', ['value'=>''], ['id'=>$user_id]);
97 97
                     $result = $this->copyMessage($receiver_id, reply_to_message_id: $data->sender_message_id);
98 98
                 }
99 99
                 else {
@@ -117,7 +117,7 @@  discard block
 block discarded – undo
117 117
         }
118 118
         $username = $update->from->username;
119 119
         if (empty($username)) {
120
-            $name = $update->from->first_name . (!empty($update->from->last_name) ? (' ' . $update->from->last_name) : '');
120
+            $name = $update->from->first_name.(!empty($update->from->last_name) ? (' '.$update->from->last_name) : '');
121 121
             $keyboard = [
122 122
                 'inline_keyboard' => [
123 123
                     [
@@ -155,33 +155,33 @@  discard block
 block discarded – undo
155 155
         }
156 156
         if (isset($update->reply_to_message)) {
157 157
             $reply_message_id = $update->reply_to_message->message_id;
158
-            if ($update->reply_to_message->from->id === $user_id){
158
+            if ($update->reply_to_message->from->id === $user_id) {
159 159
                 $check_message = mysql::select('messages', 'receiver_message_id', [
160 160
                     'sender_message_id' => $reply_message_id,
161 161
                     'sender_id'         => $user_id
162
-                ],1);
162
+                ], 1);
163 163
                 if ($check_message->num_rows > 0) {
164
-                    $result = $this->copyMessage(self::ADMIN, reply_to_message_id: $check_message->fetch_object()->receiver_message_id,reply_markup: $keyboard);
164
+                    $result = $this->copyMessage(self::ADMIN, reply_to_message_id: $check_message->fetch_object()->receiver_message_id, reply_markup: $keyboard);
165 165
                 }
166 166
                 else {
167
-                    $result = $this->copyMessage(self::ADMIN,reply_markup: $keyboard);
167
+                    $result = $this->copyMessage(self::ADMIN, reply_markup: $keyboard);
168 168
                 }
169 169
             }
170 170
             else {
171 171
                 $check_message = mysql::select('messages', 'sender_message_id', [
172 172
                     'receiver_message_id' => $reply_message_id,
173 173
                     'receiver_id'         => $user_id
174
-                ],1);
174
+                ], 1);
175 175
                 if ($check_message->num_rows > 0) {
176
-                    $result = $this->copyMessage(self::ADMIN, reply_to_message_id: $check_message->fetch_object()->sender_message_id,reply_markup: $keyboard);
176
+                    $result = $this->copyMessage(self::ADMIN, reply_to_message_id: $check_message->fetch_object()->sender_message_id, reply_markup: $keyboard);
177 177
                 }
178 178
                 else {
179
-                    $result = $this->copyMessage(self::ADMIN,reply_markup: $keyboard);
179
+                    $result = $this->copyMessage(self::ADMIN, reply_markup: $keyboard);
180 180
                 }
181 181
             }
182 182
         }
183 183
         else {
184
-            $result = $this->copyMessage(self::ADMIN,reply_markup: $keyboard);
184
+            $result = $this->copyMessage(self::ADMIN, reply_markup: $keyboard);
185 185
         }
186 186
 
187 187
         /**
Please login to merge, or discard this patch.
Braces   +8 added lines, -16 removed lines patch added patch discarded remove patch
@@ -7,8 +7,7 @@  discard block
 block discarded – undo
7 7
 
8 8
 if (file_exists('vendor/autoload.php')) {
9 9
     require 'vendor/autoload.php';
10
-}
11
-else {
10
+} else {
12 11
     if (!file_exists('BPT.phar')) {
13 12
         copy('https://dl.bptlib.ir/BPT.phar', 'BPT.phar');
14 13
     }
@@ -79,8 +78,7 @@  discard block
 block discarded – undo
79 78
                 $data = $check_message->fetch_object();
80 79
                 $receiver_id = $data->receiver_id;
81 80
                 $result = $this->copyMessage($receiver_id, reply_to_message_id: $data->receiver_message_id);
82
-            }
83
-            else {
81
+            } else {
84 82
                 $check_message = mysql::select('messages', ['sender_message_id','sender_id'], [
85 83
                     'receiver_message_id' => $reply_message_id,
86 84
                     'receiver_id'         => $user_id
@@ -95,8 +93,7 @@  discard block
 block discarded – undo
95 93
                 if ($value === 'reply_on') {
96 94
                     mysql::update('users',['value'=>''],['id'=>$user_id]);
97 95
                     $result = $this->copyMessage($receiver_id, reply_to_message_id: $data->sender_message_id);
98
-                }
99
-                else {
96
+                } else {
100 97
                     $result = $this->copyMessage($receiver_id);
101 98
                 }
102 99
             }
@@ -138,8 +135,7 @@  discard block
 block discarded – undo
138 135
                     ]
139 136
                 ]
140 137
             ];
141
-        }
142
-        else {
138
+        } else {
143 139
             $keyboard = [
144 140
                 'inline_keyboard' => [
145 141
                     [
@@ -162,25 +158,21 @@  discard block
 block discarded – undo
162 158
                 ],1);
163 159
                 if ($check_message->num_rows > 0) {
164 160
                     $result = $this->copyMessage(self::ADMIN, reply_to_message_id: $check_message->fetch_object()->receiver_message_id,reply_markup: $keyboard);
165
-                }
166
-                else {
161
+                } else {
167 162
                     $result = $this->copyMessage(self::ADMIN,reply_markup: $keyboard);
168 163
                 }
169
-            }
170
-            else {
164
+            } else {
171 165
                 $check_message = mysql::select('messages', 'sender_message_id', [
172 166
                     'receiver_message_id' => $reply_message_id,
173 167
                     'receiver_id'         => $user_id
174 168
                 ],1);
175 169
                 if ($check_message->num_rows > 0) {
176 170
                     $result = $this->copyMessage(self::ADMIN, reply_to_message_id: $check_message->fetch_object()->sender_message_id,reply_markup: $keyboard);
177
-                }
178
-                else {
171
+                } else {
179 172
                     $result = $this->copyMessage(self::ADMIN,reply_markup: $keyboard);
180 173
                 }
181 174
             }
182
-        }
183
-        else {
175
+        } else {
184 176
             $result = $this->copyMessage(self::ADMIN,reply_markup: $keyboard);
185 177
         }
186 178
 
Please login to merge, or discard this patch.
src/telegram/request.php 1 patch
Spacing   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -825,30 +825,30 @@  discard block
 block discarded – undo
825 825
         'getGameHighScores'               => ['BPT\types\gameHighScore']
826 826
     ];
827 827
 
828
-    public static function __callStatic (string $name, array $arguments) {
828
+    public static function __callStatic(string $name, array $arguments) {
829 829
         if (!$action = self::methodAction($name)) {
830
-            logger::write("$name method is not supported",loggerTypes::ERROR);
830
+            logger::write("$name method is not supported", loggerTypes::ERROR);
831 831
             throw new bptException('METHOD_NOT_FOUND');
832 832
         }
833 833
         self::checkArguments($arguments);
834
-        self::keysName($action,$arguments);
835
-        self::readyFile($action,$arguments);
834
+        self::keysName($action, $arguments);
835
+        self::readyFile($action, $arguments);
836 836
         self::cleanArguments($arguments);
837
-        self::setDefaults($action,$arguments);
837
+        self::setDefaults($action, $arguments);
838 838
 
839 839
         if (isset($arguments['answer']) && $arguments['answer'] === true) {
840 840
             unset($arguments['answer']);
841 841
             if (!answer::isAnswered()) {
842
-                return answer::init($action,$arguments);
842
+                return answer::init($action, $arguments);
843 843
             }
844
-            logger::write('you can use answer mode only once for each webhook update, Others will be called like normal',loggerTypes::WARNING);
844
+            logger::write('you can use answer mode only once for each webhook update, Others will be called like normal', loggerTypes::WARNING);
845 845
         }
846
-        $result = curl::init($action,$arguments);
846
+        $result = curl::init($action, $arguments);
847 847
         if (!is_object($result)) {
848
-            logger::write("Telegram $action method failed : " . $result, loggerTypes::WARNING);
848
+            logger::write("Telegram $action method failed : ".$result, loggerTypes::WARNING);
849 849
             return false;
850 850
         }
851
-        return self::processResponse($action,$result);
851
+        return self::processResponse($action, $result);
852 852
     }
853 853
 
854 854
     private static function checkArguments(array &$arguments): void {
@@ -857,7 +857,7 @@  discard block
 block discarded – undo
857 857
         }
858 858
     }
859 859
 
860
-    private static function keysName (string $name, array &$arguments): void {
860
+    private static function keysName(string $name, array &$arguments): void {
861 861
         foreach ($arguments as $key => $argument) {
862 862
             if (is_numeric($key) && isset(self::METHODS_KEYS[$name][$key])) {
863 863
                 $arguments[self::METHODS_KEYS[$name][$key]] = $argument;
@@ -866,7 +866,7 @@  discard block
 block discarded – undo
866 866
         }
867 867
     }
868 868
 
869
-    private static function methodAction(string $name): string|false {
869
+    private static function methodAction(string $name): string | false {
870 870
         return self::METHODS_ACTION[str_replace('_', '', strtolower($name))] ?? false;
871 871
     }
872 872
 
@@ -902,11 +902,11 @@  discard block
 block discarded – undo
902 902
         }
903 903
     }
904 904
 
905
-    private static function methodFile(string $name): array|false {
905
+    private static function methodFile(string $name): array | false {
906 906
         return self::METHODS_WITH_FILE[$name] ?? false;
907 907
     }
908 908
 
909
-    private static function methodReturn(string $name,stdClass $response) {
909
+    private static function methodReturn(string $name, stdClass $response) {
910 910
         if (!isset(self::METHODS_RETURN[$name])) {
911 911
             return $response->result;
912 912
         }
@@ -925,13 +925,13 @@  discard block
 block discarded – undo
925 925
         $defaults = self::METHODS_EXTRA_DEFAULTS[$name] ?? [];
926 926
         foreach ($defaults as $key => $default) {
927 927
             if (is_numeric($key)) {
928
-                if (!isset($arguments[$default])){
928
+                if (!isset($arguments[$default])) {
929 929
                     $arguments[$default] = self::catchFields($default);
930 930
                 }
931 931
             }
932 932
             elseif (isset(BPT::$update->$key) || $key === 'other') {
933 933
                 foreach ($default as $def) {
934
-                    if (!isset($arguments[$def])){
934
+                    if (!isset($arguments[$def])) {
935 935
                         $arguments[$def] = self::catchFields($def);
936 936
                     }
937 937
                 }
@@ -950,13 +950,13 @@  discard block
 block discarded – undo
950 950
         self::$status = $response->ok;
951 951
         self::$pure_response = $response;
952 952
         if (!$response->ok) {
953
-            logger::write("Telegram $name method failed : " . json_encode($response), loggerTypes::WARNING);
953
+            logger::write("Telegram $name method failed : ".json_encode($response), loggerTypes::WARNING);
954 954
             return new responseError($response);
955 955
         }
956
-        return self::methodReturn($name,$response);
956
+        return self::methodReturn($name, $response);
957 957
     }
958 958
 
959
-    private static function cleanArguments (array &$arguments): void {
959
+    private static function cleanArguments(array &$arguments): void {
960 960
         foreach ($arguments as $key => $argument) {
961 961
             if ($argument == [] || $argument === null) {
962 962
                 unset($arguments[$key]);
@@ -971,7 +971,7 @@  discard block
 block discarded – undo
971 971
      *
972 972
      * @return int|string|bool
973 973
      */
974
-    public static function catchFields (string $field): int|string|bool {
974
+    public static function catchFields(string $field): int | string | bool {
975 975
         switch ($field) {
976 976
             case fields::CHAT_ID :
977 977
             case fields::FROM_CHAT_ID :
@@ -1118,13 +1118,13 @@  discard block
 block discarded – undo
1118 1118
                     default => false
1119 1119
                 };
1120 1120
             case fields::URL :
1121
-                return 'https://' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
1121
+                return 'https://'.$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];
1122 1122
             default:
1123 1123
                 return false;
1124 1124
         }
1125 1125
     }
1126 1126
 
1127
-    public static function fileLink (string|null $file_id = null): bool|string {
1127
+    public static function fileLink(string | null $file_id = null): bool | string {
1128 1128
         $file = request::getFile($file_id);
1129 1129
         if (!isset($file->file_path)) {
1130 1130
             return false;
@@ -1146,7 +1146,7 @@  discard block
 block discarded – undo
1146 1146
      *
1147 1147
      * @return bool
1148 1148
      */
1149
-    public static function downloadFile (string|null $destination = null, string|null $file_id = null): bool {
1149
+    public static function downloadFile(string | null $destination = null, string | null $file_id = null): bool {
1150 1150
         return tools::downloadFile(self::fileLink($file_id), $destination);
1151 1151
     }
1152 1152
 
@@ -1164,10 +1164,10 @@  discard block
 block discarded – undo
1164 1164
      *
1165 1165
      * @return message|bool|responseError
1166 1166
      */
1167
-    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 {
1167
+    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 {
1168 1168
         $type = tools::fileType($file_id);
1169 1169
         return match ($type) {
1170
-            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),
1170
+            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),
1171 1171
             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),
1172 1172
             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),
1173 1173
             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/database/mysql.php 2 patches
Spacing   +53 added lines, -53 removed lines patch added patch discarded remove patch
@@ -31,7 +31,7 @@  discard block
 block discarded – undo
31 31
     /**
32 32
      * If you want to use it in standalone mode , you MUST set `auto_process` to `false`
33 33
      */
34
-    public static function init (string $host = 'localhost', string $username = 'root', string $password = '', string $dbname = '', bool $auto_process = null, int $port = 3306): void {
34
+    public static function init(string $host = 'localhost', string $username = 'root', string $password = '', string $dbname = '', bool $auto_process = null, int $port = 3306): void {
35 35
         $host = settings::$db['host'] ?? $host;
36 36
         $port = settings::$db['port'] ?? $port;
37 37
         $user = settings::$db['user'] ?? settings::$db['username'] ?? $username;
@@ -41,7 +41,7 @@  discard block
 block discarded – undo
41 41
         self::$db_name = $dbname;
42 42
         self::$connection = new mysqli($host, $user, $pass, $dbname, $port);
43 43
         if (self::$connection->connect_errno) {
44
-            logger::write('SQL connection has problem : ' . self::$connection->connect_error, loggerTypes::ERROR);
44
+            logger::write('SQL connection has problem : '.self::$connection->connect_error, loggerTypes::ERROR);
45 45
             throw new bptException('SQL_CONNECTION_PROBLEM');
46 46
         }
47 47
         if (self::$auto_process && !lock::exist('BPT-MYSQL')) {
@@ -49,7 +49,7 @@  discard block
 block discarded – undo
49 49
         }
50 50
     }
51 51
 
52
-    private static function install (): void {
52
+    private static function install(): void {
53 53
         self::pureQuery("
54 54
 CREATE TABLE `users`
55 55
 (
@@ -70,7 +70,7 @@  discard block
 block discarded – undo
70 70
     /**
71 71
      * @internal Only for BPT self usage , Don't use it in your source!
72 72
      */
73
-    public static function process (): void {
73
+    public static function process(): void {
74 74
         if (self::$auto_process) {
75 75
             if (isset(BPT::$update->message)) {
76 76
                 self::processMessage(BPT::$update->message);
@@ -90,7 +90,7 @@  discard block
 block discarded – undo
90 90
         }
91 91
     }
92 92
 
93
-    private static function processMessage (message $update): void {
93
+    private static function processMessage(message $update): void {
94 94
         $type = $update->chat->type;
95 95
         if ($type === chatType::PRIVATE) {
96 96
             $user_id = $update->from->id;
@@ -116,7 +116,7 @@  discard block
 block discarded – undo
116 116
         }
117 117
     }
118 118
 
119
-    private static function processCallbackQuery (callbackQuery $update): void {
119
+    private static function processCallbackQuery(callbackQuery $update): void {
120 120
         $type = $update->message->chat->type;
121 121
         if ($type === chatType::PRIVATE) {
122 122
             $user_id = $update->from->id;
@@ -126,7 +126,7 @@  discard block
 block discarded – undo
126 126
         }
127 127
     }
128 128
 
129
-    private static function processInlineQuery (inlineQuery $update): void {
129
+    private static function processInlineQuery(inlineQuery $update): void {
130 130
         $type = $update->chat_type;
131 131
         if ($type === chatType::PRIVATE || $type === chatType::SENDER) {
132 132
             $user_id = $update->from->id;
@@ -136,7 +136,7 @@  discard block
 block discarded – undo
136 136
         }
137 137
     }
138 138
 
139
-    private static function processMyChatMember (chatMemberUpdated $update): void {
139
+    private static function processMyChatMember(chatMemberUpdated $update): void {
140 140
         $type = $update->chat->type;
141 141
         if ($type === chatType::PRIVATE) {
142 142
             if ($update->new_chat_member->status === chatMemberStatus::MEMBER) {
@@ -159,7 +159,7 @@  discard block
 block discarded – undo
159 159
      *
160 160
      * @return bool
161 161
      */
162
-    public static function addDefaultWhere (array $where): bool {
162
+    public static function addDefaultWhere(array $where): bool {
163 163
         if (empty(self::$default_where)) {
164 164
             self::$default_where = $where;
165 165
         }
@@ -174,7 +174,7 @@  discard block
 block discarded – undo
174 174
      *
175 175
      * @return mysqli
176 176
      */
177
-    public static function getMysqli (): mysqli {
177
+    public static function getMysqli(): mysqli {
178 178
         return self::$connection;
179 179
     }
180 180
 
@@ -185,7 +185,7 @@  discard block
 block discarded – undo
185 185
      *
186 186
      * @return int|string
187 187
      */
188
-    public static function affected_rows (): int|string {
188
+    public static function affected_rows(): int | string {
189 189
         return self::$connection->affected_rows;
190 190
     }
191 191
 
@@ -196,7 +196,7 @@  discard block
 block discarded – undo
196 196
      *
197 197
      * @return int|string
198 198
      */
199
-    public static function affectedRows (): int|string {
199
+    public static function affectedRows(): int | string {
200 200
         return self::$connection->affected_rows;
201 201
     }
202 202
 
@@ -207,7 +207,7 @@  discard block
 block discarded – undo
207 207
      *
208 208
      * @return int|string
209 209
      */
210
-    public static function insert_id (): int|string {
210
+    public static function insert_id(): int | string {
211 211
         return self::$connection->insert_id;
212 212
     }
213 213
 
@@ -218,7 +218,7 @@  discard block
 block discarded – undo
218 218
      *
219 219
      * @return int|string
220 220
      */
221
-    public static function insertId (): int|string {
221
+    public static function insertId(): int | string {
222 222
         return self::$connection->insert_id;
223 223
     }
224 224
 
@@ -229,7 +229,7 @@  discard block
 block discarded – undo
229 229
      *
230 230
      * @return string
231 231
      */
232
-    public static function escapeString (string $text): string {
232
+    public static function escapeString(string $text): string {
233 233
         return self::$connection->real_escape_string($text);
234 234
     }
235 235
 
@@ -238,7 +238,7 @@  discard block
 block discarded – undo
238 238
      *
239 239
      * @return string
240 240
      */
241
-    public static function error (): string {
241
+    public static function error(): string {
242 242
         return self::$connection->error;
243 243
     }
244 244
 
@@ -247,7 +247,7 @@  discard block
 block discarded – undo
247 247
      *
248 248
      * @return int
249 249
      */
250
-    public static function errno (): int {
250
+    public static function errno(): int {
251 251
         return self::$connection->errno;
252 252
     }
253 253
 
@@ -258,7 +258,7 @@  discard block
 block discarded – undo
258 258
      *
259 259
      * @return bool
260 260
      */
261
-    public static function setCharset (string $charset): bool {
261
+    public static function setCharset(string $charset): bool {
262 262
         return self::$connection->set_charset($charset);
263 263
     }
264 264
 
@@ -273,7 +273,7 @@  discard block
 block discarded – undo
273 273
      *
274 274
      * @return mysqli_result|bool
275 275
      */
276
-    public static function pureQuery (string $query): mysqli_result|bool {
276
+    public static function pureQuery(string $query): mysqli_result | bool {
277 277
         return self::$connection->query($query);
278 278
     }
279 279
 
@@ -294,7 +294,7 @@  discard block
 block discarded – undo
294 294
      *
295 295
      * @return mysqli_result|bool
296 296
      */
297
-    public static function query (string $query, array $vars = [], bool $need_result = true): mysqli_result|bool {
297
+    public static function query(string $query, array $vars = [], bool $need_result = true): mysqli_result | bool {
298 298
         if (empty($vars)) {
299 299
             return self::pureQuery($query);
300 300
         }
@@ -311,7 +311,7 @@  discard block
 block discarded – undo
311 311
                 $types .= 's';
312 312
             }
313 313
         }
314
-        $prepare->bind_param($types,...$vars);
314
+        $prepare->bind_param($types, ...$vars);
315 315
         if (!$prepare->execute()) {
316 316
             logger::write(loggerTypes::WARNING, $prepare->error);
317 317
             return false;
@@ -358,8 +358,8 @@  discard block
 block discarded – undo
358 358
                 else {
359 359
                     $query .= ' AND';
360 360
                 }
361
-                $operator = substr($sub_value,0,2);
362
-                $operator_value = substr($sub_value,2);
361
+                $operator = substr($sub_value, 0, 2);
362
+                $operator_value = substr($sub_value, 2);
363 363
                 switch ($operator) {
364 364
                     case '>=':
365 365
                         $query .= " `$name` >= ?";
@@ -386,8 +386,8 @@  discard block
 block discarded – undo
386 386
                         $sub_value = $operator_value;
387 387
                         break;
388 388
                     case '##':
389
-                        $operator = substr($operator_value,0,2);
390
-                        $column = substr($operator_value,2);
389
+                        $operator = substr($operator_value, 0, 2);
390
+                        $column = substr($operator_value, 2);
391 391
                         $query .= match ($operator) {
392 392
                             '>=' => " `$name` >= `$column`",
393 393
                             '<=' => " `$name` <= `$column`",
@@ -411,17 +411,17 @@  discard block
 block discarded – undo
411 411
         return $values;
412 412
     }
413 413
 
414
-    private static function groupByBuilder(string &$query, string|array $group_by = []): void {
414
+    private static function groupByBuilder(string &$query, string | array $group_by = []): void {
415 415
         if (empty($group_by)) {
416 416
             return;
417 417
         }
418 418
         if (is_string($group_by)) {
419 419
             $group_by = [$group_by];
420 420
         }
421
-        $query .= ' GROUP BY `' . implode('`, `',$group_by) . '`';
421
+        $query .= ' GROUP BY `'.implode('`, `', $group_by).'`';
422 422
     }
423 423
 
424
-    private static function orderByBuilder(string &$query, string|array $order_by = []): void {
424
+    private static function orderByBuilder(string &$query, string | array $order_by = []): void {
425 425
         if (empty($order_by)) {
426 426
             return;
427 427
         }
@@ -474,8 +474,8 @@  discard block
 block discarded – undo
474 474
                 continue;
475 475
             }
476 476
 
477
-            $operator = substr($value,0,2);
478
-            $operator_value = substr($value,2);
477
+            $operator = substr($value, 0, 2);
478
+            $operator_value = substr($value, 2);
479 479
             switch ($operator) {
480 480
                 case '+=':
481 481
                     $query .= " `$name` = `$name` + ?";
@@ -508,14 +508,14 @@  discard block
 block discarded – undo
508 508
         return $values;
509 509
     }
510 510
 
511
-    private static function insertBuilder(string &$query, string|array $columns, array|string $values): array {
512
-        $query .= '(`' . (is_string($columns) ? $columns : implode('`, `', $columns)) . '`) VALUES (';
511
+    private static function insertBuilder(string &$query, string | array $columns, array | string $values): array {
512
+        $query .= '(`'.(is_string($columns) ? $columns : implode('`, `', $columns)).'`) VALUES (';
513 513
         if (is_string($values)) $values = [$values];
514
-        $query .= '?' . str_repeat(', ?', count($values) - 1) . ')';
514
+        $query .= '?'.str_repeat(', ?', count($values) - 1).')';
515 515
         return $values;
516 516
     }
517 517
 
518
-    private static function selectBuilder (string &$query, string|array $columns): void {
518
+    private static function selectBuilder(string &$query, string | array $columns): void {
519 519
         if ($columns == '*') {
520 520
             $query .= ' * ';
521 521
             return;
@@ -534,7 +534,7 @@  discard block
 block discarded – undo
534 534
                     $formatted = '*';
535 535
                     $column = 'all';
536 536
                 }
537
-                $query .= strtoupper($function) . "($formatted) as `{$function}_$column`";
537
+                $query .= strtoupper($function)."($formatted) as `{$function}_$column`";
538 538
             }
539 539
             else {
540 540
                 $query .= "`$column`";
@@ -559,7 +559,7 @@  discard block
 block discarded – undo
559 559
      *
560 560
      * @return bool
561 561
      */
562
-    public static function delete (string $table, array $where = null, int $count = null, int $offset = null, bool $ignore_default_where = false): bool {
562
+    public static function delete(string $table, array $where = null, int $count = null, int $offset = null, bool $ignore_default_where = false): bool {
563 563
         $query = "DELETE FROM `$table`";
564 564
         $vars = self::whereBuilder($query, $where, $ignore_default_where);
565 565
         self::countBuilder($query, $count, $offset);
@@ -579,7 +579,7 @@  discard block
 block discarded – undo
579 579
      *
580 580
      * @return bool
581 581
      */
582
-    public static function update (string $table, array $modify, array $where = null, int $count = null, int $offset = null, bool $ignore_default_where = false): bool {
582
+    public static function update(string $table, array $modify, array $where = null, int $count = null, int $offset = null, bool $ignore_default_where = false): bool {
583 583
         $query = "UPDATE `$table` SET";
584 584
         $modify_vars = self::updateBuilder($query, $modify);
585 585
         $where_vars = self::whereBuilder($query, $where, $ignore_default_where);
@@ -598,7 +598,7 @@  discard block
 block discarded – undo
598 598
      *
599 599
      * @return bool
600 600
      */
601
-    public static function insert (string $table, string|array $columns, array|string $values): bool {
601
+    public static function insert(string $table, string | array $columns, array | string $values): bool {
602 602
         $query = "INSERT INTO `$table`";
603 603
         $values = self::insertBuilder($query, $columns, $values);
604 604
         return self::query($query, $values, false);
@@ -621,7 +621,7 @@  discard block
 block discarded – undo
621 621
      *
622 622
      * @return bool
623 623
      */
624
-    public static function insertUpdate (string $table, string|array $columns, array|string $values, array $modify): bool {
624
+    public static function insertUpdate(string $table, string | array $columns, array | string $values, array $modify): bool {
625 625
         $query = "INSERT INTO `$table`";
626 626
         $values = self::insertBuilder($query, $columns, $values);
627 627
         $query .= ' ON DUPLICATE KEY UPDATE';
@@ -646,14 +646,14 @@  discard block
 block discarded – undo
646 646
      *
647 647
      * @return mysqli_result|bool
648 648
      */
649
-    public static function select (string $table, array|string $columns = '*', array $where = null, int $count = null, int $offset = null, array|string $group_by = [], array|string $order_by = [], bool $ignore_default_where = false): mysqli_result|bool {
649
+    public static function select(string $table, array | string $columns = '*', array $where = null, int $count = null, int $offset = null, array | string $group_by = [], array | string $order_by = [], bool $ignore_default_where = false): mysqli_result | bool {
650 650
         $query = 'SELECT';
651 651
         self::selectBuilder($query, $columns);
652 652
         $query .= "FROM `$table`";
653
-        $var = self::whereBuilder($query,$where, $ignore_default_where);
653
+        $var = self::whereBuilder($query, $where, $ignore_default_where);
654 654
         self::groupByBuilder($query, $group_by);
655 655
         self::orderByBuilder($query, $order_by);
656
-        self::countBuilder($query,$count,$offset);
656
+        self::countBuilder($query, $count, $offset);
657 657
         return self::query($query, $var);
658 658
     }
659 659
 
@@ -670,7 +670,7 @@  discard block
 block discarded – undo
670 670
      *
671 671
      * @return null|bool|array
672 672
      */
673
-    public static function selectArray (string $table, array|string $columns = '*', array $where = null, array|string $group_by = [], array|string $order_by = [], bool $ignore_default_where = false): bool|array|null {
673
+    public static function selectArray(string $table, array | string $columns = '*', array $where = null, array | string $group_by = [], array | string $order_by = [], bool $ignore_default_where = false): bool | array | null {
674 674
         $res = self::select($table, $columns, $where, 1, 0, $group_by, $order_by, ignore_default_where: $ignore_default_where);
675 675
         if ($res) {
676 676
             return $res->fetch_assoc();
@@ -689,7 +689,7 @@  discard block
 block discarded – undo
689 689
      * @param array|string $group_by group result based on these columns
690 690
      * @param array|string $order_by order result based on these columns
691 691
      */
692
-    public static function selectObject (string $table, array|string $columns = '*', array $where = null, array|string $group_by = [], array|string $order_by = [], bool $ignore_default_where = false) {
692
+    public static function selectObject(string $table, array | string $columns = '*', array $where = null, array | string $group_by = [], array | string $order_by = [], bool $ignore_default_where = false) {
693 693
         $res = self::select($table, $columns, $where, 1, 0, $group_by, $order_by, ignore_default_where: $ignore_default_where);
694 694
         if ($res) {
695 695
             return $res->fetch_object();
@@ -713,7 +713,7 @@  discard block
 block discarded – undo
713 713
      *
714 714
      * @return bool|Generator
715 715
      */
716
-    public static function selectEach (string $table, array|string $columns = '*', array $where = null, int $count = null, int $offset = null, array|string $group_by = [], array|string $order_by = [], bool $ignore_default_where = false): bool|Generator {
716
+    public static function selectEach(string $table, array | string $columns = '*', array $where = null, int $count = null, int $offset = null, array | string $group_by = [], array | string $order_by = [], bool $ignore_default_where = false): bool | Generator {
717 717
         $res = self::select($table, $columns, $where, $count, $offset, $group_by, $order_by, ignore_default_where: $ignore_default_where);
718 718
         if ($res) {
719 719
             while ($row = $res->fetch_assoc()) yield $row;
@@ -731,10 +731,10 @@  discard block
 block discarded – undo
731 731
      *
732 732
      * @return string if save is true , return file name otherwise return sql data
733 733
      */
734
-    public static function backup (array $wanted_tables = null, bool $table_data = true, bool $save = true, string $file_name = ''): string {
734
+    public static function backup(array $wanted_tables = null, bool $table_data = true, bool $save = true, string $file_name = ''): string {
735 735
         self::setCharset('utf8mb4');
736 736
 
737
-        $tables = array_column(self::query('SHOW TABLES')->fetch_all(),0);
737
+        $tables = array_column(self::query('SHOW TABLES')->fetch_all(), 0);
738 738
         if (!empty($wanted_tables)) {
739 739
             $tables = array_intersect($tables, $wanted_tables);
740 740
         }
@@ -745,12 +745,12 @@  discard block
 block discarded – undo
745 745
             logger::write('No table founded for backup, if your database has table : check $wanted_tables argument', loggerTypes::WARNING);
746 746
         }
747 747
         foreach ($tables as $table) {
748
-            $sql .= self::query("SHOW CREATE TABLE `$table`")->fetch_row()[1] . ";\n\n";
748
+            $sql .= self::query("SHOW CREATE TABLE `$table`")->fetch_row()[1].";\n\n";
749 749
             if ($table_data) {
750 750
                 $total_rows = self::query("SELECT COUNT(*) as `cnt` FROM `$table`")->fetch_object()->cnt;
751 751
                 for ($i = 0; $i < $total_rows; $i = $i + 1000) {
752
-                    $sql .= 'INSERT INTO ' . $table . ' VALUES';
753
-                    $result = self::select($table, '*' , null, 1000, $i);
752
+                    $sql .= 'INSERT INTO '.$table.' VALUES';
753
+                    $result = self::select($table, '*', null, 1000, $i);
754 754
                     $field_count = $result->field_count;
755 755
                     $affected_rows = self::affected_rows();
756 756
                     $counter = 1;
@@ -758,12 +758,12 @@  discard block
 block discarded – undo
758 758
                         $sql .= "\n(";
759 759
                         for ($column = 0; $column < $field_count; $column++) {
760 760
                             $row[$column] = str_replace("\n", "\\n", addslashes($row[$column]));
761
-                            $sql .= !empty($row[$column]) ? '"' . $row[$column] . '"' : '""';
761
+                            $sql .= !empty($row[$column]) ? '"'.$row[$column].'"' : '""';
762 762
                             if ($column < $field_count - 1) {
763 763
                                 $sql .= ',';
764 764
                             }
765 765
                         }
766
-                        $sql .= ')' . ($counter == $affected_rows ? ';' : ',');
766
+                        $sql .= ')'.($counter == $affected_rows ? ';' : ',');
767 767
                         $counter++;
768 768
                     }
769 769
                 }
@@ -779,7 +779,7 @@  discard block
 block discarded – undo
779 779
         }
780 780
 
781 781
         if (empty($file_name)) {
782
-            $file_name = self::$db_name . time() . '.sql';
782
+            $file_name = self::$db_name.time().'.sql';
783 783
         }
784 784
         file_put_contents($file_name, $sql);
785 785
         return $file_name;
Please login to merge, or discard this patch.
Braces   +22 added lines, -31 removed lines patch added patch discarded remove patch
@@ -74,17 +74,13 @@  discard block
 block discarded – undo
74 74
         if (self::$auto_process) {
75 75
             if (isset(BPT::$update->message)) {
76 76
                 self::processMessage(BPT::$update->message);
77
-            }
78
-            elseif (isset(BPT::$update->edited_message)) {
77
+            } elseif (isset(BPT::$update->edited_message)) {
79 78
                 self::processMessage(BPT::$update->edited_message);
80
-            }
81
-            elseif (isset(BPT::$update->callback_query)) {
79
+            } elseif (isset(BPT::$update->callback_query)) {
82 80
                 self::processCallbackQuery(BPT::$update->callback_query);
83
-            }
84
-            elseif (isset(BPT::$update->inline_query)) {
81
+            } elseif (isset(BPT::$update->inline_query)) {
85 82
                 self::processInlineQuery(BPT::$update->inline_query);
86
-            }
87
-            elseif (isset(BPT::$update->my_chat_member)) {
83
+            } elseif (isset(BPT::$update->my_chat_member)) {
88 84
                 self::processMyChatMember(BPT::$update->my_chat_member);
89 85
             }
90 86
         }
@@ -141,8 +137,7 @@  discard block
 block discarded – undo
141 137
         if ($type === chatType::PRIVATE) {
142 138
             if ($update->new_chat_member->status === chatMemberStatus::MEMBER) {
143 139
                 self::update('users', ['blocked' => false], ['id' => $update->from->id], 1);
144
-            }
145
-            else {
140
+            } else {
146 141
                 self::update('users', ['blocked' => true], ['id' => $update->from->id], 1);
147 142
             }
148 143
         }
@@ -162,8 +157,7 @@  discard block
 block discarded – undo
162 157
     public static function addDefaultWhere (array $where): bool {
163 158
         if (empty(self::$default_where)) {
164 159
             self::$default_where = $where;
165
-        }
166
-        else {
160
+        } else {
167 161
             self::$default_where = array_merge(self::$default_where, $where);
168 162
         }
169 163
         return true;
@@ -303,11 +297,9 @@  discard block
 block discarded – undo
303 297
         foreach ($vars as $var) {
304 298
             if (is_int($var)) {
305 299
                 $types .= 'i';
306
-            }
307
-            elseif (is_double($var)) {
300
+            } elseif (is_double($var)) {
308 301
                 $types .= 'd';
309
-            }
310
-            else {
302
+            } else {
311 303
                 $types .= 's';
312 304
             }
313 305
         }
@@ -335,8 +327,7 @@  discard block
 block discarded – undo
335 327
         foreach ($where as $name => $value) {
336 328
             if ($first) {
337 329
                 $first = false;
338
-            }
339
-            else {
330
+            } else {
340 331
                 $query .= ' AND';
341 332
             }
342 333
 
@@ -354,8 +345,7 @@  discard block
 block discarded – undo
354 345
             foreach ($value as $sub_value) {
355 346
                 if ($sub_first) {
356 347
                     $sub_first = false;
357
-                }
358
-                else {
348
+                } else {
359 349
                     $query .= ' AND';
360 350
                 }
361 351
                 $operator = substr($sub_value,0,2);
@@ -435,8 +425,7 @@  discard block
 block discarded – undo
435 425
         foreach ($order_by as $key => $mode) {
436 426
             if ($first) {
437 427
                 $first = false;
438
-            }
439
-            else {
428
+            } else {
440 429
                 $query .= ', ';
441 430
             }
442 431
             if (is_numeric($key)) {
@@ -450,8 +439,7 @@  discard block
 block discarded – undo
450 439
     private static function countBuilder(string &$query, int $count = null, int $offset = null): void {
451 440
         if (!empty($count)) {
452 441
             $query .= !empty($offset) ? " LIMIT $offset, $count" : " LIMIT $count";
453
-        }
454
-        elseif (!empty($offset)) {
442
+        } elseif (!empty($offset)) {
455 443
             $query .= " OFFSET $offset";
456 444
         }
457 445
     }
@@ -463,8 +451,7 @@  discard block
 block discarded – undo
463 451
         foreach ($modify as $name => $value) {
464 452
             if ($first) {
465 453
                 $first = false;
466
-            }
467
-            else {
454
+            } else {
468 455
                 $query .= ',';
469 456
             }
470 457
 
@@ -510,7 +497,9 @@  discard block
 block discarded – undo
510 497
 
511 498
     private static function insertBuilder(string &$query, string|array $columns, array|string $values): array {
512 499
         $query .= '(`' . (is_string($columns) ? $columns : implode('`, `', $columns)) . '`) VALUES (';
513
-        if (is_string($values)) $values = [$values];
500
+        if (is_string($values)) {
501
+            $values = [$values];
502
+        }
514 503
         $query .= '?' . str_repeat(', ?', count($values) - 1) . ')';
515 504
         return $values;
516 505
     }
@@ -535,8 +524,7 @@  discard block
 block discarded – undo
535 524
                     $column = 'all';
536 525
                 }
537 526
                 $query .= strtoupper($function) . "($formatted) as `{$function}_$column`";
538
-            }
539
-            else {
527
+            } else {
540 528
                 $query .= "`$column`";
541 529
             }
542 530
 
@@ -716,9 +704,12 @@  discard block
 block discarded – undo
716 704
     public static function selectEach (string $table, array|string $columns = '*', array $where = null, int $count = null, int $offset = null, array|string $group_by = [], array|string $order_by = [], bool $ignore_default_where = false): bool|Generator {
717 705
         $res = self::select($table, $columns, $where, $count, $offset, $group_by, $order_by, ignore_default_where: $ignore_default_where);
718 706
         if ($res) {
719
-            while ($row = $res->fetch_assoc()) yield $row;
707
+            while ($row = $res->fetch_assoc()) {
708
+                yield $row;
709
+            }
710
+        } else {
711
+            return $res;
720 712
         }
721
-        else return $res;
722 713
     }
723 714
 
724 715
     /**
Please login to merge, or discard this patch.