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

PluralizerFactory::withTransformations()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 5
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 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