Passed
Pull Request — master (#90)
by Jonathan
02:36
created

Rules::inflect()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
eloc 4
nc 3
nop 1
dl 0
loc 9
ccs 5
cts 5
cp 1
crap 3
rs 9.6666
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Doctrine\Inflector\Rules;
6
7
use function preg_match;
8
use function preg_replace;
9
10
class Rules
11
{
12
    /** @var Rule[] */
13
    private $rules;
14
15 530
    public function __construct(Rule ...$rules)
16
    {
17 530
        $this->rules = $rules;
18 530
    }
19
20 182
    public function inflect(string $word) : string
21
    {
22 182
        foreach ($this->rules as $rule) {
23 182
            if (preg_match($rule->getFrom(), $word)) {
24 182
                return preg_replace($rule->getFrom(), $rule->getTo(), $word);
25
            }
26
        }
27
28 2
        return $word;
29
    }
30
}
31