Passed
Push — master ( 40a4c6...6a0114 )
by Koldo
02:21
created

ArgumentTranslator::getArguments()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 3

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 12
ccs 8
cts 8
cp 1
rs 10
c 0
b 0
f 0
cc 3
nc 3
nop 2
crap 3
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
        $isService = 0 === strpos($value, '@');
28 3
        if ($isService) {
29 2
            return str_replace('@', '', $value);
30
        }
31 3
        $index = str_replace(['%config%', '%config.', '%'], '', $value);
32 3
        if (array_key_exists($index, $config)) {
33 2
            return $config[$index];
34
        }
35
36 1
        return $value;
37
    }
38
}
39