Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
12 / 12
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
LogoutUserHandler
100.00% covered (success)
100.00%
12 / 12
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
 __invoke
100.00% covered (success)
100.00%
11 / 11
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\UserLoggedOutEvent;
13use Phexium\Application\Command\CommandHandlerInterface;
14use Phexium\Plugin\Clock\Port\ClockInterface;
15use Phexium\Plugin\EventBus\Port\EventBusInterface;
16use Phexium\Plugin\IdGenerator\Port\IdGeneratorInterface;
17use Phexium\Plugin\Logger\Port\LoggerInterface;
18
19final readonly class LogoutUserHandler implements CommandHandlerInterface
20{
21    public function __construct(
22        private EventBusInterface $eventBus,
23        private ClockInterface $clock,
24        private IdGeneratorInterface $idGenerator,
25        private LoggerInterface $logger,
26    ) {}
27
28    public function __invoke(LogoutUserCommand $command): void
29    {
30        $userId = $command->userId;
31
32        $this->eventBus->dispatch(
33            new UserLoggedOutEvent(
34                $this->idGenerator->generate(),
35                $this->clock->now(),
36                $userId
37            )
38        );
39
40        $this->logger->info('LogoutUserHandler: User logout event dispatched', [
41            'userId' => $userId->getValue(),
42        ]);
43    }
44}