Skip to content

Commit ebfd9b0

Browse files
committed
Merge pull request php-telegram-bot#188 from jacklul/miscfixes
Misc fixes
2 parents e5b6d41 + 39c5009 commit ebfd9b0

33 files changed

+475
-61
lines changed

src/Commands/AdminCommands/SendtoallCommand.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@ class SendtoallCommand extends AdminCommand
3131
/**
3232
* Execute command
3333
*
34-
* @todo Don't use empty, as a string of '0' is regarded to be empty
35-
*
3634
* @return boolean
3735
*/
3836
public function execute()
@@ -42,7 +40,7 @@ public function execute()
4240
$chat_id = $message->getChat()->getId();
4341
$text = $message->getText(true);
4442

45-
if (empty($text)) {
43+
if ($text === '') {
4644
$text = 'Write the message to send: /sendtoall <message>';
4745
} else {
4846
$results = Request::sendToActiveChats(

src/Commands/AdminCommands/SendtochannelCommand.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public function execute()
6767
switch ($state) {
6868
case -1:
6969
// getConfig has not been configured asking for channel to administer
70-
if ($type != 'Message' || empty($text)) {
70+
if ($type != 'Message' || $text === '') {
7171
$this->conversation->notes['state'] = -1;
7272
$this->conversation->update();
7373

@@ -116,7 +116,7 @@ public function execute()
116116
// no break
117117
case 1:
118118
insert:
119-
if ($this->conversation->notes['last_message_id'] == $message->getMessageId() || ($type == 'Message' && empty($text))) {
119+
if ($this->conversation->notes['last_message_id'] == $message->getMessageId() || ($type == 'Message' && $text === '')) {
120120
$this->conversation->notes['state'] = 1;
121121
$this->conversation->update();
122122

@@ -245,7 +245,7 @@ public function executeNoDb()
245245
$data = [];
246246
$data['chat_id'] = $chat_id;
247247

248-
if (empty($text)) {
248+
if ($text === '') {
249249
$data['text'] = 'Usage: /sendtochannel <text>';
250250
} else {
251251
$channels = (array) $this->getConfig('your_channel');

src/Entities/Audio.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,8 @@ class Audio extends Entity
2121
protected $mime_type;
2222
protected $file_size;
2323

24-
2524
public function __construct(array $data)
2625
{
27-
2826
$this->file_id = isset($data['file_id']) ? $data['file_id'] : null;
2927
if (empty($this->file_id)) {
3028
throw new TelegramException('file_id is empty!');
@@ -40,7 +38,6 @@ public function __construct(array $data)
4038
$this->title = isset($data['title']) ? $data['title'] : null;
4139
$this->mime_type = isset($data['mime_type']) ? $data['mime_type'] : null;
4240
$this->file_size = isset($data['file_size']) ? $data['file_size'] : null;
43-
4441
}
4542

4643
public function getFileId()
@@ -57,10 +54,12 @@ public function getPerformer()
5754
{
5855
return $this->performer;
5956
}
57+
6058
public function getTitle()
6159
{
6260
return $this->title;
6361
}
62+
6463
public function getMimeType()
6564
{
6665
return $this->mime_type;

src/Entities/Chat.php

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
class Chat extends Entity
1616
{
17-
1817
protected $id;
1918
protected $type;
2019
protected $title;
@@ -81,37 +80,31 @@ public function isChannel()
8180

8281
public function getId()
8382
{
84-
8583
return $this->id;
8684
}
8785

8886
public function getType()
8987
{
90-
9188
return $this->type;
9289
}
9390

9491
public function getTitle()
9592
{
96-
9793
return $this->title;
9894
}
9995

10096
public function getFirstName()
10197
{
102-
10398
return $this->first_name;
10499
}
105100

106101
public function getLastName()
107102
{
108-
109103
return $this->last_name;
110104
}
111105

112106
public function getUsername()
113107
{
114-
115108
return $this->username;
116109
}
117110

src/Entities/ChosenInlineResult.php

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

1515
class ChosenInlineResult extends Entity
1616
{
17-
1817
protected $result_id;
1918
protected $from;
2019
protected $location;
@@ -23,7 +22,6 @@ class ChosenInlineResult extends Entity
2322

2423
public function __construct(array $data)
2524
{
26-
2725
$this->result_id = isset($data['result_id']) ? $data['result_id'] : null;
2826
if (empty($this->result_id)) {
2927
throw new TelegramException('result_id is empty!');

src/Entities/Contact.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,13 @@
1414

1515
class Contact extends Entity
1616
{
17-
1817
protected $phone_number;
1918
protected $first_name;
2019
protected $last_name;
2120
protected $user_id;
2221

2322
public function __construct(array $data)
2423
{
25-
2624
$this->phone_number = isset($data['phone_number']) ? $data['phone_number'] : null;
2725
if (empty($this->phone_number)) {
2826
throw new TelegramException('phone_number is empty!');

src/Entities/Document.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ class Document extends Entity
2222

2323
public function __construct(array $data)
2424
{
25-
2625
$this->file_id = isset($data['file_id']) ? $data['file_id'] : null;
2726
if (empty($this->file_id)) {
2827
throw new TelegramException('file_id is empty!');
@@ -36,7 +35,6 @@ public function __construct(array $data)
3635
$this->file_name = isset($data['file_name']) ? $data['file_name'] : null;
3736
$this->mime_type = isset($data['mime_type']) ? $data['mime_type'] : null;
3837
$this->file_size = isset($data['file_size']) ? $data['file_size'] : null;
39-
4038
}
4139

4240
public function getFileId()
@@ -46,21 +44,21 @@ public function getFileId()
4644

4745
public function getThumb()
4846
{
49-
return $this->thumb;
47+
return $this->thumb;
5048
}
5149

5250
public function getFileName()
5351
{
54-
return $this->file_name;
52+
return $this->file_name;
5553
}
5654

5755
public function getMimeType()
5856
{
59-
return $this->mime_type;
57+
return $this->mime_type;
6058
}
6159

6260
public function getFileSize()
6361
{
64-
return $this->file_size;
62+
return $this->file_size;
6563
}
6664
}

src/Entities/Entity.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,8 @@ class Entity
1414
{
1515
protected $bot_name;
1616

17-
1817
public function getBotName()
1918
{
20-
2119
return $this->bot_name;
2220
}
2321

src/Entities/File.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ class File extends Entity
2020

2121
public function __construct(array $data)
2222
{
23-
2423
$this->file_id = isset($data['file_id']) ? $data['file_id'] : null;
2524
if (empty($this->file_id)) {
2625
throw new TelegramException('file_id is empty!');
@@ -29,7 +28,6 @@ public function __construct(array $data)
2928
$this->file_size = isset($data['file_size']) ? $data['file_size'] : null;
3029

3130
$this->file_path = isset($data['file_path']) ? $data['file_path'] : null;
32-
3331
}
3432

3533
public function getFileId()
@@ -39,11 +37,11 @@ public function getFileId()
3937

4038
public function getFileSize()
4139
{
42-
return $this->file_size;
40+
return $this->file_size;
4341
}
4442

4543
public function getFilePath()
4644
{
47-
return $this->file_path;
45+
return $this->file_path;
4846
}
4947
}

src/Entities/InlineKeyboardButton.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ class InlineKeyboardButton extends Entity
1919
protected $callback_data;
2020
protected $switch_inline_query;
2121

22+
/**
23+
* @todo check if only one of 'url, callback_data, switch_inline_query' fields is set, documentation states that only one of these can be used
24+
*/
2225
public function __construct($data = array())
2326
{
2427
$this->text = isset($data['text']) ? $data['text'] : null;
@@ -30,12 +33,8 @@ public function __construct($data = array())
3033
$this->callback_data = isset($data['callback_data']) ? $data['callback_data'] : null;
3134
$this->switch_inline_query = isset($data['switch_inline_query']) ? $data['switch_inline_query'] : null;
3235

33-
if (empty($this->url) && empty($this->callback_data) && empty($this->switch_inline_query)) {
36+
if ($this->url === '' && $this->callback_data === '' && $this->switch_inline_query === '') {
3437
throw new TelegramException('You must use at least one of these fields: url, callback_data, switch_inline_query!');
3538
}
36-
37-
/*
38-
* @todo check if only one of 'url, callback_data, switch_inline_query' fields is set, documentation states that only one of these can be used
39-
*/
4039
}
4140
}

0 commit comments

Comments
 (0)