Skip to content

Commit

Permalink
Change type of create method
Browse files Browse the repository at this point in the history
  • Loading branch information
Mateodioev authored Jan 30, 2023
1 parent 46358bf commit 6f46dd1
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/Core.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use Mateodioev\Bots\Telegram\Exception\{TelegramParamException, TelegramApiException};
use Mateodioev\Bots\Telegram\Interfaces\{MethodInterface, TelegramInterface, TypesInterface};
use Mateodioev\Bots\Telegram\Types\Error;
use Mateodioev\Request\{Request, RequestResponse, ResponseException};
use Mateodioev\Request\{Request, ResponseException};
use Mateodioev\Utils\Exceptions\RequestException;
use Mateodioev\Utils\Network;
use stdClass;
Expand Down Expand Up @@ -106,14 +106,19 @@ public function request(MethodInterface $method): TypesInterface|stdClass|array
private function parseRequestResult(MethodInterface $method): mixed
{
$return = $method->getReturn();
$returnType = $return[0] ?? Response::class;
$methodName = $return[1] ? 'bulkCreate' : 'create';

if ($return[0] === null) return $this->result;

if ($this->result->ok) {
try {
return $return[0]::$methodName($this->result->result);
} catch (\Throwable $_) {
if ($returnType === Response::class) {
return $returnType::$methodName($this->result);
}
return $returnType::$methodName($this->result->result);

} catch (\Throwable) {
return $return[0]::$methodName($this->result);
}
}
Expand Down

0 comments on commit 6f46dd1

Please sign in to comment.