Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
13 / 13 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| LogoutUserHandler | |
100.00% |
13 / 13 |
|
100.00% |
2 / 2 |
2 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| handle | |
100.00% |
12 / 12 |
|
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 | |
| 8 | declare(strict_types=1); |
| 9 | |
| 10 | namespace AppDemo\User\Application\Command; |
| 11 | |
| 12 | use AppDemo\User\Domain\Event\UserLogoutEvent; |
| 13 | use Override; |
| 14 | use Phexium\Application\Command\AbstractCommandHandler; |
| 15 | use Phexium\Application\Command\CommandHandlerInterface; |
| 16 | use Phexium\Application\Command\CommandInterface; |
| 17 | use Phexium\Domain\TypeGuard; |
| 18 | use Phexium\Plugin\Clock\Port\ClockInterface; |
| 19 | use Phexium\Plugin\EventBus\Port\EventBusInterface; |
| 20 | use Phexium\Plugin\IdGenerator\Port\IdGeneratorInterface; |
| 21 | use Phexium\Plugin\Logger\Port\LoggerInterface; |
| 22 | |
| 23 | final 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 | } |