Completed
Push — master ( 0456c5...25ee32 )
by Oleg
04:45
created

RegexpObscuredStrategy::extract()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 4
cts 4
cp 1
rs 10
c 0
b 0
f 0
cc 3
nc 2
nop 1
crap 3
1
<?php
2
declare(strict_types=1);
3
4
namespace SlayerBirden\DataFlowServer\Doctrine\Hydrator\Strategy;
5
6
use Zend\Hydrator\Strategy\StrategyInterface;
7
8
final class RegexpObscuredStrategy implements StrategyInterface
9
{
10
    /**
11
     * @var string
12
     */
13
    private $pattern;
14
    /**
15
     * @var string
16
     */
17
    private $replacement;
18
19 30
    public function __construct(string $pattern, string $replacement = '')
20
    {
21 30
        $this->pattern = $pattern;
22 30
        $this->replacement = $replacement;
23 30
    }
24
25
    /**
26
     * @inheritdoc
27
     */
28 20
    public function extract($value)
29
    {
30 20
        if (!empty($value) && preg_match($this->pattern, $value)) {
31 2
            return preg_replace($this->pattern, $this->replacement, $value);
32
        }
33
34 18
        return $value;
35
    }
36
37
    /**
38
     * @inheritdoc
39
     */
40 6
    public function hydrate($value)
41
    {
42 6
        return $value;
43
    }
44
}
45