From ca460cca7f797affcbcafdab82c35acf16e912b8 Mon Sep 17 00:00:00 2001 From: Marijn Doeve Date: Sat, 4 Oct 2025 12:40:45 +0200 Subject: [PATCH] - Refactor ORM annotations across entities for consistency. - Adjusted migrations to align with refactored ORM annotations. - Added new PHPStan and PHP-CS-Fixer configurations, including stricter rules. - Introduced `tests/object-manager.php` to improve test environment setup. --- .php-cs-fixer.dist.php | 7 +-- compose.override.yaml | 1 - migrations/Version20250420111904.php | 4 +- migrations/Version20250420125040.php | 4 +- migrations/Version20250427174822.php | 8 ++-- migrations/Version20250504101440.php | 8 ++-- migrations/Version20250521192752.php | 20 ++++----- migrations/Version20250521194035.php | 4 +- migrations/Version20250606192337.php | 44 +++++++++---------- migrations/Version20250606195952.php | 10 ++--- migrations/Version20250607154730.php | 8 ++-- migrations/Version20250607184525.php | 16 +++---- migrations/Version20250610210417.php | 16 +++---- phpstan.dist.neon | 4 ++ src/Controller/Backoffice/QuizController.php | 10 ++--- .../Backoffice/SeasonController.php | 6 +-- src/Controller/EliminationController.php | 4 +- src/Entity/Answer.php | 6 +-- src/Entity/Candidate.php | 6 +-- src/Entity/Elimination.php | 6 +-- src/Entity/GivenAnswer.php | 10 ++--- src/Entity/Question.php | 6 +-- src/Entity/Quiz.php | 6 +-- src/Entity/QuizCandidate.php | 10 ++--- src/Entity/Season.php | 8 ++-- src/Entity/SeasonSettings.php | 4 +- src/Entity/User.php | 4 +- src/Repository/CandidateRepository.php | 32 +++++++------- src/Repository/QuestionRepository.php | 2 +- src/Repository/SeasonRepository.php | 2 +- tests/object-manager.php | 15 +++++++ 31 files changed, 155 insertions(+), 136 deletions(-) create mode 100644 tests/object-manager.php diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php index 22b0671..0b5a012 100644 --- a/.php-cs-fixer.dist.php +++ b/.php-cs-fixer.dist.php @@ -5,13 +5,13 @@ use PhpCsFixer\Config; use PhpCsFixer\Finder; use PhpCsFixer\Runner\Parallel\ParallelConfigFactory; -$finder = (new Finder()) +$finder = new Finder() ->in(__DIR__) ->exclude('var') ->exclude('bin') ; -return (new Config()) +return new Config() ->setParallelConfig(ParallelConfigFactory::detect()) ->setRules([ '@Symfony' => true, @@ -30,8 +30,9 @@ return (new Config()) 'single_line_empty_body' => true, 'strict_comparison' => true, 'strict_param' => true, + 'ordered_attributes' => true, + 'heredoc_indentation' => ['indentation' => 'start_plus_one'], 'trailing_comma_in_multiline' => ['after_heredoc' => true, 'elements' => ['arguments', 'array_destructuring', 'arrays', 'match', 'parameters']], - ]) ->setRiskyAllowed(true) ->setFinder($finder) diff --git a/compose.override.yaml b/compose.override.yaml index 9b0554e..65cb06d 100644 --- a/compose.override.yaml +++ b/compose.override.yaml @@ -15,7 +15,6 @@ services: # See https://xdebug.org/docs/all_settings#mode XDEBUG_MODE: "${XDEBUG_MODE:-off}" MAILER_DSN: "smtp://mailer:1025" - PHP_CS_FIXER_IGNORE_ENV: 1 extra_hosts: # Ensure that host.docker.internal is correctly defined on Linux - host.docker.internal:host-gateway diff --git a/migrations/Version20250420111904.php b/migrations/Version20250420111904.php index 2b664eb..b3db085 100644 --- a/migrations/Version20250420111904.php +++ b/migrations/Version20250420111904.php @@ -18,13 +18,13 @@ final class Version20250420111904 extends AbstractMigration { $this->addSql(<<<'SQL' ALTER TABLE "user" ADD is_verified BOOLEAN NOT NULL - SQL); + SQL); } public function down(Schema $schema): void { $this->addSql(<<<'SQL' ALTER TABLE "user" DROP is_verified - SQL); + SQL); } } diff --git a/migrations/Version20250420125040.php b/migrations/Version20250420125040.php index 2103f0e..fb1d52c 100644 --- a/migrations/Version20250420125040.php +++ b/migrations/Version20250420125040.php @@ -18,13 +18,13 @@ final class Version20250420125040 extends AbstractMigration { $this->addSql(<<<'SQL' ALTER TABLE season DROP preregister_candidates - SQL); + SQL); } public function down(Schema $schema): void { $this->addSql(<<<'SQL' ALTER TABLE season ADD preregister_candidates BOOLEAN NOT NULL DEFAULT true - SQL); + SQL); } } diff --git a/migrations/Version20250427174822.php b/migrations/Version20250427174822.php index 94eef38..5685b68 100644 --- a/migrations/Version20250427174822.php +++ b/migrations/Version20250427174822.php @@ -22,10 +22,10 @@ final class Version20250427174822 extends AbstractMigration // this up() migration is auto-generated, please modify it to your needs $this->addSql(<<<'SQL' ALTER TABLE answer ADD ordering SMALLINT DEFAULT 0 NOT NULL - SQL); + SQL); $this->addSql(<<<'SQL' ALTER TABLE question ADD ordering SMALLINT DEFAULT 0 NOT NULL - SQL); + SQL); } public function down(Schema $schema): void @@ -33,9 +33,9 @@ final class Version20250427174822 extends AbstractMigration // this down() migration is auto-generated, please modify it to your needs $this->addSql(<<<'SQL' ALTER TABLE answer DROP ordering - SQL); + SQL); $this->addSql(<<<'SQL' ALTER TABLE question DROP ordering - SQL); + SQL); } } diff --git a/migrations/Version20250504101440.php b/migrations/Version20250504101440.php index 0098984..d8aed42 100644 --- a/migrations/Version20250504101440.php +++ b/migrations/Version20250504101440.php @@ -22,10 +22,10 @@ final class Version20250504101440 extends AbstractMigration // this up() migration is auto-generated, please modify it to your needs $this->addSql(<<<'SQL' CREATE UNIQUE INDEX UNIQ_C8B28E445E237E064EC001D1 ON candidate (name, season_id) - SQL); + SQL); $this->addSql(<<<'SQL' CREATE UNIQUE INDEX UNIQ_A412FA925E237E064EC001D1 ON quiz (name, season_id) - SQL); + SQL); } public function down(Schema $schema): void @@ -33,9 +33,9 @@ final class Version20250504101440 extends AbstractMigration // this down() migration is auto-generated, please modify it to your needs $this->addSql(<<<'SQL' DROP INDEX UNIQ_A412FA925E237E064EC001D1 - SQL); + SQL); $this->addSql(<<<'SQL' DROP INDEX UNIQ_C8B28E445E237E064EC001D1 - SQL); + SQL); } } diff --git a/migrations/Version20250521192752.php b/migrations/Version20250521192752.php index 3cc06b4..522e6d2 100644 --- a/migrations/Version20250521192752.php +++ b/migrations/Version20250521192752.php @@ -18,37 +18,37 @@ final class Version20250521192752 extends AbstractMigration { $this->addSql(<<<'SQL' ALTER TABLE elimination ADD quiz_id UUID NOT NULL - SQL); + SQL); $this->addSql(<<<'SQL' ALTER TABLE elimination ADD CONSTRAINT FK_5947284F853CD175 FOREIGN KEY (quiz_id) REFERENCES quiz (id) NOT DEFERRABLE INITIALLY IMMEDIATE - SQL); + SQL); $this->addSql(<<<'SQL' CREATE INDEX IDX_5947284F853CD175 ON elimination (quiz_id) - SQL); + SQL); $this->addSql(<<<'SQL' ALTER TABLE quiz ALTER dropouts SET DEFAULT 1 - SQL); + SQL); $this->addSql(<<<'SQL' ALTER TABLE quiz ALTER dropouts SET NOT NULL - SQL); + SQL); } public function down(Schema $schema): void { $this->addSql(<<<'SQL' ALTER TABLE quiz ALTER dropouts DROP DEFAULT - SQL); + SQL); $this->addSql(<<<'SQL' ALTER TABLE quiz ALTER dropouts DROP NOT NULL - SQL); + SQL); $this->addSql(<<<'SQL' ALTER TABLE elimination DROP CONSTRAINT FK_5947284F853CD175 - SQL); + SQL); $this->addSql(<<<'SQL' DROP INDEX IDX_5947284F853CD175 - SQL); + SQL); $this->addSql(<<<'SQL' ALTER TABLE elimination DROP quiz_id - SQL); + SQL); } } diff --git a/migrations/Version20250521194035.php b/migrations/Version20250521194035.php index e11083d..6abc6c5 100644 --- a/migrations/Version20250521194035.php +++ b/migrations/Version20250521194035.php @@ -18,7 +18,7 @@ final class Version20250521194035 extends AbstractMigration { $this->addSql(<<<'SQL' ALTER TABLE elimination ADD created TIMESTAMP(0) WITHOUT TIME ZONE - SQL); + SQL); $this->addSql(<<<'SQL' UPDATE elimination SET created = NOW() SQL @@ -33,6 +33,6 @@ final class Version20250521194035 extends AbstractMigration { $this->addSql(<<<'SQL' ALTER TABLE elimination DROP created - SQL); + SQL); } } diff --git a/migrations/Version20250606192337.php b/migrations/Version20250606192337.php index 0ce244b..3a81ccd 100644 --- a/migrations/Version20250606192337.php +++ b/migrations/Version20250606192337.php @@ -18,73 +18,73 @@ final class Version20250606192337 extends AbstractMigration { $this->addSql(<<<'SQL' CREATE TABLE quiz_candidate (id UUID NOT NULL, corrections DOUBLE PRECISION NOT NULL, created TIMESTAMP(0) WITH TIME ZONE NOT NULL, quiz_id UUID NOT NULL, candidate_id UUID NOT NULL, PRIMARY KEY(id)) - SQL); + SQL); $this->addSql(<<<'SQL' CREATE INDEX IDX_CED2FFA2853CD175 ON quiz_candidate (quiz_id) - SQL); + SQL); $this->addSql(<<<'SQL' CREATE INDEX IDX_CED2FFA291BD8781 ON quiz_candidate (candidate_id) - SQL); + SQL); $this->addSql(<<<'SQL' CREATE UNIQUE INDEX UNIQ_CED2FFA291BD8781853CD175 ON quiz_candidate (candidate_id, quiz_id) - SQL); + SQL); $this->addSql(<<<'SQL' ALTER TABLE quiz_candidate ADD CONSTRAINT FK_CED2FFA2853CD175 FOREIGN KEY (quiz_id) REFERENCES quiz (id) NOT DEFERRABLE INITIALLY IMMEDIATE - SQL); + SQL); $this->addSql(<<<'SQL' ALTER TABLE quiz_candidate ADD CONSTRAINT FK_CED2FFA291BD8781 FOREIGN KEY (candidate_id) REFERENCES candidate (id) NOT DEFERRABLE INITIALLY IMMEDIATE - SQL); + SQL); $this->addSql(<<<'SQL' ALTER TABLE correction DROP CONSTRAINT fk_a29da1b891bd8781 - SQL); + SQL); $this->addSql(<<<'SQL' ALTER TABLE correction DROP CONSTRAINT fk_a29da1b8853cd175 - SQL); + SQL); $this->addSql(<<<'SQL' DROP TABLE correction - SQL); + SQL); $this->addSql(<<<'SQL' ALTER TABLE elimination ALTER created TYPE TIMESTAMP(0) WITH TIME ZONE - SQL); + SQL); $this->addSql(<<<'SQL' ALTER TABLE given_answer ALTER created TYPE TIMESTAMP(0) WITH TIME ZONE - SQL); + SQL); } public function down(Schema $schema): void { $this->addSql(<<<'SQL' CREATE TABLE correction (id UUID NOT NULL, candidate_id UUID NOT NULL, quiz_id UUID NOT NULL, amount DOUBLE PRECISION NOT NULL, PRIMARY KEY(id)) - SQL); + SQL); $this->addSql(<<<'SQL' CREATE UNIQUE INDEX uniq_a29da1b891bd8781853cd175 ON correction (candidate_id, quiz_id) - SQL); + SQL); $this->addSql(<<<'SQL' CREATE INDEX idx_a29da1b8853cd175 ON correction (quiz_id) - SQL); + SQL); $this->addSql(<<<'SQL' CREATE INDEX idx_a29da1b891bd8781 ON correction (candidate_id) - SQL); + SQL); $this->addSql(<<<'SQL' ALTER TABLE correction ADD CONSTRAINT fk_a29da1b891bd8781 FOREIGN KEY (candidate_id) REFERENCES candidate (id) NOT DEFERRABLE INITIALLY IMMEDIATE - SQL); + SQL); $this->addSql(<<<'SQL' ALTER TABLE correction ADD CONSTRAINT fk_a29da1b8853cd175 FOREIGN KEY (quiz_id) REFERENCES quiz (id) NOT DEFERRABLE INITIALLY IMMEDIATE - SQL); + SQL); $this->addSql(<<<'SQL' ALTER TABLE quiz_candidate DROP CONSTRAINT FK_CED2FFA2853CD175 - SQL); + SQL); $this->addSql(<<<'SQL' ALTER TABLE quiz_candidate DROP CONSTRAINT FK_CED2FFA291BD8781 - SQL); + SQL); $this->addSql(<<<'SQL' DROP TABLE quiz_candidate - SQL); + SQL); $this->addSql(<<<'SQL' ALTER TABLE given_answer ALTER created TYPE TIMESTAMP(0) WITHOUT TIME ZONE - SQL); + SQL); $this->addSql(<<<'SQL' ALTER TABLE elimination ALTER created TYPE TIMESTAMP(0) WITHOUT TIME ZONE - SQL); + SQL); } } diff --git a/migrations/Version20250606195952.php b/migrations/Version20250606195952.php index f0aa594..cb97de6 100644 --- a/migrations/Version20250606195952.php +++ b/migrations/Version20250606195952.php @@ -21,22 +21,22 @@ final class Version20250606195952 extends AbstractMigration { $this->addSql(<<<'SQL' delete from given_answer where answer_id is null - SQL); + SQL); $this->addSql(<<<'SQL' ALTER TABLE given_answer ALTER answer_id TYPE UUID - SQL); + SQL); $this->addSql(<<<'SQL' ALTER TABLE given_answer ALTER answer_id SET NOT NULL - SQL); + SQL); } public function down(Schema $schema): void { $this->addSql(<<<'SQL' ALTER TABLE given_answer ALTER answer_id TYPE UUID - SQL); + SQL); $this->addSql(<<<'SQL' ALTER TABLE given_answer ALTER answer_id DROP NOT NULL - SQL); + SQL); } } diff --git a/migrations/Version20250607154730.php b/migrations/Version20250607154730.php index 4c3868d..e37f53d 100644 --- a/migrations/Version20250607154730.php +++ b/migrations/Version20250607154730.php @@ -22,10 +22,10 @@ final class Version20250607154730 extends AbstractMigration // this up() migration is auto-generated, please modify it to your needs $this->addSql(<<<'SQL' ALTER TABLE season DROP CONSTRAINT FK_F0E45BA96706D6B - SQL); + SQL); $this->addSql(<<<'SQL' ALTER TABLE season ADD CONSTRAINT FK_F0E45BA96706D6B FOREIGN KEY (active_quiz_id) REFERENCES quiz (id) ON DELETE SET NULL NOT DEFERRABLE INITIALLY IMMEDIATE - SQL); + SQL); } public function down(Schema $schema): void @@ -33,9 +33,9 @@ final class Version20250607154730 extends AbstractMigration // this down() migration is auto-generated, please modify it to your needs $this->addSql(<<<'SQL' ALTER TABLE season DROP CONSTRAINT fk_f0e45ba96706d6b - SQL); + SQL); $this->addSql(<<<'SQL' ALTER TABLE season ADD CONSTRAINT fk_f0e45ba96706d6b FOREIGN KEY (active_quiz_id) REFERENCES quiz (id) NOT DEFERRABLE INITIALLY IMMEDIATE - SQL); + SQL); } } diff --git a/migrations/Version20250607184525.php b/migrations/Version20250607184525.php index 11d7366..ed3149b 100644 --- a/migrations/Version20250607184525.php +++ b/migrations/Version20250607184525.php @@ -22,16 +22,16 @@ final class Version20250607184525 extends AbstractMigration // this up() migration is auto-generated, please modify it to your needs $this->addSql(<<<'SQL' ALTER TABLE elimination DROP CONSTRAINT FK_5947284F853CD175 - SQL); + SQL); $this->addSql(<<<'SQL' ALTER TABLE elimination ADD CONSTRAINT FK_5947284F853CD175 FOREIGN KEY (quiz_id) REFERENCES quiz (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE - SQL); + SQL); $this->addSql(<<<'SQL' ALTER TABLE given_answer DROP CONSTRAINT FK_9AC61A30853CD175 - SQL); + SQL); $this->addSql(<<<'SQL' ALTER TABLE given_answer ADD CONSTRAINT FK_9AC61A30853CD175 FOREIGN KEY (quiz_id) REFERENCES quiz (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE - SQL); + SQL); } public function down(Schema $schema): void @@ -39,15 +39,15 @@ final class Version20250607184525 extends AbstractMigration // this down() migration is auto-generated, please modify it to your needs $this->addSql(<<<'SQL' ALTER TABLE given_answer DROP CONSTRAINT fk_9ac61a30853cd175 - SQL); + SQL); $this->addSql(<<<'SQL' ALTER TABLE given_answer ADD CONSTRAINT fk_9ac61a30853cd175 FOREIGN KEY (quiz_id) REFERENCES quiz (id) NOT DEFERRABLE INITIALLY IMMEDIATE - SQL); + SQL); $this->addSql(<<<'SQL' ALTER TABLE elimination DROP CONSTRAINT fk_5947284f853cd175 - SQL); + SQL); $this->addSql(<<<'SQL' ALTER TABLE elimination ADD CONSTRAINT fk_5947284f853cd175 FOREIGN KEY (quiz_id) REFERENCES quiz (id) NOT DEFERRABLE INITIALLY IMMEDIATE - SQL); + SQL); } } diff --git a/migrations/Version20250610210417.php b/migrations/Version20250610210417.php index 83f6260..8e71b21 100644 --- a/migrations/Version20250610210417.php +++ b/migrations/Version20250610210417.php @@ -18,31 +18,31 @@ final class Version20250610210417 extends AbstractMigration { $this->addSql(<<<'SQL' CREATE TABLE season_settings (id UUID NOT NULL, show_numbers BOOLEAN DEFAULT false NOT NULL, confirm_answers BOOLEAN DEFAULT false NOT NULL, PRIMARY KEY(id)) - SQL); + SQL); $this->addSql(<<<'SQL' ALTER TABLE season ADD settings_id UUID DEFAULT NULL - SQL); + SQL); $this->addSql(<<<'SQL' ALTER TABLE season ADD CONSTRAINT FK_F0E45BA959949888 FOREIGN KEY (settings_id) REFERENCES season_settings (id) NOT DEFERRABLE INITIALLY IMMEDIATE - SQL); + SQL); $this->addSql(<<<'SQL' CREATE UNIQUE INDEX UNIQ_F0E45BA959949888 ON season (settings_id) - SQL); + SQL); } public function down(Schema $schema): void { $this->addSql(<<<'SQL' DROP TABLE season_settings - SQL); + SQL); $this->addSql(<<<'SQL' ALTER TABLE season DROP CONSTRAINT FK_F0E45BA959949888 - SQL); + SQL); $this->addSql(<<<'SQL' DROP INDEX UNIQ_F0E45BA959949888 - SQL); + SQL); $this->addSql(<<<'SQL' ALTER TABLE season DROP settings_id - SQL); + SQL); } } diff --git a/phpstan.dist.neon b/phpstan.dist.neon index 87d6918..149767b 100644 --- a/phpstan.dist.neon +++ b/phpstan.dist.neon @@ -8,3 +8,7 @@ parameters: - src/ - tests/ treatPhpDocTypesAsCertain: false + symfony: + containerXmlPath: var/cache/dev/Tvdt_KernelDevDebugContainer.xml + doctrine: + objectManagerLoader: tests/object-manager.php diff --git a/src/Controller/Backoffice/QuizController.php b/src/Controller/Backoffice/QuizController.php index 0bb1e88..d1726fe 100644 --- a/src/Controller/Backoffice/QuizController.php +++ b/src/Controller/Backoffice/QuizController.php @@ -33,12 +33,12 @@ class QuizController extends AbstractController private readonly TranslatorInterface $translator, ) {} + #[IsGranted(SeasonVoter::EDIT, subject: 'season')] #[Route( '/backoffice/season/{seasonCode:season}/quiz/{quiz}', name: 'tvdt_backoffice_quiz', requirements: ['seasonCode' => self::SEASON_CODE_REGEX, 'quiz' => Requirement::UUID], )] - #[IsGranted(SeasonVoter::EDIT, subject: 'season')] public function index(Season $season, Quiz $quiz): Response { return $this->render('backoffice/quiz.html.twig', [ @@ -48,12 +48,12 @@ class QuizController extends AbstractController ]); } + #[IsGranted(SeasonVoter::EDIT, subject: 'season')] #[Route( '/backoffice/season/{seasonCode:season}/quiz/{quiz}/enable', name: 'tvdt_backoffice_enable', requirements: ['seasonCode' => self::SEASON_CODE_REGEX, 'quiz' => Requirement::UUID.'|null'], )] - #[IsGranted(SeasonVoter::EDIT, subject: 'season')] public function enableQuiz(Season $season, ?Quiz $quiz, EntityManagerInterface $em): RedirectResponse { $season->setActiveQuiz($quiz); @@ -66,12 +66,12 @@ class QuizController extends AbstractController return $this->redirectToRoute('tvdt_backoffice_season', ['seasonCode' => $season->getSeasonCode()]); } + #[IsGranted(SeasonVoter::EDIT, subject: 'quiz')] #[Route( '/backoffice/quiz/{quiz}/clear', name: 'tvdt_backoffice_quiz_clear', requirements: ['quiz' => Requirement::UUID], )] - #[IsGranted(SeasonVoter::EDIT, subject: 'quiz')] public function clearQuiz(Quiz $quiz, QuizRepository $quizRepository): RedirectResponse { try { @@ -84,12 +84,12 @@ class QuizController extends AbstractController return $this->redirectToRoute('tvdt_backoffice_quiz', ['seasonCode' => $quiz->getSeason()->getSeasonCode(), 'quiz' => $quiz->getId()]); } + #[IsGranted(SeasonVoter::DELETE, subject: 'quiz')] #[Route( '/backoffice/quiz/{quiz}/delete', name: 'tvdt_backoffice_quiz_delete', requirements: ['quiz' => Requirement::UUID], )] - #[IsGranted(SeasonVoter::DELETE, subject: 'quiz')] public function deleteQuiz(Quiz $quiz, QuizRepository $quizRepository): RedirectResponse { $quizRepository->deleteQuiz($quiz); @@ -99,12 +99,12 @@ class QuizController extends AbstractController return $this->redirectToRoute('tvdt_backoffice_season', ['seasonCode' => $quiz->getSeason()->getSeasonCode()]); } + #[IsGranted(SeasonVoter::EDIT, subject: 'quiz')] #[Route( '/backoffice/quiz/{quiz}/candidate/{candidate}/modify_correction', name: 'tvdt_backoffice_modify_correction', requirements: ['quiz' => Requirement::UUID, 'candidate' => Requirement::UUID], )] - #[IsGranted(SeasonVoter::EDIT, subject: 'quiz')] public function modifyCorrection(Quiz $quiz, Candidate $candidate, QuizCandidateRepository $quizCandidateRepository, Request $request): RedirectResponse { if (!$request->isMethod('POST')) { diff --git a/src/Controller/Backoffice/SeasonController.php b/src/Controller/Backoffice/SeasonController.php index 862db9e..2691edc 100644 --- a/src/Controller/Backoffice/SeasonController.php +++ b/src/Controller/Backoffice/SeasonController.php @@ -32,12 +32,12 @@ class SeasonController extends AbstractController private readonly EntityManagerInterface $em, ) {} + #[IsGranted(SeasonVoter::EDIT, subject: 'season')] #[Route( '/backoffice/season/{seasonCode:season}', name: 'tvdt_backoffice_season', requirements: ['seasonCode' => self::SEASON_CODE_REGEX], )] - #[IsGranted(SeasonVoter::EDIT, subject: 'season')] public function index(Season $season, Request $request): Response { $form = $this->createForm(SettingsForm::class, $season->getSettings()); @@ -54,13 +54,13 @@ class SeasonController extends AbstractController ]); } + #[IsGranted(SeasonVoter::EDIT, subject: 'season')] #[Route( '/backoffice/season/{seasonCode:season}/add-candidate', name: 'tvdt_backoffice_add_candidates', requirements: ['seasonCode' => self::SEASON_CODE_REGEX], priority: 10, )] - #[IsGranted(SeasonVoter::EDIT, subject: 'season')] public function addCandidates(Season $season, Request $request): Response { $form = $this->createForm(AddCandidatesFormType::class); @@ -80,13 +80,13 @@ class SeasonController extends AbstractController return $this->render('backoffice/season_add_candidates.html.twig', ['form' => $form]); } + #[IsGranted(SeasonVoter::EDIT, subject: 'season')] #[Route( '/backoffice/season/{seasonCode:season}/add-quiz', name: 'tvdt_backoffice_quiz_add', requirements: ['seasonCode' => self::SEASON_CODE_REGEX], priority: 10, )] - #[IsGranted(SeasonVoter::EDIT, subject: 'season')] public function addQuiz(Request $request, Season $season, QuizSpreadsheetService $quizSpreadsheet): Response { $quiz = new Quiz(); diff --git a/src/Controller/EliminationController.php b/src/Controller/EliminationController.php index 1573b5c..9e662aa 100644 --- a/src/Controller/EliminationController.php +++ b/src/Controller/EliminationController.php @@ -28,8 +28,8 @@ final class EliminationController extends AbstractController { public function __construct(private readonly TranslatorInterface $translator) {} - #[Route('/elimination/{elimination}', name: 'tvdt_elimination', requirements: ['elimination' => Requirement::UUID])] #[IsGranted(SeasonVoter::ELIMINATION, 'elimination')] + #[Route('/elimination/{elimination}', name: 'tvdt_elimination', requirements: ['elimination' => Requirement::UUID])] public function index(#[MapEntity] Elimination $elimination, Request $request): Response { $form = $this->createForm(EliminationEnterNameType::class); @@ -48,8 +48,8 @@ final class EliminationController extends AbstractController ]); } - #[Route('/elimination/{elimination}/{candidateHash}', name: 'tvdt_elimination_candidate', requirements: ['elimination' => Requirement::UUID, 'candidateHash' => self::CANDIDATE_HASH_REGEX])] #[IsGranted(SeasonVoter::ELIMINATION, 'elimination')] + #[Route('/elimination/{elimination}/{candidateHash}', name: 'tvdt_elimination_candidate', requirements: ['elimination' => Requirement::UUID, 'candidateHash' => self::CANDIDATE_HASH_REGEX])] public function candidateScreen(Elimination $elimination, string $candidateHash, CandidateRepository $candidateRepository): Response { $candidate = $candidateRepository->getCandidateByHash($elimination->getQuiz()->getSeason(), $candidateHash); diff --git a/src/Entity/Answer.php b/src/Entity/Answer.php index ba5d93e..e7bea03 100644 --- a/src/Entity/Answer.php +++ b/src/Entity/Answer.php @@ -16,17 +16,17 @@ use Tvdt\Repository\AnswerRepository; #[ORM\Entity(repositoryClass: AnswerRepository::class)] class Answer { - #[ORM\Id] #[ORM\Column(type: UuidType::NAME)] - #[ORM\GeneratedValue(strategy: 'CUSTOM')] #[ORM\CustomIdGenerator(class: UuidGenerator::class)] + #[ORM\GeneratedValue(strategy: 'CUSTOM')] + #[ORM\Id] private Uuid $id; #[ORM\Column(type: Types::SMALLINT, options: ['default' => 0])] private int $ordering = 0; - #[ORM\ManyToOne(inversedBy: 'answers')] #[ORM\JoinColumn(nullable: false)] + #[ORM\ManyToOne(inversedBy: 'answers')] private Question $question; /** @var Collection */ diff --git a/src/Entity/Candidate.php b/src/Entity/Candidate.php index 558deea..d52a319 100644 --- a/src/Entity/Candidate.php +++ b/src/Entity/Candidate.php @@ -17,14 +17,14 @@ use Tvdt\Repository\CandidateRepository; #[ORM\UniqueConstraint(fields: ['name', 'season'])] class Candidate { - #[ORM\Id] #[ORM\Column(type: UuidType::NAME, unique: true)] - #[ORM\GeneratedValue(strategy: 'CUSTOM')] #[ORM\CustomIdGenerator(class: UuidGenerator::class)] + #[ORM\GeneratedValue(strategy: 'CUSTOM')] + #[ORM\Id] private Uuid $id; - #[ORM\ManyToOne(inversedBy: 'candidates')] #[ORM\JoinColumn(nullable: false)] + #[ORM\ManyToOne(inversedBy: 'candidates')] private Season $season; /** @var Collection */ diff --git a/src/Entity/Elimination.php b/src/Entity/Elimination.php index 521ce36..1761402 100644 --- a/src/Entity/Elimination.php +++ b/src/Entity/Elimination.php @@ -21,10 +21,10 @@ class Elimination public const string SCREEN_RED = 'red'; - #[ORM\Id] #[ORM\Column(type: UuidType::NAME, unique: true)] - #[ORM\GeneratedValue(strategy: 'CUSTOM')] #[ORM\CustomIdGenerator(class: UuidGenerator::class)] + #[ORM\GeneratedValue(strategy: 'CUSTOM')] + #[ORM\Id] private Uuid $id; /** @var array */ @@ -35,8 +35,8 @@ class Elimination private \DateTimeImmutable $created; public function __construct( - #[ORM\ManyToOne(inversedBy: 'eliminations')] #[ORM\JoinColumn(nullable: false, onDelete: 'CASCADE')] + #[ORM\ManyToOne(inversedBy: 'eliminations')] private Quiz $quiz, ) {} diff --git a/src/Entity/GivenAnswer.php b/src/Entity/GivenAnswer.php index f0c3fec..aec5122 100644 --- a/src/Entity/GivenAnswer.php +++ b/src/Entity/GivenAnswer.php @@ -16,26 +16,26 @@ use Tvdt\Repository\GivenAnswerRepository; #[ORM\HasLifecycleCallbacks] class GivenAnswer { - #[ORM\Id] #[ORM\Column(type: UuidType::NAME, unique: true)] - #[ORM\GeneratedValue(strategy: 'CUSTOM')] #[ORM\CustomIdGenerator(class: UuidGenerator::class)] + #[ORM\GeneratedValue(strategy: 'CUSTOM')] + #[ORM\Id] private Uuid $id; #[ORM\Column(type: Types::DATETIMETZ_IMMUTABLE, nullable: false)] private \DateTimeImmutable $created; public function __construct( - #[ORM\ManyToOne(inversedBy: 'givenAnswers')] #[ORM\JoinColumn(nullable: false)] + #[ORM\ManyToOne(inversedBy: 'givenAnswers')] private Candidate $candidate, - #[ORM\ManyToOne] #[ORM\JoinColumn(nullable: false, onDelete: 'CASCADE')] + #[ORM\ManyToOne] private Quiz $quiz, - #[ORM\ManyToOne(inversedBy: 'givenAnswers')] #[ORM\JoinColumn(nullable: false)] + #[ORM\ManyToOne(inversedBy: 'givenAnswers')] private Answer $answer, ) {} diff --git a/src/Entity/Question.php b/src/Entity/Question.php index 6ca43a0..b51f48f 100644 --- a/src/Entity/Question.php +++ b/src/Entity/Question.php @@ -16,10 +16,10 @@ use Tvdt\Repository\QuestionRepository; #[ORM\Entity(repositoryClass: QuestionRepository::class)] class Question { - #[ORM\Id] #[ORM\Column(type: UuidType::NAME)] - #[ORM\GeneratedValue(strategy: 'CUSTOM')] #[ORM\CustomIdGenerator(class: UuidGenerator::class)] + #[ORM\GeneratedValue(strategy: 'CUSTOM')] + #[ORM\Id] private Uuid $id; #[ORM\Column(type: Types::SMALLINT, options: ['default' => 0])] @@ -28,8 +28,8 @@ class Question #[ORM\Column(type: Types::STRING, length: 255)] private string $question; - #[ORM\ManyToOne(inversedBy: 'questions')] #[ORM\JoinColumn(nullable: false)] + #[ORM\ManyToOne(inversedBy: 'questions')] private Quiz $quiz; #[ORM\Column] diff --git a/src/Entity/Quiz.php b/src/Entity/Quiz.php index 49848e3..7f2bc63 100644 --- a/src/Entity/Quiz.php +++ b/src/Entity/Quiz.php @@ -16,17 +16,17 @@ use Tvdt\Repository\QuizRepository; #[ORM\UniqueConstraint(fields: ['name', 'season'])] class Quiz { - #[ORM\Id] #[ORM\Column(type: UuidType::NAME)] - #[ORM\GeneratedValue(strategy: 'CUSTOM')] #[ORM\CustomIdGenerator(class: UuidGenerator::class)] + #[ORM\GeneratedValue(strategy: 'CUSTOM')] + #[ORM\Id] private Uuid $id; #[ORM\Column(length: 64)] private string $name; - #[ORM\ManyToOne(inversedBy: 'quizzes')] #[ORM\JoinColumn(nullable: false)] + #[ORM\ManyToOne(inversedBy: 'quizzes')] private Season $season; /** @var Collection */ diff --git a/src/Entity/QuizCandidate.php b/src/Entity/QuizCandidate.php index 3873133..91249bf 100644 --- a/src/Entity/QuizCandidate.php +++ b/src/Entity/QuizCandidate.php @@ -13,14 +13,14 @@ use Symfony\Component\Uid\Uuid; use Tvdt\Repository\QuizCandidateRepository; #[ORM\Entity(repositoryClass: QuizCandidateRepository::class)] -#[ORM\UniqueConstraint(columns: ['candidate_id', 'quiz_id'])] #[ORM\HasLifecycleCallbacks] +#[ORM\UniqueConstraint(columns: ['candidate_id', 'quiz_id'])] class QuizCandidate { - #[ORM\Id] #[ORM\Column(type: UuidType::NAME, unique: true)] - #[ORM\GeneratedValue(strategy: 'CUSTOM')] #[ORM\CustomIdGenerator(class: UuidGenerator::class)] + #[ORM\GeneratedValue(strategy: 'CUSTOM')] + #[ORM\Id] private Uuid $id; #[ORM\Column] @@ -30,12 +30,12 @@ class QuizCandidate private \DateTimeImmutable $created; public function __construct( - #[ORM\ManyToOne(inversedBy: 'candidateData')] #[ORM\JoinColumn(nullable: false)] + #[ORM\ManyToOne(inversedBy: 'candidateData')] private Quiz $quiz, - #[ORM\ManyToOne(inversedBy: 'quizData')] #[ORM\JoinColumn(nullable: false)] + #[ORM\ManyToOne(inversedBy: 'quizData')] private Candidate $candidate, ) {} diff --git a/src/Entity/Season.php b/src/Entity/Season.php index 6911d7c..d2579a0 100644 --- a/src/Entity/Season.php +++ b/src/Entity/Season.php @@ -17,10 +17,10 @@ class Season { private const string SEASON_CODE_CHARACTERS = 'bcdfghjklmnpqrstvwxz'; - #[ORM\Id] #[ORM\Column(type: UuidType::NAME)] - #[ORM\GeneratedValue(strategy: 'CUSTOM')] #[ORM\CustomIdGenerator(class: UuidGenerator::class)] + #[ORM\GeneratedValue(strategy: 'CUSTOM')] + #[ORM\Id] private Uuid $id; #[ORM\Column(length: 64)] @@ -42,12 +42,12 @@ class Season #[ORM\ManyToMany(targetEntity: User::class, inversedBy: 'seasons')] private Collection $owners; - #[ORM\ManyToOne] #[ORM\JoinColumn(nullable: true, onDelete: 'SET NULL')] + #[ORM\ManyToOne] private ?Quiz $ActiveQuiz = null; - #[ORM\OneToOne(cascade: ['persist', 'remove'])] #[ORM\JoinColumn(nullable: true)] + #[ORM\OneToOne(cascade: ['persist', 'remove'])] private ?SeasonSettings $settings = null; public function __construct() diff --git a/src/Entity/SeasonSettings.php b/src/Entity/SeasonSettings.php index e5bee3f..06ad685 100644 --- a/src/Entity/SeasonSettings.php +++ b/src/Entity/SeasonSettings.php @@ -14,10 +14,10 @@ use Tvdt\Repository\SeasonSettingsRepository; #[ORM\Entity(repositoryClass: SeasonSettingsRepository::class)] class SeasonSettings { - #[ORM\Id] - #[ORM\GeneratedValue(strategy: 'CUSTOM')] #[ORM\Column(type: UuidType::NAME)] #[ORM\CustomIdGenerator(class: UuidGenerator::class)] + #[ORM\GeneratedValue(strategy: 'CUSTOM')] + #[ORM\Id] private Uuid $id; #[ORM\Column(type: Types::BOOLEAN, options: ['default' => false])] diff --git a/src/Entity/User.php b/src/Entity/User.php index 87e9f2d..0882f8f 100644 --- a/src/Entity/User.php +++ b/src/Entity/User.php @@ -22,10 +22,10 @@ use Tvdt\Repository\UserRepository; #[UniqueEntity(fields: ['email'], message: 'There is already an account with this email')] class User implements UserInterface, PasswordAuthenticatedUserInterface { - #[ORM\Id] #[ORM\Column(type: UuidType::NAME, unique: true)] - #[ORM\GeneratedValue(strategy: 'CUSTOM')] #[ORM\CustomIdGenerator(class: UuidGenerator::class)] + #[ORM\GeneratedValue(strategy: 'CUSTOM')] + #[ORM\Id] private Uuid $id; #[ORM\Column(length: 180)] diff --git a/src/Repository/CandidateRepository.php b/src/Repository/CandidateRepository.php index c385a3d..d74e830 100644 --- a/src/Repository/CandidateRepository.php +++ b/src/Repository/CandidateRepository.php @@ -38,7 +38,7 @@ class CandidateRepository extends ServiceEntityRepository select c from Tvdt\Entity\Candidate c where c.season = :season and lower(c.name) = lower(:name) - DQL + DQL )->setParameter('season', $season) ->setParameter('name', $name) ->getOneOrNullResult(); @@ -57,21 +57,21 @@ class CandidateRepository extends ServiceEntityRepository public function getScores(Quiz $quiz): array { return $this->getEntityManager()->createQuery(<<setParameter('quiz', $quiz)->getResult(); } } diff --git a/src/Repository/QuestionRepository.php b/src/Repository/QuestionRepository.php index 64610fb..19335f9 100644 --- a/src/Repository/QuestionRepository.php +++ b/src/Repository/QuestionRepository.php @@ -32,7 +32,7 @@ class QuestionRepository extends ServiceEntityRepository and q1.quiz = :quiz ) and qz = :quiz - DQL) + DQL) ->setMaxResults(1) ->setParameter('candidate', $candidate) ->setParameter('quiz', $candidate->getSeason()->getActiveQuiz()) diff --git a/src/Repository/SeasonRepository.php b/src/Repository/SeasonRepository.php index b12d493..194817d 100644 --- a/src/Repository/SeasonRepository.php +++ b/src/Repository/SeasonRepository.php @@ -24,7 +24,7 @@ class SeasonRepository extends ServiceEntityRepository { return $this->getEntityManager()->createQuery(<<setParameter('user', $user)->getResult(); } } diff --git a/tests/object-manager.php b/tests/object-manager.php new file mode 100644 index 0000000..3237137 --- /dev/null +++ b/tests/object-manager.php @@ -0,0 +1,15 @@ +bootEnv(__DIR__.'/../.env'); + +$kernel = new Kernel($_SERVER['APP_ENV'], (bool) $_SERVER['APP_DEBUG']); +$kernel->boot(); + +return $kernel->getContainer()->get('doctrine')->getManager();