Updated MessageEntity

This commit is contained in:
netkas 2024-10-05 00:33:11 -04:00
parent cd84917d8f
commit 154dcbe3c6

View file

@ -6,40 +6,13 @@
class MessageEntity implements ObjectTypeInterface class MessageEntity implements ObjectTypeInterface
{ {
/** private string $type;
* @var string private int $offset;
*/ private int $length;
private $type; private ?string $url;
private ?User $user;
/** private ?string $language;
* @var int private ?string $custom_emoji_id;
*/
private $offset;
/**
* @var int
*/
private $length;
/**
* @var string|null
*/
private $url;
/**
* @var User|null
*/
private $user;
/**
* @var string|null
*/
private $language;
/**
* @var string|null
*/
private $custom_emoji_id;
/** /**
* Type of the entity. Currently, can be “mention” (@username), “hashtag” (#hashtag), “cashtag” ($USD), * Type of the entity. Currently, can be “mention” (@username), “hashtag” (#hashtag), “cashtag” ($USD),
@ -121,9 +94,7 @@
} }
/** /**
* Returns an array representation of the object * @inheritDoc
*
* @return array
*/ */
public function toArray(): array public function toArray(): array
{ {
@ -132,22 +103,23 @@
'offset' => $this->offset, 'offset' => $this->offset,
'length' => $this->length, 'length' => $this->length,
'url' => $this->url, 'url' => $this->url,
'user' => ($this->user instanceof ObjectTypeInterface) ? $this->user->toArray() : null, 'user' => $this->user?->toArray(),
'language' => $this->language, 'language' => $this->language,
'custom_emoji_id' => $this->custom_emoji_id 'custom_emoji_id' => $this->custom_emoji_id
]; ];
} }
/** /**
* Constructs object from an array representation * @inheritDoc
*
* @param array $data
* @return MessageEntity
*/ */
public static function fromArray(array $data): self public static function fromArray(?array $data): ?MessageEntity
{ {
$object = new self(); if($data === null)
{
return null;
}
$object = new self();
$object->type = $data['type'] ?? null; $object->type = $data['type'] ?? null;
$object->offset = $data['offset'] ?? null; $object->offset = $data['offset'] ?? null;
$object->length = $data['length'] ?? null; $object->length = $data['length'] ?? null;