OptionDynamicValueResolver   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 18
dl 0
loc 34
ccs 19
cts 19
cp 1
rs 10
c 0
b 0
f 0
wmc 9

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
B resolve() 0 24 8
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Darkilliant\ProcessBundle\Resolver;
6
7
use Symfony\Component\PropertyAccess\PropertyAccessorInterface;
8
9
/**
10
 * @internal
11
 */
12
class OptionDynamicValueResolver
13
{
14
    /** @var PropertyAccessorInterface */
15
    private $accessor;
16
17 1
    public function __construct(PropertyAccessorInterface $accessor)
18
    {
19 1
        $this->accessor = $accessor;
20 1
    }
21
22 1
    public function resolve(array $options, array $context): array
23
    {
24 1
        foreach ($options as $optionName => $optionValue) {
25 1
            if (is_array($optionValue)) {
26 1
                $options[$optionName] = $this->resolve($optionValue, $context);
27 1
            } elseif (!is_string($optionValue)) {
28 1
                continue;
29 1
            } elseif (false !== strpos($optionValue, '@!')) {
30 1
                $key = substr($optionValue, 2);
31 1
                list($firstLevel, $secondLevel) = explode('->', $key);
32
33 1
                if (isset($context[$firstLevel][$secondLevel])) {
34 1
                    $options[$optionName] = $context[$firstLevel][$secondLevel];
35
                }
36 1
            } elseif (false !== strpos($optionValue, '@')) {
37 1
                $key = substr($optionValue, 1);
38
39 1
                if ($this->accessor->isReadable($context, $key)) {
40 1
                    $options[$optionName] = $this->accessor->getValue($context, $key);
41
                }
42
            }
43
        }
44
45 1
        return $options;
46
    }
47
}
48