From e0075fdcdcccca6d5538d1f850e74ff2357a36a4 Mon Sep 17 00:00:00 2001 From: Marijn Doeve Date: Sat, 7 Jun 2025 22:02:43 +0200 Subject: [PATCH] Rector upgrades --- src/Command/ClaimSeasonCommand.php | 32 ++++++++++-------------------- src/Command/MakeAdminCommand.php | 26 +++++++++--------------- 2 files changed, 20 insertions(+), 38 deletions(-) diff --git a/src/Command/ClaimSeasonCommand.php b/src/Command/ClaimSeasonCommand.php index c659f3c..5f151d5 100644 --- a/src/Command/ClaimSeasonCommand.php +++ b/src/Command/ClaimSeasonCommand.php @@ -7,9 +7,9 @@ namespace App\Command; use App\Repository\SeasonRepository; use App\Repository\UserRepository; use Doctrine\ORM\EntityManagerInterface; +use Symfony\Component\Console\Attribute\Argument; use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Command\Command; -use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Style\SymfonyStyle; @@ -18,29 +18,19 @@ use Symfony\Component\Console\Style\SymfonyStyle; name: 'app:claim-season', description: 'Give a user owner rights on a season', )] -class ClaimSeasonCommand extends Command +readonly class ClaimSeasonCommand { - public function __construct( - private readonly UserRepository $userRepository, - private readonly SeasonRepository $seasonRepository, - private readonly EntityManagerInterface $entityManager) - { - parent::__construct(); - } + public function __construct(private UserRepository $userRepository, private SeasonRepository $seasonRepository, private EntityManagerInterface $entityManager) {} - protected function configure(): void - { - $this - ->addArgument('email', InputArgument::REQUIRED, 'The email of the user thats claims the season') - ->addArgument('season', InputArgument::REQUIRED, 'The season to claim') - ; - } - - protected function execute(InputInterface $input, OutputInterface $output): int - { + public function __invoke( + #[Argument] + string $seasonCode, + #[Argument] + string $email, + InputInterface $input, + OutputInterface $output, + ): int { $io = new SymfonyStyle($input, $output); - $email = $input->getArgument('email'); - $seasonCode = $input->getArgument('season'); try { $season = $this->seasonRepository->findOneBy(['seasonCode' => $seasonCode]); diff --git a/src/Command/MakeAdminCommand.php b/src/Command/MakeAdminCommand.php index 2bd81e1..74036d4 100644 --- a/src/Command/MakeAdminCommand.php +++ b/src/Command/MakeAdminCommand.php @@ -5,9 +5,9 @@ declare(strict_types=1); namespace App\Command; use App\Repository\UserRepository; +use Symfony\Component\Console\Attribute\Argument; use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Command\Command; -use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Style\SymfonyStyle; @@ -16,25 +16,17 @@ use Symfony\Component\Console\Style\SymfonyStyle; name: 'app:make-admin', description: 'Give a user the role admin', )] -class MakeAdminCommand extends Command +readonly class MakeAdminCommand { - public function __construct(private readonly UserRepository $userRepository) - { - parent::__construct(); - } + public function __construct(private UserRepository $userRepository) {} - protected function configure(): void - { - $this - ->addArgument('email', InputArgument::REQUIRED, 'The email of the user to make admin') - ; - } - - protected function execute(InputInterface $input, OutputInterface $output): int - { + public function __invoke( + #[Argument] + string $email, + InputInterface $input, + OutputInterface $output, + ): int { $io = new SymfonyStyle($input, $output); - $email = $input->getArgument('email'); - try { $this->userRepository->makeAdmin($email); } catch (\InvalidArgumentException) {