Code Coverage |
||||||||||||||||
Lines |
Branches |
Paths |
Functions and Methods |
Classes and Traits |
||||||||||||
| Total | |
100.00% |
12 / 12 |
|
100.00% |
2 / 2 |
|
100.00% |
2 / 2 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| NotificationCommandHandler | |
100.00% |
12 / 12 |
|
100.00% |
2 / 2 |
|
100.00% |
2 / 2 |
|
100.00% |
2 / 2 |
3 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| __invoke | |
100.00% |
11 / 11 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace App\Notification\Application\Handler; |
| 4 | |
| 5 | use App\Notification\Domain\Port\Driven\NotificationDispatcher; |
| 6 | use App\Notification\Domain\Service\NotificationFactory; |
| 7 | use App\Notification\Domain\Port\Driven\NotificationLogRepository; |
| 8 | use App\Notification\Domain\Service\NotificationLogService; |
| 9 | use App\Shared\Domain\Port\Driven\TransactionProvider; |
| 10 | use MyLegoCollection\SharedContracts\Command\Command; |
| 11 | |
| 12 | /** |
| 13 | * @author Wilhelm Zwertvaegher |
| 14 | */ |
| 15 | readonly class NotificationCommandHandler |
| 16 | { |
| 17 | public function __construct( |
| 18 | private NotificationFactory $notificationFactory, |
| 19 | private NotificationDispatcher $notificationDispatcher, |
| 20 | private NotificationLogService $notificationLogService, |
| 21 | private NotificationLogRepository $notificationLogRepository, |
| 22 | private TransactionProvider $transactionProvider |
| 23 | ) { |
| 24 | } |
| 25 | public function __invoke(Command $command): void |
| 26 | { |
| 27 | // create notification to be sent |
| 28 | $notification = $this->notificationFactory->createNotification($command); |
| 29 | |
| 30 | // pass to dispatcher |
| 31 | $results = $this->notificationDispatcher->dispatch($notification); |
| 32 | |
| 33 | $this->transactionProvider->transactional(function () use ($notification, $results) { |
| 34 | // save logs for the notification |
| 35 | foreach ($results as $result) { |
| 36 | $this->notificationLogRepository->save( |
| 37 | $this->notificationLogService->createFromNotification( |
| 38 | $notification, |
| 39 | $result |
| 40 | ) |
| 41 | ); |
| 42 | } |
| 43 | }); |
| 44 | } |
| 45 | } |