Skip to content

Commit 1513e97

Browse files
authored
Merge pull request #236 from MBoretto/develop
various
2 parents ea01d34 + edd902d commit 1513e97

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+367
-60
lines changed

src/BotanDB.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
namespace Longman\TelegramBot;
1212

13-
use Longman\TelegramBot\DB;
1413
use Longman\TelegramBot\Exception\TelegramException;
1514

1615
/**
@@ -33,8 +32,10 @@ public static function initializeBotanDb()
3332
*
3433
* @param $user_id
3534
* @param $url
36-
* @return bool|string
35+
*
3736
* @throws TelegramException
37+
*
38+
* @return bool|string
3839
*/
3940
public static function selectShortUrl($user_id, $url)
4041
{
@@ -65,8 +66,10 @@ public static function selectShortUrl($user_id, $url)
6566
* @param $user_id
6667
* @param $url
6768
* @param $short_url
68-
* @return bool
69+
*
6970
* @throws TelegramException
71+
*
72+
* @return bool
7073
*/
7174
public static function insertShortUrl($user_id, $url, $short_url)
7275
{

src/Commands/AdminCommands/SendtochannelCommand.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class SendtochannelCommand extends AdminCommand
3333
/**
3434
* Conversation Object
3535
*
36-
* @var Longman\TelegramBot\Conversation
36+
* @var \Longman\TelegramBot\Conversation
3737
*/
3838
protected $conversation;
3939

@@ -128,7 +128,6 @@ public function execute()
128128
$this->conversation->notes['last_message_id'] = $message->getMessageId();
129129
$this->conversation->notes['message'] = $message->reflect();
130130
$this->conversation->notes['message_type'] = $type;
131-
132131
// no break
133132
case 2:
134133
if ($this->conversation->notes['last_message_id'] == $message->getMessageId() || !($text == 'Yes' || $text == 'No')) {
@@ -258,7 +257,7 @@ public function executeNoDb()
258257
/**
259258
* Publish a message to a channel and return success or failure message
260259
*
261-
* @param Entities\Message $message
260+
* @param \Longman\TelegramBot\Entities\Message $message
262261
* @param int $channel
263262
* @param string|null $caption
264263
*
@@ -292,10 +291,10 @@ protected function publish(Message $message, $channel, $caption = null)
292291
* @todo This method will be moved at an higher level maybe in AdminCommand or Command
293292
* @todo Looking for a more significative name
294293
*
295-
* @param Entities\Message $message
294+
* @param \Longman\TelegramBot\Entities\Message $message
296295
* @param array $data
297296
*
298-
* @return Entities\ServerResponse
297+
* @return \Longman\TelegramBot\Entities\ServerResponse
299298
*/
300299
protected function sendBack(Message $message, array $data)
301300
{

src/Commands/Command.php

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@
1313
use Longman\TelegramBot\DB;
1414
use Longman\TelegramBot\Request;
1515
use Longman\TelegramBot\Telegram;
16-
use Longman\TelegramBot\Entities\Chat;
1716
use Longman\TelegramBot\Entities\Update;
18-
use Longman\TelegramBot\Entities\User;
1917

2018
/**
2119
* Abstract Command Class
@@ -32,14 +30,14 @@ abstract class Command
3230
/**
3331
* Update object
3432
*
35-
* @var Entities\Update
33+
* @var \Longman\TelegramBot\Entities\Update
3634
*/
3735
protected $update;
3836

3937
/**
4038
* Message object
4139
*
42-
* @var Entities\Message
40+
* @var \Longman\TelegramBot\Entities\Message
4341
*/
4442
protected $message;
4543

@@ -96,7 +94,7 @@ abstract class Command
9694
* Constructor
9795
*
9896
* @param Telegram $telegram
99-
* @param Entities\Update $update
97+
* @param \Longman\TelegramBot\Entities\Update $update
10098
*/
10199
public function __construct(Telegram $telegram, Update $update = null)
102100
{
@@ -108,7 +106,7 @@ public function __construct(Telegram $telegram, Update $update = null)
108106
/**
109107
* Set update object
110108
*
111-
* @param Entities\Update $update
109+
* @param \Longman\TelegramBot\Entities\Update $update
112110
* @return Command
113111
*/
114112
public function setUpdate(Update $update = null)
@@ -123,7 +121,7 @@ public function setUpdate(Update $update = null)
123121
/**
124122
* Pre-execute command
125123
*
126-
* @return Entities\ServerResponse
124+
* @return \Longman\TelegramBot\Entities\ServerResponse
127125
*/
128126
public function preExecute()
129127
{
@@ -136,14 +134,14 @@ public function preExecute()
136134
/**
137135
* Execute command
138136
*
139-
* @return Entities\ServerResponse
137+
* @return \Longman\TelegramBot\Entities\ServerResponse
140138
*/
141139
abstract public function execute();
142140

143141
/**
144142
* Execution if MySQL is required but not available
145143
*
146-
* @return Entities\ServerResponse
144+
* @return \Longman\TelegramBot\Entities\ServerResponse
147145
*/
148146
public function executeNoDb()
149147
{
@@ -162,7 +160,7 @@ public function executeNoDb()
162160
/**
163161
* Get update object
164162
*
165-
* @return Entities\Update
163+
* @return \Longman\TelegramBot\Entities\Update
166164
*/
167165
public function getUpdate()
168166
{
@@ -172,7 +170,7 @@ public function getUpdate()
172170
/**
173171
* Get message object
174172
*
175-
* @return Entities\Message
173+
* @return \Longman\TelegramBot\Entities\Message
176174
*/
177175
public function getMessage()
178176
{

src/Commands/UserCommands/CancelCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public function executeNoDb()
6868
*
6969
* @param string $text
7070
*
71-
* @return Entities\ServerResponse
71+
* @return \Longman\TelegramBot\Entities\ServerResponse
7272
*/
7373
private function hideKeyboard($text)
7474
{

src/Commands/UserCommands/DateCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ public function execute()
202202
if (empty($location)) {
203203
$text = 'You must specify location in format: /date <city>';
204204
} else {
205-
$text = $this->getformattedDate($location);
205+
$text = $this->getFormattedDate($location);
206206
}
207207

208208
$data = [

src/Commands/UserCommands/SurveyCommand.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class SurveyCommand extends UserCommand
3535
/**
3636
* Conversation Object
3737
*
38-
* @var Longman\TelegramBot\Conversation
38+
* @var \Longman\TelegramBot\Conversation
3939
*/
4040
protected $conversation;
4141

@@ -57,7 +57,6 @@ public function execute()
5757
$data = [];
5858
if ($chat->isGroupChat() || $chat->isSuperGroup()) {
5959
//reply to message id is applied by default
60-
$data['reply_to_message_id'] = $message_id;
6160
//Force reply is applied by default to so can work with privacy on
6261
$data['reply_markup'] = new ForceReply([ 'selective' => true]);
6362
}

src/ConversationDB.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
namespace Longman\TelegramBot;
1212

13-
use Longman\TelegramBot\DB;
1413
use Longman\TelegramBot\Exception\TelegramException;
1514

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

52-
$tokens = [':chat_id' => $chat_id, ':user_id' => $user_id];
5351
if (!is_null($limit)) {
5452
$query .= ' LIMIT :limit';
5553
}

src/DB.php

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ public static function selectTelegramUpdate($limit = null)
199199
$sth_select_telegram_update->bindParam(':limit', $limit, \PDO::PARAM_INT);
200200
$sth_select_telegram_update->execute();
201201
$results = $sth_select_telegram_update->fetchAll(\PDO::FETCH_ASSOC);
202-
} catch (PDOException $e) {
202+
} catch (\PDOException $e) {
203203
throw new TelegramException($e->getMessage());
204204
}
205205

@@ -234,7 +234,7 @@ public static function selectMessages($limit = null)
234234
$sth->bindParam(':limit', $limit, \PDO::PARAM_INT);
235235
$sth->execute();
236236
$results = $sth->fetchAll(\PDO::FETCH_ASSOC);
237-
} catch (PDOException $e) {
237+
} catch (\PDOException $e) {
238238
throw new TelegramException($e->getMessage());
239239
}
240240

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

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

346346
$status = $sth1->execute();
347-
} catch (PDOException $e) {
347+
} catch (\PDOException $e) {
348348
throw new TelegramException($e->getMessage());
349349
}
350350

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

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

420420
return $sth2->execute();
421-
} catch (PDOException $e) {
421+
} catch (\PDOException $e) {
422422
throw new TelegramException($e->getMessage());
423423
}
424424
}
@@ -523,7 +523,7 @@ public static function insertInlineQueryRequest(InlineQuery &$inline_query)
523523
$sth_insert_inline_query->bindParam(':created_at', $date, \PDO::PARAM_STR);
524524

525525
return $sth_insert_inline_query->execute();
526-
} catch (PDOException $e) {
526+
} catch (\PDOException $e) {
527527
throw new TelegramException($e->getMessage());
528528
}
529529
}
@@ -574,7 +574,7 @@ public static function insertChosenInlineResultRequest(ChosenInlineResult &$chos
574574
$sth_insert_chosen_inline_result->bindParam(':created_at', $date, \PDO::PARAM_STR);
575575

576576
return $sth_insert_chosen_inline_result->execute();
577-
} catch (PDOException $e) {
577+
} catch (\PDOException $e) {
578578
throw new TelegramException($e->getMessage());
579579
}
580580
}
@@ -644,7 +644,7 @@ public static function insertCallbackQueryRequest(CallbackQuery &$callback_query
644644
$sth_insert_callback_query->bindParam(':created_at', $date, \PDO::PARAM_STR);
645645

646646
return $sth_insert_callback_query->execute();
647-
} catch (PDOException $e) {
647+
} catch (\PDOException $e) {
648648
throw new TelegramException($e->getMessage());
649649
}
650650
}
@@ -685,18 +685,15 @@ public static function insertMessageRequest(Message &$message)
685685
//Insert user and the relation with the chat
686686
self::insertUser($from, $date, $chat);
687687

688-
//Forwarded object
689-
if ($forward_from || $forward_from_chat) {
690-
$forward_date = self::getTimestamp($message->getForwardDate());
691-
}
692-
693688
//Insert the forwarded message user in users table
694689
if (is_object($forward_from)) {
690+
$forward_date = self::getTimestamp($message->getForwardDate());
695691
self::insertUser($forward_from, $forward_date);
696692
$forward_from = $forward_from->getId();
697693
}
698694

699695
if (is_object($forward_from_chat)) {
696+
$forward_date = self::getTimestamp($message->getForwardDate());
700697
self::insertChat($forward_from_chat, $forward_date);
701698
$forward_from_chat = $forward_from_chat->getId();
702699
}
@@ -841,7 +838,7 @@ public static function insertMessageRequest(Message &$message)
841838
$sth->bindParam(':pinned_message', $pinned_message, \PDO::PARAM_INT);
842839

843840
return $sth->execute();
844-
} catch (PDOException $e) {
841+
} catch (\PDOException $e) {
845842
throw new TelegramException($e->getMessage());
846843
}
847844
}
@@ -911,7 +908,7 @@ public static function insertEditedMessageRequest(Message &$edited_message)
911908
$sth->bindParam(':caption', $caption, \PDO::PARAM_STR);
912909

