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

PluralizerFactory   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
dl 0
loc 39
ccs 14
cts 14
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A withIrregular() 0 5 1
A withUninflected() 0 5 1
A withTransformations() 0 5 1
A build() 0 7 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 PluralizerFactory
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::getPlural());
48 527
        $uninflected     = $this->uninflected ?? new Patterns(...English\Uninflected::getPlural());
49 527
        $irregular       = $this->irregular ?? new Substitutions(...English\Inflectible::getIrregular());
50
51 527
        return new Ruleset($transformations, $uninflected, $irregular);
52
    }
53
}
54