Code Coverage |
||||||||||||||||
Lines |
Branches |
Paths |
Functions and Methods |
Classes and Traits |
||||||||||||
| Total | |
100.00% |
14 / 14 |
|
89.47% |
17 / 19 |
|
56.25% |
9 / 16 |
|
80.00% |
4 / 5 |
CRAP | |
0.00% |
0 / 1 |
| GenderCriterion | |
100.00% |
14 / 14 |
|
89.47% |
17 / 19 |
|
56.25% |
9 / 16 |
|
100.00% |
5 / 5 |
21.13 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getAllowedValues | |
100.00% |
10 / 10 |
|
86.67% |
13 / 15 |
|
41.67% |
5 / 12 |
|
100.00% |
1 / 1 |
16.73 | |||
| getField | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| shouldApply | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getTargetEntity | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace App\Specification\Criterion; |
| 4 | |
| 5 | use App\Entity\Word; |
| 6 | use App\Enum\WordGender; |
| 7 | |
| 8 | /** |
| 9 | * @implements EnumCriterion<WordGender> |
| 10 | * |
| 11 | * @author Wilhelm Zwertvaegher |
| 12 | */ |
| 13 | readonly class GenderCriterion implements EnumCriterion |
| 14 | { |
| 15 | public function __construct( |
| 16 | private ?WordGender $gender = null, |
| 17 | private ?GenderConstraintType $genderConstraintType = GenderConstraintType::RELAXED, |
| 18 | ) { |
| 19 | } |
| 20 | |
| 21 | /** |
| 22 | * @return array<WordGender> |
| 23 | */ |
| 24 | public function getAllowedValues(): array |
| 25 | { |
| 26 | // TODO this should be removed because GenderCriterion does not apply when gender is not set |
| 27 | if (null === $this->gender || WordGender::AUTO === $this->gender) { |
| 28 | return WordGender::cases(); |
| 29 | } |
| 30 | |
| 31 | // asking for NEUTRAL always requires a word to be NEUTRAL only |
| 32 | // M, F or AUTO are compatible because they have a defined gender by definition |
| 33 | if (WordGender::NEUTRAL === $this->gender) { |
| 34 | return [WordGender::NEUTRAL]; |
| 35 | } |
| 36 | |
| 37 | if (GenderConstraintType::EXACT == $this->genderConstraintType) { |
| 38 | // asking for a non-neutral gender in EXACT mode implies compatibility with AUTO words that can be M or F |
| 39 | return [$this->gender, WordGender::AUTO]; |
| 40 | } |
| 41 | |
| 42 | return match ($this->gender) { |
| 43 | // AUTO and NEUTRAL are compatible with F |
| 44 | WordGender::F => [WordGender::F, WordGender::AUTO, WordGender::NEUTRAL], |
| 45 | // AUTO and NEUTRAL are compatible with M |
| 46 | WordGender::M => [WordGender::M, WordGender::AUTO, WordGender::NEUTRAL], |
| 47 | }; |
| 48 | } |
| 49 | |
| 50 | public function getField(): string |
| 51 | { |
| 52 | return 'gender'; |
| 53 | } |
| 54 | |
| 55 | public function shouldApply(): bool |
| 56 | { |
| 57 | return !empty($this->gender); |
| 58 | } |
| 59 | |
| 60 | public function getTargetEntity(): string |
| 61 | { |
| 62 | return Word::class; |
| 63 | } |
| 64 | } |