Code Coverage |
||||||||||||||||
Lines |
Branches |
Paths |
Functions and Methods |
Classes and Traits |
||||||||||||
| Total | |
100.00% |
16 / 16 |
|
88.89% |
8 / 9 |
|
80.00% |
4 / 5 |
|
66.67% |
2 / 3 |
CRAP | |
0.00% |
0 / 1 |
| WordFormatter | |
100.00% |
16 / 16 |
|
88.89% |
8 / 9 |
|
80.00% |
4 / 5 |
|
100.00% |
3 / 3 |
4.13 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| applyCommonFormat | |
100.00% |
5 / 5 |
|
75.00% |
3 / 4 |
|
50.00% |
1 / 2 |
|
100.00% |
1 / 1 |
1.12 | |||
| format | |
100.00% |
10 / 10 |
|
100.00% |
4 / 4 |
|
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace App\Service\Nick; |
| 4 | |
| 5 | use App\Dto\Result\FormattedNickWord; |
| 6 | use App\Entity\GrammaticalRole; |
| 7 | use App\Enum\GrammaticalRoleType; |
| 8 | use App\Enum\WordGender; |
| 9 | use Psr\Container\ContainerInterface; |
| 10 | use Symfony\Component\DependencyInjection\Attribute\AutowireLocator; |
| 11 | |
| 12 | /** |
| 13 | * @author Wilhelm Zwertvaegher |
| 14 | */ |
| 15 | readonly 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 | } |
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.
| 17 | public function __construct( |
| 18 | #[AutowireLocator('app.word_rules', indexAttribute: 'index')] |
| 19 | private ContainerInterface $wordRules, |
| 20 | ) { |
| 21 | } |
| 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))), |
| 31 | $formattedNickWord->type |
| 32 | ); |
| 33 | } |
| 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))), |
| 31 | $formattedNickWord->type |
| 32 | ); |
| 33 | } |
| 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) : |
| 45 | GrammaticalRoleType::fromClass($grammaticalRole::class) |
| 46 | ) |
| 47 | ); |
| 48 | } |
| 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) ? |
| 42 | new FormattedNickWord( |
| 43 | $word->getId(), |
| 44 | $word->getLabel(), |
| 45 | GrammaticalRoleType::fromClass($grammaticalRole::class) |
| 45 | GrammaticalRoleType::fromClass($grammaticalRole::class) |
| 46 | ) |
| 47 | ); |
| 48 | } |
| 3 | namespace App\Service\Nick; |
| 4 | |
| 5 | use App\Dto\Result\FormattedNickWord; |
| 6 | use App\Entity\GrammaticalRole; |
| 7 | use App\Enum\GrammaticalRoleType; |
| 8 | use App\Enum\WordGender; |
| 9 | use Psr\Container\ContainerInterface; |
| 10 | use Symfony\Component\DependencyInjection\Attribute\AutowireLocator; |
| 11 | |
| 12 | /** |
| 13 | * @author Wilhelm Zwertvaegher |
| 14 | */ |
| 15 | readonly 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 | } |