Passed
Push — main ( a53d1a...87c5f3 )
by Miaad
01:42
created
src/database/mysql.php 1 patch
Spacing   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -27,7 +27,7 @@  discard block
 block discarded – undo
27 27
     /**
28 28
      * @internal Only for BPT self usage , Don't use it in your source!
29 29
      */
30
-    public static function init (): void {
30
+    public static function init(): void {
31 31
         $host = settings::$db['host'] ?? 'localhost';
32 32
         $port = settings::$db['port'] ?? 3306;
33 33
         $user = settings::$db['user'] ?? settings::$db['username'] ?? 'unknown';
@@ -36,7 +36,7 @@  discard block
 block discarded – undo
36 36
         $dbname = settings::$db['dbname'];
37 37
         self::$connection = new mysqli($host, $user, $pass, $dbname, $port);
38 38
         if (self::$connection->connect_errno) {
39
-            logger::write('SQL connection has problem : ' . self::$connection->connect_error, loggerTypes::ERROR);
39
+            logger::write('SQL connection has problem : '.self::$connection->connect_error, loggerTypes::ERROR);
40 40
             throw new bptException('SQL_CONNECTION_PROBLEM');
41 41
         }
42 42
         if (self::$auto_process && !lock::exist('BPT-MYSQL')) {
@@ -44,7 +44,7 @@  discard block
 block discarded – undo
44 44
         }
45 45
     }
46 46
 
47
-    private static function install (): void {
47
+    private static function install(): void {
48 48
         self::pureQuery("
49 49
 CREATE TABLE `users`
50 50
 (
@@ -65,7 +65,7 @@  discard block
 block discarded – undo
65 65
     /**
66 66
      * @internal Only for BPT self usage , Don't use it in your source!
67 67
      */
68
-    public static function process (): void {
68
+    public static function process(): void {
69 69
         if (self::$auto_process) {
70 70
             if (isset(BPT::$update->message)) {
71 71
                 self::processMessage(BPT::$update->message);
@@ -85,7 +85,7 @@  discard block
 block discarded – undo
85 85
         }
86 86
     }
87 87
 
88
-    private static function processMessage (message $update): void {
88
+    private static function processMessage(message $update): void {
89 89
         $type = $update->chat->type;
90 90
         if ($type === chatType::PRIVATE) {
91 91
             $user_id = $update->from->id;
@@ -111,7 +111,7 @@  discard block
 block discarded – undo
111 111
         }
112 112
     }
113 113
 
114
-    private static function processCallbackQuery (callbackQuery $update): void {
114
+    private static function processCallbackQuery(callbackQuery $update): void {
115 115
         $type = $update->message->chat->type;
116 116
         if ($type === chatType::PRIVATE) {
117 117
             $user_id = $update->from->id;
@@ -121,7 +121,7 @@  discard block
 block discarded – undo
121 121
         }
122 122
     }
123 123
 
124
-    private static function processInlineQuery (inlineQuery $update): void {
124
+    private static function processInlineQuery(inlineQuery $update): void {
125 125
         $type = $update->chat_type;
126 126
         if ($type === chatType::PRIVATE || $type === chatType::SENDER) {
127 127
             $user_id = $update->from->id;
@@ -131,7 +131,7 @@  discard block
 block discarded – undo
131 131
         }
132 132
     }
133 133
 
134
-    private static function processMyChatMember (chatMemberUpdated $update): void {
134
+    private static function processMyChatMember(chatMemberUpdated $update): void {
135 135
         $type = $update->chat->type;
136 136
         if ($type === chatType::PRIVATE) {
137 137
             if ($update->new_chat_member->status === chatMemberStatus::MEMBER) {
@@ -148,7 +148,7 @@  discard block
 block discarded – undo
148 148
      *
149 149
      * @return mysqli
150 150
      */
151
-    public static function getMysqli (): mysqli {
151
+    public static function getMysqli(): mysqli {
152 152
         return self::$connection;
153 153
     }
154 154
 
@@ -157,7 +157,7 @@  discard block
 block discarded – undo
157 157
      *
158 158
      * @return int|string
159 159
      */
160
-    public static function affected_rows (): int|string {
160
+    public static function affected_rows(): int | string {
161 161
         return self::$connection->affected_rows;
162 162
     }
163 163
 
@@ -166,7 +166,7 @@  discard block
 block discarded – undo
166 166
      *
167 167
      * @return int|string
168 168
      */
169
-    public static function insert_id (): int|string {
169
+    public static function insert_id(): int | string {
170 170
         return self::$connection->insert_id;
171 171
     }
172 172
 
@@ -177,7 +177,7 @@  discard block
 block discarded – undo
177 177
      *
178 178
      * @return string
179 179
      */
180
-    public static function escapeString (string $text): string {
180
+    public static function escapeString(string $text): string {
181 181
         return self::$connection->real_escape_string($text);
182 182
     }
183 183
 
@@ -192,7 +192,7 @@  discard block
 block discarded – undo
192 192
      *
193 193
      * @return mysqli_result|bool
194 194
      */
195
-    public static function pureQuery (string $query): mysqli_result|bool {
195
+    public static function pureQuery(string $query): mysqli_result | bool {
196 196
         return self::$connection->query($query);
197 197
     }
198 198
 
@@ -211,7 +211,7 @@  discard block
 block discarded – undo
211 211
      *
212 212
      * @return mysqli_result|bool
213 213
      */
214
-    public static function query (string $query, array $vars = [], bool $need_result = true): mysqli_result|bool {
214
+    public static function query(string $query, array $vars = [], bool $need_result = true): mysqli_result | bool {
215 215
         $prepare = self::$connection->prepare($query);
216 216
         $types = '';
217 217
         foreach ($vars as $var) {
@@ -225,7 +225,7 @@  discard block
 block discarded – undo
225 225
                 $types .= 's';
226 226
             }
227 227
         }
228
-        $prepare->bind_param($types,...$vars);
228
+        $prepare->bind_param($types, ...$vars);
229 229
         if (!$prepare->execute()) {
230 230
             logger::write(loggerTypes::WARNING, $prepare->error);
231 231
             return false;
@@ -233,7 +233,7 @@  discard block
 block discarded – undo
233 233
         return $need_result ? $prepare->get_result() : true;
234 234
     }
235 235
 
236
-    private static function makeArrayReady (string &$query, array $array, string $operator = ' AND '): array {
236
+    private static function makeArrayReady(string &$query, array $array, string $operator = ' AND '): array {
237 237
         $first = true;
238 238
         $values = [];
239 239
         foreach ($array as $name => $value) {
@@ -249,7 +249,7 @@  discard block
 block discarded – undo
249 249
         return $values;
250 250
     }
251 251
 
252
-    private static function makeQueryReady (string &$query, array $where = null, int $count = null, int $offset = null): array {
252
+    private static function makeQueryReady(string &$query, array $where = null, int $count = null, int $offset = null): array {
253 253
         $values = [];
254 254
         if (!empty($where)) {
255 255
             $query .= " WHERE";
@@ -276,7 +276,7 @@  discard block
 block discarded – undo
276 276
      *
277 277
      * @return mysqli_result|bool
278 278
      */
279
-    public static function delete (string $table, array $where = null, int $count = null, int $offset = null): mysqli_result|bool {
279
+    public static function delete(string $table, array $where = null, int $count = null, int $offset = null): mysqli_result | bool {
280 280
         $query = "DELETE FROM `$table`";
281 281
         $res = self::makeQueryReady($query, $where, $count, $offset);
282 282
         return self::query($query, $res, false);
@@ -295,7 +295,7 @@  discard block
 block discarded – undo
295 295
      *
296 296
      * @return mysqli_result|bool
297 297
      */
298
-    public static function update (string $table, array $modify, array $where = null, int $count = null, int $offset = null): mysqli_result|bool {
298
+    public static function update(string $table, array $modify, array $where = null, int $count = null, int $offset = null): mysqli_result | bool {
299 299
         $query = "UPDATE `$table` SET";
300 300
         $values = self::makeArrayReady($query, $modify, ', ');
301 301
         $res = self::makeQueryReady($query, $where, $count, $offset);
@@ -313,11 +313,11 @@  discard block
 block discarded – undo
313 313
      *
314 314
      * @return mysqli_result|bool
315 315
      */
316
-    public static function insert (string $table, string|array $columns, array|string $values): mysqli_result|bool {
316
+    public static function insert(string $table, string | array $columns, array | string $values): mysqli_result | bool {
317 317
         $query = "INSERT INTO `$table`(";
318
-        $query .= '`' . (is_string($columns) ? $columns : implode('`,`', $columns)) . '`) VALUES (';
318
+        $query .= '`'.(is_string($columns) ? $columns : implode('`,`', $columns)).'`) VALUES (';
319 319
         if (is_string($values)) $values = [$values];
320
-        $query .= '?' . str_repeat(',?', count($values) - 1) . ')';
320
+        $query .= '?'.str_repeat(',?', count($values) - 1).')';
321 321
         return self::query($query, $values, false);
322 322
     }
323 323
 
@@ -336,13 +336,13 @@  discard block
 block discarded – undo
336 336
      *
337 337
      * @return mysqli_result|bool
338 338
      */
339
-    public static function select (string $table, array|string $columns = '*', array $where = null, int $count = null, int $offset = null): mysqli_result|bool {
339
+    public static function select(string $table, array | string $columns = '*', array $where = null, int $count = null, int $offset = null): mysqli_result | bool {
340 340
         $query = "SELECT ";
341 341
         if ($columns == '*') {
342 342
             $query .= "* ";
343 343
         }
344 344
         else {
345
-            $query .= '`' . (is_string($columns) ? $columns : implode('`,`', $columns)) . '` ';
345
+            $query .= '`'.(is_string($columns) ? $columns : implode('`,`', $columns)).'` ';
346 346
         }
347 347
         $query .= "FROM `$table`";
348 348
         $res = self::makeQueryReady($query, $where, $count, $offset);
@@ -360,7 +360,7 @@  discard block
 block discarded – undo
360 360
      *
361 361
      * @return null|bool|array
362 362
      */
363
-    public static function selectArray (string $table, array|string $columns = '*', array $where = null): bool|array|null {
363
+    public static function selectArray(string $table, array | string $columns = '*', array $where = null): bool | array | null {
364 364
         $res = self::select($table, $columns, $where, 1);
365 365
         if ($res) {
366 366
             return $res->fetch_assoc();
@@ -377,7 +377,7 @@  discard block
 block discarded – undo
377 377
      * @param array|string $columns sets column that you want to retrieve , set '*' to retrieve all , default : '*'
378 378
      * @param array|null   $where   Set your ifs default : null
379 379
      */
380
-    public static function selectObject (string $table, array|string $columns = '*', array $where = null) {
380
+    public static function selectObject(string $table, array | string $columns = '*', array $where = null) {
381 381
         $res = self::select($table, $columns, $where, 1);
382 382
         if ($res) {
383 383
             return $res->fetch_object();
@@ -399,7 +399,7 @@  discard block
 block discarded – undo
399 399
      *
400 400
      * @return bool|Generator
401 401
      */
402
-    public static function selectEach (string $table, array|string $columns = '*', array $where = null, int $count = null, int $offset = null): bool|Generator {
402
+    public static function selectEach(string $table, array | string $columns = '*', array $where = null, int $count = null, int $offset = null): bool | Generator {
403 403
         $res = self::select($table, $columns, $where, $count, $offset);
404 404
         if ($res) {
405 405
             while ($row = $res->fetch_assoc()) yield $row;
Please login to merge, or discard this patch.