Code Coverage |
||||||||||||||||
Lines |
Branches |
Paths |
Functions and Methods |
Classes and Traits |
||||||||||||
| Total | |
90.91% |
10 / 11 |
|
100.00% |
2 / 2 |
|
100.00% |
2 / 2 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| UpdateAvatarHandler | |
90.91% |
10 / 11 |
|
100.00% |
2 / 2 |
|
100.00% |
2 / 2 |
|
50.00% |
1 / 2 |
3 | |
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 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace App\User\Application\Handler; |
| 4 | |
| 5 | use App\Shared\Domain\Exception\EntityNotFoundException; |
| 6 | use App\Shared\Domain\Model\EntityId; |
| 7 | use App\Shared\Domain\Port\Driven\EventBus; |
| 8 | use App\Shared\Domain\Port\Driven\TransactionProvider; |
| 9 | use App\Shared\Domain\Service\StoredFileService; |
| 10 | use App\User\Application\Command\UpdateAvatarCommand; |
| 11 | use App\User\Domain\Model\User; |
| 12 | use App\User\Domain\Port\Driven\UserRepository; |
| 13 | |
| 14 | readonly class UpdateAvatarHandler |
| 15 | { |
| 16 | public function __construct( |
| 17 | private readonly TransactionProvider $transactionProvider, |
| 18 | private readonly StoredFileService $storedFileService, |
| 19 | private readonly UserRepository $userRepository, |
| 20 | private readonly EventBus $eventBus |
| 21 | ){ |
| 22 | } |
| 23 | |
| 24 | public function __invoke(UpdateAvatarCommand $command): User |
| 25 | { |
| 26 | return $this->transactionProvider->transactional(function () use ($command) { |
| 27 | $user = $this->userRepository->findByIdentityId(EntityId::fromString($command->identityId)); |
| 28 | |
| 29 | if (!$user) { |
| 30 | throw new EntityNotFoundException('User not found'); |
| 31 | } |
| 32 | |
| 33 | $storedFile = $this->storedFileService->replace($user->getAvatar(), $command->tempFile, 'user.avatar'); |
| 34 | |
| 35 | $updatedUser = $user->setAvatar($storedFile); |
| 36 | |
| 37 | $this->userRepository->save($updatedUser); |
| 38 | |
| 39 | $this->eventBus->dispatchAll($updatedUser); |
| 40 | |
| 41 | return $updatedUser; |
| 42 | }); |
| 43 | } |
| 44 | } |
Below are the source code lines that represent each code path as identified by Xdebug. Please note a path is not
necessarily coterminous with a line, a line may contain multiple paths and therefore show up more than once.
Please also be aware that some paths may include implicit rather than explicit branches, 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 readonly TransactionProvider $transactionProvider, |
| 18 | private readonly StoredFileService $storedFileService, |
| 19 | private readonly UserRepository $userRepository, |
| 20 | private readonly EventBus $eventBus |
| 21 | ){ |
| 22 | } |
| 24 | public function __invoke(UpdateAvatarCommand $command): User |
| 25 | { |
| 26 | return $this->transactionProvider->transactional(function () use ($command) { |
| 27 | $user = $this->userRepository->findByIdentityId(EntityId::fromString($command->identityId)); |
| 28 | |
| 29 | if (!$user) { |
| 30 | throw new EntityNotFoundException('User not found'); |
| 31 | } |
| 32 | |
| 33 | $storedFile = $this->storedFileService->replace($user->getAvatar(), $command->tempFile, 'user.avatar'); |
| 34 | |
| 35 | $updatedUser = $user->setAvatar($storedFile); |
| 36 | |
| 37 | $this->userRepository->save($updatedUser); |
| 38 | |
| 39 | $this->eventBus->dispatchAll($updatedUser); |
| 40 | |
| 41 | return $updatedUser; |
| 42 | }); |
| 43 | } |
| 26 | return $this->transactionProvider->transactional(function () use ($command) { |
| 27 | $user = $this->userRepository->findByIdentityId(EntityId::fromString($command->identityId)); |
| 28 | |
| 29 | if (!$user) { |
| 30 | throw new EntityNotFoundException('User not found'); |
| 26 | return $this->transactionProvider->transactional(function () use ($command) { |
| 27 | $user = $this->userRepository->findByIdentityId(EntityId::fromString($command->identityId)); |
| 28 | |
| 29 | if (!$user) { |
| 33 | $storedFile = $this->storedFileService->replace($user->getAvatar(), $command->tempFile, 'user.avatar'); |
| 34 | |
| 35 | $updatedUser = $user->setAvatar($storedFile); |
| 36 | |
| 37 | $this->userRepository->save($updatedUser); |
| 38 | |
| 39 | $this->eventBus->dispatchAll($updatedUser); |
| 40 | |
| 41 | return $updatedUser; |
| 42 | }); |
| 3 | namespace App\User\Application\Handler; |
| 4 | |
| 5 | use App\Shared\Domain\Exception\EntityNotFoundException; |
| 6 | use App\Shared\Domain\Model\EntityId; |
| 7 | use App\Shared\Domain\Port\Driven\EventBus; |
| 8 | use App\Shared\Domain\Port\Driven\TransactionProvider; |
| 9 | use App\Shared\Domain\Service\StoredFileService; |
| 10 | use App\User\Application\Command\UpdateAvatarCommand; |
| 11 | use App\User\Domain\Model\User; |
| 12 | use App\User\Domain\Port\Driven\UserRepository; |
| 13 | |
| 14 | readonly class UpdateAvatarHandler |
| 15 | { |
| 16 | public function __construct( |
| 17 | private readonly TransactionProvider $transactionProvider, |
| 18 | private readonly StoredFileService $storedFileService, |
| 19 | private readonly UserRepository $userRepository, |
| 20 | private readonly EventBus $eventBus |
| 21 | ){ |
| 22 | } |
| 23 | |
| 24 | public function __invoke(UpdateAvatarCommand $command): User |
| 25 | { |
| 26 | return $this->transactionProvider->transactional(function () use ($command) { |
| 27 | $user = $this->userRepository->findByIdentityId(EntityId::fromString($command->identityId)); |
| 28 | |
| 29 | if (!$user) { |
| 30 | throw new EntityNotFoundException('User not found'); |
| 31 | } |
| 32 | |
| 33 | $storedFile = $this->storedFileService->replace($user->getAvatar(), $command->tempFile, 'user.avatar'); |
| 34 | |
| 35 | $updatedUser = $user->setAvatar($storedFile); |
| 36 | |
| 37 | $this->userRepository->save($updatedUser); |
| 38 | |
| 39 | $this->eventBus->dispatchAll($updatedUser); |
| 40 | |
| 41 | return $updatedUser; |
| 42 | }); |
| 43 | } |