Code Coverage |
||||||||||||||||
Lines |
Branches |
Paths |
Functions and Methods |
Classes and Traits |
||||||||||||
| Total | |
100.00% |
10 / 10 |
|
100.00% |
4 / 4 |
|
100.00% |
3 / 3 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| CreateSuggestion | |
100.00% |
10 / 10 |
|
100.00% |
4 / 4 |
|
100.00% |
3 / 3 |
|
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% |
9 / 9 |
|
100.00% |
3 / 3 |
|
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace App\Application\UseCase; |
| 4 | |
| 5 | use App\Dto\Command\CreateSuggestionCommand; |
| 6 | use App\Entity\Suggestion; |
| 7 | use App\Exception\WordAlreadyExistsException; |
| 8 | use App\Message\CommandBus; |
| 9 | use App\Message\SendNotificationCommand; |
| 10 | use App\Service\Data\NotificationServiceInterface; |
| 11 | use App\Service\Data\SuggestionServiceInterface; |
| 12 | use App\Service\Data\WordServiceInterface; |
| 13 | use App\Service\Notification\Factory\NotificationPropsFactoryInterface; |
| 14 | use Doctrine\ORM\EntityManagerInterface; |
| 15 | |
| 16 | /** |
| 17 | * @author Wilhelm Zwertvaegher |
| 18 | */ |
| 19 | readonly class CreateSuggestion implements CreateSuggestionInterface |
| 20 | { |
| 21 | public function __construct( |
| 22 | private WordServiceInterface $wordService, |
| 23 | private SuggestionServiceInterface $suggestionService, |
| 24 | private NotificationServiceInterface $notificationService, |
| 25 | private EntityManagerInterface $entityManager, |
| 26 | private NotificationPropsFactoryInterface $notificationFactory, |
| 27 | private CommandBus $commandBus, |
| 28 | ) { |
| 29 | } |
| 30 | |
| 31 | public function __invoke(CreateSuggestionCommand $command): Suggestion |
| 32 | { |
| 33 | // first, let's try and find an existing word |
| 34 | $existingWord = $this->wordService->getByLabel($command->getLabel()); |
| 35 | if (null !== $existingWord) { |
| 36 | throw new WordAlreadyExistsException(); |
| 37 | } |
| 38 | $suggestion = $this->suggestionService->create($command); |
| 39 | $notificationProps = $this->notificationFactory->create($suggestion); |
| 40 | $notification = $this->notificationService->create($notificationProps); |
| 41 | $this->entityManager->flush(); |
| 42 | $this->commandBus->dispatch(new SendNotificationCommand($notification->getId())); |
| 43 | |
| 44 | return $suggestion; |
| 45 | } |
| 46 | } |
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.
| 21 | public function __construct( |
| 22 | private WordServiceInterface $wordService, |
| 23 | private SuggestionServiceInterface $suggestionService, |
| 24 | private NotificationServiceInterface $notificationService, |
| 25 | private EntityManagerInterface $entityManager, |
| 26 | private NotificationPropsFactoryInterface $notificationFactory, |
| 27 | private CommandBus $commandBus, |
| 28 | ) { |
| 29 | } |
| 31 | public function __invoke(CreateSuggestionCommand $command): Suggestion |
| 32 | { |
| 33 | // first, let's try and find an existing word |
| 34 | $existingWord = $this->wordService->getByLabel($command->getLabel()); |
| 35 | if (null !== $existingWord) { |
| 36 | throw new WordAlreadyExistsException(); |
| 38 | $suggestion = $this->suggestionService->create($command); |
| 39 | $notificationProps = $this->notificationFactory->create($suggestion); |
| 40 | $notification = $this->notificationService->create($notificationProps); |
| 41 | $this->entityManager->flush(); |
| 42 | $this->commandBus->dispatch(new SendNotificationCommand($notification->getId())); |
| 43 | |
| 44 | return $suggestion; |
| 45 | } |
| 3 | namespace App\Application\UseCase; |
| 4 | |
| 5 | use App\Dto\Command\CreateSuggestionCommand; |
| 6 | use App\Entity\Suggestion; |
| 7 | use App\Exception\WordAlreadyExistsException; |
| 8 | use App\Message\CommandBus; |
| 9 | use App\Message\SendNotificationCommand; |
| 10 | use App\Service\Data\NotificationServiceInterface; |
| 11 | use App\Service\Data\SuggestionServiceInterface; |
| 12 | use App\Service\Data\WordServiceInterface; |
| 13 | use App\Service\Notification\Factory\NotificationPropsFactoryInterface; |
| 14 | use Doctrine\ORM\EntityManagerInterface; |
| 15 | |
| 16 | /** |
| 17 | * @author Wilhelm Zwertvaegher |
| 18 | */ |
| 19 | readonly class CreateSuggestion implements CreateSuggestionInterface |
| 20 | { |
| 21 | public function __construct( |
| 22 | private WordServiceInterface $wordService, |
| 23 | private SuggestionServiceInterface $suggestionService, |
| 24 | private NotificationServiceInterface $notificationService, |
| 25 | private EntityManagerInterface $entityManager, |
| 26 | private NotificationPropsFactoryInterface $notificationFactory, |
| 27 | private CommandBus $commandBus, |
| 28 | ) { |
| 29 | } |
| 30 | |
| 31 | public function __invoke(CreateSuggestionCommand $command): Suggestion |
| 32 | { |
| 33 | // first, let's try and find an existing word |
| 34 | $existingWord = $this->wordService->getByLabel($command->getLabel()); |
| 35 | if (null !== $existingWord) { |
| 36 | throw new WordAlreadyExistsException(); |
| 37 | } |
| 38 | $suggestion = $this->suggestionService->create($command); |
| 39 | $notificationProps = $this->notificationFactory->create($suggestion); |
| 40 | $notification = $this->notificationService->create($notificationProps); |
| 41 | $this->entityManager->flush(); |
| 42 | $this->commandBus->dispatch(new SendNotificationCommand($notification->getId())); |
| 43 | |
| 44 | return $suggestion; |
| 45 | } |