mirror of
https://github.com/MarijnDoeve/TijdVoorDeTest.git
synced 2026-07-07 16:10:15 +02:00
Refactor for code consistency and type safety assertions across repositories and entities
This commit is contained in:
@@ -7,6 +7,8 @@ parameters:
|
|||||||
- public/
|
- public/
|
||||||
- src/
|
- src/
|
||||||
- tests/
|
- tests/
|
||||||
|
excludePaths:
|
||||||
|
- config/reference.php
|
||||||
treatPhpDocTypesAsCertain: false
|
treatPhpDocTypesAsCertain: false
|
||||||
symfony:
|
symfony:
|
||||||
containerXmlPath: var/cache/dev/Tvdt_KernelDevDebugContainer.xml
|
containerXmlPath: var/cache/dev/Tvdt_KernelDevDebugContainer.xml
|
||||||
|
|||||||
@@ -96,6 +96,7 @@ class QuizController extends AbstractController
|
|||||||
$fetchedQuiz = $this->quizRepository->fetchWithQuestions($quiz->id);
|
$fetchedQuiz = $this->quizRepository->fetchWithQuestions($quiz->id);
|
||||||
\assert($fetchedQuiz->questions->count() > 0);
|
\assert($fetchedQuiz->questions->count() > 0);
|
||||||
$firstQuestion = $fetchedQuiz->questions->first();
|
$firstQuestion = $fetchedQuiz->questions->first();
|
||||||
|
\assert($firstQuestion instanceof Question);
|
||||||
|
|
||||||
return $this->redirectToRoute('tvdt_backoffice_quiz_candidates_question', [
|
return $this->redirectToRoute('tvdt_backoffice_quiz_candidates_question', [
|
||||||
'seasonCode' => $season->seasonCode,
|
'seasonCode' => $season->seasonCode,
|
||||||
@@ -264,7 +265,7 @@ class QuizController extends AbstractController
|
|||||||
'candidate' => $candidate,
|
'candidate' => $candidate,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
if (!$quizCandidate instanceof \Tvdt\Entity\QuizCandidate) {
|
if (!$quizCandidate instanceof QuizCandidate) {
|
||||||
// Create new QuizCandidate if it doesn't exist (inactive by default when first toggling)
|
// Create new QuizCandidate if it doesn't exist (inactive by default when first toggling)
|
||||||
$quizCandidate = new QuizCandidate($quiz, $candidate);
|
$quizCandidate = new QuizCandidate($quiz, $candidate);
|
||||||
$quizCandidate->active = false;
|
$quizCandidate->active = false;
|
||||||
|
|||||||
+3
-3
@@ -155,9 +155,9 @@ class Quiz
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($missing !== [] || $duplicates !== []) {
|
if ([] !== $missing || [] !== $duplicates) {
|
||||||
$errors = [];
|
$errors = [];
|
||||||
if ($missing !== []) {
|
if ([] !== $missing) {
|
||||||
// If all active candidates are missing, show a special message
|
// If all active candidates are missing, show a special message
|
||||||
if (\count($missing) === \count($activeCandidates)) {
|
if (\count($missing) === \count($activeCandidates)) {
|
||||||
$errors[] = 'No candidates assigned to this question';
|
$errors[] = 'No candidates assigned to this question';
|
||||||
@@ -166,7 +166,7 @@ class Quiz
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($duplicates !== []) {
|
if ([] !== $duplicates) {
|
||||||
$errors[] = 'Duplicate candidates: '.implode(', ', $duplicates);
|
$errors[] = 'Duplicate candidates: '.implode(', ', $duplicates);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ namespace Tvdt\Repository;
|
|||||||
|
|
||||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||||
use Doctrine\Persistence\ManagerRegistry;
|
use Doctrine\Persistence\ManagerRegistry;
|
||||||
|
use Safe\DateTimeImmutable;
|
||||||
use Tvdt\Entity\Candidate;
|
use Tvdt\Entity\Candidate;
|
||||||
use Tvdt\Entity\Quiz;
|
use Tvdt\Entity\Quiz;
|
||||||
use Tvdt\Entity\QuizCandidate;
|
use Tvdt\Entity\QuizCandidate;
|
||||||
@@ -33,7 +34,7 @@ class QuizCandidateRepository extends ServiceEntityRepository
|
|||||||
|
|
||||||
// If QuizCandidate exists but hasn't started yet, set the started timestamp
|
// If QuizCandidate exists but hasn't started yet, set the started timestamp
|
||||||
if (null === $quizCandidate->started) {
|
if (null === $quizCandidate->started) {
|
||||||
$quizCandidate->started = new \DateTimeImmutable();
|
$quizCandidate->started = new DateTimeImmutable();
|
||||||
$this->getEntityManager()->flush();
|
$this->getEntityManager()->flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -41,7 +42,7 @@ class QuizCandidateRepository extends ServiceEntityRepository
|
|||||||
}
|
}
|
||||||
|
|
||||||
$quizCandidate = new QuizCandidate($quiz, $candidate);
|
$quizCandidate = new QuizCandidate($quiz, $candidate);
|
||||||
$quizCandidate->started = new \Safe\DateTimeImmutable();
|
$quizCandidate->started = new DateTimeImmutable();
|
||||||
$this->getEntityManager()->persist($quizCandidate);
|
$this->getEntityManager()->persist($quizCandidate);
|
||||||
$this->getEntityManager()->flush();
|
$this->getEntityManager()->flush();
|
||||||
|
|
||||||
|
|||||||
@@ -96,15 +96,19 @@ class QuizRepository extends ServiceEntityRepository
|
|||||||
DQL
|
DQL
|
||||||
)->setParameter('quiz', $quiz)->getResult();
|
)->setParameter('quiz', $quiz)->getResult();
|
||||||
|
|
||||||
return array_map(static fn (array $row): Result => new Result(
|
return array_map(static function (array $row): Result {
|
||||||
id: $row['id'],
|
\assert($row['start_time'] instanceof \DateTimeImmutable);
|
||||||
name: $row['name'],
|
|
||||||
correct: (int) $row['correct'],
|
return new Result(
|
||||||
corrections: $row['corrections'],
|
id: $row['id'],
|
||||||
penaltySeconds: $row['penaltySeconds'],
|
name: $row['name'],
|
||||||
time: $row['start_time']->diff(new DateTimeImmutable($row['end_time'])),
|
correct: (int) $row['correct'],
|
||||||
score: $row['score'],
|
corrections: $row['corrections'],
|
||||||
), $result);
|
penaltySeconds: $row['penaltySeconds'],
|
||||||
|
time: $row['start_time']->diff(new DateTimeImmutable($row['end_time'])),
|
||||||
|
score: $row['score'],
|
||||||
|
);
|
||||||
|
}, $result);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function fetchWithQuestions(Uuid $id): Quiz
|
public function fetchWithQuestions(Uuid $id): Quiz
|
||||||
|
|||||||
Reference in New Issue
Block a user