Skip to content

Commit

Permalink
Simplify code for handleUpdate
Browse files Browse the repository at this point in the history
  • Loading branch information
punyflash committed Sep 7, 2020
1 parent 297b514 commit a0b44fc
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions src/Bot.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,12 +140,7 @@ private function isUpdateHandler($handler)
*/
public function handleUpdate(Update $update = null)
{
if (is_null($update))
{
$data = json_decode(file_get_contents('php://input'), true);
if (is_null($data) || !isset($data['update_id'])) return false;
$update = new Update($data);
}
if(!$this->validUpdate($update)) return false;

foreach ($this->properties['handlers'] as $handler)
{
Expand All @@ -162,6 +157,18 @@ public function handleUpdate(Update $update = null)
return true;
}

private function validUpdate(Update &$update)
{
if (is_null($update))
{
$data = json_decode(file_get_contents('php://input'), true);
if (is_null($data) || !isset($data['update_id'])) return false;
$update = new Update($data);
}

return true;
}

/**
* Bot methods list for "call" magick
* @return string[]
Expand Down

0 comments on commit a0b44fc

Please sign in to comment.