Passed
Push — master ( 021f1c...1478fc )
by Evgeniy
01:24 queued 11s
created

ParamTranfromer   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

3 Methods

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