Updated InlineQuery

This commit is contained in:
netkas 2024-10-04 00:18:19 -04:00
parent ad1094de38
commit fe1fd3083b

View file

@ -4,41 +4,19 @@
namespace TgBotLib\Objects\Inline; namespace TgBotLib\Objects\Inline;
use TgBotLib\Enums\Types\ChatType;
use TgBotLib\Interfaces\ObjectTypeInterface; use TgBotLib\Interfaces\ObjectTypeInterface;
use TgBotLib\Objects\Location; use TgBotLib\Objects\Location;
use TgBotLib\Objects\User; use TgBotLib\Objects\User;
class InlineQuery implements ObjectTypeInterface class InlineQuery implements ObjectTypeInterface
{ {
/** private string $id;
* @var string private User $from;
*/ private string $query;
private $id; private string $offset;
private ?ChatType $chat_type;
/** private ?Location $location;
* @var User
*/
private $from;
/**
* @var string
*/
private $query;
/**
* @var string
*/
private $offset;
/**
* @var string|null
*/
private $chat_type;
/**
* @var Location|null
*/
private $location;
/** /**
* Unique identifier for this query * Unique identifier for this query
@ -86,9 +64,9 @@
* known for requests sent from official clients and most third-party clients, unless the request was sent from * known for requests sent from official clients and most third-party clients, unless the request was sent from
* a secret chat * a secret chat
* *
* @return string|null * @return ChatType|null
*/ */
public function getChatType(): ?string public function getChatType(): ?ChatType
{ {
return $this->chat_type; return $this->chat_type;
} }
@ -104,27 +82,22 @@
} }
/** /**
* Returns an array representation of the object * @inheritDoc
*
* @return array
*/ */
public function toArray(): array public function toArray(): array
{ {
return [ return [
'id' => $this->id, 'id' => $this->id,
'from' => ($this->from instanceof ObjectTypeInterface) ? $this->from->toArray() : $this->from, 'from' => $this->from?->toArray(),
'query' => $this->query, 'query' => $this->query,
'offset' => $this->offset, 'offset' => $this->offset,
'chat_type' => $this->chat_type, 'chat_type' => $this->chat_type?->value,
'location' => ($this->location instanceof ObjectTypeInterface) ? $this->location->toArray() : $this->location, 'location' => $this->location?->toArray()
]; ];
} }
/** /**
* Constructs object from an array representation * @inheritDoc
*
* @param array|null $data
* @return InlineQuery|null
*/ */
public static function fromArray(?array $data): ?InlineQuery public static function fromArray(?array $data): ?InlineQuery
{ {
@ -135,11 +108,11 @@
$object = new self(); $object = new self();
$object->id = $data['id']; $object->id = $data['id'];
$object->from = isset($data['from']) && is_array($data['from']) ? User::fromArray($data['from']) : $data['from']; $object->from = isset($data['from']) ? User::fromArray($data['from']) : null;
$object->query = $data['query']; $object->query = $data['query'];
$object->offset = $data['offset']; $object->offset = $data['offset'];
$object->chat_type = $data['chat_type'] ?? null; $object->chat_type = $data['chat_type'] ?? null;
$object->location = isset($data['location']) && is_array($data['location']) ? Location::fromArray($data['location']) : $data['location']; $object->location = isset($data['location']) ? Location::fromArray($data['location']) : null;
return $object; return $object;
} }