Skip to content

Commit

Permalink
fixup! feat(polls): allow editing of draft polls
Browse files Browse the repository at this point in the history
  • Loading branch information
miaulalala committed Dec 4, 2024
1 parent cc416a5 commit 124f93b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 56 deletions.
13 changes: 11 additions & 2 deletions lib/Model/Poll.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,11 @@ public function setOptions(array $options): void {
throw new PollPropertyException(PollPropertyException::REASON_OPTIONS);
}

$this->options = $jsonOptions;
$this->setter('options', [$jsonOptions]);
}

public function getOptions(): string {
return $this->options;
}

/**
Expand All @@ -166,11 +170,16 @@ public function setOptions(array $options): void {
* @throws PollPropertyException
*/
public function setQuestion(string $question): void {
nvlog($question);

Check failure on line 173 in lib/Model/Poll.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis

UndefinedFunction

lib/Model/Poll.php:173:3: UndefinedFunction: Function OCA\Talk\Model\nvlog does not exist (see https://psalm.dev/021)
$question = trim($question);
if ($question === '' || strlen($question) > 32_000) {
throw new PollPropertyException(PollPropertyException::REASON_QUESTION);
}

$this->question = $question;
$this->setter('question', [$question]);
}

public function getQuestion(): string {

Check failure on line 182 in lib/Model/Poll.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis

MoreSpecificReturnType

lib/Model/Poll.php:182:33: MoreSpecificReturnType: The declared return type 'non-empty-string' for OCA\Talk\Model\Poll::getQuestion is more specific than the inferred return type 'string' (see https://psalm.dev/070)
return $this->question;

Check failure on line 183 in lib/Model/Poll.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis

LessSpecificReturnStatement

lib/Model/Poll.php:183:10: LessSpecificReturnStatement: The type 'string' is more general than the declared return type 'non-empty-string' for OCA\Talk\Model\Poll::getQuestion (see https://psalm.dev/129)
}
}
54 changes: 0 additions & 54 deletions lib/Service/PollService.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,48 +85,6 @@ public function updatePoll(Participant $participant, Poll $poll): void {
$this->pollMapper->update($poll);
}

/**
* @param array $options
* @return string
*
* @since 21.0.0
*/
public function validatePollOptions(array $options): string {
try {
json_encode($options, JSON_THROW_ON_ERROR, 1);
} catch (\Exception) {
throw new PollPropertyException(PollPropertyException::REASON_OPTIONS);
}

$validOptions = [];
foreach ($options as $option) {
if (!is_string($option)) {
throw new PollPropertyException(PollPropertyException::REASON_OPTIONS);
}

$option = trim($option);
if ($option !== '') {
$validOptions[] = $option;
}
}

if (count($validOptions) < 2) {
throw new PollPropertyException(PollPropertyException::REASON_OPTIONS);
}

try {
$jsonOptions = json_encode($validOptions, JSON_THROW_ON_ERROR, 1);
} catch (\Exception) {
throw new PollPropertyException(PollPropertyException::REASON_OPTIONS);
}

if (strlen($jsonOptions) > 60_000) {
throw new PollPropertyException(PollPropertyException::REASON_OPTIONS);
}

return $jsonOptions;
}

/**
* @param Participant $participant
* @param Poll $poll
Expand Down Expand Up @@ -366,16 +324,4 @@ public function neutralizeDeletedUser(string $actorType, string $actorId): void
->andWhere($update->expr()->eq('actor_id', $update->createNamedParameter($actorId)));
$update->executeStatement();
}

/**
* @param string $question
* @return string
*/
public function validatePollQuestion(string $question): string {
$question = trim($question);
if ($question === '' || strlen($question) > 32_000) {
throw new PollPropertyException(PollPropertyException::REASON_QUESTION);
}
return $question;
}
}

0 comments on commit 124f93b

Please sign in to comment.