Code Coverage |
||||||||||||||||
Lines |
Branches |
Paths |
Functions and Methods |
Classes and Traits |
||||||||||||
| Total | |
100.00% |
9 / 9 |
|
100.00% |
9 / 9 |
|
100.00% |
5 / 5 |
|
100.00% |
3 / 3 |
CRAP | |
100.00% |
1 / 1 |
| DefaultNotificationFactory | |
100.00% |
9 / 9 |
|
100.00% |
9 / 9 |
|
100.00% |
5 / 5 |
|
100.00% |
3 / 3 |
6 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| createNotification | |
100.00% |
4 / 4 |
|
100.00% |
5 / 5 |
|
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
3 | |||
| createWelcomeNotification | |
100.00% |
4 / 4 |
|
100.00% |
3 / 3 |
|
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace App\Notification\Domain\Service; |
| 4 | |
| 5 | use App\Notification\Domain\Model\Notification; |
| 6 | use App\Notification\Domain\Model\WelcomeNotification; |
| 7 | use App\Notification\Domain\Port\Driven\RetrieveIdentityInfo; |
| 8 | use App\Shared\Domain\Exception\EntityNotFoundException; |
| 9 | use MyLegoCollection\SharedContracts\Command\SendWelcomeNotificationCommand; |
| 10 | use MyLegoCollection\SharedContracts\Message; |
| 11 | |
| 12 | /** |
| 13 | * @author Wilhelm Zwertvaegher |
| 14 | */ |
| 15 | readonly class DefaultNotificationFactory implements NotificationFactory |
| 16 | { |
| 17 | |
| 18 | public function __construct(private RetrieveIdentityInfo $retrieveIdentityInfo) |
| 19 | { |
| 20 | } |
| 21 | |
| 22 | public function createNotification(Message $message): Notification |
| 23 | { |
| 24 | return match ($message::class) { |
| 25 | SendWelcomeNotificationCommand::class => $this->createWelcomeNotification($message), |
| 26 | default => throw new \InvalidArgumentException('Unknown command type ' . $message->type()), |
| 27 | }; |
| 28 | } |
| 29 | |
| 30 | |
| 31 | private function createWelcomeNotification(SendWelcomeNotificationCommand $command): WelcomeNotification |
| 32 | { |
| 33 | $identityInfo = $this->retrieveIdentityInfo->getIdentityInfoFromId($command->getIdentityId()); |
| 34 | if ($identityInfo === null) { |
| 35 | throw new EntityNotFoundException('Cannot load IdentityInfo for ' . $command->getIdentityId()); |
| 36 | } |
| 37 | return new WelcomeNotification($command->id(), $identityInfo, $command->getValidationToken()); |
| 38 | } |
| 39 | |
| 40 | } |