From c70f713f7ea4e3f80a8a03063150d295b6ea3c63 Mon Sep 17 00:00:00 2001 From: Marijn Doeve Date: Mon, 14 Apr 2025 18:13:01 +0200 Subject: [PATCH] Refactor Base64 encoding/decoding methods for consistency, update controller routes, and improve CI configuration --- .github/workflows/ci.yml | 47 +++++++------------ Justfile | 3 ++ src/Controller/BackofficeController.php | 1 - src/Controller/LoginController.php | 2 + .../PrepareEliminationController.php | 21 +++++++++ src/Controller/QuizController.php | 4 +- src/Entity/Candidate.php | 2 +- src/Helpers/Base64.php | 6 +-- src/Repository/CandidateRepository.php | 2 +- .../prepare_elimination/index.html.twig | 3 ++ 10 files changed, 51 insertions(+), 40 deletions(-) create mode 100644 src/Controller/PrepareEliminationController.php create mode 100644 templates/backoffice/prepare_elimination/index.html.twig diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8b0f691..7cdd1bf 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -16,14 +16,11 @@ jobs: name: Tests runs-on: ubuntu-latest steps: - - - name: Checkout + - name: Checkout uses: actions/checkout@v4 - - - name: Set up Docker Buildx + - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 - - - name: Build Docker images + - name: Build Docker images uses: docker/bake-action@v4 with: pull: true @@ -35,42 +32,30 @@ jobs: *.cache-from=type=gha,scope=${{github.ref}} *.cache-from=type=gha,scope=refs/heads/main *.cache-to=type=gha,scope=${{github.ref}},mode=max - - - name: Start services + - name: Start services run: docker compose up --wait --no-build - - - name: Check HTTP reachability + - name: Check HTTP reachability run: curl -v --fail-with-body http://localhost - - - name: Check HTTPS reachability + - name: Check HTTPS reachability if: false # Remove this line when the homepage will be configured, or change the path to check run: curl -vk --fail-with-body https://localhost - - - name: Check Mercure reachability + - name: Check Mercure reachability run: curl -vkI --fail-with-body https://localhost/.well-known/mercure?topic=test - - - name: Create test database - if: false # Remove this line if Doctrine ORM is installed + - name: Create test database run: docker compose exec -T php bin/console -e test doctrine:database:create - - - name: Run migrations - if: false # Remove this line if Doctrine Migrations is installed + - name: Run migrations run: docker compose exec -T php bin/console -e test doctrine:migrations:migrate --no-interaction - - - name: Run PHPUnit - if: false # Remove this line if PHPUnit is installed - run: docker compose exec -T php bin/phpunit - - - name: Doctrine Schema Validator - if: false # Remove this line if Doctrine ORM is installed + - name: Run PHPUnit + if: false # Remove this line when the tests are ready + run: docker compose exec -T php vendor/bin/phpunit + - name: Doctrine Schema Validator run: docker compose exec -T php bin/console -e test doctrine:schema:validate lint: name: Docker Lint runs-on: ubuntu-latest steps: - - - name: Checkout + - name: Checkout uses: actions/checkout@v4 - - - name: Lint Dockerfile + - name: Lint Dockerfile uses: hadolint/hadolint-action@v3.1.0 + diff --git a/Justfile b/Justfile index 8e2b001..b32596f 100644 --- a/Justfile +++ b/Justfile @@ -22,3 +22,6 @@ fixtures: translations: docker compose exec php bin/console translation:extract --domain=messages --force --format=yaml --sort=asc --clean nl + +fix-cs: + docker compose exec php vendor/bin/php-cs-fixer fix diff --git a/src/Controller/BackofficeController.php b/src/Controller/BackofficeController.php index 08ba3ba..ae71e00 100644 --- a/src/Controller/BackofficeController.php +++ b/src/Controller/BackofficeController.php @@ -8,7 +8,6 @@ use App\Entity\Quiz; use App\Entity\Season; use App\Repository\CandidateRepository; use App\Repository\SeasonRepository; -use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\Attribute\AsController; use Symfony\Component\Routing\Attribute\Route; diff --git a/src/Controller/LoginController.php b/src/Controller/LoginController.php index a5a6838..c581f81 100644 --- a/src/Controller/LoginController.php +++ b/src/Controller/LoginController.php @@ -6,9 +6,11 @@ namespace App\Controller; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\Response; +use Symfony\Component\HttpKernel\Attribute\AsController; use Symfony\Component\Routing\Attribute\Route; use Symfony\Component\Security\Http\Authentication\AuthenticationUtils; +#[AsController] class LoginController extends AbstractController { #[Route(path: '/login', name: 'app_login_login')] diff --git a/src/Controller/PrepareEliminationController.php b/src/Controller/PrepareEliminationController.php new file mode 100644 index 0000000..adcc94f --- /dev/null +++ b/src/Controller/PrepareEliminationController.php @@ -0,0 +1,21 @@ +render('prepare_elimination/index.html.twig', [ + 'controller_name' => 'PrepareEliminationController', + ]); + } +} diff --git a/src/Controller/QuizController.php b/src/Controller/QuizController.php index c376647..b0d3016 100644 --- a/src/Controller/QuizController.php +++ b/src/Controller/QuizController.php @@ -60,7 +60,7 @@ final class QuizController extends AbstractController $data = $form->getData(); $name = $data['name']; - return $this->redirectToRoute('app_quiz_quizpage', ['seasonCode' => $season->getSeasonCode(), 'nameHash' => Base64::base64_url_encode($name)]); + return $this->redirectToRoute('app_quiz_quizpage', ['seasonCode' => $season->getSeasonCode(), 'nameHash' => Base64::base64UrlEncode($name)]); } return $this->render('quiz/enter_name.twig', ['season' => $season, 'form' => $form]); @@ -90,7 +90,7 @@ final class QuizController extends AbstractController return $this->redirectToRoute('app_quiz_entername', ['seasonCode' => $season->getSeasonCode()]); } - $candidate = new Candidate(Base64::base64_url_decode($nameHash)); + $candidate = new Candidate(Base64::base64UrlDecode($nameHash)); $candidateRepository->save($candidate); } diff --git a/src/Entity/Candidate.php b/src/Entity/Candidate.php index b086ca9..38a03e5 100644 --- a/src/Entity/Candidate.php +++ b/src/Entity/Candidate.php @@ -135,6 +135,6 @@ class Candidate public function getNameHash(): string { - return Base64::base64_url_encode($this->name); + return Base64::base64UrlEncode($this->name); } } diff --git a/src/Helpers/Base64.php b/src/Helpers/Base64.php index 8fbba4e..1bf6f87 100644 --- a/src/Helpers/Base64.php +++ b/src/Helpers/Base64.php @@ -8,15 +8,13 @@ use Safe\Exceptions\UrlException; class Base64 { - private function __construct() {} - - public static function base64_url_encode(string $input): string + public static function base64UrlEncode(string $input): string { return rtrim(strtr(base64_encode($input), '+/', '-_'), '='); } /** @throws UrlException */ - public static function base64_url_decode(string $input): string + public static function base64UrlDecode(string $input): string { return \Safe\base64_decode(strtr($input, '-_', '+/'), true); } diff --git a/src/Repository/CandidateRepository.php b/src/Repository/CandidateRepository.php index fdf622c..c789d35 100644 --- a/src/Repository/CandidateRepository.php +++ b/src/Repository/CandidateRepository.php @@ -30,7 +30,7 @@ class CandidateRepository extends ServiceEntityRepository public function getCandidateByHash(Season $season, string $hash): ?Candidate { try { - $name = Base64::base64_url_decode($hash); + $name = Base64::base64UrlDecode($hash); } catch (UrlException) { return null; } diff --git a/templates/backoffice/prepare_elimination/index.html.twig b/templates/backoffice/prepare_elimination/index.html.twig new file mode 100644 index 0000000..8dff5b5 --- /dev/null +++ b/templates/backoffice/prepare_elimination/index.html.twig @@ -0,0 +1,3 @@ +{% extends 'backoffice/base.html.twig' %} +{% block body %} +{% endblock %}