Passed
Pull Request — master (#97)
by Jonathan
09:17
created

Transformations::inflect()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 9
ccs 5
cts 5
cp 1
rs 9.9666
c 0
b 0
f 0
cc 3
nc 3
nop 1
crap 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Doctrine\Inflector\Rules;
6
7
use Doctrine\Inflector\WordInflector;
8
9
class Transformations implements WordInflector
10
{
11
    /** @var Transformation[] */
12
    private $transformations;
13
14 761
    public function __construct(Transformation ...$transformations)
15
    {
16 761
        $this->transformations = $transformations;
17 761
    }
18
19 342
    public function inflect(string $word) : string
20
    {
21 342
        foreach ($this->transformations as $transformation) {
22 342
            if ($transformation->getPattern()->matches($word)) {
23 342
                return $transformation->inflect($word);
24
            }
25
        }
26
27 2
        return $word;
28
    }
29
}
30