Code Coverage
 
Lines
Branches
Paths
Functions and Methods
Classes and Traits
Total
92.31% covered (success)
92.31%
12 / 13
75.00% covered (warning)
75.00%
3 / 4
66.67% covered (warning)
66.67%
2 / 3
50.00% covered (danger)
50.00%
1 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
GetWord
92.31% covered (success)
92.31%
12 / 13
75.00% covered (warning)
75.00%
3 / 4
66.67% covered (warning)
66.67%
2 / 3
50.00% covered (danger)
50.00%
1 / 2
3.33
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
 __invoke
91.67% covered (success)
91.67%
11 / 12
66.67% covered (warning)
66.67%
2 / 3
50.00% covered (danger)
50.00%
1 / 2
0.00% covered (danger)
0.00%
0 / 1
2.50
1<?php
2
3namespace App\Application\UseCase;
4
5use App\Dto\Command\GetWordCommand;
6use App\Dto\Response\NickWordDto;
7use App\Service\Generator\WordFinderInterface;
8use App\Service\Nick\WordFormatterInterface;
9use Doctrine\ORM\EntityManagerInterface;
10use Psr\Container\ContainerInterface;
11use Symfony\Component\DependencyInjection\Attribute\AutowireLocator;
12
13/**
14 * @author Wilhelm Zwertvaegher
15 */
16readonly class GetWord implements GetWordInterface
17{
18    public function __construct(
19        #[AutowireLocator('app.word_type_data_service', indexAttribute: 'index')]
20        private ContainerInterface $services,
21        private WordFinderInterface $wordFinder,
22        private WordFormatterInterface $formatter,
23        private EntityManagerInterface $entityManager,
24    ) {
25    }
26
27    public function __invoke(GetWordCommand $command): NickWordDto
28    {
29        $new = $this->wordFinder->findSimilar($command);
30        if (!$this->services->has($command->getRole()->value)) {
31            throw new \LogicException('Command with role "'.$command->getRole()->value.'" has no matching GrammaticalRoleServiceInterface.');
32        }
33        $this->services->get($command->getRole()->value)->incrementUsageCount($new);
34        $this->entityManager->flush();
35        // build the nick word dto
36        $targetGender = $command->getGender();
37        $formattedNickWord = $this->formatter->format($new, $targetGender);
38
39        return new NickWordDto(
40            $new->getWord()->getId(),
41            $formattedNickWord->label,
42            $formattedNickWord->type
43        );
44    }
45}

Paths

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.

GetWord->__construct
18    public function __construct(
19        #[AutowireLocator('app.word_type_data_service', indexAttribute: 'index')]
20        private ContainerInterface $services,
21        private WordFinderInterface $wordFinder,
22        private WordFormatterInterface $formatter,
23        private EntityManagerInterface $entityManager,
24    ) {
25    }
GetWord->__invoke
27    public function __invoke(GetWordCommand $command): NickWordDto
28    {
29        $new = $this->wordFinder->findSimilar($command);
30        if (!$this->services->has($command->getRole()->value)) {
 
31            throw new \LogicException('Command with role "'.$command->getRole()->value.'" has no matching GrammaticalRoleServiceInterface.');
27    public function __invoke(GetWordCommand $command): NickWordDto
28    {
29        $new = $this->wordFinder->findSimilar($command);
30        if (!$this->services->has($command->getRole()->value)) {
 
33        $this->services->get($command->getRole()->value)->incrementUsageCount($new);
34        $this->entityManager->flush();
35        // build the nick word dto
36        $targetGender = $command->getGender();
37        $formattedNickWord = $this->formatter->format($new, $targetGender);
38
39        return new NickWordDto(
40            $new->getWord()->getId(),
41            $formattedNickWord->label,
42            $formattedNickWord->type
43        );
44    }
{main}
3namespace App\Application\UseCase;
4
5use App\Dto\Command\GetWordCommand;
6use App\Dto\Response\NickWordDto;
7use App\Service\Generator\WordFinderInterface;
8use App\Service\Nick\WordFormatterInterface;
9use Doctrine\ORM\EntityManagerInterface;
10use Psr\Container\ContainerInterface;
11use Symfony\Component\DependencyInjection\Attribute\AutowireLocator;
12
13/**
14 * @author Wilhelm Zwertvaegher
15 */
16readonly class GetWord implements GetWordInterface
17{
18    public function __construct(
19        #[AutowireLocator('app.word_type_data_service', indexAttribute: 'index')]
20        private ContainerInterface $services,
21        private WordFinderInterface $wordFinder,
22        private WordFormatterInterface $formatter,
23        private EntityManagerInterface $entityManager,
24    ) {
25    }
26
27    public function __invoke(GetWordCommand $command): NickWordDto
28    {
29        $new = $this->wordFinder->findSimilar($command);
30        if (!$this->services->has($command->getRole()->value)) {
31            throw new \LogicException('Command with role "'.$command->getRole()->value.'" has no matching GrammaticalRoleServiceInterface.');
32        }
33        $this->services->get($command->getRole()->value)->incrementUsageCount($new);
34        $this->entityManager->flush();
35        // build the nick word dto
36        $targetGender = $command->getGender();
37        $formattedNickWord = $this->formatter->format($new, $targetGender);
38
39        return new NickWordDto(
40            $new->getWord()->getId(),
41            $formattedNickWord->label,
42            $formattedNickWord->type
43        );
44    }