Skip to content

various #236

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 1, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/BotanDB.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

namespace Longman\TelegramBot;

use Longman\TelegramBot\DB;
use Longman\TelegramBot\Exception\TelegramException;

/**
Expand All @@ -33,8 +32,10 @@ public static function initializeBotanDb()
*
* @param $user_id
* @param $url
* @return bool|string
*
* @throws TelegramException
*
* @return bool|string
*/
public static function selectShortUrl($user_id, $url)
{
Expand Down Expand Up @@ -65,8 +66,10 @@ public static function selectShortUrl($user_id, $url)
* @param $user_id
* @param $url
* @param $short_url
* @return bool
*
* @throws TelegramException
*
* @return bool
*/
public static function insertShortUrl($user_id, $url, $short_url)
{
Expand Down
9 changes: 4 additions & 5 deletions src/Commands/AdminCommands/SendtochannelCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class SendtochannelCommand extends AdminCommand
/**
* Conversation Object
*
* @var Longman\TelegramBot\Conversation
* @var \Longman\TelegramBot\Conversation
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MBoretto Did you deliberately leave all full namespaces as opposed to simplified ones?

PhpStorm automatically prefers simplified ones for me.

@akalongman @jacklul
Asking you guys too, which standard shall we go by?

@var \Longman\TelegramBot\Conversation

or

@var Conversation

(this obviously implies that we have a use Longman\TelegramBot\Conversation at the top.

*/
protected $conversation;

Expand Down Expand Up @@ -128,7 +128,6 @@ public function execute()
$this->conversation->notes['last_message_id'] = $message->getMessageId();
$this->conversation->notes['message'] = $message->reflect();
$this->conversation->notes['message_type'] = $type;

// no break
case 2:
if ($this->conversation->notes['last_message_id'] == $message->getMessageId() || !($text == 'Yes' || $text == 'No')) {
Expand Down Expand Up @@ -258,7 +257,7 @@ public function executeNoDb()
/**
* Publish a message to a channel and return success or failure message
*
* @param Entities\Message $message
* @param \Longman\TelegramBot\Entities\Message $message
* @param int $channel
* @param string|null $caption
*
Expand Down Expand Up @@ -292,10 +291,10 @@ protected function publish(Message $message, $channel, $caption = null)
* @todo This method will be moved at an higher level maybe in AdminCommand or Command
* @todo Looking for a more significative name
*
* @param Entities\Message $message
* @param \Longman\TelegramBot\Entities\Message $message
* @param array $data
*
* @return Entities\ServerResponse
* @return \Longman\TelegramBot\Entities\ServerResponse
*/
protected function sendBack(Message $message, array $data)
{
Expand Down
20 changes: 9 additions & 11 deletions src/Commands/Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@
use Longman\TelegramBot\DB;
use Longman\TelegramBot\Request;
use Longman\TelegramBot\Telegram;
use Longman\TelegramBot\Entities\Chat;
use Longman\TelegramBot\Entities\Update;
use Longman\TelegramBot\Entities\User;

/**
* Abstract Command Class
Expand All @@ -32,14 +30,14 @@ abstract class Command
/**
* Update object
*
* @var Entities\Update
* @var \Longman\TelegramBot\Entities\Update
*/
protected $update;

/**
* Message object
*
* @var Entities\Message
* @var \Longman\TelegramBot\Entities\Message
*/
protected $message;

Expand Down Expand Up @@ -96,7 +94,7 @@ abstract class Command
* Constructor
*
* @param Telegram $telegram
* @param Entities\Update $update
* @param \Longman\TelegramBot\Entities\Update $update
*/
public function __construct(Telegram $telegram, Update $update = null)
{
Expand All @@ -108,7 +106,7 @@ public function __construct(Telegram $telegram, Update $update = null)
/**
* Set update object
*
* @param Entities\Update $update
* @param \Longman\TelegramBot\Entities\Update $update
* @return Command
*/
public function setUpdate(Update $update = null)
Expand All @@ -123,7 +121,7 @@ public function setUpdate(Update $update = null)
/**
* Pre-execute command
*
* @return Entities\ServerResponse
* @return \Longman\TelegramBot\Entities\ServerResponse
*/
public function preExecute()
{
Expand All @@ -136,14 +134,14 @@ public function preExecute()
/**
* Execute command
*
* @return Entities\ServerResponse
* @return \Longman\TelegramBot\Entities\ServerResponse
*/
abstract public function execute();

/**
* Execution if MySQL is required but not available
*
* @return Entities\ServerResponse
* @return \Longman\TelegramBot\Entities\ServerResponse
*/
public function executeNoDb()
{
Expand All @@ -162,7 +160,7 @@ public function executeNoDb()
/**
* Get update object
*
* @return Entities\Update
* @return \Longman\TelegramBot\Entities\Update
*/
public function getUpdate()
{
Expand All @@ -172,7 +170,7 @@ public function getUpdate()
/**
* Get message object
*
* @return Entities\Message
* @return \Longman\TelegramBot\Entities\Message
*/
public function getMessage()
{
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/UserCommands/CancelCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public function executeNoDb()
*
* @param string $text
*
* @return Entities\ServerResponse
* @return \Longman\TelegramBot\Entities\ServerResponse
*/
private function hideKeyboard($text)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/UserCommands/DateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ public function execute()
if (empty($location)) {
$text = 'You must specify location in format: /date <city>';
} else {
$text = $this->getformattedDate($location);
$text = $this->getFormattedDate($location);
}

$data = [
Expand Down
3 changes: 1 addition & 2 deletions src/Commands/UserCommands/SurveyCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class SurveyCommand extends UserCommand
/**
* Conversation Object
*
* @var Longman\TelegramBot\Conversation
* @var \Longman\TelegramBot\Conversation
*/
protected $conversation;

Expand All @@ -57,7 +57,6 @@ public function execute()
$data = [];
if ($chat->isGroupChat() || $chat->isSuperGroup()) {
//reply to message id is applied by default
$data['reply_to_message_id'] = $message_id;
//Force reply is applied by default to so can work with privacy on
$data['reply_markup'] = new ForceReply([ 'selective' => true]);
}
Expand Down
2 changes: 0 additions & 2 deletions src/ConversationDB.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

namespace Longman\TelegramBot;

use Longman\TelegramBot\DB;
use Longman\TelegramBot\Exception\TelegramException;

/**
Expand Down Expand Up @@ -49,7 +48,6 @@ public static function selectConversation($user_id, $chat_id, $limit = null)
$query .= 'AND `chat_id` = :chat_id ';
$query .= 'AND `user_id` = :user_id ';

$tokens = [':chat_id' => $chat_id, ':user_id' => $user_id];
if (!is_null($limit)) {
$query .= ' LIMIT :limit';
}
Expand Down
31 changes: 14 additions & 17 deletions src/DB.php
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ public static function selectTelegramUpdate($limit = null)
$sth_select_telegram_update->bindParam(':limit', $limit, \PDO::PARAM_INT);
$sth_select_telegram_update->execute();
$results = $sth_select_telegram_update->fetchAll(\PDO::FETCH_ASSOC);
} catch (PDOException $e) {
} catch (\PDOException $e) {
throw new TelegramException($e->getMessage());
}

Expand Down Expand Up @@ -234,7 +234,7 @@ public static function selectMessages($limit = null)
$sth->bindParam(':limit', $limit, \PDO::PARAM_INT);
$sth->execute();
$results = $sth->fetchAll(\PDO::FETCH_ASSOC);
} catch (PDOException $e) {
} catch (\PDOException $e) {
throw new TelegramException($e->getMessage());
}

Expand Down Expand Up @@ -299,7 +299,7 @@ public static function insertTelegramUpdate($id, $chat_id, $message_id, $inline_
$sth_insert_telegram_update->bindParam(':edited_message_id', $edited_message_id, \PDO::PARAM_INT);

return $sth_insert_telegram_update->execute();
} catch (PDOException $e) {
} catch (\PDOException $e) {
throw new TelegramException($e->getMessage());
}
}
Expand Down Expand Up @@ -344,7 +344,7 @@ public static function insertUser(User $user, $date, Chat $chat = null)
$sth1->bindParam(':date', $date, \PDO::PARAM_STR);

$status = $sth1->execute();
} catch (PDOException $e) {
} catch (\PDOException $e) {
throw new TelegramException($e->getMessage());
}

Expand All @@ -364,7 +364,7 @@ public static function insertUser(User $user, $date, Chat $chat = null)
$sth3->bindParam(':chat_id', $chat_id, \PDO::PARAM_INT);

$status = $sth3->execute();
} catch (PDOException $e) {
} catch (\PDOException $e) {
throw new TelegramException($e->getMessage());
}
}
Expand Down Expand Up @@ -418,7 +418,7 @@ public static function insertChat(Chat $chat, $date, $migrate_to_chat_id = null)
$sth2->bindParam(':date', $date, \PDO::PARAM_STR);

return $sth2->execute();
} catch (PDOException $e) {
} catch (\PDOException $e) {
throw new TelegramException($e->getMessage());
}
}
Expand Down Expand Up @@ -523,7 +523,7 @@ public static function insertInlineQueryRequest(InlineQuery &$inline_query)
$sth_insert_inline_query->bindParam(':created_at', $date, \PDO::PARAM_STR);

return $sth_insert_inline_query->execute();
} catch (PDOException $e) {
} catch (\PDOException $e) {
throw new TelegramException($e->getMessage());
}
}
Expand Down Expand Up @@ -574,7 +574,7 @@ public static function insertChosenInlineResultRequest(ChosenInlineResult &$chos
$sth_insert_chosen_inline_result->bindParam(':created_at', $date, \PDO::PARAM_STR);

return $sth_insert_chosen_inline_result->execute();
} catch (PDOException $e) {
} catch (\PDOException $e) {
throw new TelegramException($e->getMessage());
}
}
Expand Down Expand Up @@ -626,7 +626,7 @@ public static function insertCallbackQueryRequest(CallbackQuery &$callback_query
$sth_insert_callback_query->bindParam(':created_at', $date, \PDO::PARAM_STR);

return $sth_insert_callback_query->execute();
} catch (PDOException $e) {
} catch (\PDOException $e) {
throw new TelegramException($e->getMessage());
}
}
Expand Down Expand Up @@ -666,18 +666,15 @@ public static function insertMessageRequest(Message &$message)
//Insert user and the relation with the chat
self::insertUser($from, $date, $chat);

//Forwarded object
if ($forward_from || $forward_from_chat) {
$forward_date = self::getTimestamp($message->getForwardDate());
}

//Insert the forwarded message user in users table
if (is_object($forward_from)) {
$forward_date = self::getTimestamp($message->getForwardDate());
self::insertUser($forward_from, $forward_date);
$forward_from = $forward_from->getId();
}

if (is_object($forward_from_chat)) {
$forward_date = self::getTimestamp($message->getForwardDate());
self::insertChat($forward_from_chat, $forward_date);
$forward_from_chat = $forward_from_chat->getId();
}
Expand Down Expand Up @@ -821,7 +818,7 @@ public static function insertMessageRequest(Message &$message)
$sth->bindParam(':pinned_message', $pinned_message, \PDO::PARAM_INT);

return $sth->execute();
} catch (PDOException $e) {
} catch (\PDOException $e) {
throw new TelegramException($e->getMessage());
}
}
Expand Down Expand Up @@ -885,7 +882,7 @@ public static function insertEditedMessageRequest(Message &$edited_message)
$sth->bindParam(':caption', $caption, \PDO::PARAM_STR);

return $sth->execute();
} catch (PDOException $e) {
} catch (\PDOException $e) {
throw new TelegramException($e->getMessage());
}
}
Expand Down Expand Up @@ -1001,7 +998,7 @@ public static function selectChats(
$sth->execute($tokens);

$result = $sth->fetchAll(\PDO::FETCH_ASSOC);
} catch (PDOException $e) {
} catch (\PDOException $e) {
throw new TelegramException($e->getMessage());
}

Expand Down
5 changes: 5 additions & 0 deletions src/Entities/Audio.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ class Audio extends Entity
protected $mime_type;
protected $file_size;

/**
* Audio constructor.
*
* @param array $data
*/
public function __construct(array $data)
{
$this->file_id = isset($data['file_id']) ? $data['file_id'] : null;
Expand Down
5 changes: 5 additions & 0 deletions src/Entities/CallbackQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ class CallbackQuery extends Entity
protected $inline_message_id;
protected $data;

/**
* CallbackQuery constructor.
*
* @param array $data
*/
public function __construct(array $data)
{
$this->id = isset($data['id']) ? $data['id'] : null;
Expand Down
5 changes: 5 additions & 0 deletions src/Entities/Chat.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ class Chat extends Entity
protected $first_name;
protected $last_name;

/**
* Chat constructor.
*
* @param array $data
*/
public function __construct(array $data)
{
$this->id = isset($data['id']) ? $data['id'] : null;
Expand Down
5 changes: 5 additions & 0 deletions src/Entities/ChatMember.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ class ChatMember extends Entity
protected $user;
protected $status;

/**
* ChatMember constructor.
*
* @param array $data
*/
public function __construct(array $data)
{
$this->user = isset($data['user']) ? $data['user'] : null;
Expand Down
5 changes: 5 additions & 0 deletions src/Entities/ChosenInlineResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ class ChosenInlineResult extends Entity
protected $inline_message_id;
protected $query;

/**
* ChosenInlineResult constructor.
*
* @param array $data
*/
public function __construct(array $data)
{
$this->result_id = isset($data['result_id']) ? $data['result_id'] : null;
Expand Down
Loading