From 180bc5c556629af0306c18a817cda0fae1a159f3 Mon Sep 17 00:00:00 2001 From: Matthieu Date: Thu, 9 Apr 2026 14:16:14 +0200 Subject: [PATCH] fix : fix UserOutput type and use UserRepositoryInterface in CreateUserCommand Change UserOutput.id from int to ?int to match User::getId() return type. Replace EntityManagerInterface with UserRepositoryInterface in CreateUserCommand. Co-Authored-By: Claude Opus 4.6 (1M context) --- src/Module/Core/Application/DTO/UserOutput.php | 2 +- .../Core/Infrastructure/Console/CreateUserCommand.php | 7 +++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/Module/Core/Application/DTO/UserOutput.php b/src/Module/Core/Application/DTO/UserOutput.php index b1eb8ea..5ebdd22 100644 --- a/src/Module/Core/Application/DTO/UserOutput.php +++ b/src/Module/Core/Application/DTO/UserOutput.php @@ -10,7 +10,7 @@ use DateTimeImmutable; final readonly class UserOutput { public function __construct( - public int $id, + public ?int $id, public string $username, /** @var list */ public array $roles, diff --git a/src/Module/Core/Infrastructure/Console/CreateUserCommand.php b/src/Module/Core/Infrastructure/Console/CreateUserCommand.php index eeb7731..ba647e2 100644 --- a/src/Module/Core/Infrastructure/Console/CreateUserCommand.php +++ b/src/Module/Core/Infrastructure/Console/CreateUserCommand.php @@ -5,7 +5,7 @@ declare(strict_types=1); namespace App\Module\Core\Infrastructure\Console; use App\Module\Core\Domain\Entity\User; -use Doctrine\ORM\EntityManagerInterface; +use App\Module\Core\Domain\Repository\UserRepositoryInterface; use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputArgument; @@ -22,7 +22,7 @@ use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface; class CreateUserCommand extends Command { public function __construct( - private readonly EntityManagerInterface $em, + private readonly UserRepositoryInterface $userRepository, private readonly UserPasswordHasherInterface $passwordHasher, ) { parent::__construct(); @@ -52,8 +52,7 @@ class CreateUserCommand extends Command $user->setRoles(['ROLE_ADMIN']); } - $this->em->persist($user); - $this->em->flush(); + $this->userRepository->save($user); $io->success(sprintf('User "%s" created%s.', $username, $input->getOption('admin') ? ' with ROLE_ADMIN' : ''));