Skip to content

Commit cdb8846

Browse files
committed
Remove optional parameters for handleGetUpdates method and use array $data instead.
1 parent 520e564 commit cdb8846

File tree

3 files changed

+27
-7
lines changed

3 files changed

+27
-7
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Exclamation symbols (:exclamation:) note something of importance e.g. breaking c
1010
- Bot API 5.1 (ChatMember Update types, Improved Invite Links, Voice Chat). (@massadm, @noplanman)
1111
### Changed
1212
### Deprecated
13+
- `Telegram::handleGetUpdates` method should be passed a `$data` array for parameters.
1314
### Removed
1415
### Fixed
1516
- `message.edit_date` is now of type `timestamp`.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ $allowed_updates = [
375375
$telegram->setWebhook($hook_url, ['allowed_types' => $allowed_updates]);
376376

377377
// When handling the getUpdates method.
378-
$telegram->handleGetUpdates($limit = null, $timeout = null, $allowed_updates);
378+
$telegram->handleGetUpdates(['allowed_types' => $allowed_updates]);
379379
```
380380

381381
## Support

src/Telegram.php

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -391,14 +391,15 @@ public function getLastCommandResponse(): ServerResponse
391391
/**
392392
* Handle getUpdates method
393393
*
394-
* @param int|null $limit
395-
* @param int|null $timeout
396-
* @param array|null $allowed_updates
394+
* @todo Remove backwards compatibility for old signature and force $data to be an array.
395+
*
396+
* @param array|int|null $data
397+
* @param int|null $timeout
397398
*
398399
* @return ServerResponse
399400
* @throws TelegramException
400401
*/
401-
public function handleGetUpdates(?int $limit = null, ?int $timeout = null, ?array $allowed_updates = null): ServerResponse
402+
public function handleGetUpdates($data = null, ?int $timeout = null): ServerResponse
402403
{
403404
if (empty($this->bot_username)) {
404405
throw new TelegramException('Bot Username is not defined!');
@@ -414,13 +415,31 @@ public function handleGetUpdates(?int $limit = null, ?int $timeout = null, ?arra
414415
);
415416
}
416417

418+
$offset = 0;
419+
$limit = null;
420+
$allowed_updates = null;
421+
422+
// @todo Backwards compatibility for old signature, remove in next version.
423+
if (!is_array($data)) {
424+
$limit = $data;
425+
426+
@trigger_error(
427+
sprintf('Use of $limit and $timeout parameters in %s is deprecated. Use $data array instead.', __METHOD__),
428+
E_USER_DEPRECATED
429+
);
430+
} else {
431+
$offset = $data['offset'] ?? $offset;
432+
$limit = $data['limit'] ?? $limit;
433+
$timeout = $data['timeout'] ?? $timeout;
434+
$allowed_updates = $data['allowed_updates'] ?? $allowed_updates;
435+
}
436+
417437
// By default, allow ALL known update types.
418438
if ($allowed_updates === null) {
419439
$allowed_updates = Update::getUpdateTypes();
420440
}
421-
$offset = 0;
422441

423-
//Take custom input into account.
442+
// Take custom input into account.
424443
if ($custom_input = $this->getCustomInput()) {
425444
try {
426445
$input = json_decode($this->input, true, 512, JSON_THROW_ON_ERROR);

0 commit comments

Comments
 (0)