Passed
Pull Request — master (#97)
by Jonathan
02:23
created

SingularizerFactory   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
dl 0
loc 46
ccs 17
cts 17
cp 1
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A withUninflected() 0 5 1
A withIrregular() 0 5 1
A withTransformations() 0 5 1
A build() 0 7 1
A getDefaultIrregular() 0 5 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Doctrine\Inflector;
6
7
use Doctrine\Inflector\Rules\English;
8
use Doctrine\Inflector\Rules\Patterns;
9
use Doctrine\Inflector\Rules\Ruleset;
10
use Doctrine\Inflector\Rules\Substitutions;
11
use Doctrine\Inflector\Rules\Transformations;
12
13
final class SingularizerFactory
14
{
15
    /** @var Transformations */
16
    private $transformations;
17
18
    /** @var Patterns */
19
    private $uninflected;
20
21
    /** @var Substitutions */
22
    private $irregular;
23
24 3
    public function withTransformations(Transformations $transformations) : self
25
    {
26 3
        $this->transformations = $transformations;
27
28 3
        return $this;
29
    }
30
31 3
    public function withUninflected(Patterns $uninflected) : self
32
    {
33 3
        $this->uninflected = $uninflected;
34
35 3
        return $this;
36
    }
37
38 3
    public function withIrregular(Substitutions $irregular) : self
39
    {
40 3
        $this->irregular = $irregular;
41
42 3
        return $this;
43
    }
44
45 527
    public function build() : Ruleset
46
    {
47 527
        $transformations = $this->transformations ?? new Transformations(...English\Inflectible::getSingular());
48 527
        $uninflected     = $this->uninflected ?? new Patterns(...English\Uninflected::getSingular());
49 527
        $irregular       = $this->irregular ?? $this->getDefaultIrregular();
50
51 527
        return new Ruleset($transformations, $uninflected, $irregular);
52
    }
53
54 524
    private function getDefaultIrregular() : Substitutions
55
    {
56 524
        $irregular = new Substitutions(...English\Inflectible::getIrregular());
57
58 524
        return $irregular->getFlippedSubstitutions();
59
    }
60
}
61