2023-02-12 17:24:05 -05:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
2024-10-02 00:18:12 -04:00
|
|
|
namespace TgBotLib\Objects;
|
2023-02-12 17:24:05 -05:00
|
|
|
|
|
|
|
use TgBotLib\Interfaces\ObjectTypeInterface;
|
|
|
|
|
|
|
|
class PollOption implements ObjectTypeInterface
|
|
|
|
{
|
2024-10-05 00:49:53 -04:00
|
|
|
private string $text;
|
|
|
|
private int $voter_count;
|
2023-02-12 17:24:05 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Option text, 1-100 characters
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getText(): string
|
|
|
|
{
|
|
|
|
return $this->text;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Number of users that voted for this option
|
|
|
|
*
|
|
|
|
* @return int
|
|
|
|
*/
|
|
|
|
public function getVoterCount(): int
|
|
|
|
{
|
|
|
|
return $this->voter_count;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2024-10-05 00:49:53 -04:00
|
|
|
* @inheritDoc
|
2023-02-12 17:24:05 -05:00
|
|
|
*/
|
|
|
|
public function toArray(): array
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
'text' => $this->text,
|
|
|
|
'voter_count' => $this->voter_count,
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2024-10-05 00:49:53 -04:00
|
|
|
* @inheritDoc
|
2023-02-12 17:24:05 -05:00
|
|
|
*/
|
2024-10-05 00:49:53 -04:00
|
|
|
public static function fromArray(?array $data): ?PollOption
|
2023-02-12 17:24:05 -05:00
|
|
|
{
|
2024-10-05 00:49:53 -04:00
|
|
|
if($data === null)
|
|
|
|
{
|
|
|
|
return null;
|
|
|
|
}
|
2023-02-12 17:24:05 -05:00
|
|
|
|
2024-10-05 00:49:53 -04:00
|
|
|
$object = new self();
|
2023-02-14 17:35:16 -05:00
|
|
|
$object->text = $data['text'] ?? null;
|
|
|
|
$object->voter_count = $data['voter_count'] ?? null;
|
2023-02-12 17:24:05 -05:00
|
|
|
|
|
|
|
return $object;
|
|
|
|
}
|
|
|
|
}
|