913910
return $sth->execute();
914-
} catch (PDOException $e) {
911+
} catch (\PDOException $e) {
915912
throw new TelegramException($e->getMessage());
916913
}
917914
}
@@ -1027,7 +1024,7 @@ public static function selectChats(
10271024
$sth->execute($tokens);
10281025

10291026
$result = $sth->fetchAll(\PDO::FETCH_ASSOC);
1030-
} catch (PDOException $e) {
1027+
} catch (\PDOException $e) {
10311028
throw new TelegramException($e->getMessage());
10321029
}
10331030

src/Entities/Audio.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ class Audio extends Entity
2121
protected $mime_type;
2222
protected $file_size;
2323

24+
/**
25+
* Audio constructor.
26+
*
27+
* @param array $data
28+
*/
2429
public function __construct(array $data)
2530
{
2631
$this->file_id = isset($data['file_id']) ? $data['file_id'] : null;

src/Entities/CallbackQuery.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ class CallbackQuery extends Entity
2020
protected $inline_message_id;
2121
protected $data;
2222

23+
/**
24+
* CallbackQuery constructor.
25+
*
26+
* @param array $data
27+
*/
2328
public function __construct(array $data)
2429
{
2530
$this->id = isset($data['id']) ? $data['id'] : null;

0 commit comments

Comments
 (0)