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}

Branches

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.

NotificationService->__construct
17    public function __construct(
18        private NotificationRepository $notificationRepository,
19        private EntityManagerInterface $entityManager,
20        private ClockInterface $clock,
21    ) {
22    }
NotificationService->create
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    }
NotificationService->getById
24    public function getById(int $id): ?Notification
25    {
26        return $this->notificationRepository->getById($id);
27    }
NotificationService->save
29    public function save(Notification $notification): void
30    {
31        $this->entityManager->persist($notification);
32    }
NotificationService->updateStatus
52    public function updateStatus(Notification $notification, NotificationStatus $notificationStatus): void
53    {
54        $notification->setStatus($notificationStatus, $this->clock->now());
55        $this->save($notification);
56    }
{main}
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    }