Code Coverage
 
Lines
Branches
Paths
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
23 / 23
93.33% covered (success)
93.33%
14 / 15
66.67% covered (warning)
66.67%
6 / 9
66.67% covered (warning)
66.67%
2 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
FrenchWordRules
100.00% covered (success)
100.00%
23 / 23
93.33% covered (success)
93.33%
14 / 15
66.67% covered (warning)
66.67%
6 / 9
100.00% covered (success)
100.00%
3 / 3
8.81
100.00% covered (success)
100.00%
1 / 1
 getLang
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
 getLabel
100.00% covered (success)
100.00%
16 / 16
92.31% covered (success)
92.31%
12 / 13
57.14% covered (warning)
57.14%
4 / 7
100.00% covered (success)
100.00%
1 / 1
6.97
 resolve
100.00% covered (success)
100.00%
6 / 6
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
1<?php
2
3namespace App\Service\Nick\Strategy;
4
5use App\Dto\Result\FormattedNickWord;
6use App\Entity\GrammaticalRole;
7use App\Entity\Word;
8use App\Enum\GrammaticalRoleType;
9use App\Enum\Lang;
10use App\Enum\WordGender;
11use Symfony\Component\DependencyInjection\Attribute\AsTaggedItem;
12
13/**
14 * @author Wilhelm Zwertvaegher
15 */
16#[AsTaggedItem(index: Lang::FR->value)]
17class 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}

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.

FrenchWordRules->getLabel
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    }
FrenchWordRules->getLang
21        return Lang::FR;
22    }
FrenchWordRules->resolve
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    }
{main}
3namespace App\Service\Nick\Strategy;
4
5use App\Dto\Result\FormattedNickWord;
6use App\Entity\GrammaticalRole;
7use App\Entity\Word;
8use App\Enum\GrammaticalRoleType;
9use App\Enum\Lang;
10use App\Enum\WordGender;
11use Symfony\Component\DependencyInjection\Attribute\AsTaggedItem;
12
13/**
14 * @author Wilhelm Zwertvaegher
15 */
16#[AsTaggedItem(index: Lang::FR->value)]
17class 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    }