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

RegexpObscuredStrategy   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 0
dl 0
loc 37
ccs 10
cts 10
cp 1
rs 10
c 0
b 0
f 0

3 Methods

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