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

OptionDynamicValueResolver   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 25
ccs 12
cts 12
cp 1
rs 10
c 0
b 0
f 0
wmc 6

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A resolve() 0 15 5
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