Code Coverage
 
Lines
Branches
Paths
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
17 / 17
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
5 / 5
CRAP
100.00% covered (success)
100.00%
1 / 1
NotificationService
100.00% covered (success)
100.00%
17 / 17
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
5 / 5
5
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
 getById
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%
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
 create
100.00% covered (success)
100.00%
12 / 12
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
 updateStatus
100.00% covered (success)
100.00%
2 / 2
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\Service\Data;
4
5use App\Entity\Notification;
6use App\Enum\NotificationStatus;
7use App\Repository\NotificationRepository;
8use App\Service\Notification\Factory\NotificationProps;
9use Doctrine\ORM\EntityManagerInterface;
10use Psr\Clock\ClockInterface;
11
12/**
13 * @author Wilhelm Zwertvaegher
14 */
15readonly class NotificationService implements NotificationServiceInterface
16{
17    public function __construct(
18        private NotificationRepository $notificationRepository,
19        private EntityManagerInterface $entityManager,
20        private ClockInterface $clock,
21    ) {
22    }
23
24    public function getById(int $id): ?Notification
25    {
26        return $this->notificationRepository->getById($id);
27    }
28
29    public function save(Notification $notification): void
30    {
31        $this->entityManager->persist($notification);
32    }
33
34    public function create(NotificationProps $props): Notification
35    {
36        $now = $this->clock->now();
37        $message = new Notification(
38            $props->getType(),
39            $props->getRecipientEmail(),
40            $props->getSubject(),
41            $props->getContent(),
42            NotificationStatus::PENDING,
43            $now,
44            $now
45        );
46
47        $this->save($message);
48
49        return $message;
50    }
51
52    public function updateStatus(Notification $notification, NotificationStatus $notificationStatus): void
53    {
54        $notification->setStatus($notificationStatus, $this->clock->now());
55        $this->save($notification);
56    }
57}