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

Prefix::transformParam()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
eloc 4
nc 3
nop 1
dl 0
loc 8
ccs 5
cts 5
cp 1
crap 3
rs 10
c 0
b 0
f 0
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