Passed
Push — master ( e37ab6...297052 )
by Koldo
02:10
created

ParseArguments::process()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 20
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 4.0119

Importance

Changes 0
Metric Value
cc 4
eloc 11
nc 4
nop 2
dl 0
loc 20
ccs 10
cts 11
cp 0.9091
crap 4.0119
rs 9.9
c 0
b 0
f 0
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 ParseArguments
11
{
12 2
    public function process(array $config, array $service): array
13
    {
14 2
        $arguments = [];
15
        /**
16
         * @var string $argument
17
         * @var string $value
18
         */
19 2
        foreach ($service['arguments'] as $argument => $value) {
20 2
            $isService = 0 === strpos($value, '@');
21 2
            if ($isService) {
22 2
                $arguments[str_replace('$', '', $argument)] = str_replace('@', '', $value);
23
            } else {
24 2
                $index = str_replace(['%config%', '%config.', '%'], '', $value);
25 2
                $arguments[str_replace('$', '', $argument)] = empty($index)
26
                    ? $config
27 2
                    : $config[$index];
28
            }
29
        }
30
31 2
        return $arguments;
32
    }
33
}
34