Code Coverage
 
Lines
Branches
Paths
Functions and Methods
Classes and Traits
Total
87.50% covered (warning)
87.50%
14 / 16
71.43% covered (warning)
71.43%
5 / 7
60.00% covered (warning)
60.00%
3 / 5
66.67% covered (warning)
66.67%
2 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
ReportService
87.50% covered (warning)
87.50%
14 / 16
71.43% covered (warning)
71.43%
5 / 7
60.00% covered (warning)
60.00%
3 / 5
66.67% covered (warning)
66.67%
2 / 3
6.60
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%
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
85.71% covered (warning)
85.71%
12 / 14
60.00% covered (warning)
60.00%
3 / 5
33.33% covered (danger)
33.33%
1 / 3
0.00% covered (danger)
0.00%
0 / 1
5.67
1<?php
2
3namespace App\Service\Data;
4
5use App\Dto\Command\CreateReportCommand;
6use App\Entity\Report;
7use App\Exception\NickNotFoundException;
8use App\Repository\NickRepositoryInterface;
9use App\Repository\ReportRepositoryInterface;
10use Doctrine\ORM\EntityManagerInterface;
11use Psr\Clock\ClockInterface;
12
13/**
14 * @author Wilhelm Zwertvaegher
15 */
16readonly class ReportService implements ReportServiceInterface
17{
18    public function __construct(
19        private NickRepositoryInterface $nickRepository,
20        private ReportRepositoryInterface $reportRepository,
21        private EntityManagerInterface $entityManager,
22        private ClockInterface $clock,
23    ) {
24    }
25
26    public function save(Report $report): void
27    {
28        $this->entityManager->persist($report);
29    }
30
31    public function create(CreateReportCommand $command): Report
32    {
33        $nick = $this->nickRepository->getById($command->getNickId());
34        if (null === $nick) {
35            throw new NickNotFoundException();
36        }
37
38        $existingReport = $this->reportRepository->getByNickIdAndSenderEmail($nick->getId(), $command->getSenderEmail());
39        if (null !== $existingReport) {
40            return $existingReport;
41        }
42
43        $report = new Report(
44            senderEmail: $command->getSenderEmail(),
45            reason: $command->getReason(),
46            nick: $nick,
47            createdAt: $this->clock->now()
48        );
49
50        $this->save($report);
51
52        return $report;
53    }
54}

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.

ReportService->__construct
18    public function __construct(
19        private NickRepositoryInterface $nickRepository,
20        private ReportRepositoryInterface $reportRepository,
21        private EntityManagerInterface $entityManager,
22        private ClockInterface $clock,
23    ) {
24    }
ReportService->create
31    public function create(CreateReportCommand $command): Report
32    {
33        $nick = $this->nickRepository->getById($command->getNickId());
34        if (null === $nick) {
35            throw new NickNotFoundException();
38        $existingReport = $this->reportRepository->getByNickIdAndSenderEmail($nick->getId(), $command->getSenderEmail());
39        if (null !== $existingReport) {
40            return $existingReport;
43        $report = new Report(
44            senderEmail: $command->getSenderEmail(),
45            reason: $command->getReason(),
46            nick: $nick,
47            createdAt: $this->clock->now()
48        );
49
50        $this->save($report);
51
52        return $report;
53    }
ReportService->save
26    public function save(Report $report): void
27    {
28        $this->entityManager->persist($report);
29    }
{main}
3namespace App\Service\Data;
4
5use App\Dto\Command\CreateReportCommand;
6use App\Entity\Report;
7use App\Exception\NickNotFoundException;
8use App\Repository\NickRepositoryInterface;
9use App\Repository\ReportRepositoryInterface;
10use Doctrine\ORM\EntityManagerInterface;
11use Psr\Clock\ClockInterface;
12
13/**
14 * @author Wilhelm Zwertvaegher
15 */
16readonly class ReportService implements ReportServiceInterface
17{
18    public function __construct(
19        private NickRepositoryInterface $nickRepository,
20        private ReportRepositoryInterface $reportRepository,
21        private EntityManagerInterface $entityManager,
22        private ClockInterface $clock,
23    ) {
24    }
25
26    public function save(Report $report): void
27    {
28        $this->entityManager->persist($report);
29    }
30
31    public function create(CreateReportCommand $command): Report
32    {
33        $nick = $this->nickRepository->getById($command->getNickId());
34        if (null === $nick) {
35            throw new NickNotFoundException();
36        }
37
38        $existingReport = $this->reportRepository->getByNickIdAndSenderEmail($nick->getId(), $command->getSenderEmail());
39        if (null !== $existingReport) {
40            return $existingReport;
41        }
42
43        $report = new Report(
44            senderEmail: $command->getSenderEmail(),
45            reason: $command->getReason(),
46            nick: $nick,
47            createdAt: $this->clock->now()
48        );
49
50        $this->save($report);
51
52        return $report;
53    }