Apply suggestions from code review

This commit is contained in:
Loïc Frémont 2026-05-19 11:06:19 +02:00
parent fe843f4157
commit 525cadc45f
5 changed files with 10 additions and 20 deletions

View file

@ -20,8 +20,8 @@ class SendAccountRegistrationEmail
{ {
public function __construct( public function __construct(
public readonly string $shopUserEmail, public readonly string $shopUserEmail,
public readonly string $localeCode,
public readonly string $channelCode, public readonly string $channelCode,
public readonly string $localeCode,
) { ) {
} }
} }

View file

@ -19,9 +19,9 @@ namespace Sylius\Bundle\CoreBundle\Command\Shop\Account;
class VerifyShopUser class VerifyShopUser
{ {
public function __construct( public function __construct(
public readonly string $token,
public readonly string $channelCode, public readonly string $channelCode,
public readonly string $localeCode, public readonly string $localeCode,
public readonly string $token,
) { ) {
} }
} }

View file

@ -20,9 +20,10 @@ use Sylius\Component\Core\Model\ChannelInterface;
use Sylius\Component\Core\Model\ShopUserInterface; use Sylius\Component\Core\Model\ShopUserInterface;
use Sylius\Component\User\Repository\UserRepositoryInterface; use Sylius\Component\User\Repository\UserRepositoryInterface;
use Symfony\Component\Messenger\Attribute\AsMessageHandler; use Symfony\Component\Messenger\Attribute\AsMessageHandler;
use Webmozart\Assert\Assert;
#[AsMessageHandler] #[AsMessageHandler]
final class SendAccountRegistrationEmailHandler final readonly class SendAccountRegistrationEmailHandler
{ {
public function __construct( public function __construct(
private UserRepositoryInterface $shopUserRepository, private UserRepositoryInterface $shopUserRepository,
@ -35,19 +36,11 @@ final class SendAccountRegistrationEmailHandler
{ {
/** @var ShopUserInterface|null $shopUser */ /** @var ShopUserInterface|null $shopUser */
$shopUser = $this->shopUserRepository->findOneByEmail($command->shopUserEmail); $shopUser = $this->shopUserRepository->findOneByEmail($command->shopUserEmail);
if (null === $shopUser) { Assert::notNull($shopUser, sprintf('There is no shop user with %s email', $command->shopUserEmail));
throw new \InvalidArgumentException(
sprintf('There is no shop user with %s email', $command->shopUserEmail),
);
}
/** @var ChannelInterface|null $channel */ /** @var ChannelInterface|null $channel */
$channel = $this->channelRepository->findOneByCode($command->channelCode); $channel = $this->channelRepository->findOneByCode($command->channelCode);
if (null === $channel) { Assert::notNull($channel, sprintf('There is no channel with %s email', $command->channelCode));
throw new \InvalidArgumentException(
sprintf('There is no channel with %s code', $command->channelCode),
);
}
if ($channel->isAccountVerificationRequired() && !$shopUser->isEnabled()) { if ($channel->isAccountVerificationRequired() && !$shopUser->isEnabled()) {
return; return;

View file

@ -21,6 +21,7 @@ use Symfony\Component\Clock\ClockInterface;
use Symfony\Component\Messenger\Attribute\AsMessageHandler; use Symfony\Component\Messenger\Attribute\AsMessageHandler;
use Symfony\Component\Messenger\MessageBusInterface; use Symfony\Component\Messenger\MessageBusInterface;
use Symfony\Component\Messenger\Stamp\DispatchAfterCurrentBusStamp; use Symfony\Component\Messenger\Stamp\DispatchAfterCurrentBusStamp;
use Webmozart\Assert\Assert;
#[AsMessageHandler] #[AsMessageHandler]
final readonly class VerifyShopUserHandler final readonly class VerifyShopUserHandler
@ -37,18 +38,14 @@ final readonly class VerifyShopUserHandler
{ {
/** @var ShopUserInterface|null $user */ /** @var ShopUserInterface|null $user */
$user = $this->shopUserRepository->findOneBy(['emailVerificationToken' => $command->token]); $user = $this->shopUserRepository->findOneBy(['emailVerificationToken' => $command->token]);
if (null === $user) { Assert::notNull($user, sprintf('There is no shop user with %s email verification token', $command->token));
throw new \InvalidArgumentException(
sprintf('There is no shop user with %s email verification token', $command->token),
);
}
$user->setVerifiedAt($this->clock->now()); $user->setVerifiedAt($this->clock->now());
$user->setEmailVerificationToken(null); $user->setEmailVerificationToken(null);
$user->enable(); $user->enable();
$this->commandBus->dispatch( $this->commandBus->dispatch(
new SendAccountRegistrationEmail($user->getEmail(), $command->localeCode, $command->channelCode), new SendAccountRegistrationEmail($user->getEmail(), $command->channelCode, $command->localeCode),
[new DispatchAfterCurrentBusStamp()], [new DispatchAfterCurrentBusStamp()],
); );
} }

View file

@ -55,9 +55,9 @@ final readonly class VerifyShopUserAction
} }
$this->messageBus->dispatch(new VerifyShopUser( $this->messageBus->dispatch(new VerifyShopUser(
$token,
$this->channelContext->getChannel()->getCode(), $this->channelContext->getChannel()->getCode(),
$this->localeContext->getLocaleCode(), $this->localeContext->getLocaleCode(),
$token,
)); ));
FlashBagProvider::getFlashBag($this->requestStack)->add('success', 'sylius.user.verify_email'); FlashBagProvider::getFlashBag($this->requestStack)->add('success', 'sylius.user.verify_email');