Code Coverage
 
Lines
Branches
Paths
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
9 / 9
100.00% covered (success)
100.00%
9 / 9
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
3 / 3
CRAP
100.00% covered (success)
100.00%
1 / 1
DefaultNotificationFactory
100.00% covered (success)
100.00%
9 / 9
100.00% covered (success)
100.00%
9 / 9
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
3 / 3
6
100.00% covered (success)
100.00%
1 / 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
 createNotification
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
3
 createWelcomeNotification
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
2
1<?php
2
3namespace App\Notification\Domain\Service;
4
5use App\Notification\Domain\Model\Notification;
6use App\Notification\Domain\Model\WelcomeNotification;
7use App\Notification\Domain\Port\Driven\RetrieveIdentityInfo;
8use App\Shared\Domain\Exception\EntityNotFoundException;
9use MyLegoCollection\SharedContracts\Command\SendWelcomeNotificationCommand;
10use MyLegoCollection\SharedContracts\Message;
11
12/**
13 * @author Wilhelm Zwertvaegher
14 */
15readonly 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}

Branches

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.

DefaultNotificationFactory->__construct
18    public function __construct(private RetrieveIdentityInfo $retrieveIdentityInfo)
19    {
20    }
DefaultNotificationFactory->createNotification
22    public function createNotification(Message $message): Notification
23    {
24        return match ($message::class) {
24        return match ($message::class) {
25            SendWelcomeNotificationCommand::class => $this->createWelcomeNotification($message),
26            default => throw new \InvalidArgumentException('Unknown command type ' . $message->type()),
26            default => throw new \InvalidArgumentException('Unknown command type ' . $message->type()),
27        };
28    }
DefaultNotificationFactory->createWelcomeNotification
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());
37        return new WelcomeNotification($command->id(), $identityInfo, $command->getValidationToken());
38    }
{main}
3namespace App\Notification\Domain\Service;
4
5use App\Notification\Domain\Model\Notification;
6use App\Notification\Domain\Model\WelcomeNotification;
7use App\Notification\Domain\Port\Driven\RetrieveIdentityInfo;
8use App\Shared\Domain\Exception\EntityNotFoundException;
9use MyLegoCollection\SharedContracts\Command\SendWelcomeNotificationCommand;
10use MyLegoCollection\SharedContracts\Message;
11
12/**
13 * @author Wilhelm Zwertvaegher
14 */
15readonly 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