Updated KeyboardButtonPollType

This commit is contained in:
netkas 2024-10-05 00:24:58 -04:00
parent 3746009e4e
commit 63970f807e
2 changed files with 22 additions and 16 deletions

View file

@ -0,0 +1,9 @@
<?php
namespace TgBotLib\Enums\Types;
enum KeyboardButtonPollType : string
{
case QUIZ = 'quiz';
case REGULAR = 'regular';
}

View file

@ -3,31 +3,27 @@
namespace TgBotLib\Objects; namespace TgBotLib\Objects;
use TgBotLib\Enums\Types\KeyboardButtonPollType as type;
use TgBotLib\Interfaces\ObjectTypeInterface; use TgBotLib\Interfaces\ObjectTypeInterface;
class KeyboardButtonPollType implements ObjectTypeInterface class KeyboardButtonPollType implements ObjectTypeInterface
{ {
/** private ?type $type;
* @var string|null
*/
private $type;
/** /**
* Optional. If quiz is passed, the user will be allowed to create only polls in the quiz mode. * Optional. If quiz is passed, the user will be allowed to create only polls in the quiz mode.
* If regular is passed, only regular polls will be allowed. Otherwise, the user will be allowed * If regular is passed, only regular polls will be allowed. Otherwise, the user will be allowed
* to create a poll of any type. * to create a poll of any type.
* *
* @return string|null * @return type|null
*/ */
public function getType(): ?string public function getType(): ?type
{ {
return $this->type; return $this->type;
} }
/** /**
* Returns an array representation of the object * @inheritDoc
*
* @return null[]|string[]
*/ */
public function toArray(): array public function toArray(): array
{ {
@ -37,16 +33,17 @@
} }
/** /**
* Constructs the object from an array representation * @inheritDoc
*
* @param array $data
* @return KeyboardButtonPollType
*/ */
public static function fromArray(array $data): self public static function fromArray(?array $data): ?KeyboardButtonPollType
{ {
$object = new self(); if ($data === null)
{
return null;
}
$object->type = $data['type'] ?? null; $object = new self();
$object->type = type::tryFrom($data['type']);
return $object; return $object;
} }