Passed
Push — master ( b6978d...998e8b )
by Koldo
04:49
created

ArgumentTranslator   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Test Coverage

Coverage 93.33%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 6
eloc 13
c 1
b 0
f 1
dl 0
loc 31
ccs 14
cts 15
cp 0.9333
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A process() 0 11 2
A getArguments() 0 16 4
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Antidot\SymfonyConfigTranslator;
6
7
use function str_replace;
8
use function strpos;
9
10
class ArgumentTranslator
11
{
12 3
    public function process(array $config, array $service): array
13
    {
14 3
        $arguments = [];
15
        /**
16
         * @var string $argument
17
         */
18 3
        foreach ($service['arguments'] as $argument => $value) {
19 3
            $arguments[str_replace('$', '', $argument)] = $this->getArguments($config, $value);
20
        }
21
22 3
        return $arguments;
23
    }
24
25 3
    private function getArguments(array $config, $value)
26
    {
27 3
        if (is_array($value)) {
28
            return $value;
29
        }
30
31 3
        $isService = 0 === strpos($value, '@');
32 3
        if ($isService) {
33 2
            return str_replace('@', '', $value);
34
        }
35 3
        $index = str_replace(['%config%', '%config.', '%'], '', $value);
36 3
        if (array_key_exists($index, $config)) {
37 2
            return $config[$index];
38
        }
39
40 1
        return $value;
41
    }
42
}
43