Code Coverage
 
Lines
Branches
Paths
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
CreateContact
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
2 / 2
2
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
 __invoke
100.00% covered (success)
100.00%
6 / 6
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
1<?php
2
3namespace App\Application\UseCase;
4
5use App\Dto\Command\CreateContactCommand;
6use App\Entity\Contact;
7use App\Message\CommandBus;
8use App\Message\SendNotificationCommand;
9use App\Service\Data\ContactServiceInterface;
10use App\Service\Data\NotificationServiceInterface;
11use App\Service\Notification\Factory\NotificationPropsFactoryInterface;
12use Doctrine\ORM\EntityManagerInterface;
13
14/**
15 * @author Wilhelm Zwertvaegher
16 */
17readonly class CreateContact implements CreateContactInterface
18{
19    public function __construct(
20        private ContactServiceInterface $contactService,
21        private NotificationServiceInterface $notificationService,
22        private EntityManagerInterface $entityManager,
23        private NotificationPropsFactoryInterface $notificationFactory,
24        private CommandBus $commandBus,
25    ) {
26    }
27
28    public function __invoke(CreateContactCommand $command): Contact
29    {
30        $contact = $this->contactService->create($command);
31        $notificationProps = $this->notificationFactory->create($contact);
32        $notification = $this->notificationService->create($notificationProps);
33        $this->entityManager->flush();
34        $this->commandBus->dispatch(new SendNotificationCommand($notification->getId()));
35
36        return $contact;
37    }
38}