Code Coverage
 
Lines
Branches
Paths
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
16 / 16
88.89% covered (warning)
88.89%
8 / 9
80.00% covered (warning)
80.00%
4 / 5
66.67% covered (warning)
66.67%
2 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
WordFormatter
100.00% covered (success)
100.00%
16 / 16
88.89% covered (warning)
88.89%
8 / 9
80.00% covered (warning)
80.00%
4 / 5
100.00% covered (success)
100.00%
3 / 3
4.13
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
 applyCommonFormat
100.00% covered (success)
100.00%
5 / 5
75.00% covered (warning)
75.00%
3 / 4
50.00% covered (danger)
50.00%
1 / 2
100.00% covered (success)
100.00%
1 / 1
1.12
 format
100.00% covered (success)
100.00%
10 / 10
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
2
1<?php
2
3namespace App\Service\Nick;
4
5use App\Dto\Result\FormattedNickWord;
6use App\Entity\GrammaticalRole;
7use App\Enum\GrammaticalRoleType;
8use App\Enum\WordGender;
9use Psr\Container\ContainerInterface;
10use Symfony\Component\DependencyInjection\Attribute\AutowireLocator;
11
12/**
13 * @author Wilhelm Zwertvaegher
14 */
15readonly class WordFormatter implements WordFormatterInterface
16{
17    public function __construct(
18        #[AutowireLocator('app.word_rules', indexAttribute: 'index')]
19        private ContainerInterface $wordRules,
20    ) {
21    }
22
23    /**
24     * Apply common formatting on a GeneratedNickWord.
25     */
26    private function applyCommonFormat(FormattedNickWord $formattedNickWord): FormattedNickWord
27    {
28        return new FormattedNickWord(
29            $formattedNickWord->id,
30            trim(ucfirst(strtolower($formattedNickWord->label))),
31            $formattedNickWord->type
32        );
33    }
34
35    public function format(GrammaticalRole $grammaticalRole, WordGender $gender): FormattedNickWord
36    {
37        $word = $grammaticalRole->getWord();
38
39        return $this->applyCommonFormat(
40            $this->wordRules->has($word->getLang()->value) ?
41                $this->wordRules->get($word->getLang()->value)->resolve($grammaticalRole, $gender) :
42                new FormattedNickWord(
43                    $word->getId(),
44                    $word->getLabel(),
45                    GrammaticalRoleType::fromClass($grammaticalRole::class)
46                )
47        );
48    }
49}

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.

WordFormatter->__construct
17    public function __construct(
18        #[AutowireLocator('app.word_rules', indexAttribute: 'index')]
19        private ContainerInterface $wordRules,
20    ) {
21    }
WordFormatter->applyCommonFormat
26    private function applyCommonFormat(FormattedNickWord $formattedNickWord): FormattedNickWord
27    {
28        return new FormattedNickWord(
29            $formattedNickWord->id,
30            trim(ucfirst(strtolower($formattedNickWord->label))),
30            trim(ucfirst(strtolower($formattedNickWord->label))),
30            trim(ucfirst(strtolower($formattedNickWord->label))),
30            trim(ucfirst(strtolower($formattedNickWord->label))),
31            $formattedNickWord->type
32        );
33    }
WordFormatter->format
35    public function format(GrammaticalRole $grammaticalRole, WordGender $gender): FormattedNickWord
36    {
37        $word = $grammaticalRole->getWord();
38
39        return $this->applyCommonFormat(
40            $this->wordRules->has($word->getLang()->value) ?
41                $this->wordRules->get($word->getLang()->value)->resolve($grammaticalRole, $gender) :
42                new FormattedNickWord(
43                    $word->getId(),
44                    $word->getLabel(),
45                    GrammaticalRoleType::fromClass($grammaticalRole::class)
45                    GrammaticalRoleType::fromClass($grammaticalRole::class)
46                )
47        );
48    }
{main}
3namespace App\Service\Nick;
4
5use App\Dto\Result\FormattedNickWord;
6use App\Entity\GrammaticalRole;
7use App\Enum\GrammaticalRoleType;
8use App\Enum\WordGender;
9use Psr\Container\ContainerInterface;
10use Symfony\Component\DependencyInjection\Attribute\AutowireLocator;
11
12/**
13 * @author Wilhelm Zwertvaegher
14 */
15readonly class WordFormatter implements WordFormatterInterface
16{
17    public function __construct(
18        #[AutowireLocator('app.word_rules', indexAttribute: 'index')]
19        private ContainerInterface $wordRules,
20    ) {
21    }
22
23    /**
24     * Apply common formatting on a GeneratedNickWord.
25     */
26    private function applyCommonFormat(FormattedNickWord $formattedNickWord): FormattedNickWord
27    {
28        return new FormattedNickWord(
29            $formattedNickWord->id,
30            trim(ucfirst(strtolower($formattedNickWord->label))),
31            $formattedNickWord->type
32        );
33    }
34
35    public function format(GrammaticalRole $grammaticalRole, WordGender $gender): FormattedNickWord
36    {
37        $word = $grammaticalRole->getWord();
38
39        return $this->applyCommonFormat(
40            $this->wordRules->has($word->getLang()->value) ?
41                $this->wordRules->get($word->getLang()->value)->resolve($grammaticalRole, $gender) :
42                new FormattedNickWord(
43                    $word->getId(),
44                    $word->getLabel(),
45                    GrammaticalRoleType::fromClass($grammaticalRole::class)
46                )
47        );
48    }