Passed
Push — main ( 6b17f2...1e3b41 )
by Miaad
11:18
created
src/receiver/getUpdates.php 1 patch
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -16,31 +16,31 @@
 block discarded – undo
16 16
  */
17 17
 class getUpdates extends receiver {
18 18
     #[NoReturn]
19
-    public static function init () {
19
+    public static function init() {
20 20
         $last_update_id = self::loadData();
21 21
         lock::set('getUpdateHook');
22
-        while(true) {
22
+        while (true) {
23 23
             if (!lock::exist('getUpdateHook')) {
24 24
                 break;
25 25
             }
26
-            $updates = telegram::getUpdates($last_update_id,allowed_updates: settings::$allowed_updates);
26
+            $updates = telegram::getUpdates($last_update_id, allowed_updates: settings::$allowed_updates);
27 27
             if (!telegram::$status) {
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
             self::handleUpdates($updates);
32
-            $last_update_id = BPT::$update->update_id+1;
33
-            lock::save('getUpdate',$last_update_id);
32
+            $last_update_id = BPT::$update->update_id + 1;
33
+            lock::save('getUpdate', $last_update_id);
34 34
         }
35 35
     }
36 36
 
37
-    private static function loadData(): bool|int|string {
37
+    private static function loadData(): bool | int | string {
38 38
         if (lock::exist('getUpdate')) {
39 39
             return lock::read('getUpdate');
40 40
         }
41 41
         self::deleteOldLocks();
42 42
         telegram::deleteWebhook();
43
-        lock::save('getUpdate',0);
43
+        lock::save('getUpdate', 0);
44 44
         return 0;
45 45
     }
46 46
 
Please login to merge, or discard this patch.
src/receiver/webhook.php 2 patches
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -19,7 +19,7 @@  discard block
 block discarded – undo
19 19
     /**
20 20
      * @internal Only for BPT self usage , Don't use it in your source!
21 21
      */
22
-    public static function init () {
22
+    public static function init() {
23 23
         if (settings::$multi) {
24 24
             multi::init();
25 25
         }
@@ -39,24 +39,24 @@  discard block
 block discarded – undo
39 39
         lock::deleteIfExist(['BPT-MULTI-EXEC', 'BPT-MULTI-CURL', 'getUpdate', 'getUpdateHook']);
40 40
     }
41 41
 
42
-    protected static function setWebhook(string $url,string $secret = '') {
42
+    protected static function setWebhook(string $url, string $secret = '') {
43 43
         $res = BPT::setWebhook($url, settings::$certificate, max_connections: settings::$max_connection, allowed_updates: settings::$allowed_updates, drop_pending_updates: settings::$skip_old_updates, secret_token: $secret);
44 44
         if (!BPT::$status) {
45
-            logger::write("There is some problem happened , telegram response : \n".json_encode($res),loggerTypes::ERROR);
46
-            BPT::exit(print_r($res,true));
45
+            logger::write("There is some problem happened , telegram response : \n".json_encode($res), loggerTypes::ERROR);
46
+            BPT::exit(print_r($res, true));
47 47
         }
48
-        logger::write('Webhook was set successfully',loggerTypes::INFO);
48
+        logger::write('Webhook was set successfully', loggerTypes::INFO);
49 49
     }
50 50
 
51 51
     protected static function checkURL() {
52 52
         if (!(isset($_SERVER['SERVER_NAME']) && isset($_SERVER['REQUEST_URI']))) {
53
-            logger::write('For using webhook receiver , you should open this file in your webserver(by domain)',loggerTypes::ERROR);
53
+            logger::write('For using webhook receiver , you should open this file in your webserver(by domain)', loggerTypes::ERROR);
54 54
             throw new bptException('WEBHOOK_NEED_URL');
55 55
         }
56 56
     }
57 57
 
58 58
     private static function setURL(): string {
59
-        return (isset(settings::$certificate) ? 'http://' : 'https://') . $_SERVER['SERVER_NAME'] . $_SERVER['SCRIPT_NAME'];
59
+        return (isset(settings::$certificate) ? 'http://' : 'https://').$_SERVER['SERVER_NAME'].$_SERVER['SCRIPT_NAME'];
60 60
     }
61 61
 
62 62
     protected static function setCertificate() {
@@ -72,15 +72,15 @@  discard block
 block discarded – undo
72 72
         self::setCertificate();
73 73
         $url = self::setURL();
74 74
         $secret = !empty(settings::$secret) ? settings::$secret : tools::randomString(64);
75
-        self::setWebhook($url,$secret);
76
-        lock::save('BPT-HOOK',$secret);
75
+        self::setWebhook($url, $secret);
76
+        lock::save('BPT-HOOK', $secret);
77 77
         BPT::exit('Done');
78 78
     }
79 79
 
80 80
     private static function checkSecret() {
81 81
         $secret = lock::read('BPT-HOOK');
82 82
         if ($secret !== self::getSecret()) {
83
-            logger::write('This is not webhook set by BPT, webhook will reset',loggerTypes::WARNING);
83
+            logger::write('This is not webhook set by BPT, webhook will reset', loggerTypes::WARNING);
84 84
             self::processSetWebhook();
85 85
         }
86 86
     }
@@ -98,7 +98,7 @@  discard block
 block discarded – undo
98 98
      *
99 99
      * @return bool
100 100
      */
101
-    public static function fastClose (int $timeout = 86400): bool {
101
+    public static function fastClose(int $timeout = 86400): bool {
102 102
         if (settings::$multi || !lock::exist('BPT-HOOK') || settings::$receiver !== \BPT\constants\receiver::WEBHOOK) {
103 103
             return false;
104 104
         }
Please login to merge, or discard this patch.
Braces   +3 added lines, -6 removed lines patch added patch discarded remove patch
@@ -22,8 +22,7 @@  discard block
 block discarded – undo
22 22
     public static function init () {
23 23
         if (settings::$multi) {
24 24
             multi::init();
25
-        }
26
-        else {
25
+        } else {
27 26
             if (!lock::exist('BPT-HOOK')) {
28 27
                 self::processSetWebhook();
29 28
             }
@@ -108,11 +107,9 @@  discard block
 block discarded – undo
108 107
         ignore_user_abort(true);
109 108
         if (function_exists('fastcgi_finish_request')) {
110 109
             fastcgi_finish_request();
111
-        }
112
-        elseif (function_exists('litespeed_finish_request')) {
110
+        } elseif (function_exists('litespeed_finish_request')) {
113 111
             litespeed_finish_request();
114
-        }
115
-        else {
112
+        } else {
116 113
             return false;
117 114
         }
118 115
 
Please login to merge, or discard this patch.
src/pay/pay.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -5,7 +5,7 @@
 block discarded – undo
5 5
 use BPT\settings;
6 6
 
7 7
 class pay {
8
-    public static function init (): void {
8
+    public static function init(): void {
9 9
         if (isset(settings::$pay['crypto'])) {
10 10
             crypto::init();
11 11
         }
Please login to merge, or discard this patch.
src/pay/crypto.php 1 patch
Spacing   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -21,7 +21,7 @@  discard block
 block discarded – undo
21 21
 
22 22
     private static CurlHandle $session;
23 23
 
24
-    public static function init (string $api_key = '', string $ipn_secret = ''): void {
24
+    public static function init(string $api_key = '', string $ipn_secret = ''): void {
25 25
         self::$api_key = settings::$pay['crypto']['api_key'] ?? $api_key;
26 26
         self::$ipn_secret = settings::$pay['crypto']['ipn_secret'] ?? $ipn_secret;
27 27
         self::$session = curl_init();
@@ -29,12 +29,12 @@  discard block
 block discarded – undo
29 29
         curl_setopt(self::$session, CURLOPT_SSL_VERIFYPEER, 1);
30 30
         curl_setopt(self::$session, CURLOPT_SSL_VERIFYHOST, 2);
31 31
         curl_setopt(self::$session, CURLOPT_HTTPHEADER, [
32
-            'X-API-KEY: ' . self::$api_key,
32
+            'X-API-KEY: '.self::$api_key,
33 33
             'Content-Type: application/json'
34 34
         ]);
35 35
     }
36 36
 
37
-    private static function execute (string $method, string $endpoint, string|array $data = '') {
37
+    private static function execute(string $method, string $endpoint, string | array $data = '') {
38 38
         if (is_array($data)) {
39 39
             foreach ($data as $key => $value) {
40 40
                 if (empty($value)) {
@@ -47,12 +47,12 @@  discard block
 block discarded – undo
47 47
 
48 48
         switch ($method) {
49 49
             case 'GET':
50
-                curl_setopt($session, CURLOPT_URL, self::API_BASE . $endpoint . !empty($data) && is_array($data) ? ('?' . http_build_query($data)) : '');
50
+                curl_setopt($session, CURLOPT_URL, self::API_BASE.$endpoint.!empty($data) && is_array($data) ? ('?'.http_build_query($data)) : '');
51 51
                 break;
52 52
             case 'POST':
53 53
                 curl_setopt($session, CURLOPT_POST, true);
54 54
                 curl_setopt($session, CURLOPT_POSTFIELDS, json_encode($data));
55
-                curl_setopt($session, CURLOPT_URL, self::API_BASE . $endpoint);
55
+                curl_setopt($session, CURLOPT_URL, self::API_BASE.$endpoint);
56 56
                 break;
57 57
             default:
58 58
                 return false;
@@ -60,14 +60,14 @@  discard block
 block discarded – undo
60 60
         return json_decode(curl_exec($session));
61 61
     }
62 62
 
63
-    public static function status (): bool {
63
+    public static function status(): bool {
64 64
         return self::execute('GET', 'status')->message === 'OK';
65 65
     }
66 66
 
67 67
     /**
68 68
      * @return estimatePriceInterface|mixed
69 69
      */
70
-    public static function getEstimatePrice (int|float $amount, string $currency_from, string $currency_to) {
70
+    public static function getEstimatePrice(int | float $amount, string $currency_from, string $currency_to) {
71 71
         return self::execute('GET', 'estimate', [
72 72
             'amount'        => $amount,
73 73
             'currency_from' => $currency_from,
@@ -78,7 +78,7 @@  discard block
 block discarded – undo
78 78
     /**
79 79
      * @return invoicePaymentInterface|mixed
80 80
      */
81
-    public static function createPayment (int|float $price_amount, string $price_currency, string $pay_currency, int|float $pay_amount = null, string $ipn_callback_url = null, string $order_id = null, string $order_description = null, string $purchase_id = null, string $payout_address = null, string $payout_currency = null, string $payout_extra_id = null, bool $fixed_rate = null) {
81
+    public static function createPayment(int | float $price_amount, string $price_currency, string $pay_currency, int | float $pay_amount = null, string $ipn_callback_url = null, string $order_id = null, string $order_description = null, string $purchase_id = null, string $payout_address = null, string $payout_currency = null, string $payout_extra_id = null, bool $fixed_rate = null) {
82 82
         return self::execute('POST', 'payment', [
83 83
             'price_amount'      => $price_amount,
84 84
             'price_currency'    => $price_currency,
@@ -98,7 +98,7 @@  discard block
 block discarded – undo
98 98
     /**
99 99
      * @return invoicePaymentInterface|mixed
100 100
      */
101
-    public static function createInvoicePayment (string $iid, string $pay_currency, string $purchase_id = null, string $order_description = null, string $customer_email = null, string $payout_address = null, string $payout_extra_id = null, string $payout_currency = null) {
101
+    public static function createInvoicePayment(string $iid, string $pay_currency, string $purchase_id = null, string $order_description = null, string $customer_email = null, string $payout_address = null, string $payout_extra_id = null, string $payout_currency = null) {
102 102
         return self::execute('POST', 'invoice', [
103 103
             'iid'               => $iid,
104 104
             'pay_currency'      => $pay_currency,
@@ -114,18 +114,18 @@  discard block
 block discarded – undo
114 114
     /**
115 115
      * @return estimateUpdateInterface|mixed
116 116
      */
117
-    public static function updateEstimatePrice (int $paymentID) {
118
-        return self::execute('POST', 'payment/' . $paymentID . '/update-merchant-estimate');
117
+    public static function updateEstimatePrice(int $paymentID) {
118
+        return self::execute('POST', 'payment/'.$paymentID.'/update-merchant-estimate');
119 119
     }
120 120
 
121 121
     /**
122 122
      * @return paymentInterface|mixed
123 123
      */
124
-    public static function getPaymentStatus (int $paymentID) {
125
-        return self::execute('GET', 'payment/' . $paymentID);
124
+    public static function getPaymentStatus(int $paymentID) {
125
+        return self::execute('GET', 'payment/'.$paymentID);
126 126
     }
127 127
 
128
-    public static function getMinimumPaymentAmount (string $currency_from, string $currency_to): float {
128
+    public static function getMinimumPaymentAmount(string $currency_from, string $currency_to): float {
129 129
         return self::execute('GET', 'min-amount', [
130 130
             'currency_from' => $currency_from,
131 131
             'currency_to'   => $currency_to
@@ -135,7 +135,7 @@  discard block
 block discarded – undo
135 135
     /**
136 136
      * @return invoiceResponseInterface|mixed
137 137
      */
138
-    public static function createInvoice (int|float $price_amount, string $price_currency, string $pay_currency, int|float $pay_amount = null, string $ipn_callback_url = null, string $order_id = null, string $order_description = null, string $success_url = null, string $cancel_url = null) {
138
+    public static function createInvoice(int | float $price_amount, string $price_currency, string $pay_currency, int | float $pay_amount = null, string $ipn_callback_url = null, string $order_id = null, string $order_description = null, string $success_url = null, string $cancel_url = null) {
139 139
         return self::execute('POST', 'invoice', [
140 140
             'price_amount'      => $price_amount,
141 141
             'price_currency'    => $price_currency,
@@ -149,7 +149,7 @@  discard block
 block discarded – undo
149 149
         ]);
150 150
     }
151 151
 
152
-    public static function getCurrencies (): array {
152
+    public static function getCurrencies(): array {
153 153
         return self::execute('GET', 'currencies')->currencies;
154 154
     }
155 155
 
@@ -157,7 +157,7 @@  discard block
 block discarded – undo
157 157
         return tools::remoteIP() === '144.76.201.30';
158 158
     }
159 159
 
160
-    public static function isIPNRequestValid (): bool {
160
+    public static function isIPNRequestValid(): bool {
161 161
         if (empty($_SERVER['HTTP_X_NOWPAYMENTS_SIG'])) {
162 162
             return false;
163 163
         }
@@ -177,7 +177,7 @@  discard block
 block discarded – undo
177 177
     /**
178 178
      * @return ipnDataInterface|mixed
179 179
      */
180
-    public static function getIPN () {
180
+    public static function getIPN() {
181 181
         if (!self::isIPNRequestValid()) {
182 182
             return false;
183 183
         }
Please login to merge, or discard this patch.
src/pay/idpay.php 2 patches
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -16,20 +16,20 @@  discard block
 block discarded – undo
16 16
 
17 17
     private static CurlHandle $session;
18 18
 
19
-    public static function init (string $api_key = '', bool $sandbox = false): void {
19
+    public static function init(string $api_key = '', bool $sandbox = false): void {
20 20
         self::$session = curl_init();
21 21
         curl_setopt(self::$session, CURLOPT_RETURNTRANSFER, true);
22 22
         curl_setopt(self::$session, CURLOPT_SSL_VERIFYPEER, 1);
23 23
         curl_setopt(self::$session, CURLOPT_SSL_VERIFYHOST, 2);
24 24
         curl_setopt(self::$session, CURLOPT_HTTPHEADER, [
25 25
             'Content-Type: application/json',
26
-            'X-API-KEY: ' . settings::$pay['idpay']['api_key'] ?? $api_key,
27
-            'X-SANDBOX: ' . (int) (settings::$pay['idpay']['sandbox'] ?? $sandbox),
26
+            'X-API-KEY: '.settings::$pay['idpay']['api_key'] ?? $api_key,
27
+            'X-SANDBOX: '.(int) (settings::$pay['idpay']['sandbox'] ?? $sandbox),
28 28
         ]);
29 29
         curl_setopt(self::$session, CURLOPT_POST, true);
30 30
     }
31 31
 
32
-    private static function execute (string $endpoint, array $params) {
32
+    private static function execute(string $endpoint, array $params) {
33 33
         foreach ($params as $key => $value) {
34 34
             if (empty($value)) {
35 35
                 unset($params[$key]);
@@ -39,7 +39,7 @@  discard block
 block discarded – undo
39 39
         $session = self::$session;
40 40
 
41 41
         curl_setopt($session, CURLOPT_POSTFIELDS, json_encode($params));
42
-        curl_setopt($session, CURLOPT_URL, self::API_BASE . $endpoint);
42
+        curl_setopt($session, CURLOPT_URL, self::API_BASE.$endpoint);
43 43
 
44 44
         return json_decode(curl_exec($session));
45 45
     }
@@ -47,7 +47,7 @@  discard block
 block discarded – undo
47 47
     /**
48 48
      * @return paymentCreateInterface|errorInterface|object|bool
49 49
      */
50
-    public static function createPayment (string $order_id, int $amount, string $name = '', string $phone = '', string $mail = '', string $desc = '', string $callback = ''): object|bool {
50
+    public static function createPayment(string $order_id, int $amount, string $name = '', string $phone = '', string $mail = '', string $desc = '', string $callback = ''): object | bool {
51 51
         return self::execute('payment', [
52 52
             'order_id' => $order_id,
53 53
             'amount'   => $amount,
@@ -62,7 +62,7 @@  discard block
 block discarded – undo
62 62
     /**
63 63
      * @return paymentInterface|errorInterface|object|bool
64 64
      */
65
-    public static function paymentDetail (string $id, string $order_id): object {
65
+    public static function paymentDetail(string $id, string $order_id): object {
66 66
         return self::execute('payment/inquiry', [
67 67
             'order_id' => $order_id,
68 68
             'id'       => $id
@@ -72,7 +72,7 @@  discard block
 block discarded – undo
72 72
     /**
73 73
      * @return paymentInterface|errorInterface|object|bool
74 74
      */
75
-    public static function paymentConfirm (string $id, string $order_id): object {
75
+    public static function paymentConfirm(string $id, string $order_id): object {
76 76
         return self::execute('payment/verify', [
77 77
             'order_id' => $order_id,
78 78
             'id'       => $id
@@ -82,14 +82,14 @@  discard block
 block discarded – undo
82 82
     /**
83 83
      * @return paymentListInterface|errorInterface|object|bool
84 84
      */
85
-    public static function paymentList (int $page = 0, int $page_size = 25): object {
85
+    public static function paymentList(int $page = 0, int $page_size = 25): object {
86 86
         return self::execute('payment/transactions', [
87 87
             'page'      => $page,
88 88
             'page_size' => $page_size
89 89
         ]);
90 90
     }
91 91
 
92
-    public static function processCallback (): bool|int {
92
+    public static function processCallback(): bool | int {
93 93
         if ($_SERVER['REQUEST_METHOD'] === 'POST') {
94 94
             $response = $_POST;
95 95
         }
Please login to merge, or discard this patch.
Braces   +2 added lines, -4 removed lines patch added patch discarded remove patch
@@ -92,11 +92,9 @@
 block discarded – undo
92 92
     public static function processCallback (): bool|int {
93 93
         if ($_SERVER['REQUEST_METHOD'] === 'POST') {
94 94
             $response = $_POST;
95
-        }
96
-        elseif ($_SERVER['REQUEST_METHOD'] === 'GET') {
95
+        } elseif ($_SERVER['REQUEST_METHOD'] === 'GET') {
97 96
             $response = $_GET;
98
-        }
99
-        else {
97
+        } else {
100 98
             return false;
101 99
         }
102 100
 
Please login to merge, or discard this patch.
src/pay/zarinpal.php 2 patches
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -25,7 +25,7 @@  discard block
 block discarded – undo
25 25
 
26 26
     private static CurlHandle $session;
27 27
 
28
-    public static function init (string $merchant_id = '', bool $sandbox = false, bool $zarin_gate = false): void {
28
+    public static function init(string $merchant_id = '', bool $sandbox = false, bool $zarin_gate = false): void {
29 29
         self::$sandbox = settings::$pay['zarinpal']['sandbox'] ?? $sandbox;
30 30
         self::$zarin_gate = settings::$pay['zarinpal']['zarin_gate'] ?? settings::$pay['zarinpal']['zaringate'] ?? $zarin_gate;
31 31
         self::$merchant_id = settings::$pay['zarinpal']['merchant_id'] ?? $merchant_id;
@@ -40,7 +40,7 @@  discard block
 block discarded – undo
40 40
         curl_setopt(self::$session, CURLOPT_POST, true);
41 41
     }
42 42
 
43
-    private static function getUrl (string $endpoint, bool $pay = false): string {
43
+    private static function getUrl(string $endpoint, bool $pay = false): string {
44 44
         if ($pay) {
45 45
             $url = self::$sandbox ? self::SANDBOX_PAY_BASE : self::PAY_BASE;
46 46
         }
@@ -54,7 +54,7 @@  discard block
 block discarded – undo
54 54
         return $url;
55 55
     }
56 56
 
57
-    private static function execute (string $endpoint, array $params = []): object {
57
+    private static function execute(string $endpoint, array $params = []): object {
58 58
         foreach ($params as $key => $value) {
59 59
             if (empty($value)) {
60 60
                 unset($params[$key]);
@@ -88,7 +88,7 @@  discard block
 block discarded – undo
88 88
     /**
89 89
      * @return object|requestInterface
90 90
      */
91
-    public static function request (int $amount, string $description, string $callback_url, array $metadata = [], string $mobile = '', string $email = '', array $wages = [], int $card_pan = null, string $currency = ''): object {
91
+    public static function request(int $amount, string $description, string $callback_url, array $metadata = [], string $mobile = '', string $email = '', array $wages = [], int $card_pan = null, string $currency = ''): object {
92 92
         return self::execute('/request.json', [
93 93
             'amount'       => $amount,
94 94
             'description'  => $description,
@@ -102,7 +102,7 @@  discard block
 block discarded – undo
102 102
         ]);
103 103
     }
104 104
 
105
-    public static function payURL (string|array $authority): bool|string {
105
+    public static function payURL(string | array $authority): bool | string {
106 106
         if (is_array($authority)) {
107 107
             if (!isset($authority->authority)) {
108 108
                 return false;
@@ -115,7 +115,7 @@  discard block
 block discarded – undo
115 115
     /**
116 116
      * @return object|verifyInterface
117 117
      */
118
-    public static function verify (int $amount, string $authority): object {
118
+    public static function verify(int $amount, string $authority): object {
119 119
         return self::execute('/verify.json', [
120 120
             'amount'    => $amount,
121 121
             'authority' => $authority
@@ -125,14 +125,14 @@  discard block
 block discarded – undo
125 125
     /**
126 126
      * @return object|unverifiedInterface
127 127
      */
128
-    public static function unVerified (): object {
128
+    public static function unVerified(): object {
129 129
         return self::execute('/unVerified.json');
130 130
     }
131 131
 
132 132
     /**
133 133
      * @return object|refundInterface
134 134
      */
135
-    public static function refund (string $authorization, string $authority): object {
135
+    public static function refund(string $authorization, string $authority): object {
136 136
         return self::execute('/refund.json', [
137 137
             'authorization' => $authorization,
138 138
             'authority'     => $authority
@@ -140,12 +140,12 @@  discard block
 block discarded – undo
140 140
     }
141 141
 
142 142
     #[NoReturn]
143
-    public static function redirect (string $url): void {
144
-        @header('Location: ' . $url);
143
+    public static function redirect(string $url): void {
144
+        @header('Location: '.$url);
145 145
         die("<meta http-equiv='refresh' content='0; url=$url' /><script>window.location.href = '$url';</script>");
146 146
     }
147 147
 
148
-    public static function processCallback (int $amount): object|bool|int {
148
+    public static function processCallback(int $amount): object | bool | int {
149 149
         if (!isset($_GET['Authority']) || !isset($_GET['Status'])) {
150 150
             return false;
151 151
         }
Please login to merge, or discard this patch.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -43,8 +43,7 @@
 block discarded – undo
43 43
     private static function getUrl (string $endpoint, bool $pay = false): string {
44 44
         if ($pay) {
45 45
             $url = self::$sandbox ? self::SANDBOX_PAY_BASE : self::PAY_BASE;
46
-        }
47
-        else {
46
+        } else {
48 47
             $url = self::$sandbox ? self::SANDBOX_API_BASE : self::API_BASE;
49 48
         }
50 49
         $url .= $endpoint;
Please login to merge, or discard this patch.
src/database/mysql.php 2 patches
Spacing   +49 added lines, -49 removed lines patch added patch discarded remove patch
@@ -29,7 +29,7 @@  discard block
 block discarded – undo
29 29
     /**
30 30
      * If you want to use it in standalone mode , you MUST set `auto_process` to `false`
31 31
      */
32
-    public static function init (string $host = 'localhost', string $username = 'root', string $password = '', string $dbname = '', bool $auto_process = null, int $port = 3306): void {
32
+    public static function init(string $host = 'localhost', string $username = 'root', string $password = '', string $dbname = '', bool $auto_process = null, int $port = 3306): void {
33 33
         $host = settings::$db['host'] ?? $host;
34 34
         $port = settings::$db['port'] ?? $port;
35 35
         $user = settings::$db['user'] ?? settings::$db['username'] ?? $username;
@@ -39,7 +39,7 @@  discard block
 block discarded – undo
39 39
         self::$db_name = $dbname;
40 40
         self::$connection = new mysqli($host, $user, $pass, $dbname, $port);
41 41
         if (self::$connection->connect_errno) {
42
-            logger::write('SQL connection has problem : ' . self::$connection->connect_error, loggerTypes::ERROR);
42
+            logger::write('SQL connection has problem : '.self::$connection->connect_error, loggerTypes::ERROR);
43 43
             throw new bptException('SQL_CONNECTION_PROBLEM');
44 44
         }
45 45
         if (self::$auto_process && !lock::exist('BPT-MYSQL')) {
@@ -47,7 +47,7 @@  discard block
 block discarded – undo
47 47
         }
48 48
     }
49 49
 
50
-    private static function install (): void {
50
+    private static function install(): void {
51 51
         self::pureQuery("
52 52
 CREATE TABLE `users`
53 53
 (
@@ -68,7 +68,7 @@  discard block
 block discarded – undo
68 68
     /**
69 69
      * @internal Only for BPT self usage , Don't use it in your source!
70 70
      */
71
-    public static function process (): void {
71
+    public static function process(): void {
72 72
         if (self::$auto_process) {
73 73
             if (isset(BPT::$update->message)) {
74 74
                 self::processMessage(BPT::$update->message);
@@ -88,7 +88,7 @@  discard block
 block discarded – undo
88 88
         }
89 89
     }
90 90
 
91
-    private static function processMessage (message $update): void {
91
+    private static function processMessage(message $update): void {
92 92
         $type = $update->chat->type;
93 93
         if ($type === chatType::PRIVATE) {
94 94
             $user_id = $update->from->id;
@@ -114,7 +114,7 @@  discard block
 block discarded – undo
114 114
         }
115 115
     }
116 116
 
117
-    private static function processCallbackQuery (callbackQuery $update): void {
117
+    private static function processCallbackQuery(callbackQuery $update): void {
118 118
         $type = $update->message->chat->type;
119 119
         if ($type === chatType::PRIVATE) {
120 120
             $user_id = $update->from->id;
@@ -124,7 +124,7 @@  discard block
 block discarded – undo
124 124
         }
125 125
     }
126 126
 
127
-    private static function processInlineQuery (inlineQuery $update): void {
127
+    private static function processInlineQuery(inlineQuery $update): void {
128 128
         $type = $update->chat_type;
129 129
         if ($type === chatType::PRIVATE || $type === chatType::SENDER) {
130 130
             $user_id = $update->from->id;
@@ -134,7 +134,7 @@  discard block
 block discarded – undo
134 134
         }
135 135
     }
136 136
 
137
-    private static function processMyChatMember (chatMemberUpdated $update): void {
137
+    private static function processMyChatMember(chatMemberUpdated $update): void {
138 138
         $type = $update->chat->type;
139 139
         if ($type === chatType::PRIVATE) {
140 140
             if ($update->new_chat_member->status === chatMemberStatus::MEMBER) {
@@ -151,7 +151,7 @@  discard block
 block discarded – undo
151 151
      *
152 152
      * @return mysqli
153 153
      */
154
-    public static function getMysqli (): mysqli {
154
+    public static function getMysqli(): mysqli {
155 155
         return self::$connection;
156 156
     }
157 157
 
@@ -162,7 +162,7 @@  discard block
 block discarded – undo
162 162
      *
163 163
      * @return int|string
164 164
      */
165
-    public static function affected_rows (): int|string {
165
+    public static function affected_rows(): int | string {
166 166
         return self::$connection->affected_rows;
167 167
     }
168 168
 
@@ -173,7 +173,7 @@  discard block
 block discarded – undo
173 173
      *
174 174
      * @return int|string
175 175
      */
176
-    public static function affectedRows (): int|string {
176
+    public static function affectedRows(): int | string {
177 177
         return self::$connection->affected_rows;
178 178
     }
179 179
 
@@ -184,7 +184,7 @@  discard block
 block discarded – undo
184 184
      *
185 185
      * @return int|string
186 186
      */
187
-    public static function insert_id (): int|string {
187
+    public static function insert_id(): int | string {
188 188
         return self::$connection->insert_id;
189 189
     }
190 190
 
@@ -195,7 +195,7 @@  discard block
 block discarded – undo
195 195
      *
196 196
      * @return int|string
197 197
      */
198
-    public static function insertId (): int|string {
198
+    public static function insertId(): int | string {
199 199
         return self::$connection->insert_id;
200 200
     }
201 201
 
@@ -206,7 +206,7 @@  discard block
 block discarded – undo
206 206
      *
207 207
      * @return string
208 208
      */
209
-    public static function escapeString (string $text): string {
209
+    public static function escapeString(string $text): string {
210 210
         return self::$connection->real_escape_string($text);
211 211
     }
212 212
 
@@ -215,7 +215,7 @@  discard block
 block discarded – undo
215 215
      *
216 216
      * @return string
217 217
      */
218
-    public static function error (): string {
218
+    public static function error(): string {
219 219
         return self::$connection->error;
220 220
     }
221 221
 
@@ -224,7 +224,7 @@  discard block
 block discarded – undo
224 224
      *
225 225
      * @return int
226 226
      */
227
-    public static function errno (): int {
227
+    public static function errno(): int {
228 228
         return self::$connection->errno;
229 229
     }
230 230
 
@@ -235,7 +235,7 @@  discard block
 block discarded – undo
235 235
      *
236 236
      * @return bool
237 237
      */
238
-    public static function setCharset (string $charset): bool {
238
+    public static function setCharset(string $charset): bool {
239 239
         return self::$connection->set_charset($charset);
240 240
     }
241 241
 
@@ -250,7 +250,7 @@  discard block
 block discarded – undo
250 250
      *
251 251
      * @return mysqli_result|bool
252 252
      */
253
-    public static function pureQuery (string $query): mysqli_result|bool {
253
+    public static function pureQuery(string $query): mysqli_result | bool {
254 254
         return self::$connection->query($query);
255 255
     }
256 256
 
@@ -271,7 +271,7 @@  discard block
 block discarded – undo
271 271
      *
272 272
      * @return mysqli_result|bool
273 273
      */
274
-    public static function query (string $query, array $vars = [], bool $need_result = true): mysqli_result|bool {
274
+    public static function query(string $query, array $vars = [], bool $need_result = true): mysqli_result | bool {
275 275
         if (empty($vars)) {
276 276
             return self::pureQuery($query);
277 277
         }
@@ -288,7 +288,7 @@  discard block
 block discarded – undo
288 288
                 $types .= 's';
289 289
             }
290 290
         }
291
-        $prepare->bind_param($types,...$vars);
291
+        $prepare->bind_param($types, ...$vars);
292 292
         if (!$prepare->execute()) {
293 293
             logger::write(loggerTypes::WARNING, $prepare->error);
294 294
             return false;
@@ -313,8 +313,8 @@  discard block
 block discarded – undo
313 313
                 $query .= ' AND';
314 314
             }
315 315
 
316
-            $operator = substr($value,0,2);
317
-            $operator_value = substr($value,2);
316
+            $operator = substr($value, 0, 2);
317
+            $operator_value = substr($value, 2);
318 318
             switch ($operator) {
319 319
                 case '>=':
320 320
                     $query .= " `$name` >= ?";
@@ -351,17 +351,17 @@  discard block
 block discarded – undo
351 351
         return $values;
352 352
     }
353 353
 
354
-    private static function groupByBuilder(string &$query, string|array $group_by = []): void {
354
+    private static function groupByBuilder(string &$query, string | array $group_by = []): void {
355 355
         if (empty($group_by)) {
356 356
             return;
357 357
         }
358 358
         if (is_string($group_by)) {
359 359
             $group_by = [$group_by];
360 360
         }
361
-        $query .= ' GROUP BY `' . implode('`, `',$group_by) . '`';
361
+        $query .= ' GROUP BY `'.implode('`, `', $group_by).'`';
362 362
     }
363 363
 
364
-    private static function orderByBuilder(string &$query, string|array $order_by = []): void {
364
+    private static function orderByBuilder(string &$query, string | array $order_by = []): void {
365 365
         if (empty($order_by)) {
366 366
             return;
367 367
         }
@@ -408,8 +408,8 @@  discard block
 block discarded – undo
408 408
                 $query .= ' ,';
409 409
             }
410 410
 
411
-            $operator = substr($value,0,2);
412
-            $operator_value = substr($value,2);
411
+            $operator = substr($value, 0, 2);
412
+            $operator_value = substr($value, 2);
413 413
             switch ($operator) {
414 414
                 case '+=':
415 415
                     $query .= " `$name` = `$name` + ?";
@@ -442,19 +442,19 @@  discard block
 block discarded – undo
442 442
         return $values;
443 443
     }
444 444
 
445
-    private static function insertBuilder(string &$query, string|array $columns, array|string $values): array {
446
-        $query .= '(`' . (is_string($columns) ? $columns : implode('`,`', $columns)) . '`) VALUES (';
445
+    private static function insertBuilder(string &$query, string | array $columns, array | string $values): array {
446
+        $query .= '(`'.(is_string($columns) ? $columns : implode('`,`', $columns)).'`) VALUES (';
447 447
         if (is_string($values)) $values = [$values];
448
-        $query .= '?' . str_repeat(',?', count($values) - 1) . ')';
448
+        $query .= '?'.str_repeat(',?', count($values) - 1).')';
449 449
         return $values;
450 450
     }
451 451
 
452
-    private static function selectBuilder(string &$query, string|array $columns): void {
452
+    private static function selectBuilder(string &$query, string | array $columns): void {
453 453
         if ($columns == '*') {
454 454
             $query .= " * ";
455 455
         }
456 456
         else {
457
-            $query .= ' `' . (is_string($columns) ? $columns : implode('`,`', $columns)) . '` ';
457
+            $query .= ' `'.(is_string($columns) ? $columns : implode('`,`', $columns)).'` ';
458 458
         }
459 459
     }
460 460
 
@@ -470,7 +470,7 @@  discard block
 block discarded – undo
470 470
      *
471 471
      * @return mysqli_result|bool
472 472
      */
473
-    public static function delete (string $table, array $where = null, int $count = null, int $offset = null): bool {
473
+    public static function delete(string $table, array $where = null, int $count = null, int $offset = null): bool {
474 474
         $query = "DELETE FROM `$table`";
475 475
         $vars = self::whereBuilder($query, $where);
476 476
         return self::query($query, $vars, false);
@@ -489,7 +489,7 @@  discard block
 block discarded – undo
489 489
      *
490 490
      * @return mysqli_result|bool
491 491
      */
492
-    public static function update (string $table, array $modify, array $where = null, int $count = null, int $offset = null): bool {
492
+    public static function update(string $table, array $modify, array $where = null, int $count = null, int $offset = null): bool {
493 493
         $query = "UPDATE `$table` SET";
494 494
         $modify_vars = self::updateBuilder($query, $modify);
495 495
         $where_vars = self::whereBuilder($query, $where);
@@ -508,7 +508,7 @@  discard block
 block discarded – undo
508 508
      *
509 509
      * @return mysqli_result|bool
510 510
      */
511
-    public static function insert (string $table, string|array $columns, array|string $values): bool {
511
+    public static function insert(string $table, string | array $columns, array | string $values): bool {
512 512
         $query = "INSERT INTO `$table`";
513 513
         $values = self::insertBuilder($query, $columns, $values);
514 514
         return self::query($query, $values, false);
@@ -531,14 +531,14 @@  discard block
 block discarded – undo
531 531
      *
532 532
      * @return mysqli_result|bool
533 533
      */
534
-    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 = []): mysqli_result|bool {
534
+    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 = []): mysqli_result | bool {
535 535
         $query = "SELECT";
536 536
         self::selectBuilder($query, $columns);
537 537
         $query .= "FROM `$table`";
538
-        $var = self::whereBuilder($query,$where);
538
+        $var = self::whereBuilder($query, $where);
539 539
         self::groupByBuilder($query, $group_by);
540 540
         self::orderByBuilder($query, $order_by);
541
-        self::countBuilder($query,$count,$offset);
541
+        self::countBuilder($query, $count, $offset);
542 542
         return self::query($query, $var);
543 543
     }
544 544
 
@@ -555,7 +555,7 @@  discard block
 block discarded – undo
555 555
      *
556 556
      * @return null|bool|array
557 557
      */
558
-    public static function selectArray (string $table, array|string $columns = '*', array $where = null, array|string $group_by = [], array|string $order_by = []): bool|array|null {
558
+    public static function selectArray(string $table, array | string $columns = '*', array $where = null, array | string $group_by = [], array | string $order_by = []): bool | array | null {
559 559
         $res = self::select($table, $columns, $where, 1, $group_by, $order_by);
560 560
         if ($res) {
561 561
             return $res->fetch_assoc();
@@ -574,7 +574,7 @@  discard block
 block discarded – undo
574 574
      * @param array|string $group_by group result based on these columns
575 575
      * @param array|string $order_by order result based on these columns
576 576
      */
577
-    public static function selectObject (string $table, array|string $columns = '*', array $where = null, array|string $group_by = [], array|string $order_by = []) {
577
+    public static function selectObject(string $table, array | string $columns = '*', array $where = null, array | string $group_by = [], array | string $order_by = []) {
578 578
         $res = self::select($table, $columns, $where, 1, $group_by, $order_by);
579 579
         if ($res) {
580 580
             return $res->fetch_object();
@@ -598,7 +598,7 @@  discard block
 block discarded – undo
598 598
      *
599 599
      * @return bool|Generator
600 600
      */
601
-    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|Generator {
601
+    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 | Generator {
602 602
         $res = self::select($table, $columns, $where, $count, $offset, $group_by, $order_by);
603 603
         if ($res) {
604 604
             while ($row = $res->fetch_assoc()) yield $row;
@@ -616,10 +616,10 @@  discard block
 block discarded – undo
616 616
      *
617 617
      * @return string if save is true , return file name otherwise return sql data
618 618
      */
619
-    public static function backup (array $wanted_tables = null, bool $table_data = true, bool $save = true, string $file_name = ''): string {
619
+    public static function backup(array $wanted_tables = null, bool $table_data = true, bool $save = true, string $file_name = ''): string {
620 620
         self::setCharset('utf8mb4');
621 621
 
622
-        $tables = array_column(self::query('SHOW TABLES')->fetch_all(),0);
622
+        $tables = array_column(self::query('SHOW TABLES')->fetch_all(), 0);
623 623
         if (!empty($wanted_tables)) {
624 624
             $tables = array_intersect($tables, $wanted_tables);
625 625
         }
@@ -630,12 +630,12 @@  discard block
 block discarded – undo
630 630
             logger::write('No table founded for backup, if your database has table : check $wanted_tables argument', loggerTypes::WARNING);
631 631
         }
632 632
         foreach ($tables as $table) {
633
-            $sql .= self::query("SHOW CREATE TABLE `$table`")->fetch_row()[1] . ";\n\n";
633
+            $sql .= self::query("SHOW CREATE TABLE `$table`")->fetch_row()[1].";\n\n";
634 634
             if ($table_data) {
635 635
                 $total_rows = self::query("SELECT COUNT(*) as `cnt` FROM `$table`")->fetch_object()->cnt;
636 636
                 for ($i = 0; $i < $total_rows; $i = $i + 1000) {
637
-                    $sql .= "INSERT INTO " . $table . " VALUES";
638
-                    $result = self::select($table, '*' , null, 1000, $i);
637
+                    $sql .= "INSERT INTO ".$table." VALUES";
638
+                    $result = self::select($table, '*', null, 1000, $i);
639 639
                     $field_count = $result->field_count;
640 640
                     $affected_rows = self::affected_rows();
641 641
                     $counter = 1;
@@ -643,12 +643,12 @@  discard block
 block discarded – undo
643 643
                         $sql .= "\n(";
644 644
                         for ($column = 0; $column < $field_count; $column++) {
645 645
                             $row[$column] = str_replace("\n", "\\n", addslashes($row[$column]));
646
-                            $sql .= !empty($row[$column]) ? '"' . $row[$column] . '"' : '""';
646
+                            $sql .= !empty($row[$column]) ? '"'.$row[$column].'"' : '""';
647 647
                             if ($column < $field_count - 1) {
648 648
                                 $sql .= ',';
649 649
                             }
650 650
                         }
651
-                        $sql .= ')' . ($counter == $affected_rows ? ';' : ',');
651
+                        $sql .= ')'.($counter == $affected_rows ? ';' : ',');
652 652
                         $counter++;
653 653
                     }
654 654
                 }
@@ -664,7 +664,7 @@  discard block
 block discarded – undo
664 664
         }
665 665
 
666 666
         if (empty($file_name)) {
667
-            $file_name = self::$db_name . time() . '.sql';
667
+            $file_name = self::$db_name.time().'.sql';
668 668
         }
669 669
         file_put_contents($file_name, $sql);
670 670
         return $file_name;
Please login to merge, or discard this patch.
Braces   +20 added lines, -27 removed lines patch added patch discarded remove patch
@@ -72,17 +72,13 @@  discard block
 block discarded – undo
72 72
         if (self::$auto_process) {
73 73
             if (isset(BPT::$update->message)) {
74 74
                 self::processMessage(BPT::$update->message);
75
-            }
76
-            elseif (isset(BPT::$update->edited_message)) {
75
+            } elseif (isset(BPT::$update->edited_message)) {
77 76
                 self::processMessage(BPT::$update->edited_message);
78
-            }
79
-            elseif (isset(BPT::$update->callback_query)) {
77
+            } elseif (isset(BPT::$update->callback_query)) {
80 78
                 self::processCallbackQuery(BPT::$update->callback_query);
81
-            }
82
-            elseif (isset(BPT::$update->inline_query)) {
79
+            } elseif (isset(BPT::$update->inline_query)) {
83 80
                 self::processInlineQuery(BPT::$update->inline_query);
84
-            }
85
-            elseif (isset(BPT::$update->my_chat_member)) {
81
+            } elseif (isset(BPT::$update->my_chat_member)) {
86 82
                 self::processMyChatMember(BPT::$update->my_chat_member);
87 83
             }
88 84
         }
@@ -139,8 +135,7 @@  discard block
 block discarded – undo
139 135
         if ($type === chatType::PRIVATE) {
140 136
             if ($update->new_chat_member->status === chatMemberStatus::MEMBER) {
141 137
                 self::update('users', ['blocked' => false], ['id' => $update->from->id], 1);
142
-            }
143
-            else {
138
+            } else {
144 139
                 self::update('users', ['blocked' => true], ['id' => $update->from->id], 1);
145 140
             }
146 141
         }
@@ -280,11 +275,9 @@  discard block
 block discarded – undo
280 275
         foreach ($vars as $var) {
281 276
             if (is_int($var)) {
282 277
                 $types .= 'i';
283
-            }
284
-            elseif (is_double($var)) {
278
+            } elseif (is_double($var)) {
285 279
                 $types .= 'd';
286
-            }
287
-            else {
280
+            } else {
288 281
                 $types .= 's';
289 282
             }
290 283
         }
@@ -308,8 +301,7 @@  discard block
 block discarded – undo
308 301
         foreach ($where as $name => $value) {
309 302
             if ($first) {
310 303
                 $first = false;
311
-            }
312
-            else {
304
+            } else {
313 305
                 $query .= ' AND';
314 306
             }
315 307
 
@@ -375,8 +367,7 @@  discard block
 block discarded – undo
375 367
         foreach ($order_by as $key => $mode) {
376 368
             if ($first) {
377 369
                 $first = false;
378
-            }
379
-            else {
370
+            } else {
380 371
                 $query .= ', ';
381 372
             }
382 373
             if (is_numeric($key)) {
@@ -390,8 +381,7 @@  discard block
 block discarded – undo
390 381
     private static function countBuilder(string &$query, int $count = null, int $offset = null): void {
391 382
         if (!empty($count)) {
392 383
             $query .= !empty($offset) ? " LIMIT $offset,$count" : " LIMIT $count";
393
-        }
394
-        elseif (!empty($offset)) {
384
+        } elseif (!empty($offset)) {
395 385
             $query .= " OFFSET $offset";
396 386
         }
397 387
     }
@@ -403,8 +393,7 @@  discard block
 block discarded – undo
403 393
         foreach ($modify as $name => $value) {
404 394
             if ($first) {
405 395
                 $first = false;
406
-            }
407
-            else {
396
+            } else {
408 397
                 $query .= ' ,';
409 398
             }
410 399
 
@@ -444,7 +433,9 @@  discard block
 block discarded – undo
444 433
 
445 434
     private static function insertBuilder(string &$query, string|array $columns, array|string $values): array {
446 435
         $query .= '(`' . (is_string($columns) ? $columns : implode('`,`', $columns)) . '`) VALUES (';
447
-        if (is_string($values)) $values = [$values];
436
+        if (is_string($values)) {
437
+            $values = [$values];
438
+        }
448 439
         $query .= '?' . str_repeat(',?', count($values) - 1) . ')';
449 440
         return $values;
450 441
     }
@@ -452,8 +443,7 @@  discard block
 block discarded – undo
452 443
     private static function selectBuilder(string &$query, string|array $columns): void {
453 444
         if ($columns == '*') {
454 445
             $query .= " * ";
455
-        }
456
-        else {
446
+        } else {
457 447
             $query .= ' `' . (is_string($columns) ? $columns : implode('`,`', $columns)) . '` ';
458 448
         }
459 449
     }
@@ -601,9 +591,12 @@  discard block
 block discarded – undo
601 591
     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|Generator {
602 592
         $res = self::select($table, $columns, $where, $count, $offset, $group_by, $order_by);
603 593
         if ($res) {
604
-            while ($row = $res->fetch_assoc()) yield $row;
594
+            while ($row = $res->fetch_assoc()) {
595
+                yield $row;
596
+            }
597
+        } else {
598
+            return $res;
605 599
         }
606
-        else return $res;
607 600
     }
608 601
 
609 602
     /**
Please login to merge, or discard this patch.