Passed
Push — main ( 1e0eff...d761d2 )
by Miaad
01:42
created
src/receiver/multi/curl.php 1 patch
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -14,12 +14,12 @@  discard block
 block discarded – undo
14 14
  * curl class , for multiprocessing with curl tricks
15 15
  */
16 16
 class curl extends webhook {
17
-    public static function init (): string|null {
17
+    public static function init(): string | null {
18 18
         if (self::checkIP()) {
19 19
             return self::getUpdate();
20 20
         }
21 21
         else {
22
-            logger::write('not authorized access denied. IP : '. $_SERVER['REMOTE_ADDR'] ?? 'unknown',loggerTypes::WARNING);
22
+            logger::write('not authorized access denied. IP : '.$_SERVER['REMOTE_ADDR'] ?? 'unknown', loggerTypes::WARNING);
23 23
             BPT::exit();
24 24
             return null;
25 25
         }
@@ -29,7 +29,7 @@  discard block
 block discarded – undo
29 29
         return $_SERVER['REMOTE_ADDR'] === $_SERVER['SERVER_ADDR'];
30 30
     }
31 31
 
32
-    private static function getUpdate (): string {
32
+    private static function getUpdate(): string {
33 33
         $input = json_decode(file_get_contents("php://input"), true);
34 34
         webhook::telegramVerify($input['ip']);
35 35
         return $input['update'];
@@ -42,14 +42,14 @@  discard block
 block discarded – undo
42 42
         $urls = self::setURLS();
43 43
         $file = $urls['file'];
44 44
         $timeout = self::getTimeout($file);
45
-        self::create($file,$timeout);
45
+        self::create($file, $timeout);
46 46
         self::setWebhook($urls['url']);
47 47
         lock::set('BPT-MULTI-CURL');
48 48
     }
49 49
 
50
-    private static function getTimeout($url): float|int {
50
+    private static function getTimeout($url): float | int {
51 51
         $times = [];
52
-        for ($i = 0; $i < 10; $i ++) {
52
+        for ($i = 0; $i < 10; $i++) {
53 53
             $ch = curl_init($url);
54 54
             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']]);
55 55
             $start = microtime(true);
@@ -60,12 +60,12 @@  discard block
 block discarded – undo
60 60
         return $timeout > 50 ? $timeout + 10 : 50;
61 61
     }
62 62
 
63
-    private static function create($file,$timeout) {
64
-        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);?>');
63
+    private static function create($file, $timeout) {
64
+        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);?>');
65 65
     }
66 66
 
67 67
     private static function setURLS(): array {
68
-        $base_url = (isset(settings::$certificate) ? 'http://' : 'https://') . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
68
+        $base_url = (isset(settings::$certificate) ? 'http://' : 'https://').$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];
69 69
         $file = basename($_SERVER['REQUEST_URI']);
70 70
         return [
71 71
             'url'=>str_replace($file, 'receiver.php', $base_url),
Please login to merge, or discard this patch.
src/receiver/multi/exec.php 1 patch
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -17,11 +17,11 @@  discard block
 block discarded – undo
17 17
     /**
18 18
      * @internal Only for BPT self usage , Don't use it in your source!
19 19
      */
20
-    public static function init(): string|null {
20
+    public static function init(): string | null {
21 21
         return self::getUpdate();
22 22
     }
23 23
 
24
-    private static function getUpdate (): string|null {
24
+    private static function getUpdate(): string | null {
25 25
         $up = glob('*.update');
26 26
         if (isset($up[0])) {
27 27
             $up = end($up);
@@ -32,7 +32,7 @@  discard block
 block discarded – undo
32 32
             return $update;
33 33
         }
34 34
         else {
35
-            logger::write('not authorized access denied. IP : '. $_SERVER['REMOTE_ADDR'] ?? 'unknown',loggerTypes::WARNING);
35
+            logger::write('not authorized access denied. IP : '.$_SERVER['REMOTE_ADDR'] ?? 'unknown', loggerTypes::WARNING);
36 36
             BPT::exit();
37 37
             return null;
38 38
         }
@@ -59,11 +59,11 @@  discard block
 block discarded – undo
59 59
     }
60 60
 
61 61
     private static function create($file) {
62
-        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 &");');
62
+        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 &");');
63 63
     }
64 64
 
65 65
     private static function setURLS(): array {
66
-        $base_url = (isset(settings::$certificate) ? 'http://' : 'https://') . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
66
+        $base_url = (isset(settings::$certificate) ? 'http://' : 'https://').$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];
67 67
         return [
68 68
             'url'=>str_replace(basename($_SERVER['REQUEST_URI']), 'receiver.php', $base_url),
69 69
             'file'=>basename($_SERVER['SCRIPT_NAME'])
Please login to merge, or discard this patch.
src/receiver/receiver.php 1 patch
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -41,13 +41,13 @@  discard block
 block discarded – undo
41 41
             }
42 42
 
43 43
             if (!tools::isTelegram($ip ?? '')) {
44
-                logger::write('not authorized access denied. IP : '. $ip ?? 'unknown',loggerTypes::WARNING);
44
+                logger::write('not authorized access denied. IP : '.$ip ?? 'unknown', loggerTypes::WARNING);
45 45
                 BPT::exit();
46 46
             }
47 47
         }
48 48
     }
49 49
 
50
-    protected static function processUpdate(string|stdClass|update $update = null): void {
50
+    protected static function processUpdate(string | stdClass | update $update = null): void {
51 51
         if (!is_object($update)) {
52 52
             $update = json_decode($update ?? file_get_contents("php://input"));
53 53
             if (!$update) {
@@ -55,7 +55,7 @@  discard block
 block discarded – undo
55 55
             }
56 56
         }
57 57
 
58
-        if (!is_a($update,'update')) {
58
+        if (!is_a($update, 'update')) {
59 59
             $update = new update($update);
60 60
         }
61 61
 
@@ -66,7 +66,7 @@  discard block
 block discarded – undo
66 66
         db::save();
67 67
     }
68 68
 
69
-    protected static function setMessageExtra (update &$update): void {
69
+    protected static function setMessageExtra(update & $update): void {
70 70
         if ((isset($update->message) && isset($update->message->text)) || (isset($update->edited_message) && isset($update->edited_message->text))) {
71 71
             $type = isset($update->message) ? 'message' : 'edited_message';
72 72
             $text = &$update->$type->text;
@@ -139,7 +139,7 @@  discard block
 block discarded – undo
139 139
                 BPT::$handler->something_else(BPT::$update);
140 140
             }
141 141
             else {
142
-                logger::write('Update received but handlers does not set',loggerTypes::WARNING);
142
+                logger::write('Update received but handlers does not set', loggerTypes::WARNING);
143 143
             }
144 144
         }
145 145
     }
Please login to merge, or discard this patch.
src/receiver/getUpdates.php 1 patch
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -14,25 +14,25 @@  discard block
 block discarded – undo
14 14
  * getUpdates class , For receiving updates by polling methods
15 15
  */
16 16
 class getUpdates extends receiver {
17
-    public static function init () {
17
+    public static function init() {
18 18
         $last_update_id = self::loadData();
19
-        while(true) {
19
+        while (true) {
20 20
             if (!lock::exist('getUpdate')) {
21
-                $updates = telegram::getUpdates($last_update_id,allowed_updates: settings::$allowed_updates);
21
+                $updates = telegram::getUpdates($last_update_id, allowed_updates: settings::$allowed_updates);
22 22
                 if (telegram::$status) {
23 23
                     self::handleUpdates($updates);
24
-                    lock::save('getUpdate',BPT::$update->update_id+1);
25
-                    $last_update_id = BPT::$update->update_id+1;
24
+                    lock::save('getUpdate', BPT::$update->update_id + 1);
25
+                    $last_update_id = BPT::$update->update_id + 1;
26 26
                 }
27 27
                 else {
28
-                    logger::write("There is some problem happened , telegram response : \n".json_encode($updates),loggerTypes::ERROR);
29
-                    BPT::exit(print_r($updates,true));
28
+                    logger::write("There is some problem happened , telegram response : \n".json_encode($updates), loggerTypes::ERROR);
29
+                    BPT::exit(print_r($updates, true));
30 30
                 }
31 31
             }
32 32
         }
33 33
     }
34 34
 
35
-    private static function loadData(): bool|int|string {
35
+    private static function loadData(): bool | int | string {
36 36
         if (lock::exist('getUpdate')) {
37 37
             $last_update_id = lock::read('getUpdate');
38 38
         }
@@ -40,7 +40,7 @@  discard block
 block discarded – undo
40 40
             self::deleteOldLocks();
41 41
             telegram::deleteWebhook();
42 42
             $last_update_id = 0;
43
-            lock::save('getUpdate',0);
43
+            lock::save('getUpdate', 0);
44 44
         }
45 45
         return $last_update_id;
46 46
     }
Please login to merge, or discard this patch.
src/lock.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -35,8 +35,8 @@  discard block
 block discarded – undo
35 35
      *
36 36
      * @return bool|int
37 37
      */
38
-    public static function save(string $name, string $data): bool|int {
39
-        return file_put_contents(settings::$name."$name.lock", $data) && chmod(settings::$name."$name.lock",0640);
38
+    public static function save(string $name, string $data): bool | int {
39
+        return file_put_contents(settings::$name."$name.lock", $data) && chmod(settings::$name."$name.lock", 0640);
40 40
     }
41 41
 
42 42
     /**
@@ -46,7 +46,7 @@  discard block
 block discarded – undo
46 46
      *
47 47
      * @return bool|string
48 48
      */
49
-    public static function read(string $name): bool|string {
49
+    public static function read(string $name): bool | string {
50 50
         return file_get_contents(settings::$name."$name.lock");
51 51
     }
52 52
 
@@ -57,7 +57,7 @@  discard block
 block discarded – undo
57 57
      *
58 58
      * @return bool|int
59 59
      */
60
-    public static function mtime(string $name): bool|int {
60
+    public static function mtime(string $name): bool | int {
61 61
         return filemtime(settings::$name."$name.lock");
62 62
     }
63 63
 
Please login to merge, or discard this patch.
src/tools.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -2,12 +2,12 @@
 block discarded – undo
2 2
 
3 3
 namespace BPT;
4 4
 
5
-use BPT\tools\{is,file,convert,generator,encrypt};
5
+use BPT\tools\{is, file, convert, generator, encrypt};
6 6
 
7 7
 /**
8 8
  * tools class , gather what ever you need
9 9
  */
10
-class tools{
10
+class tools {
11 11
     use is;
12 12
     use file;
13 13
     use convert;
Please login to merge, or discard this patch.
src/database/db.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -17,7 +17,7 @@
 block discarded – undo
17 17
     /**
18 18
      * @internal Only for BPT self usage , Don't use it in your source!
19 19
      */
20
-    public static function init (): void {
20
+    public static function init(): void {
21 21
         if (!empty(settings::$db)) {
22 22
             if (!isset(settings::$db['type'])) {
23 23
                 settings::$db['type'] = dbTypes::JSON;
Please login to merge, or discard this patch.
src/database/json.php 1 patch
Spacing   +79 added lines, -79 removed lines patch added patch discarded remove patch
@@ -103,7 +103,7 @@  discard block
 block discarded – undo
103 103
     /**
104 104
      * @internal Only for BPT self usage , Don't use it in your source!
105 105
      */
106
-    public static function init (): void {
106
+    public static function init(): void {
107 107
         self::$folder = settings::$name.'database';
108 108
         self::$global_default_data = settings::$db['global'] ?? self::$global_default_data;
109 109
         self::setUserDefaultData();
@@ -115,7 +115,7 @@  discard block
 block discarded – undo
115 115
         self::load();
116 116
     }
117 117
 
118
-    private static function setUserDefaultData (): void {
118
+    private static function setUserDefaultData(): void {
119 119
         self::$user_default_data = settings::$db['user'] ?? self::$user_default_data;
120 120
         if (!isset(self::$user_default_data['step'])) {
121 121
             self::$user_default_data['step'] = 'none';
@@ -134,7 +134,7 @@  discard block
 block discarded – undo
134 134
         }
135 135
     }
136 136
 
137
-    private static function setGroupUserDefaultData (): void {
137
+    private static function setGroupUserDefaultData(): void {
138 138
         self::$group_user_default_data = settings::$db['group_user'] ?? self::$group_user_default_data;
139 139
         if (!isset(self::$group_user_default_data['step'])) {
140 140
             self::$group_user_default_data['step'] = 'none';
@@ -162,10 +162,10 @@  discard block
 block discarded – undo
162 162
         }
163 163
 
164 164
         if (!file_exists(self::$folder.'/global.json')) {
165
-            file_put_contents(self::$folder.'/global.json',self::$global_default_data);
165
+            file_put_contents(self::$folder.'/global.json', self::$global_default_data);
166 166
         }
167 167
         if (!file_exists(self::$folder.'/ids.json')) {
168
-            file_put_contents(self::$folder.'/ids.json',json_encode([
168
+            file_put_contents(self::$folder.'/ids.json', json_encode([
169 169
                 'privates' => [],
170 170
                 'groups' => [],
171 171
                 'supergroups' => [],
@@ -174,25 +174,25 @@  discard block
 block discarded – undo
174 174
         }
175 175
     }
176 176
 
177
-    private static function load (): void {
177
+    private static function load(): void {
178 178
         self::$global = json_decode(file_get_contents(self::$folder.'/global.json'));
179 179
         self::$old_global = clone self::$global;
180
-        self::$ids = json_decode(file_get_contents(self::$folder.'/ids.json'),true);
180
+        self::$ids = json_decode(file_get_contents(self::$folder.'/ids.json'), true);
181 181
         self::$old_ids = clone self::$ids;
182 182
     }
183 183
 
184
-    private static function read (string $address) {
184
+    private static function read(string $address) {
185 185
         return file_exists(self::$folder.'/'.$address.'.json') ? json_decode(file_get_contents(self::$folder.'/'.$address.'.json'), false) : null;
186 186
     }
187 187
 
188
-    private static function write (string $address,string $data): void {
189
-        file_put_contents(self::$folder.'/'.$address.'.json',$data);
188
+    private static function write(string $address, string $data): void {
189
+        file_put_contents(self::$folder.'/'.$address.'.json', $data);
190 190
     }
191 191
 
192 192
     /**
193 193
      * @internal Only for BPT self usage , Don't use it in your source!
194 194
      */
195
-    public static function process (): void {
195
+    public static function process(): void {
196 196
         if (isset(BPT::$update->message)) {
197 197
             self::processMessage(BPT::$update->message);
198 198
         }
@@ -215,16 +215,16 @@  discard block
 block discarded – undo
215 215
      */
216 216
     public static function save(): void {
217 217
         if (self::$user !== self::$old_user && !empty(self::$user_id)) {
218
-            self::write('privates/' . self::$user_id,json_encode(self::$user));
218
+            self::write('privates/'.self::$user_id, json_encode(self::$user));
219 219
         }
220 220
         if (self::$group !== self::$old_group && !empty(self::$group_id)) {
221
-            self::write('groups/' . self::$group_id,json_encode(self::$group));
221
+            self::write('groups/'.self::$group_id, json_encode(self::$group));
222 222
         }
223 223
         if (self::$supergroup !== self::$old_supergroup && !empty(self::$supergroup_id)) {
224
-            self::write('supergroups/' . self::$supergroup_id,json_encode(self::$supergroup));
224
+            self::write('supergroups/'.self::$supergroup_id, json_encode(self::$supergroup));
225 225
         }
226 226
         if (self::$channel !== self::$old_channel && !empty(self::$channel_id)) {
227
-            self::write('channels/' . self::$channel_id,json_encode(self::$channel));
227
+            self::write('channels/'.self::$channel_id, json_encode(self::$channel));
228 228
         }
229 229
         if (self::$group_user !== self::$old_group_user && !empty(self::$group_user_id)) {
230 230
             if (empty(self::$group)) {
@@ -235,13 +235,13 @@  discard block
 block discarded – undo
235 235
                 $category = 'groups';
236 236
                 $group_id = self::$group_id;
237 237
             }
238
-            self::write($category . '/' . $group_id . '/' . self::$group_user_id,json_encode(self::$group_user));
238
+            self::write($category.'/'.$group_id.'/'.self::$group_user_id, json_encode(self::$group_user));
239 239
         }
240 240
         if (self::$ids !== self::$old_ids) {
241
-            self::write('ids',json_encode(self::$ids));
241
+            self::write('ids', json_encode(self::$ids));
242 242
         }
243 243
         if (self::$global !== self::$old_global) {
244
-            self::write('global',json_encode(self::$global));
244
+            self::write('global', json_encode(self::$global));
245 245
         }
246 246
         if (self::$group_ids !== self::$old_group_ids) {
247 247
             if (empty(self::$group)) {
@@ -252,17 +252,17 @@  discard block
 block discarded – undo
252 252
                 $category = 'groups';
253 253
                 $group_id = self::$group_id;
254 254
             }
255
-            self::write($category . '/' . $group_id . '/users',json_encode(self::$group_user));
255
+            self::write($category.'/'.$group_id.'/users', json_encode(self::$group_user));
256 256
         }
257 257
     }
258 258
 
259 259
     private static function processMessage(message $update): void {
260 260
         $type = $update->chat->type;
261
-        $category = $type . 's';
261
+        $category = $type.'s';
262 262
         if ($type === chatType::PRIVATE) {
263 263
             self::$user_id = $update->from->id;
264
-            if (in_array(self::$user_id,self::$ids[$category])) {
265
-                self::$user = self::read($category . '/' . self::$user_id);
264
+            if (in_array(self::$user_id, self::$ids[$category])) {
265
+                self::$user = self::read($category.'/'.self::$user_id);
266 266
                 self::$old_user = clone self::$user;
267 267
                 self::$user->last_active = time();
268 268
             }
@@ -270,10 +270,10 @@  discard block
 block discarded – undo
270 270
                 self::$ids[$category][] = self::$user_id;
271 271
                 self::$user = (object) self::$user_default_data;
272 272
                 self::$user->first_active = self::$user->last_active = time();
273
-                if (isset($update->commend) && isset($update->commend_payload) && $update->commend === 'start' && str_starts_with($update->commend_payload,'ref_')) {
274
-                    if (tools::isShorted(substr($update->commend_payload,4))) {
275
-                        $referral = tools::shortDecode(substr($update->commend_payload,4));
276
-                        if (in_array($referral,self::$ids[$category])) {
273
+                if (isset($update->commend) && isset($update->commend_payload) && $update->commend === 'start' && str_starts_with($update->commend_payload, 'ref_')) {
274
+                    if (tools::isShorted(substr($update->commend_payload, 4))) {
275
+                        $referral = tools::shortDecode(substr($update->commend_payload, 4));
276
+                        if (in_array($referral, self::$ids[$category])) {
277 277
                             self::$user->referral = $referral;
278 278
                         }
279 279
                     }
@@ -282,8 +282,8 @@  discard block
 block discarded – undo
282 282
         }
283 283
         elseif ($type === chatType::CHANNEL) {
284 284
             self::$channel_id = $update->chat->id;
285
-            if (in_array(self::$channel_id,self::$ids[$category])) {
286
-                self::$channel = self::read($category . '/' . self::$channel_id);
285
+            if (in_array(self::$channel_id, self::$ids[$category])) {
286
+                self::$channel = self::read($category.'/'.self::$channel_id);
287 287
                 self::$old_channel = clone self::$channel;
288 288
             }
289 289
             else {
@@ -297,10 +297,10 @@  discard block
 block discarded – undo
297 297
             $chat_id = $update->chat->id;
298 298
             if ($type === chatType::SUPERGROUP) {
299 299
                 self::$supergroup_id = $update->chat->id;
300
-                if (in_array($chat_id,self::$ids[$category])) {
301
-                    self::$supergroup = self::read($category . '/' . $chat_id);
300
+                if (in_array($chat_id, self::$ids[$category])) {
301
+                    self::$supergroup = self::read($category.'/'.$chat_id);
302 302
                     self::$old_supergroup = clone self::$supergroup;
303
-                    self::$group_ids = self::read($category . '/' . $chat_id . '/users');
303
+                    self::$group_ids = self::read($category.'/'.$chat_id.'/users');
304 304
                     self::$old_group_ids = clone self::$group_ids;
305 305
                 }
306 306
                 else {
@@ -311,10 +311,10 @@  discard block
 block discarded – undo
311 311
             }
312 312
             else {
313 313
                 self::$group_id = $update->chat->id;
314
-                if (in_array($chat_id,self::$ids[$category])) {
315
-                    self::$group = self::read($category . '/' . $chat_id);
314
+                if (in_array($chat_id, self::$ids[$category])) {
315
+                    self::$group = self::read($category.'/'.$chat_id);
316 316
                     self::$old_group = clone self::$group;
317
-                    self::$group_ids = self::read($category . '/' . $chat_id . '/users');
317
+                    self::$group_ids = self::read($category.'/'.$chat_id.'/users');
318 318
                     self::$old_group_ids = clone self::$group_ids;
319 319
                 }
320 320
                 else {
@@ -324,8 +324,8 @@  discard block
 block discarded – undo
324 324
                 }
325 325
             }
326 326
 
327
-            if (in_array(self::$user_id,self::$group_ids)) {
328
-                self::$group_user = self::read($category . '/' . $chat_id . '/' . self::$user_id);
327
+            if (in_array(self::$user_id, self::$group_ids)) {
328
+                self::$group_user = self::read($category.'/'.$chat_id.'/'.self::$user_id);
329 329
                 self::$old_group_user = clone self::$group_user;
330 330
             }
331 331
             else {
@@ -341,42 +341,42 @@  discard block
 block discarded – undo
341 341
 
342 342
     private static function processCallbackQuery(callbackQuery $update): void {
343 343
         $type = $update->message->chat->type;
344
-        $category = $type . 's';
344
+        $category = $type.'s';
345 345
         if ($type === chatType::PRIVATE) {
346 346
             self::$user_id = $update->from->id;
347
-            if (in_array(self::$user_id,self::$ids[$category])) {
348
-                self::$user = self::read($category . '/' . self::$user_id);
347
+            if (in_array(self::$user_id, self::$ids[$category])) {
348
+                self::$user = self::read($category.'/'.self::$user_id);
349 349
                 self::$old_user = clone self::$user;
350 350
                 self::$user->last_active = time();
351 351
             }
352 352
         }
353 353
         elseif ($type === chatType::CHANNEL) {
354 354
             self::$channel_id = $update->message->chat->id;
355
-            if (in_array(self::$channel_id,self::$ids[$category])) {
356
-                self::$channel = self::read($category . '/' . self::$channel_id);
355
+            if (in_array(self::$channel_id, self::$ids[$category])) {
356
+                self::$channel = self::read($category.'/'.self::$channel_id);
357 357
                 self::$old_channel = clone self::$channel;
358 358
             }
359 359
         }
360 360
         else {
361 361
             self::$user_id = $update->from->id;
362 362
             $chat_id = $update->message->chat->id;
363
-            if (in_array($chat_id,self::$ids[$category])) {
363
+            if (in_array($chat_id, self::$ids[$category])) {
364 364
                 if ($type === chatType::SUPERGROUP) {
365 365
                     self::$supergroup_id = $update->message->chat->id;
366
-                    self::$supergroup = self::read($category . '/' . $chat_id);
366
+                    self::$supergroup = self::read($category.'/'.$chat_id);
367 367
                     self::$old_supergroup = clone self::$supergroup;
368 368
                 }
369 369
                 else {
370 370
                     self::$group_id = $update->message->chat->id;
371
-                    self::$group = self::read($category . '/' . $chat_id);
371
+                    self::$group = self::read($category.'/'.$chat_id);
372 372
                     self::$old_group = clone self::$group;
373 373
                 }
374
-                self::$group_ids = self::read($category . '/' . $chat_id . '/users');
374
+                self::$group_ids = self::read($category.'/'.$chat_id.'/users');
375 375
                 self::$old_group_ids = clone self::$group_ids;
376 376
             }
377 377
 
378
-            if (in_array(self::$user_id,self::$group_ids)) {
379
-                self::$group_user = self::read($category . '/' . $chat_id . '/' . self::$user_id);
378
+            if (in_array(self::$user_id, self::$group_ids)) {
379
+                self::$group_user = self::read($category.'/'.$chat_id.'/'.self::$user_id);
380 380
                 self::$group_user_id = self::$user_id;
381 381
                 self::$old_group_user = clone self::$group_user;
382 382
             }
@@ -390,10 +390,10 @@  discard block
 block discarded – undo
390 390
     private static function processInlineQuery(inlineQuery $update): void {
391 391
         $type = $update->chat_type;
392 392
         if ($type === chatType::PRIVATE || $type === chatType::SENDER) {
393
-            $category = chatType::PRIVATE . 's';
393
+            $category = chatType::PRIVATE.'s';
394 394
             self::$user_id = $update->from->id;
395
-            if (in_array(self::$user_id,self::$ids[$category])) {
396
-                self::$user = self::read($category . '/' . self::$user_id);
395
+            if (in_array(self::$user_id, self::$ids[$category])) {
396
+                self::$user = self::read($category.'/'.self::$user_id);
397 397
                 self::$old_user = clone self::$user;
398 398
                 self::$user->last_active = time();
399 399
             }
@@ -403,11 +403,11 @@  discard block
 block discarded – undo
403 403
     private static function processChatMember(chatMemberUpdated $update): void {
404 404
         $type = $update->chat->type;
405 405
 
406
-        $category = $type . 's';
406
+        $category = $type.'s';
407 407
         if ($type === chatType::CHANNEL) {
408 408
             self::$channel_id = $update->chat->id;
409
-            if (in_array(self::$channel_id,self::$ids[$category])) {
410
-                self::$channel = self::read($category . '/' . self::$channel_id);
409
+            if (in_array(self::$channel_id, self::$ids[$category])) {
410
+                self::$channel = self::read($category.'/'.self::$channel_id);
411 411
                 self::$old_channel = clone self::$channel;
412 412
             }
413 413
             else {
@@ -426,10 +426,10 @@  discard block
 block discarded – undo
426 426
 
427 427
             if ($type === chatType::SUPERGROUP) {
428 428
                 self::$supergroup_id = $chat_id;
429
-                if (in_array($chat_id,self::$ids[$category])) {
430
-                    self::$supergroup = self::read($category . '/' . $chat_id);
429
+                if (in_array($chat_id, self::$ids[$category])) {
430
+                    self::$supergroup = self::read($category.'/'.$chat_id);
431 431
                     self::$old_supergroup = clone self::$supergroup;
432
-                    self::$group_ids = self::read($category . '/' . $chat_id . '/users');
432
+                    self::$group_ids = self::read($category.'/'.$chat_id.'/users');
433 433
                     self::$old_group_ids = clone self::$group_ids;
434 434
                 }
435 435
                 else {
@@ -440,10 +440,10 @@  discard block
 block discarded – undo
440 440
             }
441 441
             elseif ($type === chatType::GROUP) {
442 442
                 self::$group_id = $chat_id;
443
-                if (in_array($chat_id,self::$ids[$category])) {
444
-                    self::$group = self::read($category . '/' . $chat_id);
443
+                if (in_array($chat_id, self::$ids[$category])) {
444
+                    self::$group = self::read($category.'/'.$chat_id);
445 445
                     self::$old_group = clone self::$group;
446
-                    self::$group_ids = self::read($category . '/' . $chat_id . '/users');
446
+                    self::$group_ids = self::read($category.'/'.$chat_id.'/users');
447 447
                     self::$old_group_ids = clone self::$group_ids;
448 448
                 }
449 449
                 else {
@@ -453,13 +453,13 @@  discard block
 block discarded – undo
453 453
                 }
454 454
             }
455 455
 
456
-            if (!in_array($user_id,self::$group_ids)) {
456
+            if (!in_array($user_id, self::$group_ids)) {
457 457
                 self::$group_ids[] = $user_id;
458 458
                 self::$group_user = (object) self::$group_user_default_data;
459 459
             }
460 460
             else {
461 461
                 self::$group_user_id = $by_id == $user_id ? $user_id : $by_id;
462
-                self::$group_user = self::read($category . '/' . $chat_id . '/' . self::$group_user_id);
462
+                self::$group_user = self::read($category.'/'.$chat_id.'/'.self::$group_user_id);
463 463
             }
464 464
 
465 465
             if ($new_user->status === chatMemberStatus::LEFT || $new_user->status === chatMemberStatus::KICKED) {
@@ -500,15 +500,15 @@  discard block
 block discarded – undo
500 500
      * @return bool
501 501
      * @throws bptException
502 502
      */
503
-    public static function deleteUser (int $user_id = null): bool {
503
+    public static function deleteUser(int $user_id = null): bool {
504 504
         if (empty($user_id)) $user_id = telegram::catchFields(fields::USER_ID);
505
-        if (file_exists(self::$folder . '/privates/' . $user_id . '.json')) {
505
+        if (file_exists(self::$folder.'/privates/'.$user_id.'.json')) {
506 506
             unset(self::$ids['privates'][array_search($user_id, self::$ids['privates'])]);
507 507
             sort(self::$ids['privates']);
508 508
             if ($user_id === self::$user_id) {
509 509
                 self::$user = self::$old_user = null;
510 510
             }
511
-            return tools::delete(self::$folder . '/privates/' . $user_id . '.json');
511
+            return tools::delete(self::$folder.'/privates/'.$user_id.'.json');
512 512
         }
513 513
         return false;
514 514
     }
@@ -521,16 +521,16 @@  discard block
 block discarded – undo
521 521
      * @return bool
522 522
      * @throws bptException
523 523
      */
524
-    public static function deleteGroup (int $group_id = null): bool {
524
+    public static function deleteGroup(int $group_id = null): bool {
525 525
         if (empty($group_id)) $group_id = telegram::catchFields(fields::CHAT_ID);
526
-        if (file_exists(self::$folder . '/groups/' . $group_id . '.json')) {
526
+        if (file_exists(self::$folder.'/groups/'.$group_id.'.json')) {
527 527
             unset(self::$ids['groups'][array_search($group_id, self::$ids['groups'])]);
528 528
             sort(self::$ids['groups']);
529
-            tools::delete(self::$folder . '/groups/' . $group_id);
529
+            tools::delete(self::$folder.'/groups/'.$group_id);
530 530
             if ($group_id === self::$group_id) {
531 531
                 self::$group = self::$old_group = null;
532 532
             }
533
-            return tools::delete(self::$folder . '/groups/' . $group_id . '.json');
533
+            return tools::delete(self::$folder.'/groups/'.$group_id.'.json');
534 534
         }
535 535
         return false;
536 536
     }
@@ -543,16 +543,16 @@  discard block
 block discarded – undo
543 543
      * @return bool
544 544
      * @throws bptException
545 545
      */
546
-    public static function deleteSuperGroup (int $group_id = null): bool {
546
+    public static function deleteSuperGroup(int $group_id = null): bool {
547 547
         if (empty($group_id)) $group_id = telegram::catchFields(fields::CHAT_ID);
548
-        if (file_exists(self::$folder . '/supergroups/' . $group_id . '.json')) {
548
+        if (file_exists(self::$folder.'/supergroups/'.$group_id.'.json')) {
549 549
             unset(self::$ids['supergroups'][array_search($group_id, self::$ids['supergroups'])]);
550 550
             sort(self::$ids['supergroups']);
551
-            tools::delete(self::$folder . '/supergroups/' . $group_id);
551
+            tools::delete(self::$folder.'/supergroups/'.$group_id);
552 552
             if ($group_id === self::$supergroup_id) {
553 553
                 self::$supergroup = self::$old_supergroup = null;
554 554
             }
555
-            return tools::delete(self::$folder . '/supergroups/' . $group_id . '.json');
555
+            return tools::delete(self::$folder.'/supergroups/'.$group_id.'.json');
556 556
         }
557 557
         return false;
558 558
     }
@@ -565,15 +565,15 @@  discard block
 block discarded – undo
565 565
      * @return bool
566 566
      * @throws bptException
567 567
      */
568
-    public static function deleteChannel (int $channel_id = null): bool {
568
+    public static function deleteChannel(int $channel_id = null): bool {
569 569
         if (empty($channel_id)) $channel_id = telegram::catchFields(fields::CHAT_ID);
570
-        if (file_exists(self::$folder . '/channels/' . $channel_id . '.json')) {
570
+        if (file_exists(self::$folder.'/channels/'.$channel_id.'.json')) {
571 571
             unset(self::$ids['channels'][array_search($channel_id, self::$ids['channels'])]);
572 572
             sort(self::$ids['channels']);
573 573
             if ($channel_id === self::$channel_id) {
574 574
                 self::$channel = self::$old_channel = null;
575 575
             }
576
-            return tools::delete(self::$folder . '/channels/' . $channel_id . '.json');
576
+            return tools::delete(self::$folder.'/channels/'.$channel_id.'.json');
577 577
         }
578 578
         return false;
579 579
     }
@@ -583,7 +583,7 @@  discard block
 block discarded – undo
583 583
      *
584 584
      * @return int[]
585 585
      */
586
-    public static function getUsers (): array {
586
+    public static function getUsers(): array {
587 587
         return self::$ids['privates'] ?? [];
588 588
     }
589 589
 
@@ -592,7 +592,7 @@  discard block
 block discarded – undo
592 592
      *
593 593
      * @return int[]
594 594
      */
595
-    public static function getGroups (): array {
595
+    public static function getGroups(): array {
596 596
         return self::$ids['groups'] ?? [];
597 597
     }
598 598
 
@@ -601,7 +601,7 @@  discard block
 block discarded – undo
601 601
      *
602 602
      * @return int[]
603 603
      */
604
-    public static function getSuperGroups (): array {
604
+    public static function getSuperGroups(): array {
605 605
         return self::$ids['supergroups'] ?? [];
606 606
     }
607 607
 
@@ -610,7 +610,7 @@  discard block
 block discarded – undo
610 610
      *
611 611
      * @return int[]
612 612
      */
613
-    public static function getChannels (): array {
613
+    public static function getChannels(): array {
614 614
         return self::$ids['channels'] ?? [];
615 615
     }
616 616
 }
Please login to merge, or discard this patch.
src/api/request/answer.php 1 patch
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -17,44 +17,44 @@
 block discarded – undo
17 17
     /**
18 18
      * @internal Only for BPT self usage , Don't use it in your source!
19 19
      */
20
-    public static function init(string $method,array $data): bool {
20
+    public static function init(string $method, array $data): bool {
21 21
         self::checkAnswered();
22 22
         self::checkWebhook();
23 23
         self::sieveData($data);
24 24
         self::$is_answered = true;
25 25
         $data['method'] = $method;
26 26
         $payload = json_encode($data);
27
-        header('Content-Type: application/json;Content-Length: ' . strlen($payload));
27
+        header('Content-Type: application/json;Content-Length: '.strlen($payload));
28 28
         echo $payload;
29 29
         return true;
30 30
     }
31 31
 
32 32
     private static function checkAnswered(): void {
33 33
         if (self::$is_answered) {
34
-            logger::write('You can use answer mode only once for each webhook update , You already did it!',loggerTypes::ERROR);
34
+            logger::write('You can use answer mode only once for each webhook update , You already did it!', loggerTypes::ERROR);
35 35
             throw new bptException('ANSWER_MODE_USED');
36 36
         }
37 37
     }
38 38
 
39 39
     private static function checkWebhook(): void {
40
-        if(settings::$receiver === receiver::GETUPDATES) {
41
-            logger::write('Answer mode only work when receiver is webhook',loggerTypes::ERROR);
40
+        if (settings::$receiver === receiver::GETUPDATES) {
41
+            logger::write('Answer mode only work when receiver is webhook', loggerTypes::ERROR);
42 42
             throw new bptException('ANSWER_MODE_GETUPDATES');
43 43
         }
44
-        elseif(settings::$multi) {
45
-            logger::write('You can not use answer mode when multi setting is on',loggerTypes::ERROR);
44
+        elseif (settings::$multi) {
45
+            logger::write('You can not use answer mode when multi setting is on', loggerTypes::ERROR);
46 46
             throw new bptException('ANSWER_MODE_MULTI');
47 47
         }
48 48
     }
49 49
 
50 50
     private static function sieveData(array &$data): void {
51
-        unset($data['token'],$data['forgot'],$data['return_array']);
51
+        unset($data['token'], $data['forgot'], $data['return_array']);
52 52
 
53
-        foreach ($data as $key=>&$value){
54
-            if (!isset($value)){
53
+        foreach ($data as $key=>&$value) {
54
+            if (!isset($value)) {
55 55
                 unset($data[$key]);
56 56
             }
57
-            elseif (is_array($value) || is_object($value)){
57
+            elseif (is_array($value) || is_object($value)) {
58 58
                 $value = json_encode($value);
59 59
             }
60 60
         }
Please login to merge, or discard this patch.