Code Coverage |
||||||||||||||||
Lines |
Branches |
Paths |
Functions and Methods |
Classes and Traits |
||||||||||||
| Total | |
100.00% |
23 / 23 |
|
93.33% |
14 / 15 |
|
66.67% |
6 / 9 |
|
66.67% |
2 / 3 |
CRAP | |
0.00% |
0 / 1 |
| FrenchWordRules | |
100.00% |
23 / 23 |
|
93.33% |
14 / 15 |
|
66.67% |
6 / 9 |
|
100.00% |
3 / 3 |
8.81 | |
100.00% |
1 / 1 |
| getLang | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getLabel | |
100.00% |
16 / 16 |
|
92.31% |
12 / 13 |
|
57.14% |
4 / 7 |
|
100.00% |
1 / 1 |
6.97 | |||
| resolve | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace App\Service\Nick\Strategy; |
| 4 | |
| 5 | use App\Dto\Result\FormattedNickWord; |
| 6 | use App\Entity\GrammaticalRole; |
| 7 | use App\Entity\Word; |
| 8 | use App\Enum\GrammaticalRoleType; |
| 9 | use App\Enum\Lang; |
| 10 | use App\Enum\WordGender; |
| 11 | use Symfony\Component\DependencyInjection\Attribute\AsTaggedItem; |
| 12 | |
| 13 | /** |
| 14 | * @author Wilhelm Zwertvaegher |
| 15 | */ |
| 16 | #[AsTaggedItem(index: Lang::FR->value)] |
| 17 | class FrenchWordRules implements WordRules |
| 18 | { |
| 19 | public function getLang(): Lang |
| 20 | { |
| 21 | return Lang::FR; |
| 22 | } |
| 23 | |
| 24 | private function getLabel(Word $word, WordGender $targetGender): string |
| 25 | { |
| 26 | // sadly, we assume that we don't need to do anything when the target gender is not female |
| 27 | if (WordGender::F != $targetGender) { |
| 28 | return $word->getLabel(); |
| 29 | } |
| 30 | |
| 31 | if (WordGender::AUTO != $word->getGender()) { |
| 32 | return $word->getLabel(); |
| 33 | } |
| 34 | |
| 35 | $rules = [ |
| 36 | 'eux' => 'euse', |
| 37 | 'ien' => 'ienne', |
| 38 | 'eur' => 'euse', |
| 39 | 'if' => 'ive', |
| 40 | 'et' => 'ette', |
| 41 | 'on' => 'onne', |
| 42 | ]; |
| 43 | foreach ($rules as $source => $target) { |
| 44 | if (str_ends_with($word->getLabel(), $source)) { |
| 45 | return preg_replace("/{$source}$/", $target, $word->getLabel()); |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | return $word->getLabel().'e'; |
| 50 | } |
| 51 | |
| 52 | public function resolve(GrammaticalRole $grammaticalRole, WordGender $targetGender): FormattedNickWord |
| 53 | { |
| 54 | $word = $grammaticalRole->getWord(); |
| 55 | |
| 56 | return new FormattedNickWord( |
| 57 | $grammaticalRole->getWord()->getId(), |
| 58 | $this->getLabel($word, $targetGender), |
| 59 | GrammaticalRoleType::fromClass($grammaticalRole::class) |
| 60 | ); |
| 61 | } |
| 62 | } |
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.
| 24 | private function getLabel(Word $word, WordGender $targetGender): string |
| 25 | { |
| 26 | // sadly, we assume that we don't need to do anything when the target gender is not female |
| 27 | if (WordGender::F != $targetGender) { |
| 28 | return $word->getLabel(); |
| 31 | if (WordGender::AUTO != $word->getGender()) { |
| 32 | return $word->getLabel(); |
| 35 | $rules = [ |
| 36 | 'eux' => 'euse', |
| 37 | 'ien' => 'ienne', |
| 38 | 'eur' => 'euse', |
| 39 | 'if' => 'ive', |
| 40 | 'et' => 'ette', |
| 41 | 'on' => 'onne', |
| 42 | ]; |
| 43 | foreach ($rules as $source => $target) { |
| 43 | foreach ($rules as $source => $target) { |
| 43 | foreach ($rules as $source => $target) { |
| 44 | if (str_ends_with($word->getLabel(), $source)) { |
| 45 | return preg_replace("/{$source}$/", $target, $word->getLabel()); |
| 45 | return preg_replace("/{$source}$/", $target, $word->getLabel()); |
| 45 | return preg_replace("/{$source}$/", $target, $word->getLabel()); |
| 45 | return preg_replace("/{$source}$/", $target, $word->getLabel()); |
| 43 | foreach ($rules as $source => $target) { |
| 43 | foreach ($rules as $source => $target) { |
| 44 | if (str_ends_with($word->getLabel(), $source)) { |
| 45 | return preg_replace("/{$source}$/", $target, $word->getLabel()); |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | return $word->getLabel().'e'; |
| 50 | } |
| 21 | return Lang::FR; |
| 22 | } |
| 52 | public function resolve(GrammaticalRole $grammaticalRole, WordGender $targetGender): FormattedNickWord |
| 53 | { |
| 54 | $word = $grammaticalRole->getWord(); |
| 55 | |
| 56 | return new FormattedNickWord( |
| 57 | $grammaticalRole->getWord()->getId(), |
| 58 | $this->getLabel($word, $targetGender), |
| 59 | GrammaticalRoleType::fromClass($grammaticalRole::class) |
| 60 | ); |
| 61 | } |
| 3 | namespace App\Service\Nick\Strategy; |
| 4 | |
| 5 | use App\Dto\Result\FormattedNickWord; |
| 6 | use App\Entity\GrammaticalRole; |
| 7 | use App\Entity\Word; |
| 8 | use App\Enum\GrammaticalRoleType; |
| 9 | use App\Enum\Lang; |
| 10 | use App\Enum\WordGender; |
| 11 | use Symfony\Component\DependencyInjection\Attribute\AsTaggedItem; |
| 12 | |
| 13 | /** |
| 14 | * @author Wilhelm Zwertvaegher |
| 15 | */ |
| 16 | #[AsTaggedItem(index: Lang::FR->value)] |
| 17 | class FrenchWordRules implements WordRules |
| 18 | { |
| 19 | public function getLang(): Lang |
| 20 | { |
| 21 | return Lang::FR; |
| 22 | } |
| 23 | |
| 24 | private function getLabel(Word $word, WordGender $targetGender): string |
| 25 | { |
| 26 | // sadly, we assume that we don't need to do anything when the target gender is not female |
| 27 | if (WordGender::F != $targetGender) { |
| 28 | return $word->getLabel(); |
| 29 | } |
| 30 | |
| 31 | if (WordGender::AUTO != $word->getGender()) { |
| 32 | return $word->getLabel(); |
| 33 | } |
| 34 | |
| 35 | $rules = [ |
| 36 | 'eux' => 'euse', |
| 37 | 'ien' => 'ienne', |
| 38 | 'eur' => 'euse', |
| 39 | 'if' => 'ive', |
| 40 | 'et' => 'ette', |
| 41 | 'on' => 'onne', |
| 42 | ]; |
| 43 | foreach ($rules as $source => $target) { |
| 44 | if (str_ends_with($word->getLabel(), $source)) { |
| 45 | return preg_replace("/{$source}$/", $target, $word->getLabel()); |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | return $word->getLabel().'e'; |
| 50 | } |
| 51 | |
| 52 | public function resolve(GrammaticalRole $grammaticalRole, WordGender $targetGender): FormattedNickWord |
| 53 | { |
| 54 | $word = $grammaticalRole->getWord(); |
| 55 | |
| 56 | return new FormattedNickWord( |
| 57 | $grammaticalRole->getWord()->getId(), |
| 58 | $this->getLabel($word, $targetGender), |
| 59 | GrammaticalRoleType::fromClass($grammaticalRole::class) |
| 60 | ); |
| 61 | } |