Skip to content

Commit fd76d0f

Browse files
committed
Minor code cleanup.
1 parent 27318c3 commit fd76d0f

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

src/Request.php

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -219,12 +219,12 @@ public static function getInput()
219219
}
220220

221221
// Make sure we have a string to work with.
222-
if (is_string($input)) {
223-
self::$input = $input;
224-
} else {
222+
if (!is_string($input)) {
225223
throw new TelegramException('Input must be a string!');
226224
}
227225

226+
self::$input = $input;
227+
228228
TelegramLog::update(self::$input);
229229

230230
return self::$input;
@@ -281,7 +281,7 @@ public static function generateGeneralFakeServerResponse(array $data = [])
281281
private static function setUpRequestParams(array $data)
282282
{
283283
$has_resource = false;
284-
$multipart = [];
284+
$multipart = [];
285285

286286
// Convert any nested arrays into JSON strings.
287287
array_walk($data, function (&$item) {
@@ -291,7 +291,7 @@ private static function setUpRequestParams(array $data)
291291
//Reformat data array in multipart way if it contains a resource
292292
foreach ($data as $key => $item) {
293293
$has_resource |= (is_resource($item) || $item instanceof \GuzzleHttp\Psr7\Stream);
294-
$multipart[] = ['name' => $key, 'contents' => $item];
294+
$multipart[] = ['name' => $key, 'contents' => $item];
295295
}
296296
if ($has_resource) {
297297
return ['multipart' => $multipart];
@@ -316,16 +316,16 @@ public static function execute($action, array $data = [])
316316
$data['reply_markup'] = json_encode($data['reply_markup']);
317317
}
318318

319-
$result = null;
320-
$request_params = self::setUpRequestParams($data);
319+
$result = null;
320+
$request_params = self::setUpRequestParams($data);
321321
$request_params['debug'] = TelegramLog::getDebugLogTempStream();
322322

323323
try {
324324
$response = self::$client->post(
325325
'/bot' . self::$telegram->getApiKey() . '/' . $action,
326326
$request_params
327327
);
328-
$result = (string) $response->getBody();
328+
$result = (string) $response->getBody();
329329

330330
//Logging getUpdates Update
331331
if ($action === 'getUpdates') {
@@ -404,6 +404,7 @@ public static function encodeFile($file)
404404
* Send command
405405
*
406406
* @todo Fake response doesn't need json encoding?
407+
* @todo Write debug entry on failure
407408
*
408409
* @param string $action
409410
* @param array $data
@@ -598,7 +599,7 @@ public static function setLimiter($value = true, array $options = [])
598599
}
599600

600601
self::$limiter_interval = $options['interval'];
601-
self::$limiter_enabled = $value;
602+
self::$limiter_enabled = $value;
602603
}
603604
}
604605

@@ -636,7 +637,7 @@ private static function limitTelegramRequests($action, array $data = [])
636637
'setChatDescription',
637638
];
638639

639-
$chat_id = isset($data['chat_id']) ? $data['chat_id'] : null;
640+
$chat_id = isset($data['chat_id']) ? $data['chat_id'] : null;
640641
$inline_message_id = isset($data['inline_message_id']) ? $data['inline_message_id'] : null;
641642

642643
if (($chat_id || $inline_message_id) && in_array($action, $limited_methods)) {
@@ -649,7 +650,7 @@ private static function limitTelegramRequests($action, array $data = [])
649650

650651
$requests = DB::getTelegramRequestCount($chat_id, $inline_message_id);
651652

652-
$chat_per_second = ($requests['LIMIT_PER_SEC'] == 0); // No more than one message per second inside a particular chat
653+
$chat_per_second = ($requests['LIMIT_PER_SEC'] == 0); // No more than one message per second inside a particular chat
653654
$global_per_second = ($requests['LIMIT_PER_SEC_ALL'] < 30); // No more than 30 messages per second to different chats
654655
$groups_per_minute = (((is_numeric($chat_id) && $chat_id > 0) || !is_null($inline_message_id)) || ((!is_numeric($chat_id) || $chat_id < 0) && $requests['LIMIT_PER_MINUTE'] < 20)); // No more than 20 messages per minute in groups and channels
655656

0 commit comments

Comments
 (0)