Code Coverage
 
Lines
Branches
Paths
Functions and Methods
Classes and Traits
Total
88.89% covered (warning)
88.89%
8 / 9
85.71% covered (warning)
85.71%
6 / 7
85.71% covered (warning)
85.71%
6 / 7
85.71% covered (warning)
85.71%
6 / 7
CRAP
0.00% covered (danger)
0.00%
0 / 1
DoctrineNotificationLogRepository
88.89% covered (warning)
88.89%
8 / 9
85.71% covered (warning)
85.71%
6 / 7
85.71% covered (warning)
85.71%
6 / 7
85.71% covered (warning)
85.71%
6 / 7
7.14
0.00% covered (danger)
0.00%
0 / 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
 save
100.00% covered (success)
100.00%
3 / 3
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
 findByMessageId
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
 findByMessageIdAndSender
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 findByMessageIdAndSenderAndStatus
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
 findByMessageIdAndStatus
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
 hasSuccess
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
1<?php
2
3namespace App\Notification\Infrastructure\Persistence\Doctrine\Repository;
4
5use App\Notification\Domain\Model\NotificationLog;
6use App\Notification\Domain\Model\NotificationStatus;
7use App\Notification\Domain\Port\Driven\NotificationLogRepository;
8use App\Notification\Infrastructure\Persistence\Doctrine\Entity\DoctrineNotificationLog;
9use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
10use Doctrine\ORM\EntityManagerInterface;
11use Doctrine\Persistence\ManagerRegistry;
12
13/**
14 * @author Wilhelm Zwertvaegher
15 * @extends ServiceEntityRepository<DoctrineNotificationLog>
16 */
17class 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}