Skip to content

Commit faba124

Browse files
Fix code style
1 parent debe318 commit faba124

File tree

11 files changed

+95
-20
lines changed

11 files changed

+95
-20
lines changed

src/Bot.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,14 @@ class Bot
4141
public function __construct(string $token, Config $config = null)
4242
{
4343
self::$token = $token;
44+
4445
if (is_null($config)) {
46+
4547
$config = new Config();
4648
}
4749

4850
self::$config = $config;
51+
4952
self::$log = new Log(
5053
$config->logDatabase,
5154
$config->logDatabaseTableName,
@@ -55,6 +58,7 @@ public function __construct(string $token, Config $config = null)
5558
);
5659

5760
if (self::$config->autoUseWebhook) {
61+
5862
return $this->setUpdate();
5963
}
6064
}
@@ -77,11 +81,14 @@ public function setUpdate(?string $input = null)
7781
self::$input = $input;
7882

7983
if (self::$config->convertToObject) {
84+
8085
self::$update = new Update($input);
86+
8187
self::$helper = new Helper($input);
8288
}
8389

8490
if (self::$config->logUpdate) {
91+
8592
self::$log->update($input);
8693
}
8794

@@ -131,6 +138,7 @@ public static function sendRequest(string $method, array $parameters = [], ?stri
131138
$token = is_null($token) ? self::$token : $token;
132139
$botApiServerUrl = self::$config->botApiServerUrl;
133140
$url = "{$botApiServerUrl}{$token}/{$method}";
141+
134142
$ch = curl_init($url);
135143

136144
curl_setopt_array($ch, [
@@ -166,18 +174,22 @@ public static function sendRequest(string $method, array $parameters = [], ?stri
166174
throw new BotException("something went wrong. Request failed Error: {$error}");
167175
}
168176
} else {
177+
169178
if (self::$config->logRequest === true && self::$config->logResponse === false) {
179+
170180
self::$log->request([
171181
'method' => $method,
172182
'parameters' => $parameters,
173183
]);
174184
}
175185

176186
if (self::$config->logRequest === false && self::$config->logResponse === true) {
187+
177188
self::$log->response($response);
178189
}
179190

180191
if (self::$config->logRequest === true && self::$config->logResponse === true) {
192+
181193
self::$log->requestAndResponse([
182194
'method' => $method,
183195
'parameters' => $parameters,
@@ -186,6 +198,7 @@ public static function sendRequest(string $method, array $parameters = [], ?stri
186198
}
187199

188200
if (self::$config->convertToObject) {
201+
189202
return new Response($response, $method, $parameters);
190203
}
191204

@@ -207,12 +220,14 @@ public static function downloadFile(string $filePath, string $localFilePath)
207220
$localFile = fopen($localFilePath, 'wb');
208221

209222
if (!$file || !$localFile) {
223+
210224
return false;
211225
}
212226

213227
while (!feof($file)) {
214228

215229
if (fwrite($localFile, fread($file, 8192), 8192) === FALSE) {
230+
216231
return false;
217232
}
218233
}
@@ -240,6 +255,7 @@ public static function downloadFileByFileId(string $fileId, string $localFilePat
240255
if ($file->isOk()) {
241256

242257
$filePath = $file->getResult()->filePath;
258+
243259
return self::downloadFile($filePath, $localFilePath);
244260
}
245261

@@ -274,10 +290,12 @@ public static function isTelegramIp(string $ip)
274290
$ipDecimal = ip2long($ip);
275291

276292
if (($ipDecimal & $ranges[0]['netmask_decimal']) == $ranges[0]['integer_id']) {
293+
277294
return true;
278295
}
279296

280297
if (($ipDecimal & $ranges[1]['netmask_decimal']) == $ranges[1]['integer_id']) {
298+
281299
return true;
282300
}
283301

src/Format.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,22 +26,27 @@ class Format
2626
public static function mention(int $userId = null, string $text = null, string $parseMode = ParseMode::MARKDOWN): string
2727
{
2828
if (is_null($userId)) {
29+
2930
$userId = Helper::getUserId();
3031
}
3132

3233
if (empty($text)) {
34+
3335
$text = Helper::getMessageText();
3436
}
3537

3638
$parseMode = strtolower($parseMode);
37-
39+
3840
if ($parseMode == ParseMode::MARKDOWNV2) {
41+
3942
$text = self::markdownV2($text);
4043
$url = "[{$text}](tg://user?id={$userId})";
4144
} elseif ($parseMode == ParseMode::HTML) {
45+
4246
$text = self::html($text);
4347
$url = "<a href=\"tg://user?id={$userId}\">{$text}</a>";
4448
} else {
49+
4550
$text = self::markdown($text);
4651
$url = "[{$text}](tg://user?id={$userId})";
4752
}
@@ -152,9 +157,12 @@ public static function replaceKeyToValue(string $string, array $array): string
152157
public static function toCamelCase(string $string, bool $capitalizeFirstCharacter = true): string
153158
{
154159
$string = str_replace('_', '', ucwords($string, '_'));
160+
155161
if ($capitalizeFirstCharacter) {
162+
156163
$string = lcfirst($string);
157164
}
165+
158166
return $string;
159167
}
160168
}

src/Method.php

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ trait Method
139139
public static function sendMessage(array $parameters, string $token = null)
140140
{
141141
if (self::$config->autofillParameters && !isset($parameters['chat_id'])) {
142+
142143
$parameters['chat_id'] = Helper::getChatId();
143144
}
144145

@@ -157,16 +158,19 @@ public static function sendMessage(array $parameters, string $token = null)
157158
public static function forwardMessage(array $parameters, string $token = null)
158159
{
159160
if (self::$config->autofillParameters) {
160-
161+
161162
if (!isset($parameters['chat_id'])) {
163+
162164
$parameters['chat_id'] = Helper::getChatId();
163165
}
164166

165167
if (!isset($parameters['from_chat_id'])) {
168+
166169
$parameters['from_chat_id'] = Helper::getChatId();
167170
}
168171

169172
if (!isset($parameters['message_id'])) {
173+
170174
$parameters['message_id'] = Helper::getMessageId();
171175
}
172176
}
@@ -186,16 +190,19 @@ public static function forwardMessage(array $parameters, string $token = null)
186190
public static function copyMessage(array $parameters, string $token = null)
187191
{
188192
if (self::$config->autofillParameters) {
189-
193+
190194
if (!isset($parameters['chat_id'])) {
195+
191196
$parameters['chat_id'] = Helper::getChatId();
192197
}
193198

194199
if (!isset($parameters['from_chat_id'])) {
200+
195201
$parameters['from_chat_id'] = Helper::getChatId();
196202
}
197203

198204
if (!isset($parameters['message_id'])) {
205+
199206
$parameters['message_id'] = Helper::getMessageId();
200207
}
201208
}
@@ -215,6 +222,7 @@ public static function copyMessage(array $parameters, string $token = null)
215222
public static function sendPhoto(array $parameters, string $token = null)
216223
{
217224
if (self::$config->autofillParameters && !isset($parameters['chat_id'])) {
225+
218226
$parameters['chat_id'] = Helper::getChatId();
219227
}
220228

@@ -233,6 +241,7 @@ public static function sendPhoto(array $parameters, string $token = null)
233241
public static function sendAudio(array $parameters, string $token = null)
234242
{
235243
if (self::$config->autofillParameters && !isset($parameters['chat_id'])) {
244+
236245
$parameters['chat_id'] = Helper::getChatId();
237246
}
238247

@@ -251,6 +260,7 @@ public static function sendAudio(array $parameters, string $token = null)
251260
public static function sendDocument(array $parameters, string $token = null)
252261
{
253262
if (self::$config->autofillParameters && !isset($parameters['chat_id'])) {
263+
254264
$parameters['chat_id'] = Helper::getChatId();
255265
}
256266

@@ -269,6 +279,7 @@ public static function sendDocument(array $parameters, string $token = null)
269279
public static function sendVideo(array $parameters, string $token = null)
270280
{
271281
if (self::$config->autofillParameters && !isset($parameters['chat_id'])) {
282+
272283
$parameters['chat_id'] = Helper::getChatId();
273284
}
274285

@@ -289,10 +300,12 @@ public static function editMessageText(array $parameters, string $token = null)
289300
if (self::$config->autofillParameters && !isset($parameters['inline_message_id'])) {
290301

291302
if (!isset($parameters['chat_id'])) {
303+
292304
$parameters['chat_id'] = Helper::getChatId();
293305
}
294306

295307
if (!isset($parameters['message_id'])) {
308+
296309
$parameters['message_id'] = Helper::getMessageId();
297310
}
298311
}
@@ -314,10 +327,12 @@ public static function editMessageCaption(array $parameters, string $token = nul
314327
if (self::$config->autofillParameters && !isset($parameters['inline_message_id'])) {
315328

316329
if (!isset($parameters['chat_id'])) {
330+
317331
$parameters['chat_id'] = Helper::getChatId();
318332
}
319333

320334
if (!isset($parameters['message_id'])) {
335+
321336
$parameters['message_id'] = Helper::getMessageId();
322337
}
323338
}
@@ -339,10 +354,12 @@ public static function editMessageMedia(array $parameters, string $token = null)
339354
if (self::$config->autofillParameters && !isset($parameters['inline_message_id'])) {
340355

341356
if (!isset($parameters['chat_id'])) {
357+
342358
$parameters['chat_id'] = Helper::getChatId();
343359
}
344360

345361
if (!isset($parameters['message_id'])) {
362+
346363
$parameters['message_id'] = Helper::getMessageId();
347364
}
348365
}
@@ -364,10 +381,12 @@ public static function editMessageReplyMarkup(array $parameters, string $token =
364381
if (self::$config->autofillParameters && !isset($parameters['inline_message_id'])) {
365382

366383
if (!isset($parameters['chat_id'])) {
384+
367385
$parameters['chat_id'] = Helper::getChatId();
368386
}
369387

370388
if (!isset($parameters['message_id'])) {
389+
371390
$parameters['message_id'] = Helper::getMessageId();
372391
}
373392
}
@@ -389,13 +408,14 @@ public static function stopPoll(array $parameters, string $token = null)
389408
if (self::$config->autofillParameters) {
390409

391410
if (!isset($parameters['chat_id'])) {
411+
392412
$parameters['chat_id'] = Helper::getChatId();
393413
}
394414

395415
if (!isset($parameters['message_id'])) {
416+
396417
$parameters['message_id'] = Helper::getMessageId();
397418
}
398-
399419
}
400420

401421
return self::__callStatic('stopPoll', [$parameters, $token]);
@@ -424,13 +444,14 @@ public static function deleteMessage(array $parameters, string $token = null)
424444
if (self::$config->autofillParameters) {
425445

426446
if (!isset($parameters['chat_id'])) {
447+
427448
$parameters['chat_id'] = Helper::getChatId();
428449
}
429450

430451
if (!isset($parameters['message_id'])) {
452+
431453
$parameters['message_id'] = Helper::getMessageId();
432454
}
433-
434455
}
435456

436457
return self::__callStatic('deleteMessage', [$parameters, $token]);
@@ -448,11 +469,13 @@ public static function executeMethod(string $name, array $parameters = [])
448469
$name = Format::toCamelCase($name);
449470

450471
if (in_array($name, self::$parameterlessMethods)) {
472+
451473
$parameters[1] = $parameters[0] ?? null;
452474
$parameters[0] = [];
453475
}
454476

455477
if (isset($parameters[0]['reply_markup']) && is_array($parameters[0]['reply_markup'])) {
478+
456479
$parameters[0]['reply_markup'] = json_encode($parameters[0]['reply_markup']);
457480
}
458481

src/Response/Response.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ public function __construct(array $data, string $method, array $parameters)
3333
$this->data = $data;
3434

3535
if (isset($this->data['ok']) && $this->data['ok'] === true) {
36+
3637
$this->result = $this->convertToResponseType($data['result']);
3738
}
3839
}
@@ -55,16 +56,20 @@ private function convertToResponseType($result)
5556
'empty_list',
5657
];
5758
*/
58-
59+
5960
if (is_array($result) && !empty($result)) {
6061

6162
if (is_array($resultType)) {
62-
63+
6364
$class = $resultType[0];
65+
6466
$resultArray = [];
67+
6568
foreach ($result as $value) {
69+
6670
$resultArray[] = new $class($value);
6771
}
72+
6873
return $resultArray;
6974
}
7075

0 commit comments

Comments
 (0)