Skip to content

Commit

Permalink
🎨 Handle setting the answers attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
Log1x committed Jul 21, 2024
1 parent bd3dfc1 commit f77e41f
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/Discord/Parts/Channel/Poll.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ class Poll extends Part
// events
'channel_id',
'message_id',

// repositories
'answers',
];

/**
Expand All @@ -62,6 +65,28 @@ class Poll extends Part
'answers' => PollAnswerRepository::class,
];

/**
* Sets the answers attribute.
*
* @param array $answers
*/
protected function setAnswersAttribute(array $answers): void
{
foreach ($answers as $answer) {
/** @var ?PollAnswer */
if ($part = $this->answers->offsetGet($answer->answer_id)) {
$part->fill($answer);
} else {
/** @var PollAnswer */
$part = $this->answers->create($answer);
}

$this->answers->pushItem($part);
}

$this->attributes['answers'] = $answers;
}

/**
* Returns the question attribute.
*
Expand Down

0 comments on commit f77e41f

Please sign in to comment.