Code Coverage
 
Lines
Branches
Paths
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
14 / 14
89.47% covered (warning)
89.47%
17 / 19
56.25% covered (warning)
56.25%
9 / 16
80.00% covered (warning)
80.00%
4 / 5
CRAP
0.00% covered (danger)
0.00%
0 / 1
GenderCriterion
100.00% covered (success)
100.00%
14 / 14
89.47% covered (warning)
89.47%
17 / 19
56.25% covered (warning)
56.25%
9 / 16
100.00% covered (success)
100.00%
5 / 5
21.13
100.00% covered (success)
100.00%
1 / 1
 __construct
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
 getAllowedValues
100.00% covered (success)
100.00%
10 / 10
86.67% covered (warning)
86.67%
13 / 15
41.67% covered (danger)
41.67%
5 / 12
100.00% covered (success)
100.00%
1 / 1
16.73
 getField
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
 shouldApply
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
 getTargetEntity
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
1<?php
2
3namespace App\Specification\Criterion;
4
5use App\Entity\Word;
6use App\Enum\WordGender;
7
8/**
9 * @implements EnumCriterion<WordGender>
10 *
11 * @author Wilhelm Zwertvaegher
12 */
13readonly 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}

Paths

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.

GenderCriterion->__construct
15    public function __construct(
16        private ?WordGender $gender = null,
17        private ?GenderConstraintType $genderConstraintType = GenderConstraintType::RELAXED,
18    ) {
19    }
GenderCriterion->getAllowedValues
27        if (null === $this->gender || WordGender::AUTO === $this->gender) {
 
27        if (null === $this->gender || WordGender::AUTO === $this->gender) {
 
27        if (null === $this->gender || WordGender::AUTO === $this->gender) {
 
28            return WordGender::cases();
27        if (null === $this->gender || WordGender::AUTO === $this->gender) {
 
27        if (null === $this->gender || WordGender::AUTO === $this->gender) {
 
27        if (null === $this->gender || WordGender::AUTO === $this->gender) {
 
33        if (WordGender::NEUTRAL === $this->gender) {
 
34            return [WordGender::NEUTRAL];
27        if (null === $this->gender || WordGender::AUTO === $this->gender) {
 
27        if (null === $this->gender || WordGender::AUTO === $this->gender) {
 
27        if (null === $this->gender || WordGender::AUTO === $this->gender) {
 
33        if (WordGender::NEUTRAL === $this->gender) {
 
37        if (GenderConstraintType::EXACT == $this->genderConstraintType) {
 
39            return [$this->gender, WordGender::AUTO];
27        if (null === $this->gender || WordGender::AUTO === $this->gender) {
 
27        if (null === $this->gender || WordGender::AUTO === $this->gender) {
 
27        if (null === $this->gender || WordGender::AUTO === $this->gender) {
 
33        if (WordGender::NEUTRAL === $this->gender) {
 
37        if (GenderConstraintType::EXACT == $this->genderConstraintType) {
 
42        return match ($this->gender) {
43            // AUTO and NEUTRAL are compatible with F
44            WordGender::F => [WordGender::F, WordGender::AUTO, WordGender::NEUTRAL],
 
46            WordGender::M => [WordGender::M, WordGender::AUTO, WordGender::NEUTRAL],
 
46            WordGender::M => [WordGender::M, WordGender::AUTO, WordGender::NEUTRAL],
 
46            WordGender::M => [WordGender::M, WordGender::AUTO, WordGender::NEUTRAL],
27        if (null === $this->gender || WordGender::AUTO === $this->gender) {
 
27        if (null === $this->gender || WordGender::AUTO === $this->gender) {
 
27        if (null === $this->gender || WordGender::AUTO === $this->gender) {
 
33        if (WordGender::NEUTRAL === $this->gender) {
 
37        if (GenderConstraintType::EXACT == $this->genderConstraintType) {
 
42        return match ($this->gender) {
43            // AUTO and NEUTRAL are compatible with F
44            WordGender::F => [WordGender::F, WordGender::AUTO, WordGender::NEUTRAL],
 
46            WordGender::M => [WordGender::M, WordGender::AUTO, WordGender::NEUTRAL],
 
46            WordGender::M => [WordGender::M, WordGender::AUTO, WordGender::NEUTRAL],
 
46            WordGender::M => [WordGender::M, WordGender::AUTO, WordGender::NEUTRAL],
47        };
48    }
27        if (null === $this->gender || WordGender::AUTO === $this->gender) {
 
27        if (null === $this->gender || WordGender::AUTO === $this->gender) {
 
27        if (null === $this->gender || WordGender::AUTO === $this->gender) {
 
33        if (WordGender::NEUTRAL === $this->gender) {
 
37        if (GenderConstraintType::EXACT == $this->genderConstraintType) {
 
42        return match ($this->gender) {
43            // AUTO and NEUTRAL are compatible with F
44            WordGender::F => [WordGender::F, WordGender::AUTO, WordGender::NEUTRAL],
 
44            WordGender::F => [WordGender::F, WordGender::AUTO, WordGender::NEUTRAL],
 
46            WordGender::M => [WordGender::M, WordGender::AUTO, WordGender::NEUTRAL],
47        };
48    }
27        if (null === $this->gender || WordGender::AUTO === $this->gender) {
 
27        if (null === $this->gender || WordGender::AUTO === $this->gender) {
 
28            return WordGender::cases();
27        if (null === $this->gender || WordGender::AUTO === $this->gender) {
 
27        if (null === $this->gender || WordGender::AUTO === $this->gender) {
 
33        if (WordGender::NEUTRAL === $this->gender) {
 
34            return [WordGender::NEUTRAL];
27        if (null === $this->gender || WordGender::AUTO === $this->gender) {
 
27        if (null === $this->gender || WordGender::AUTO === $this->gender) {
 
33        if (WordGender::NEUTRAL === $this->gender) {
 
37        if (GenderConstraintType::EXACT == $this->genderConstraintType) {
 
39            return [$this->gender, WordGender::AUTO];
27        if (null === $this->gender || WordGender::AUTO === $this->gender) {
 
27        if (null === $this->gender || WordGender::AUTO === $this->gender) {
 
33        if (WordGender::NEUTRAL === $this->gender) {
 
37        if (GenderConstraintType::EXACT == $this->genderConstraintType) {
 
42        return match ($this->gender) {
43            // AUTO and NEUTRAL are compatible with F
44            WordGender::F => [WordGender::F, WordGender::AUTO, WordGender::NEUTRAL],
 
46            WordGender::M => [WordGender::M, WordGender::AUTO, WordGender::NEUTRAL],
 
46            WordGender::M => [WordGender::M, WordGender::AUTO, WordGender::NEUTRAL],
 
46            WordGender::M => [WordGender::M, WordGender::AUTO, WordGender::NEUTRAL],
27        if (null === $this->gender || WordGender::AUTO === $this->gender) {
 
27        if (null === $this->gender || WordGender::AUTO === $this->gender) {
 
33        if (WordGender::NEUTRAL === $this->gender) {
 
37        if (GenderConstraintType::EXACT == $this->genderConstraintType) {
 
42        return match ($this->gender) {
43            // AUTO and NEUTRAL are compatible with F
44            WordGender::F => [WordGender::F, WordGender::AUTO, WordGender::NEUTRAL],
 
46            WordGender::M => [WordGender::M, WordGender::AUTO, WordGender::NEUTRAL],
 
46            WordGender::M => [WordGender::M, WordGender::AUTO, WordGender::NEUTRAL],
 
46            WordGender::M => [WordGender::M, WordGender::AUTO, WordGender::NEUTRAL],
47        };
48    }
27        if (null === $this->gender || WordGender::AUTO === $this->gender) {
 
27        if (null === $this->gender || WordGender::AUTO === $this->gender) {
 
33        if (WordGender::NEUTRAL === $this->gender) {
 
37        if (GenderConstraintType::EXACT == $this->genderConstraintType) {
 
42        return match ($this->gender) {
43            // AUTO and NEUTRAL are compatible with F
44            WordGender::F => [WordGender::F, WordGender::AUTO, WordGender::NEUTRAL],
 
44            WordGender::F => [WordGender::F, WordGender::AUTO, WordGender::NEUTRAL],
 
46            WordGender::M => [WordGender::M, WordGender::AUTO, WordGender::NEUTRAL],
47        };
48    }
GenderCriterion->getField
52        return 'gender';
53    }
GenderCriterion->getTargetEntity
62        return Word::class;
63    }
GenderCriterion->shouldApply
57        return !empty($this->gender);
58    }