Passed
Push — master ( 142814...e15b12 )
by Evgeniy
49s queued 11s
created

Prefix   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 12
dl 0
loc 33
ccs 13
cts 13
cp 1
rs 10
c 0
b 0
f 0
wmc 6

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A transformParam() 0 8 3
A transform() 0 6 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Cekta\DI\ReflectionTransformer;
6
7
use Cekta\DI\ReflectionTransformerInterface;
8
9
class Prefix implements ReflectionTransformerInterface
10
{
11
    /**
12
     * @var string
13
     */
14
    private $prefix;
15
    /**
16
     * @var array
17
     */
18
    private $replace;
19
20 9
    public function __construct(string $prefix, array $replace)
21
    {
22 9
        $this->prefix = $prefix;
23 9
        $this->replace = $replace;
24 9
    }
25
26 6
    public function transform(string $name, array $params): array
27
    {
28 6
        if (strpos($name, $this->prefix) === 0) {
29 3
            $params = $this->transformParam($params);
30
        }
31 6
        return $params;
32
    }
33
34 3
    private function transformParam(array $params): array
35
    {
36 3
        foreach ($params as $key => $value) {
37 3
            if (array_key_exists($value, $this->replace)) {
38 3
                $params[$key] = $this->replace[$value];
39
            }
40
        }
41 3
        return $params;
42
    }
43
}
44