Code Coverage |
||||||||||||||||
Lines |
Branches |
Paths |
Functions and Methods |
Classes and Traits |
||||||||||||
| Total | |
88.89% |
8 / 9 |
|
85.71% |
6 / 7 |
|
85.71% |
6 / 7 |
|
85.71% |
6 / 7 |
CRAP | |
0.00% |
0 / 1 |
| DoctrineNotificationLogRepository | |
88.89% |
8 / 9 |
|
85.71% |
6 / 7 |
|
85.71% |
6 / 7 |
|
85.71% |
6 / 7 |
7.14 | |
0.00% |
0 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| save | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| findByMessageId | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| findByMessageIdAndSender | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| findByMessageIdAndSenderAndStatus | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| findByMessageIdAndStatus | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| hasSuccess | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace App\Notification\Infrastructure\Persistence\Doctrine\Repository; |
| 4 | |
| 5 | use App\Notification\Domain\Model\NotificationLog; |
| 6 | use App\Notification\Domain\Model\NotificationStatus; |
| 7 | use App\Notification\Domain\Port\Driven\NotificationLogRepository; |
| 8 | use App\Notification\Infrastructure\Persistence\Doctrine\Entity\DoctrineNotificationLog; |
| 9 | use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; |
| 10 | use Doctrine\ORM\EntityManagerInterface; |
| 11 | use Doctrine\Persistence\ManagerRegistry; |
| 12 | |
| 13 | /** |
| 14 | * @author Wilhelm Zwertvaegher |
| 15 | * @extends ServiceEntityRepository<DoctrineNotificationLog> |
| 16 | */ |
| 17 | class DoctrineNotificationLogRepository extends ServiceEntityRepository implements NotificationLogRepository |
| 18 | { |
| 19 | |
| 20 | public function __construct(ManagerRegistry $managerRegistry, private readonly EntityManagerInterface $entityManager) |
| 21 | { |
| 22 | parent::__construct($managerRegistry, DoctrineNotificationLog::class); |
| 23 | } |
| 24 | |
| 25 | public function save(NotificationLog $notificationLog): void |
| 26 | { |
| 27 | // reloading to get an attached entity if it already exists |
| 28 | $doctrineEntity = $this->find($notificationLog->getId()) ?? new DoctrineNotificationLog(); |
| 29 | $doctrineEntity->fromDomain($notificationLog); |
| 30 | $this->entityManager->persist($doctrineEntity); |
| 31 | } |
| 32 | |
| 33 | /** |
| 34 | * @param string $messageId |
| 35 | * @return array<NotificationLog> |
| 36 | */ |
| 37 | public function findByMessageId(string $messageId): array |
| 38 | { |
| 39 | return array_map(fn(DoctrineNotificationLog $log) => $log->toDomain(), $this->findBy(['messageId' => $messageId])); |
| 40 | } |
| 41 | |
| 42 | /** |
| 43 | * @param string $messageId |
| 44 | * @param string $sender |
| 45 | * @return array<NotificationLog> |
| 46 | */ |
| 47 | public function findByMessageIdAndSender(string $messageId, string $sender): array |
| 48 | { |
| 49 | return array_map(fn(DoctrineNotificationLog $log) => $log->toDomain(), $this->findBy(['messageId' => $messageId, 'sender' => $sender])); |
| 50 | } |
| 51 | |
| 52 | /** |
| 53 | * @param string $messageId |
| 54 | * @param string $sender |
| 55 | * @param NotificationStatus $status |
| 56 | * @return array<NotificationLog> |
| 57 | */ |
| 58 | public function findByMessageIdAndSenderAndStatus(string $messageId, string $sender, NotificationStatus $status): array |
| 59 | { |
| 60 | return array_map(fn(DoctrineNotificationLog $log) => $log->toDomain(), $this->findBy(['messageId' => $messageId, 'sender' => $sender, 'status' => $status])); |
| 61 | } |
| 62 | |
| 63 | /** |
| 64 | * @param string $messageId |
| 65 | * @param NotificationStatus $status |
| 66 | * @return array<NotificationLog> |
| 67 | */ |
| 68 | public function findByMessageIdAndStatus(string $messageId, NotificationStatus $status): array |
| 69 | { |
| 70 | return array_map(fn(DoctrineNotificationLog $log) => $log->toDomain(), $this->findBy(['messageId' => $messageId, 'status' => $status])); |
| 71 | } |
| 72 | |
| 73 | public function hasSuccess(string $messageId, string $sender): bool |
| 74 | { |
| 75 | return count($this->findByMessageIdAndSenderAndStatus($messageId, $sender, NotificationStatus::SENT)) > 0; |
| 76 | } |
| 77 | } |
Below are the source code lines that represent each code path as identified by Xdebug. Please note a path is not
necessarily coterminous with a line, a line may contain multiple paths and therefore show up more than once.
Please also be aware that some paths may include implicit rather than explicit branches, e.g. an if statement
always has an else as part of its logical flow even if you didn't write one.
| 20 | public function __construct(ManagerRegistry $managerRegistry, private readonly EntityManagerInterface $entityManager) |
| 21 | { |
| 22 | parent::__construct($managerRegistry, DoctrineNotificationLog::class); |
| 23 | } |
| 37 | public function findByMessageId(string $messageId): array |
| 38 | { |
| 39 | return array_map(fn(DoctrineNotificationLog $log) => $log->toDomain(), $this->findBy(['messageId' => $messageId])); |
| 40 | } |
| 47 | public function findByMessageIdAndSender(string $messageId, string $sender): array |
| 48 | { |
| 49 | return array_map(fn(DoctrineNotificationLog $log) => $log->toDomain(), $this->findBy(['messageId' => $messageId, 'sender' => $sender])); |
| 50 | } |
| 58 | public function findByMessageIdAndSenderAndStatus(string $messageId, string $sender, NotificationStatus $status): array |
| 59 | { |
| 60 | return array_map(fn(DoctrineNotificationLog $log) => $log->toDomain(), $this->findBy(['messageId' => $messageId, 'sender' => $sender, 'status' => $status])); |
| 61 | } |
| 68 | public function findByMessageIdAndStatus(string $messageId, NotificationStatus $status): array |
| 69 | { |
| 70 | return array_map(fn(DoctrineNotificationLog $log) => $log->toDomain(), $this->findBy(['messageId' => $messageId, 'status' => $status])); |
| 71 | } |
| 73 | public function hasSuccess(string $messageId, string $sender): bool |
| 74 | { |
| 75 | return count($this->findByMessageIdAndSenderAndStatus($messageId, $sender, NotificationStatus::SENT)) > 0; |
| 76 | } |
| 25 | public function save(NotificationLog $notificationLog): void |
| 26 | { |
| 27 | // reloading to get an attached entity if it already exists |
| 28 | $doctrineEntity = $this->find($notificationLog->getId()) ?? new DoctrineNotificationLog(); |
| 29 | $doctrineEntity->fromDomain($notificationLog); |
| 30 | $this->entityManager->persist($doctrineEntity); |
| 31 | } |
| 39 | return array_map(fn(DoctrineNotificationLog $log) => $log->toDomain(), $this->findBy(['messageId' => $messageId])); |
| 49 | return array_map(fn(DoctrineNotificationLog $log) => $log->toDomain(), $this->findBy(['messageId' => $messageId, 'sender' => $sender])); |
| 60 | return array_map(fn(DoctrineNotificationLog $log) => $log->toDomain(), $this->findBy(['messageId' => $messageId, 'sender' => $sender, 'status' => $status])); |
| 70 | return array_map(fn(DoctrineNotificationLog $log) => $log->toDomain(), $this->findBy(['messageId' => $messageId, 'status' => $status])); |
| 3 | namespace App\Notification\Infrastructure\Persistence\Doctrine\Repository; |
| 4 | |
| 5 | use App\Notification\Domain\Model\NotificationLog; |
| 6 | use App\Notification\Domain\Model\NotificationStatus; |
| 7 | use App\Notification\Domain\Port\Driven\NotificationLogRepository; |
| 8 | use App\Notification\Infrastructure\Persistence\Doctrine\Entity\DoctrineNotificationLog; |
| 9 | use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; |
| 10 | use Doctrine\ORM\EntityManagerInterface; |
| 11 | use Doctrine\Persistence\ManagerRegistry; |
| 12 | |
| 13 | /** |
| 14 | * @author Wilhelm Zwertvaegher |
| 15 | * @extends ServiceEntityRepository<DoctrineNotificationLog> |
| 16 | */ |
| 17 | class DoctrineNotificationLogRepository extends ServiceEntityRepository implements NotificationLogRepository |
| 18 | { |
| 19 | |
| 20 | public function __construct(ManagerRegistry $managerRegistry, private readonly EntityManagerInterface $entityManager) |
| 21 | { |
| 22 | parent::__construct($managerRegistry, DoctrineNotificationLog::class); |
| 23 | } |
| 24 | |
| 25 | public function save(NotificationLog $notificationLog): void |
| 26 | { |
| 27 | // reloading to get an attached entity if it already exists |
| 28 | $doctrineEntity = $this->find($notificationLog->getId()) ?? new DoctrineNotificationLog(); |
| 29 | $doctrineEntity->fromDomain($notificationLog); |
| 30 | $this->entityManager->persist($doctrineEntity); |
| 31 | } |
| 32 | |
| 33 | /** |
| 34 | * @param string $messageId |
| 35 | * @return array<NotificationLog> |
| 36 | */ |
| 37 | public function findByMessageId(string $messageId): array |
| 38 | { |
| 39 | return array_map(fn(DoctrineNotificationLog $log) => $log->toDomain(), $this->findBy(['messageId' => $messageId])); |
| 40 | } |
| 41 | |
| 42 | /** |
| 43 | * @param string $messageId |
| 44 | * @param string $sender |
| 45 | * @return array<NotificationLog> |
| 46 | */ |
| 47 | public function findByMessageIdAndSender(string $messageId, string $sender): array |
| 48 | { |
| 49 | return array_map(fn(DoctrineNotificationLog $log) => $log->toDomain(), $this->findBy(['messageId' => $messageId, 'sender' => $sender])); |
| 50 | } |
| 51 | |
| 52 | /** |
| 53 | * @param string $messageId |
| 54 | * @param string $sender |
| 55 | * @param NotificationStatus $status |
| 56 | * @return array<NotificationLog> |
| 57 | */ |
| 58 | public function findByMessageIdAndSenderAndStatus(string $messageId, string $sender, NotificationStatus $status): array |
| 59 | { |
| 60 | return array_map(fn(DoctrineNotificationLog $log) => $log->toDomain(), $this->findBy(['messageId' => $messageId, 'sender' => $sender, 'status' => $status])); |
| 61 | } |
| 62 | |
| 63 | /** |
| 64 | * @param string $messageId |
| 65 | * @param NotificationStatus $status |
| 66 | * @return array<NotificationLog> |
| 67 | */ |
| 68 | public function findByMessageIdAndStatus(string $messageId, NotificationStatus $status): array |
| 69 | { |
| 70 | return array_map(fn(DoctrineNotificationLog $log) => $log->toDomain(), $this->findBy(['messageId' => $messageId, 'status' => $status])); |
| 71 | } |
| 72 | |
| 73 | public function hasSuccess(string $messageId, string $sender): bool |
| 74 | { |
| 75 | return count($this->findByMessageIdAndSenderAndStatus($messageId, $sender, NotificationStatus::SENT)) > 0; |
| 76 | } |