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

Transformation::inflect()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 3
ccs 2
cts 2
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\Rules;
6
7
use Doctrine\Inflector\WordInflector;
8
use function preg_replace;
9
10
final class Transformation implements WordInflector
11
{
12
    /** @var Pattern */
13
    private $pattern;
14
15
    /** @var string */
16
    private $replacement;
17
18 764
    public function __construct(Pattern $pattern, string $replacement)
19
    {
20 764
        $this->pattern     = $pattern;
21 764
        $this->replacement = $replacement;
22 764
    }
23
24 343
    public function getPattern() : Pattern
25
    {
26 343
        return $this->pattern;
27
    }
28
29 1
    public function getReplacement() : string
30
    {
31 1
        return $this->replacement;
32
    }
33
34 341
    public function inflect(string $word) : string
35
    {
36 341
        return preg_replace($this->pattern->getRegex(), $this->replacement, $word);
37
    }
38
}
39