Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
13 / 13
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
LogoutUserHandler
100.00% covered (success)
100.00%
13 / 13
100.00% covered (success)
100.00%
2 / 2
2
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 handle
100.00% covered (success)
100.00%
12 / 12
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3// ╔════════════════════════════════════════════════════════════╗
4// ║ MIT Licence (#Expat) - https://opensource.org/licenses/MIT ║
5// ║ Copyright 2026 Frederic Poeydomenge <dyno@phexium.com>     ║
6// ╚════════════════════════════════════════════════════════════╝
7
8declare(strict_types=1);
9
10namespace AppDemo\User\Application\Command;
11
12use AppDemo\User\Domain\Event\UserLogoutEvent;
13use Override;
14use Phexium\Application\Command\AbstractCommandHandler;
15use Phexium\Application\Command\CommandHandlerInterface;
16use Phexium\Application\Command\CommandInterface;
17use Phexium\Domain\TypeGuard;
18use Phexium\Plugin\Clock\Port\ClockInterface;
19use Phexium\Plugin\EventBus\Port\EventBusInterface;
20use Phexium\Plugin\IdGenerator\Port\IdGeneratorInterface;
21use Phexium\Plugin\Logger\Port\LoggerInterface;
22
23final class LogoutUserHandler extends AbstractCommandHandler implements CommandHandlerInterface
24{
25    public function __construct(
26        private readonly EventBusInterface $eventBus,
27        private readonly ClockInterface $clock,
28        private readonly IdGeneratorInterface $idGenerator,
29        private readonly LoggerInterface $logger,
30    ) {}
31
32    #[Override]
33    public function handle(CommandInterface $command): void
34    {
35        TypeGuard::that($command)->isInstanceOf(LogoutUserCommand::class);
36
37        $userId = $command->userId;
38
39        $this->eventBus->dispatch(
40            new UserLogoutEvent(
41                $this->idGenerator->generate(),
42                $this->clock->now(),
43                $userId
44            )
45        );
46
47        $this->logger->info('LogoutUserHandler: User logout event dispatched', [
48            'userId' => $userId->getValue(),
49        ]);
50    }
51}