Completed
Pull Request — master (#90)
by Jonathan
02:06
created

Singularizer::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

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 9.4285
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 2
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Doctrine\Inflector;
6
7
use Doctrine\Inflector\Rules\Ruleset;
8
use Doctrine\Inflector\Rules\Singular;
9
use Doctrine\Inflector\Rules\Uninflected;
10
use function array_flip;
11
use function array_merge;
12
13
class Singularizer extends Converse
14
{
15
    /** @var Pluralizer */
16
    private $pluralizer;
17
18 526
    public function __construct(Uninflected $uninflected, Pluralizer $pluralizer)
19
    {
20 526
        $this->pluralizer = $pluralizer;
21
22 526
        parent::__construct($uninflected);
23 526
    }
24
25 526
    public function getRuleset() : Ruleset
26
    {
27 526
        return new Ruleset(Singular::RULES, Singular::UNINFLECTED, Singular::IRREGULAR);
28
    }
29
30 526
    protected function initializeIrregular() : void
31
    {
32 526
        if (isset($this->rules['merged']['irregular'])) {
33 3
            return;
34
        }
35
36 526
        $this->rules['merged']['irregular'] = array_merge(
37 526
            $this->rules['irregular'],
38 526
            array_flip($this->pluralizer->getRuleset()->getIrregular())
39
        );
40 526
    }
41
}
42