RegexReplaceStringModifier   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 88.89%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 0
dl 0
loc 30
ccs 8
cts 9
cp 0.8889
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A modify() 0 8 2
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