Code Coverage |
||||||||||||||||
Lines |
Branches |
Paths |
Functions and Methods |
Classes and Traits |
||||||||||||
| Total | |
92.31% |
12 / 13 |
|
75.00% |
3 / 4 |
|
66.67% |
2 / 3 |
|
50.00% |
1 / 2 |
CRAP | |
0.00% |
0 / 1 |
| GetWord | |
92.31% |
12 / 13 |
|
75.00% |
3 / 4 |
|
66.67% |
2 / 3 |
|
50.00% |
1 / 2 |
3.33 | |
0.00% |
0 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| __invoke | |
91.67% |
11 / 12 |
|
66.67% |
2 / 3 |
|
50.00% |
1 / 2 |
|
0.00% |
0 / 1 |
2.50 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace App\Application\UseCase; |
| 4 | |
| 5 | use App\Dto\Command\GetWordCommand; |
| 6 | use App\Dto\Response\NickWordDto; |
| 7 | use App\Service\Generator\WordFinderInterface; |
| 8 | use App\Service\Nick\WordFormatterInterface; |
| 9 | use Doctrine\ORM\EntityManagerInterface; |
| 10 | use Psr\Container\ContainerInterface; |
| 11 | use Symfony\Component\DependencyInjection\Attribute\AutowireLocator; |
| 12 | |
| 13 | /** |
| 14 | * @author Wilhelm Zwertvaegher |
| 15 | */ |
| 16 | readonly 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 | } |