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/
|
||||
- src/
|
||||
- tests/
|
||||
excludePaths:
|
||||
- config/reference.php
|
||||
treatPhpDocTypesAsCertain: false
|
||||
symfony:
|
||||
containerXmlPath: var/cache/dev/Tvdt_KernelDevDebugContainer.xml
|
||||
|
||||
@@ -96,6 +96,7 @@ class QuizController extends AbstractController
|
||||
$fetchedQuiz = $this->quizRepository->fetchWithQuestions($quiz->id);
|
||||
\assert($fetchedQuiz->questions->count() > 0);
|
||||
$firstQuestion = $fetchedQuiz->questions->first();
|
||||
\assert($firstQuestion instanceof Question);
|
||||
|
||||
return $this->redirectToRoute('tvdt_backoffice_quiz_candidates_question', [
|
||||
'seasonCode' => $season->seasonCode,
|
||||
@@ -264,7 +265,7 @@ class QuizController extends AbstractController
|
||||
'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)
|
||||
$quizCandidate = new QuizCandidate($quiz, $candidate);
|
||||
$quizCandidate->active = false;
|
||||
|
||||
+3
-3
@@ -155,9 +155,9 @@ class Quiz
|
||||
}
|
||||
}
|
||||
|
||||
if ($missing !== [] || $duplicates !== []) {
|
||||
if ([] !== $missing || [] !== $duplicates) {
|
||||
$errors = [];
|
||||
if ($missing !== []) {
|
||||
if ([] !== $missing) {
|
||||
// If all active candidates are missing, show a special message
|
||||
if (\count($missing) === \count($activeCandidates)) {
|
||||
$errors[] = 'No candidates assigned to this question';
|
||||
@@ -166,7 +166,7 @@ class Quiz
|
||||
}
|
||||
}
|
||||
|
||||
if ($duplicates !== []) {
|
||||
if ([] !== $duplicates) {
|
||||
$errors[] = 'Duplicate candidates: '.implode(', ', $duplicates);
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ namespace Tvdt\Repository;
|
||||
|
||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
use Safe\DateTimeImmutable;
|
||||
use Tvdt\Entity\Candidate;
|
||||
use Tvdt\Entity\Quiz;
|
||||
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 (null === $quizCandidate->started) {
|
||||
$quizCandidate->started = new \DateTimeImmutable();
|
||||
$quizCandidate->started = new DateTimeImmutable();
|
||||
$this->getEntityManager()->flush();
|
||||
}
|
||||
|
||||
@@ -41,7 +42,7 @@ class QuizCandidateRepository extends ServiceEntityRepository
|
||||
}
|
||||
|
||||
$quizCandidate = new QuizCandidate($quiz, $candidate);
|
||||
$quizCandidate->started = new \Safe\DateTimeImmutable();
|
||||
$quizCandidate->started = new DateTimeImmutable();
|
||||
$this->getEntityManager()->persist($quizCandidate);
|
||||
$this->getEntityManager()->flush();
|
||||
|
||||
|
||||
@@ -96,7 +96,10 @@ class QuizRepository extends ServiceEntityRepository
|
||||
DQL
|
||||
)->setParameter('quiz', $quiz)->getResult();
|
||||
|
||||
return array_map(static fn (array $row): Result => new Result(
|
||||
return array_map(static function (array $row): Result {
|
||||
\assert($row['start_time'] instanceof \DateTimeImmutable);
|
||||
|
||||
return new Result(
|
||||
id: $row['id'],
|
||||
name: $row['name'],
|
||||
correct: (int) $row['correct'],
|
||||
@@ -104,7 +107,8 @@ class QuizRepository extends ServiceEntityRepository
|
||||
penaltySeconds: $row['penaltySeconds'],
|
||||
time: $row['start_time']->diff(new DateTimeImmutable($row['end_time'])),
|
||||
score: $row['score'],
|
||||
), $result);
|
||||
);
|
||||
}, $result);
|
||||
}
|
||||
|
||||
public function fetchWithQuestions(Uuid $id): Quiz
|
||||
|
||||
Reference in New Issue
Block a user