Smaller refactorings and DocBlock adjustments.

parent 12f46a2b
...@@ -87,6 +87,7 @@ class Request ...@@ -87,6 +87,7 @@ class Request
* Initialize * Initialize
* *
* @param \Longman\TelegramBot\Telegram $telegram * @param \Longman\TelegramBot\Telegram $telegram
*
* @throws \Longman\TelegramBot\Exception\TelegramException * @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public static function initialize(Telegram $telegram) public static function initialize(Telegram $telegram)
...@@ -120,6 +121,7 @@ class Request ...@@ -120,6 +121,7 @@ class Request
} }
TelegramLog::update(self::$input); TelegramLog::update(self::$input);
return self::$input; return self::$input;
} }
...@@ -140,7 +142,7 @@ class Request ...@@ -140,7 +142,7 @@ class Request
$fake_response = ['ok' => true]; // :) $fake_response = ['ok' => true]; // :)
if (!isset($data)) { if ($data === null) {
$fake_response['result'] = true; $fake_response['result'] = true;
} }
...@@ -176,7 +178,7 @@ class Request ...@@ -176,7 +178,7 @@ class Request
//Fix so that the keyboard markup is a string, not an object //Fix so that the keyboard markup is a string, not an object
if (isset($data['reply_markup']) && !is_string($data['reply_markup'])) { if (isset($data['reply_markup']) && !is_string($data['reply_markup'])) {
$data['reply_markup'] = (string) $data['reply_markup']; $data['reply_markup'] = (string)$data['reply_markup'];
} }
$request_params = ['debug' => $debug_handle]; $request_params = ['debug' => $debug_handle];
...@@ -193,17 +195,18 @@ class Request ...@@ -193,17 +195,18 @@ class Request
//Reformat data array in multipart way //Reformat data array in multipart way
if ($contains_resource) { if ($contains_resource) {
foreach ($data as $key => $item) { foreach ($data as $key => $item) {
$request_params['multipart'][] = array('name' => $key, 'contents' => $item); $request_params['multipart'][] = ['name' => $key, 'contents' => $item];
} }
} else { } else {
$request_params['form_params'] = $data; $request_params['form_params'] = $data;
} }
$result = '';
try { try {
$response = self::$client->post( $result = (string)self::$client->post(
'/bot' . self::$telegram->getApiKey() . '/' . $action, '/bot' . self::$telegram->getApiKey() . '/' . $action,
$request_params $request_params
); )->getBody();
} catch (RequestException $e) { } catch (RequestException $e) {
throw new TelegramException($e->getMessage()); throw new TelegramException($e->getMessage());
} finally { } finally {
...@@ -211,8 +214,6 @@ class Request ...@@ -211,8 +214,6 @@ class Request
TelegramLog::endDebugLogTempStream("Verbose HTTP Request output:\n%s\n"); TelegramLog::endDebugLogTempStream("Verbose HTTP Request output:\n%s\n");
} }
$result = $response->getBody();
//Logging getUpdates Update //Logging getUpdates Update
if ($action === 'getUpdates') { if ($action === 'getUpdates') {
TelegramLog::update($result); TelegramLog::update($result);
...@@ -224,7 +225,7 @@ class Request ...@@ -224,7 +225,7 @@ class Request
/** /**
* Download file * Download file
* *
* @param Entities\File $file * @param \Longman\TelegramBot\Entities\File $file
* *
* @return boolean * @return boolean
* @throws \Longman\TelegramBot\Exception\TelegramException * @throws \Longman\TelegramBot\Exception\TelegramException
...@@ -244,7 +245,7 @@ class Request ...@@ -244,7 +245,7 @@ class Request
$debug_handle = TelegramLog::getDebugLogTempStream(); $debug_handle = TelegramLog::getDebugLogTempStream();
try { try {
$response = self::$client->get( self::$client->get(
'/file/bot' . self::$telegram->getApiKey() . '/' . $path, '/file/bot' . self::$telegram->getApiKey() . '/' . $path,
['debug' => $debug_handle, 'sink' => $loc_path] ['debug' => $debug_handle, 'sink' => $loc_path]
); );
...@@ -272,6 +273,7 @@ class Request ...@@ -272,6 +273,7 @@ class Request
if ($fp === false) { if ($fp === false) {
throw new TelegramException('Cannot open ' . $file . ' for reading'); throw new TelegramException('Cannot open ' . $file . ' for reading');
} }
return $fp; return $fp;
} }
...@@ -294,6 +296,7 @@ class Request ...@@ -294,6 +296,7 @@ class Request
if (defined('PHPUNIT_TESTSUITE')) { if (defined('PHPUNIT_TESTSUITE')) {
$fake_response = self::generateGeneralFakeServerResponse($data); $fake_response = self::generateGeneralFakeServerResponse($data);
return new ServerResponse($fake_response, $bot_name); return new ServerResponse($fake_response, $bot_name);
} }
...@@ -301,8 +304,8 @@ class Request ...@@ -301,8 +304,8 @@ class Request
$response = json_decode(self::execute($action, $data), true); $response = json_decode(self::execute($action, $data), true);
if (is_null($response)) { if (null === $response) {
throw new TelegramException('Telegram returned an invalid response! Please your bot name and api token.'); throw new TelegramException('Telegram returned an invalid response! Please review your bot name and API key.');
} }
return new ServerResponse($response, $bot_name); return new ServerResponse($response, $bot_name);
...@@ -356,6 +359,7 @@ class Request ...@@ -356,6 +359,7 @@ class Request
* Get me * Get me
* *
* @return mixed * @return mixed
* @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public static function getMe() public static function getMe()
{ {
...@@ -573,6 +577,7 @@ class Request ...@@ -573,6 +577,7 @@ class Request
* @param array $data * @param array $data
* *
* @return mixed * @return mixed
* @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public static function getUpdates(array $data) public static function getUpdates(array $data)
{ {
...@@ -586,6 +591,7 @@ class Request ...@@ -586,6 +591,7 @@ class Request
* @param string $file * @param string $file
* *
* @return mixed * @return mixed
* @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public static function setWebhook($url = '', $file = null) public static function setWebhook($url = '', $file = null)
{ {
...@@ -779,7 +785,8 @@ class Request ...@@ -779,7 +785,8 @@ class Request
* No request to telegram are sent, this function is used in commands that * No request to telegram are sent, this function is used in commands that
* don't need to fire a message after execution * don't need to fire a message after execution
* *
* @return Entities\ServerResponse * @return \Longman\TelegramBot\Entities\ServerResponse
* @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public static function emptyResponse() public static function emptyResponse()
{ {
...@@ -817,9 +824,11 @@ class Request ...@@ -817,9 +824,11 @@ class Request
$chats = DB::selectChats($send_groups, $send_super_groups, $send_users, $date_from, $date_to); $chats = DB::selectChats($send_groups, $send_super_groups, $send_users, $date_from, $date_to);
$results = []; $results = [];
foreach ($chats as $row) { if (is_array($chats)) {
$data['chat_id'] = $row['chat_id']; foreach ($chats as $row) {
$results[] = call_user_func_array($callback_path . '::' . $callback_function, [$data]); $data['chat_id'] = $row['chat_id'];
$results[] = call_user_func_array($callback_path . '::' . $callback_function, [$data]);
}
} }
return $results; return $results;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment