Failed Conditions
Pull Request — 0.3 (#20)
by jean
12:27
created

OptionDynamicValueResolver::resolve()   A

Complexity

Conditions 5
Paths 5

Size

Total Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 5

Importance

Changes 0
Metric Value
cc 5
nc 5
nop 2
dl 0
loc 15
ccs 9
cts 9
cp 1
crap 5
rs 9.4555
c 0
b 0
f 0
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: darkilliant
5
 * Date: 5/9/18
6
 * Time: 7:32 AM.
7
 */
8
9
namespace Darkilliant\ProcessBundle\Resolver;
10
11
use Symfony\Component\PropertyAccess\PropertyAccessor;
12
13
/**
14
 * @internal
15
 */
16
class OptionDynamicValueResolver
17
{
18
    /** @var PropertyAccessor */
19
    private $accessor;
20
21 1
    public function __construct(PropertyAccessor $accessor)
22
    {
23 1
        $this->accessor = $accessor;
24 1
    }
25
26 1
    public function resolve(array $options, array $context): array
27
    {
28 1
        foreach ($options as $optionName => $optionValue) {
29 1
            if (is_array($optionValue)) {
30 1
                $options[$optionName] = $this->resolve($optionValue, $context);
31 1
            } elseif (false !== strpos($optionValue, '@')) {
32 1
                $key = substr($optionValue, 1);
33
34 1
                if ($this->accessor->isReadable($context, $key)) {
35 1
                    $options[$optionName] = $this->accessor->getValue($context, $key);
36
                }
37
            }
38
        }
39
40 1
        return $options;
41
    }
42
}
43