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

ParamTranfromer::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 1
Bugs 0 Features 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 1
b 0
f 0
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