Code Coverage
 
Lines
Branches
Paths
Functions and Methods
Classes and Traits
Total
90.91% covered (success)
90.91%
10 / 11
75.00% covered (warning)
75.00%
3 / 4
66.67% covered (warning)
66.67%
2 / 3
50.00% covered (danger)
50.00%
1 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
UserCreatedHandler
90.91% covered (success)
90.91%
10 / 11
75.00% covered (warning)
75.00%
3 / 4
66.67% covered (warning)
66.67%
2 / 3
50.00% covered (danger)
50.00%
1 / 2
3.33
0.00% covered (danger)
0.00%
0 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 __invoke
90.00% covered (success)
90.00%
9 / 10
66.67% covered (warning)
66.67%
2 / 3
50.00% covered (danger)
50.00%
1 / 2
0.00% covered (danger)
0.00%
0 / 1
2.50
1<?php
2
3namespace App\Auth\Application\Handler;
4
5use App\Auth\Domain\Port\Driven\IdentityRepository;
6use App\Auth\Domain\Service\IdentityService;
7use App\Shared\Domain\Exception\EntityNotFoundException;
8use App\Shared\Domain\Model\EntityId;
9use App\Shared\Domain\Port\Driven\EventBus;
10use App\Shared\Domain\Port\Driven\TransactionProvider;
11use MyLegoCollection\SharedContracts\Event\UserCreatedIntegrationEvent;
12
13readonly class UserCreatedHandler
14{
15    public function __construct(
16        private IdentityService  $identityService,
17        private IdentityRepository  $identityRepository,
18        private TransactionProvider $transactionProvider,
19        private EventBus $eventBus
20
21    ) {
22    }
23
24    public function __invoke(UserCreatedIntegrationEvent $event): void
25    {
26        $identityId = EntityId::fromString($event->getEntityId());
27        $identity = $this->identityRepository->findById($identityId);
28        if (null === $identity) {
29            throw new EntityNotFoundException("Identity with id $identityId could not be found");
30        }
31
32        $this->transactionProvider->transactional(function () use ($identity) {
33            $identity = $this->identityService->complete($identity);
34            $this->identityRepository->save($identity);
35            $this->eventBus->dispatchAll($identity);
36            return $identity;
37        });
38    }
39}