Skip to content

Commit ee77f9a

Browse files
committed
Touch up code and changelog, fix docblocks.
1 parent 4cb69b5 commit ee77f9a

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Exclamation symbols (:exclamation:) note something of importance e.g. breaking c
77
### Notes
88
- [:ledger: View file changes][Unreleased]
99
### Added
10-
- New method `setUpdateFilter($callback)` used to filter `processUpdate(Update $update)` calls. If `$callback` evaluates to false the update is not processed and a `ServerResponse()` is returned where `->isOk()` is false.
10+
- New method `setUpdateFilter($callback)` used to filter `processUpdate(Update $update)` calls. If `$callback` returns `false` the update isn't processed and an empty falsey `ServerResponse` is returned. (@VRciF)
1111
- Replaced 'generic' and 'genericmessage' strings with Telegram::GENERIC_COMMAND and Telegram::GENERIC_MESSAGE_COMMAND constants (@1int)
1212
- Bot API 4.8 (Extra Poll and Dice features).
1313
- Allow custom MySQL port to be defined for tests.

src/Telegram.php

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ class Telegram
144144
*
145145
* @var integer
146146
*/
147-
protected $last_update_id = null;
147+
protected $last_update_id;
148148

149149
/**
150150
* The command to be executed when there's a new message update and nothing more suitable is found
@@ -162,7 +162,7 @@ class Telegram
162162
*
163163
* @var callback
164164
*/
165-
protected $update_filter = null;
165+
protected $update_filter;
166166

167167
/**
168168
* Telegram constructor.
@@ -463,18 +463,17 @@ public function processUpdate(Update $update)
463463
$this->update = $update;
464464
$this->last_update_id = $update->getUpdateId();
465465

466-
$allowed = true;
467466
if (is_callable($this->update_filter)) {
468467
try {
469-
$allowed = (bool)call_user_func_array($this->update_filter, [$update, $this]);
468+
$allowed = (bool) call_user_func($this->update_filter, $update, $this);
470469
} catch (\Exception $e) {
471470
$allowed = false;
472471
}
473-
}
474472

475-
if (!$allowed) {
476-
TelegramLog::debug('Update denied by update_filter');
477-
return new ServerResponse(['ok' => false, 'description' => 'denied'], null);
473+
if (!$allowed) {
474+
TelegramLog::debug('Update denied by update_filter');
475+
return new ServerResponse(['ok' => false, 'description' => 'denied'], null);
476+
}
478477
}
479478

480479
//Load admin commands
@@ -1016,18 +1015,21 @@ public function getLastUpdateId()
10161015
/**
10171016
* Set an update filter callback
10181017
*
1018+
* @param callable $callback
1019+
*
10191020
* @return Telegram
10201021
*/
10211022
public function setUpdateFilter(callable $callback)
10221023
{
10231024
$this->update_filter = $callback;
1025+
10241026
return $this;
10251027
}
10261028

10271029
/**
10281030
* Return update filter callback
10291031
*
1030-
* @return callable or null
1032+
* @return callable|null
10311033
*/
10321034
public function getUpdateFilter()
10331035
{

0 commit comments

Comments
 (0)