Failed Conditions
Pull Request — master (#97)
by Jonathan
03:14
created

PluralizerFactory   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
dl 0
loc 44
ccs 17
cts 17
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 build() 0 12 1
A withTransformations() 0 5 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Doctrine\Inflector;
6
7
use Doctrine\Inflector\Rules\Irregular;
8
use Doctrine\Inflector\Rules\Plural;
9
use Doctrine\Inflector\Rules\Ruleset;
10
use Doctrine\Inflector\Rules\Transformations;
11
use Doctrine\Inflector\Rules\Uninflected;
12
13
final class PluralizerFactory
14
{
15
    /** @var Transformations */
16
    private $transformations;
17
18
    /** @var Uninflected */
19
    private $uninflected;
20
21
    /** @var Irregular */
22
    private $irregular;
23
24 2
    public function withTransformations(Transformations $transformations) : self
25
    {
26 2
        $this->transformations = $transformations;
27
28 2
        return $this;
29
    }
30
31 2
    public function withUninflected(Uninflected $uninflected) : self
32
    {
33 2
        $this->uninflected = $uninflected;
34
35 2
        return $this;
36
    }
37
38 2
    public function withIrregular(Irregular $irregular) : self
39
    {
40 2
        $this->irregular = $irregular;
41
42 2
        return $this;
43
    }
44
45 525
    public function build() : Ruleset
46
    {
47 525
        $transformations = $this->transformations ?? new Transformations(...Plural::getDefaultTransformations());
48 525
        $uninflected     = $this->uninflected ?? new Uninflected(...Plural::getUninflectedWords());
49 525
        $irregular       = $this->irregular ?? new Irregular(...Plural::getIrregularRules());
50
51
        $pluralUninflected = new Uninflected(...(static function () use ($uninflected) : iterable {
52 525
            yield from $uninflected->getWords();
53 525
            yield from Uninflected::getDefaultWords();
54 525
        })());
55
56 525
        return new Ruleset($transformations, $pluralUninflected, $irregular);
57
    }
58
}
59