Add SendPoll method with tests and enhance Poll object
This commit is contained in:
parent
33f7a094fc
commit
9a4e537294
6 changed files with 234 additions and 11 deletions
|
@ -14,6 +14,17 @@
|
|||
*/
|
||||
private ?array $text_entities;
|
||||
|
||||
|
||||
/**
|
||||
* InputPollOption constructor.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->text = (string)null;
|
||||
$this->text_parse_mode = null;
|
||||
$this->text_entities = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Option text, 1-100 characters
|
||||
*
|
||||
|
@ -24,6 +35,16 @@
|
|||
return $this->text;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $text
|
||||
* @return InputPollOption
|
||||
*/
|
||||
public function setText(string $text): InputPollOption
|
||||
{
|
||||
$this->text = $text;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Optional. Mode for parsing entities in the text. See formatting options for more details.
|
||||
* Currently, only custom emoji entities are allowed
|
||||
|
@ -35,6 +56,16 @@
|
|||
return $this->text_parse_mode;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ParseMode|null $text_parse_mode
|
||||
* @return InputPollOption
|
||||
*/
|
||||
public function setTextParseMode(?ParseMode $text_parse_mode): InputPollOption
|
||||
{
|
||||
$this->text_parse_mode = $text_parse_mode;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Optional. A JSON-serialized list of special entities that appear in the poll option text.
|
||||
* It can be specified instead of text_parse_mode
|
||||
|
@ -46,16 +77,36 @@
|
|||
return $this->text_entities;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param MessageEntity[]|null $text_entities
|
||||
* @return InputPollOption
|
||||
*/
|
||||
public function setTextEntities(?array $text_entities): InputPollOption
|
||||
{
|
||||
$this->text_entities = $text_entities;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function toArray(): ?array
|
||||
{
|
||||
return [
|
||||
'text' => $this->text,
|
||||
'text_parse_mode' => $this->text_parse_mode?->value,
|
||||
'text_entities' => array_map(fn(MessageEntity $item) => $item->toArray(), $this->text_entities)
|
||||
$array = [
|
||||
'text' => $this->text
|
||||
];
|
||||
|
||||
if($this->text_parse_mode !== null)
|
||||
{
|
||||
$array['text_parse_mode'] = $this->text_parse_mode->value;
|
||||
}
|
||||
|
||||
if($this->text_entities !== null)
|
||||
{
|
||||
$array['text_entities'] = array_map(fn($item) => $item->toArray(), $this->text_entities);
|
||||
}
|
||||
|
||||
return $array;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
private string $type;
|
||||
private bool $allow_multiple_answers;
|
||||
private ?int $correct_option_id;
|
||||
private string $explanation;
|
||||
private ?string $explanation;
|
||||
/**
|
||||
* @var MessageEntity[]|null
|
||||
*/
|
||||
|
@ -122,9 +122,9 @@
|
|||
* Optional. Text that is shown when a user chooses an incorrect answer or taps on the lamp icon in
|
||||
* a quiz-style poll, 0-200 characters
|
||||
*
|
||||
* @return string
|
||||
* @return string|null
|
||||
*/
|
||||
public function getExplanation(): string
|
||||
public function getExplanation(): ?string
|
||||
{
|
||||
return $this->explanation;
|
||||
}
|
||||
|
@ -201,10 +201,10 @@
|
|||
$object->id = $data['id'] ?? null;
|
||||
$object->question = $data['question'] ?? null;
|
||||
$object->total_voter_count = $data['total_voter_count'] ?? null;
|
||||
$object->is_closed = $data['is_closed'] ?? null;
|
||||
$object->is_anonymous = $data['is_anonymous'] ?? null;
|
||||
$object->is_closed = $data['is_closed'] ?? false;
|
||||
$object->is_anonymous = $data['is_anonymous'] ?? false;
|
||||
$object->type = $data['type'] ?? null;
|
||||
$object->allow_multiple_answers = $data['allow_multiple_answers'] ?? null;
|
||||
$object->allow_multiple_answers = $data['allow_multiple_answers'] ?? false;
|
||||
$object->correct_option_id = $data['correct_option_id'] ?? null;
|
||||
$object->explanation = $data['explanation'] ?? null;
|
||||
$object->open_period = $data['open_period'] ?? null;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue