RegexReplaceStringModifier::modify()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2.032

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 4
cts 5
cp 0.8
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 5
nc 2
nop 1
crap 2.032
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Funivan\CabbageCore\String\StringModifier\RegexReplace;
6
7
use Funivan\CabbageCore\String\StringModifier\StringModifierInterface;
8
9
class RegexReplaceStringModifier implements StringModifierInterface
10
{
11
12
    /**
13
     * @var string
14
     */
15
    private $from;
16
17
    /**
18
     * @var string
19
     */
20
    private $to;
21
22
23 1
    public function __construct(string $from, string $to)
24
    {
25 1
        $this->from = $from;
26 1
        $this->to = $to;
27 1
    }
28
29
30 1
    public function modify(string $input): string
31
    {
32 1
        $result = preg_replace($this->from, $this->to, $input);
33 1
        if (\is_string($result)) {
34 1
            return $result;
35
        }
36
        throw new \RuntimeException('Can not replace string');
37
    }
38
}
39