Code Coverage |
||||||||||||||||
Lines |
Branches |
Paths |
Functions and Methods |
Classes and Traits |
||||||||||||
| Total | |
90.91% |
10 / 11 |
|
75.00% |
3 / 4 |
|
66.67% |
2 / 3 |
|
50.00% |
1 / 2 |
CRAP | |
0.00% |
0 / 1 |
| ChangeEmailHandler | |
90.91% |
10 / 11 |
|
75.00% |
3 / 4 |
|
66.67% |
2 / 3 |
|
50.00% |
1 / 2 |
3.33 | |
0.00% |
0 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| __invoke | |
90.00% |
9 / 10 |
|
66.67% |
2 / 3 |
|
50.00% |
1 / 2 |
|
0.00% |
0 / 1 |
2.50 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace App\Auth\Application\Handler; |
| 4 | |
| 5 | use App\Auth\Application\Command\ChangeEmailCommand; |
| 6 | use App\Auth\Domain\Model\Identity; |
| 7 | use App\Auth\Domain\Port\Driven\IdentityRepository; |
| 8 | use App\Auth\Domain\Service\IdentityService; |
| 9 | use App\Shared\Domain\Exception\EntityNotFoundException; |
| 10 | use App\Shared\Domain\Model\EntityId; |
| 11 | use App\Shared\Domain\Port\Driven\EventBus; |
| 12 | use App\Shared\Domain\Port\Driven\TransactionProvider; |
| 13 | |
| 14 | readonly class ChangeEmailHandler |
| 15 | { |
| 16 | public function __construct( |
| 17 | private IdentityService $identityService, |
| 18 | private IdentityRepository $identityRepository, |
| 19 | private TransactionProvider $transactionProvider, |
| 20 | private EventBus $eventBus |
| 21 | |
| 22 | ) { |
| 23 | } |
| 24 | |
| 25 | public function __invoke(ChangeEmailCommand $command): ?Identity |
| 26 | { |
| 27 | $identityId = EntityId::fromString($command->identityId); |
| 28 | $identity = $this->identityRepository->findById($identityId); |
| 29 | if (null === $identity) { |
| 30 | throw new EntityNotFoundException("Identity with identifier could not be found"); |
| 31 | } |
| 32 | |
| 33 | return $this->transactionProvider->transactional(function () use ($identity, $command) { |
| 34 | $identity = $this->identityService->changeEmail($identity, $command->email); |
| 35 | $this->identityRepository->save($identity); |
| 36 | $this->eventBus->dispatchAll($identity); |
| 37 | return $identity; |
| 38 | }); |
| 39 | } |
| 40 | } |
Below are the source code lines that represent each code branch as identified by Xdebug. Please note a branch is not
necessarily coterminous with a line, a line may contain multiple branches and therefore show up more than once.
Please also be aware that some branches may be implicit rather than explicit, e.g. an if statement
always has an else as part of its logical flow even if you didn't write one.
| 16 | public function __construct( |
| 17 | private IdentityService $identityService, |
| 18 | private IdentityRepository $identityRepository, |
| 19 | private TransactionProvider $transactionProvider, |
| 20 | private EventBus $eventBus |
| 21 | |
| 22 | ) { |
| 23 | } |
| 25 | public function __invoke(ChangeEmailCommand $command): ?Identity |
| 26 | { |
| 27 | $identityId = EntityId::fromString($command->identityId); |
| 28 | $identity = $this->identityRepository->findById($identityId); |
| 29 | if (null === $identity) { |
| 30 | throw new EntityNotFoundException("Identity with identifier could not be found"); |
| 33 | return $this->transactionProvider->transactional(function () use ($identity, $command) { |
| 34 | $identity = $this->identityService->changeEmail($identity, $command->email); |
| 35 | $this->identityRepository->save($identity); |
| 36 | $this->eventBus->dispatchAll($identity); |
| 37 | return $identity; |
| 38 | }); |
| 39 | } |
| 33 | return $this->transactionProvider->transactional(function () use ($identity, $command) { |
| 34 | $identity = $this->identityService->changeEmail($identity, $command->email); |
| 35 | $this->identityRepository->save($identity); |
| 36 | $this->eventBus->dispatchAll($identity); |
| 37 | return $identity; |
| 38 | }); |
| 3 | namespace App\Auth\Application\Handler; |
| 4 | |
| 5 | use App\Auth\Application\Command\ChangeEmailCommand; |
| 6 | use App\Auth\Domain\Model\Identity; |
| 7 | use App\Auth\Domain\Port\Driven\IdentityRepository; |
| 8 | use App\Auth\Domain\Service\IdentityService; |
| 9 | use App\Shared\Domain\Exception\EntityNotFoundException; |
| 10 | use App\Shared\Domain\Model\EntityId; |
| 11 | use App\Shared\Domain\Port\Driven\EventBus; |
| 12 | use App\Shared\Domain\Port\Driven\TransactionProvider; |
| 13 | |
| 14 | readonly class ChangeEmailHandler |
| 15 | { |
| 16 | public function __construct( |
| 17 | private IdentityService $identityService, |
| 18 | private IdentityRepository $identityRepository, |
| 19 | private TransactionProvider $transactionProvider, |
| 20 | private EventBus $eventBus |
| 21 | |
| 22 | ) { |
| 23 | } |
| 24 | |
| 25 | public function __invoke(ChangeEmailCommand $command): ?Identity |
| 26 | { |
| 27 | $identityId = EntityId::fromString($command->identityId); |
| 28 | $identity = $this->identityRepository->findById($identityId); |
| 29 | if (null === $identity) { |
| 30 | throw new EntityNotFoundException("Identity with identifier could not be found"); |
| 31 | } |
| 32 | |
| 33 | return $this->transactionProvider->transactional(function () use ($identity, $command) { |
| 34 | $identity = $this->identityService->changeEmail($identity, $command->email); |
| 35 | $this->identityRepository->save($identity); |
| 36 | $this->eventBus->dispatchAll($identity); |
| 37 | return $identity; |
| 38 | }); |
| 39 | } |