Commit a8c27913 authored by Avtandil Kikabidze's avatar Avtandil Kikabidze

Improved code and doc-blocks

parent 87e0d1c4
...@@ -40,7 +40,10 @@ class Botan ...@@ -40,7 +40,10 @@ class Botan
public static $command = ''; public static $command = '';
/** /**
* Initilize botan * Initialize Botan
*
* @param $token
* @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public static function initializeBotan($token) public static function initializeBotan($token)
{ {
...@@ -71,7 +74,7 @@ class Botan ...@@ -71,7 +74,7 @@ class Botan
* @param string $command * @param string $command
* *
* @return bool|string * @return bool|string
* @throws TelegramException * @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public static function track($input, $command = '') public static function track($input, $command = '')
{ {
...@@ -155,7 +158,7 @@ class Botan ...@@ -155,7 +158,7 @@ class Botan
* @param $user_id * @param $user_id
* *
* @return string * @return string
* @throws TelegramException * @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public static function shortenUrl($url, $user_id) public static function shortenUrl($url, $user_id)
{ {
...@@ -192,6 +195,7 @@ class Botan ...@@ -192,6 +195,7 @@ class Botan
if (!filter_var($response, FILTER_VALIDATE_URL) === false) { if (!filter_var($response, FILTER_VALIDATE_URL) === false) {
BotanDB::insertShortUrl($user_id, $url, $response); BotanDB::insertShortUrl($user_id, $url, $response);
} else { } else {
// @FIXME: Add telegram log
error_log('Botan.io API replied with error: ' . $response); error_log('Botan.io API replied with error: ' . $response);
return $url; return $url;
} }
......
...@@ -10,7 +10,9 @@ ...@@ -10,7 +10,9 @@
namespace Longman\TelegramBot; namespace Longman\TelegramBot;
use Exception;
use Longman\TelegramBot\Exception\TelegramException; use Longman\TelegramBot\Exception\TelegramException;
use PDO;
/** /**
* Class BotanDB * Class BotanDB
...@@ -33,7 +35,7 @@ class BotanDB extends DB ...@@ -33,7 +35,7 @@ class BotanDB extends DB
* @param $user_id * @param $user_id
* @param $url * @param $url
* *
* @throws TelegramException * @throws \Longman\TelegramBot\Exception\TelegramException
* *
* @return bool|string * @return bool|string
*/ */
...@@ -48,12 +50,12 @@ class BotanDB extends DB ...@@ -48,12 +50,12 @@ class BotanDB extends DB
WHERE `user_id` = :user_id AND `url` = :url WHERE `user_id` = :user_id AND `url` = :url
'); ');
$sth->bindParam(':user_id', $user_id, \PDO::PARAM_INT); $sth->bindParam(':user_id', $user_id, PDO::PARAM_INT);
$sth->bindParam(':url', $url, \PDO::PARAM_INT); $sth->bindParam(':url', $url, PDO::PARAM_INT);
$sth->execute(); $sth->execute();
$results = $sth->fetchAll(\PDO::FETCH_ASSOC); $results = $sth->fetchAll(PDO::FETCH_ASSOC);
} catch (\Exception $e) { } catch (Exception $e) {
throw new TelegramException($e->getMessage()); throw new TelegramException($e->getMessage());
} }
...@@ -67,7 +69,7 @@ class BotanDB extends DB ...@@ -67,7 +69,7 @@ class BotanDB extends DB
* @param $url * @param $url
* @param $short_url * @param $short_url
* *
* @throws TelegramException * @throws \Longman\TelegramBot\Exception\TelegramException
* *
* @return bool * @return bool
*/ */
...@@ -95,7 +97,7 @@ class BotanDB extends DB ...@@ -95,7 +97,7 @@ class BotanDB extends DB
$sth->bindParam(':date', $created_at); $sth->bindParam(':date', $created_at);
$status = $sth->execute(); $status = $sth->execute();
} catch (\Exception $e) { } catch (Exception $e) {
throw new TelegramException($e->getMessage()); throw new TelegramException($e->getMessage());
} }
......
...@@ -146,7 +146,8 @@ class Conversation ...@@ -146,7 +146,8 @@ class Conversation
$this->user_id, $this->user_id,
$this->chat_id, $this->chat_id,
$this->command $this->command
)) { )
) {
return $this->load(); return $this->load();
} }
} }
......
...@@ -10,11 +10,10 @@ ...@@ -10,11 +10,10 @@
namespace Longman\TelegramBot; namespace Longman\TelegramBot;
use Exception;
use Longman\TelegramBot\Exception\TelegramException; use Longman\TelegramBot\Exception\TelegramException;
use PDO;
/**
* Class ConversationDB
*/
class ConversationDB extends DB class ConversationDB extends DB
{ {
/** /**
...@@ -35,6 +34,7 @@ class ConversationDB extends DB ...@@ -35,6 +34,7 @@ class ConversationDB extends DB
* @param bool $limit * @param bool $limit
* *
* @return array|bool * @return array|bool
* @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public static function selectConversation($user_id, $chat_id, $limit = null) public static function selectConversation($user_id, $chat_id, $limit = null)
{ {
...@@ -54,14 +54,14 @@ class ConversationDB extends DB ...@@ -54,14 +54,14 @@ class ConversationDB extends DB
$sth = self::$pdo->prepare($query); $sth = self::$pdo->prepare($query);
$active = 'active'; $active = 'active';
$sth->bindParam(':status', $active, \PDO::PARAM_STR); $sth->bindParam(':status', $active, PDO::PARAM_STR);
$sth->bindParam(':user_id', $user_id, \PDO::PARAM_INT); $sth->bindParam(':user_id', $user_id, PDO::PARAM_INT);
$sth->bindParam(':chat_id', $chat_id, \PDO::PARAM_INT); $sth->bindParam(':chat_id', $chat_id, PDO::PARAM_INT);
$sth->bindParam(':limit', $limit, \PDO::PARAM_INT); $sth->bindParam(':limit', $limit, PDO::PARAM_INT);
$sth->execute(); $sth->execute();
$results = $sth->fetchAll(\PDO::FETCH_ASSOC); $results = $sth->fetchAll(PDO::FETCH_ASSOC);
} catch (\Exception $e) { } catch (Exception $e) {
throw new TelegramException($e->getMessage()); throw new TelegramException($e->getMessage());
} }
return $results; return $results;
...@@ -75,6 +75,7 @@ class ConversationDB extends DB ...@@ -75,6 +75,7 @@ class ConversationDB extends DB
* @param string $command * @param string $command
* *
* @return bool * @return bool
* @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public static function insertConversation($user_id, $chat_id, $command) public static function insertConversation($user_id, $chat_id, $command)
{ {
...@@ -104,7 +105,7 @@ class ConversationDB extends DB ...@@ -104,7 +105,7 @@ class ConversationDB extends DB
$sth->bindParam(':date', $created_at); $sth->bindParam(':date', $created_at);
$status = $sth->execute(); $status = $sth->execute();
} catch (\Exception $e) { } catch (Exception $e) {
throw new TelegramException($e->getMessage()); throw new TelegramException($e->getMessage());
} }
return $status; return $status;
...@@ -133,6 +134,7 @@ class ConversationDB extends DB ...@@ -133,6 +134,7 @@ class ConversationDB extends DB
* @todo This function is generic should be moved in DB.php * @todo This function is generic should be moved in DB.php
* *
* @return bool * @return bool
* @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public static function update($table, array $fields_values, array $where_fields_values) public static function update($table, array $fields_values, array $where_fields_values)
{ {
...@@ -168,7 +170,7 @@ class ConversationDB extends DB ...@@ -168,7 +170,7 @@ class ConversationDB extends DB
$where .= 'WHERE '; $where .= 'WHERE ';
} }
++$tokens_counter; ++$tokens_counter;
$where .= '`' . $field .'`= :' . $tokens_counter; $where .= '`' . $field . '`= :' . $tokens_counter;
$tokens[':' . $tokens_counter] = $value; $tokens[':' . $tokens_counter] = $value;
} }
...@@ -176,7 +178,7 @@ class ConversationDB extends DB ...@@ -176,7 +178,7 @@ class ConversationDB extends DB
try { try {
$sth = self::$pdo->prepare($query); $sth = self::$pdo->prepare($query);
$status = $sth->execute($tokens); $status = $sth->execute($tokens);
} catch (\Exception $e) { } catch (Exception $e) {
throw new TelegramException($e->getMessage()); throw new TelegramException($e->getMessage());
} }
return $status; return $status;
......
This diff is collapsed.
...@@ -21,7 +21,7 @@ class Request ...@@ -21,7 +21,7 @@ class Request
/** /**
* Telegram object * Telegram object
* *
* @var Telegram * @var \Longman\TelegramBot\Telegram
*/ */
private static $telegram; private static $telegram;
...@@ -86,7 +86,8 @@ class Request ...@@ -86,7 +86,8 @@ class Request
/** /**
* Initialize * Initialize
* *
* @param Telegram $telegram * @param \Longman\TelegramBot\Telegram $telegram
* @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public static function initialize(Telegram $telegram) public static function initialize(Telegram $telegram)
{ {
...@@ -102,6 +103,7 @@ class Request ...@@ -102,6 +103,7 @@ class Request
* Set input from custom input or stdin and return it * Set input from custom input or stdin and return it
* *
* @return string * @return string
* @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public static function getInput() public static function getInput()
{ {
...@@ -166,6 +168,7 @@ class Request ...@@ -166,6 +168,7 @@ class Request
* @param array|null $data Data to attach to the execution * @param array|null $data Data to attach to the execution
* *
* @return mixed Result of the HTTP Request * @return mixed Result of the HTTP Request
* @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public static function execute($action, array $data = null) public static function execute($action, array $data = null)
{ {
...@@ -224,6 +227,7 @@ class Request ...@@ -224,6 +227,7 @@ class Request
* @param Entities\File $file * @param Entities\File $file
* *
* @return boolean * @return boolean
* @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public static function downloadFile(File $file) public static function downloadFile(File $file)
{ {
...@@ -260,6 +264,7 @@ class Request ...@@ -260,6 +264,7 @@ class Request
* @param string $file * @param string $file
* *
* @return resource * @return resource
* @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
protected static function encodeFile($file) protected static function encodeFile($file)
{ {
...@@ -278,7 +283,8 @@ class Request ...@@ -278,7 +283,8 @@ class Request
* @param string $action * @param string $action
* @param array|null $data * @param array|null $data
* *
* @return Entities\ServerResponse * @return \Longman\TelegramBot\Entities\ServerResponse
* @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public static function send($action, array $data = null) public static function send($action, array $data = null)
{ {
...@@ -322,6 +328,7 @@ class Request ...@@ -322,6 +328,7 @@ class Request
* @param array $data * @param array $data
* *
* @return mixed * @return mixed
* @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public static function sendMessage(array $data) public static function sendMessage(array $data)
{ {
...@@ -345,6 +352,7 @@ class Request ...@@ -345,6 +352,7 @@ class Request
* @param array $data * @param array $data
* *
* @return mixed * @return mixed
* @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public static function forwardMessage(array $data) public static function forwardMessage(array $data)
{ {
...@@ -362,6 +370,7 @@ class Request ...@@ -362,6 +370,7 @@ class Request
* @param string $file * @param string $file
* *
* @return mixed * @return mixed
* @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public static function sendPhoto(array $data, $file = null) public static function sendPhoto(array $data, $file = null)
{ {
...@@ -383,6 +392,7 @@ class Request ...@@ -383,6 +392,7 @@ class Request
* @param string $file * @param string $file
* *
* @return mixed * @return mixed
* @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public static function sendAudio(array $data, $file = null) public static function sendAudio(array $data, $file = null)
{ {
...@@ -404,6 +414,7 @@ class Request ...@@ -404,6 +414,7 @@ class Request
* @param string $file * @param string $file
* *
* @return mixed * @return mixed
* @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public static function sendDocument(array $data, $file = null) public static function sendDocument(array $data, $file = null)
{ {
...@@ -425,6 +436,7 @@ class Request ...@@ -425,6 +436,7 @@ class Request
* @param string $file * @param string $file
* *
* @return mixed * @return mixed
* @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public static function sendSticker(array $data, $file = null) public static function sendSticker(array $data, $file = null)
{ {
...@@ -446,6 +458,7 @@ class Request ...@@ -446,6 +458,7 @@ class Request
* @param string $file * @param string $file
* *
* @return mixed * @return mixed
* @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public static function sendVideo(array $data, $file = null) public static function sendVideo(array $data, $file = null)
{ {
...@@ -467,6 +480,7 @@ class Request ...@@ -467,6 +480,7 @@ class Request
* @param string $file * @param string $file
* *
* @return mixed * @return mixed
* @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public static function sendVoice(array $data, $file = null) public static function sendVoice(array $data, $file = null)
{ {
...@@ -487,6 +501,7 @@ class Request ...@@ -487,6 +501,7 @@ class Request
* @param array $data * @param array $data
* *
* @return mixed * @return mixed
* @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public static function sendLocation(array $data) public static function sendLocation(array $data)
{ {
...@@ -503,6 +518,7 @@ class Request ...@@ -503,6 +518,7 @@ class Request
* @param array $data * @param array $data
* *
* @return mixed * @return mixed
* @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public static function sendVenue(array $data) public static function sendVenue(array $data)
{ {
...@@ -519,6 +535,7 @@ class Request ...@@ -519,6 +535,7 @@ class Request
* @param array $data * @param array $data
* *
* @return mixed * @return mixed
* @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public static function sendContact(array $data) public static function sendContact(array $data)
{ {
...@@ -535,6 +552,7 @@ class Request ...@@ -535,6 +552,7 @@ class Request
* @param array $data * @param array $data
* *
* @return mixed * @return mixed
* @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public static function sendChatAction(array $data) public static function sendChatAction(array $data)
{ {
...@@ -551,6 +569,7 @@ class Request ...@@ -551,6 +569,7 @@ class Request
* @param array $data * @param array $data
* *
* @return mixed * @return mixed
* @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public static function getUserProfilePhotos(array $data) public static function getUserProfilePhotos(array $data)
{ {
...@@ -602,6 +621,7 @@ class Request ...@@ -602,6 +621,7 @@ class Request
* @param array $data * @param array $data
* *
* @return mixed * @return mixed
* @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public static function getFile(array $data) public static function getFile(array $data)
{ {
...@@ -618,6 +638,7 @@ class Request ...@@ -618,6 +638,7 @@ class Request
* @param array $data * @param array $data
* *
* @return mixed * @return mixed
* @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public static function kickChatMember(array $data) public static function kickChatMember(array $data)
{ {
...@@ -634,6 +655,7 @@ class Request ...@@ -634,6 +655,7 @@ class Request
* @param array $data * @param array $data
* *
* @return mixed * @return mixed
* @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public static function leaveChat(array $data) public static function leaveChat(array $data)
{ {
...@@ -650,6 +672,7 @@ class Request ...@@ -650,6 +672,7 @@ class Request
* @param array $data * @param array $data
* *
* @return mixed * @return mixed
* @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public static function unbanChatMember(array $data) public static function unbanChatMember(array $data)
{ {
...@@ -668,6 +691,7 @@ class Request ...@@ -668,6 +691,7 @@ class Request
* @param array $data * @param array $data
* *
* @return mixed * @return mixed
* @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public static function getChat(array $data) public static function getChat(array $data)
{ {
...@@ -686,6 +710,7 @@ class Request ...@@ -686,6 +710,7 @@ class Request
* @param array $data * @param array $data
* *
* @return mixed * @return mixed
* @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public static function getChatAdministrators(array $data) public static function getChatAdministrators(array $data)
{ {
...@@ -704,6 +729,7 @@ class Request ...@@ -704,6 +729,7 @@ class Request
* @param array $data * @param array $data
* *
* @return mixed * @return mixed
* @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public static function getChatMembersCount(array $data) public static function getChatMembersCount(array $data)
{ {
...@@ -722,6 +748,7 @@ class Request ...@@ -722,6 +748,7 @@ class Request
* @param array $data * @param array $data
* *
* @return mixed * @return mixed
* @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public static function getChatMember(array $data) public static function getChatMember(array $data)
{ {
...@@ -738,6 +765,7 @@ class Request ...@@ -738,6 +765,7 @@ class Request
* @param array $data * @param array $data
* *
* @return mixed * @return mixed
* @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public static function answerCallbackQuery(array $data) public static function answerCallbackQuery(array $data)
{ {
...@@ -754,6 +782,7 @@ class Request ...@@ -754,6 +782,7 @@ class Request
* @param array $data * @param array $data
* *
* @return mixed * @return mixed
* @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public static function answerInlineQuery(array $data) public static function answerInlineQuery(array $data)
{ {
...@@ -770,6 +799,7 @@ class Request ...@@ -770,6 +799,7 @@ class Request
* @param array $data * @param array $data
* *
* @return mixed * @return mixed
* @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public static function editMessageText(array $data) public static function editMessageText(array $data)
{ {
...@@ -786,6 +816,7 @@ class Request ...@@ -786,6 +816,7 @@ class Request
* @param array $data * @param array $data
* *
* @return mixed * @return mixed
* @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public static function editMessageCaption(array $data) public static function editMessageCaption(array $data)
{ {
...@@ -802,6 +833,7 @@ class Request ...@@ -802,6 +833,7 @@ class Request
* @param array $data * @param array $data
* *
* @return mixed * @return mixed
* @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public static function editMessageReplyMarkup(array $data) public static function editMessageReplyMarkup(array $data)
{ {
...@@ -837,6 +869,7 @@ class Request ...@@ -837,6 +869,7 @@ class Request
* @param string $date_to * @param string $date_to
* *
* @return array * @return array
* @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public static function sendToActiveChats( public static function sendToActiveChats(
$callback_function, $callback_function,
......
...@@ -16,7 +16,6 @@ define('BASE_COMMANDS_PATH', BASE_PATH . '/Commands'); ...@@ -16,7 +16,6 @@ define('BASE_COMMANDS_PATH', BASE_PATH . '/Commands');
use Longman\TelegramBot\Entities\Update; use Longman\TelegramBot\Entities\Update;
use Longman\TelegramBot\Exception\TelegramException; use Longman\TelegramBot\Exception\TelegramException;
class Telegram class Telegram
{ {
/** /**
...@@ -152,6 +151,7 @@ class Telegram ...@@ -152,6 +151,7 @@ class Telegram
* *
* @param array $credential * @param array $credential
* @param string $table_prefix * @param string $table_prefix
* @param string $encoding
* *
* @return \Longman\TelegramBot\Telegram * @return \Longman\TelegramBot\Telegram
*/ */
......
...@@ -15,9 +15,6 @@ use Monolog\Handler\StreamHandler; ...@@ -15,9 +15,6 @@ use Monolog\Handler\StreamHandler;
use Monolog\Formatter\LineFormatter; use Monolog\Formatter\LineFormatter;
use Longman\TelegramBot\Exception\TelegramLogException; use Longman\TelegramBot\Exception\TelegramLogException;
/**
* Class TelegramLog.
*/
class TelegramLog class TelegramLog
{ {
/** /**
...@@ -99,6 +96,7 @@ class TelegramLog ...@@ -99,6 +96,7 @@ class TelegramLog
* @param string $path * @param string $path
* *
* @return \Monolog\Logger * @return \Monolog\Logger
* @throws \Longman\TelegramBot\Exception\TelegramLogException
*/ */
public static function initErrorLog($path) public static function initErrorLog($path)
{ {
...@@ -120,6 +118,7 @@ class TelegramLog ...@@ -120,6 +118,7 @@ class TelegramLog
* @param string $path * @param string $path
* *
* @return \Monolog\Logger * @return \Monolog\Logger
* @throws \Longman\TelegramBot\Exception\TelegramLogException
*/ */
public static function initDebugLog($path) public static function initDebugLog($path)
{ {
...@@ -179,6 +178,7 @@ class TelegramLog ...@@ -179,6 +178,7 @@ class TelegramLog
* @param string $path * @param string $path
* *
* @return \Monolog\Logger * @return \Monolog\Logger
* @throws \Longman\TelegramBot\Exception\TelegramLogException
*/ */
public static function initUpdateLog($path) public static function initUpdateLog($path)
{ {
......
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