From 6f46dd187db2d0069e5f6ec40c9f69c1d8d717a9 Mon Sep 17 00:00:00 2001 From: Mateo O <68271130+Mateodioev@users.noreply.github.com> Date: Mon, 30 Jan 2023 12:00:51 -0500 Subject: [PATCH] Change type of create method --- src/Core.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/Core.php b/src/Core.php index a61212f..060fe4c 100644 --- a/src/Core.php +++ b/src/Core.php @@ -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; @@ -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); } }