Remove dead code and validate new polls only once
- Drop the unused polls.show_results_to_participants column (idempotent migration). - Remove CaptchaInterface::getType(), the unused AjaxView with its layout, the empty cell template folder and a redundant setNew() call. - PollsTable::newPoll() normalises and validates once; the create form used to validate the raw input first, so an e-mail address with surrounding spaces was rejected although it would have been trimmed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
8b0e82d806
commit
121097f7a7
13 files changed
+78
-102
No files matched your search
@@ -182,6 +182,22 @@ class PollsTable extends Table
|
||||
return (string)preg_replace('/[^A-Z0-9]/', '', strtoupper($code));
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds and validates a new, not yet saved poll from form input (title + email, normalised).
|
||||
*
|
||||
* @param array<string, mixed> $data Request data
|
||||
* @return \App\Model\Entity\Poll Check getErrors()
|
||||
*/
|
||||
public function newPoll(array $data): Poll
|
||||
{
|
||||
$field = fn(string $key): string => is_scalar($data[$key] ?? null) ? trim((string)$data[$key]) : '';
|
||||
|
||||
return $this->newEntity([
|
||||
'title' => $field('title'),
|
||||
'email' => strtolower($field('email')),
|
||||
], ['fields' => ['title', 'email']]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates and persists a new poll.
|
||||
*
|
||||
@@ -190,11 +206,17 @@ class PollsTable extends Table
|
||||
*/
|
||||
public function createPoll(array $data): array
|
||||
{
|
||||
$poll = $this->newEntity([
|
||||
'title' => trim((string)($data['title'] ?? '')),
|
||||
'email' => strtolower(trim((string)($data['email'] ?? ''))),
|
||||
], ['fields' => ['title', 'email']]);
|
||||
return $this->insertPoll($this->newPoll($data));
|
||||
}
|
||||
|
||||
/**
|
||||
* Assigns token and join code and saves a poll built by newPoll().
|
||||
*
|
||||
* @param \App\Model\Entity\Poll $poll New poll
|
||||
* @return array{0: \App\Model\Entity\Poll, 1: string|null} The entity (check getErrors()) and the plain token on success
|
||||
*/
|
||||
public function insertPoll(Poll $poll): array
|
||||
{
|
||||
if ($poll->hasErrors()) {
|
||||
return [$poll, null];
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user