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

Rules::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

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