Code Coverage |
||||||||||||||||
Lines |
Branches |
Paths |
Functions and Methods |
Classes and Traits |
||||||||||||
| Total | |
100.00% |
23 / 23 |
|
100.00% |
9 / 9 |
|
42.86% |
3 / 7 |
|
100.00% |
3 / 3 |
CRAP | |
100.00% |
1 / 1 |
| FrenchNickComposerRules | |
100.00% |
23 / 23 |
|
100.00% |
9 / 9 |
|
42.86% |
3 / 7 |
|
100.00% |
3 / 3 |
16.14 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
12 / 12 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
3 | |||
| getLang | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| apply | |
100.00% |
10 / 10 |
|
100.00% |
7 / 7 |
|
20.00% |
1 / 5 |
|
100.00% |
1 / 1 |
7.61 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace App\Service\Nick\Strategy; |
| 4 | |
| 5 | use App\Dto\Result\ComposedNick; |
| 6 | use App\Dto\Result\FormattedNickWord; |
| 7 | use App\Enum\Lang; |
| 8 | use App\Enum\WordGender; |
| 9 | use Symfony\Component\DependencyInjection\Attribute\AsTaggedItem; |
| 10 | |
| 11 | #[AsTaggedItem(index: Lang::FR->value)] |
| 12 | class FrenchNickComposerRules implements NickComposerRules |
| 13 | { |
| 14 | /** |
| 15 | * @var array<\Closure> |
| 16 | */ |
| 17 | private array $rules; |
| 18 | |
| 19 | public function __construct() |
| 20 | { |
| 21 | $this->rules = [ |
| 22 | 'apostrophe' => function (ComposedNick $words, FormattedNickWord $word, int $key, int $lastKey) { |
| 23 | if ($key !== $lastKey && preg_match('/^[aeiouyàâäéèêëîïôöùûüÿ]/i', $words->getWords()[$key + 1]->label)) { |
| 24 | return new FormattedNickWord( |
| 25 | $word->id, |
| 26 | preg_replace('/ ([dsl])e$/', " \\1'", $word->label), |
| 27 | $word->type, |
| 28 | '' |
| 29 | ); |
| 30 | } |
| 31 | |
| 32 | return $word; |
| 33 | }, |
| 34 | ]; |
| 35 | } |
| 36 | |
| 37 | public function getLang(): Lang |
| 38 | { |
| 39 | return Lang::FR; |
| 40 | } |
| 41 | |
| 42 | public function apply(ComposedNick $composedNick, WordGender $targetGender): ComposedNick |
| 43 | { |
| 44 | /** |
| 45 | * @var array<FormattedNickWord> $resultWords |
| 46 | */ |
| 47 | $resultWords = []; |
| 48 | |
| 49 | $lastKey = array_key_last($composedNick->getWords()); |
| 50 | foreach ($composedNick->getWords() as $key => $word) { |
| 51 | foreach ($this->rules as $rule) { |
| 52 | $resultWords[$key] = $rule($composedNick, $word, $key, $lastKey); |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | return new ComposedNick( |
| 57 | $composedNick->getTargetGender(), |
| 58 | $composedNick->getTargetOffenseLevel(), |
| 59 | $resultWords |
| 60 | ); |
| 61 | } |
| 62 | } |