Completed
Push — master ( 67bc81...8de48f )
by Saulius
10s
created

OptionsResolver::processDotNotatedValues()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
eloc 4
nc 3
nop 1
dl 0
loc 9
ccs 5
cts 5
cp 1
crap 3
rs 9.6666
c 0
b 0
f 0
1
<?php
2
/**
3
 * This file is part of the sauls/options-resolver package.
4
 *
5
 * @author    Saulius Vaičeliūnas <[email protected]>
6
 * @link      http://saulius.vaiceliunas.lt
7
 * @copyright 2018
8
 *
9
 * For the full copyright and license information, please view the LICENSE
10
 * file that was distributed with this source code.
11
 */
12
13
namespace Sauls\Component\OptionsResolver;
14
15
use function Sauls\Component\Helper\array_key_childs_exist;
16
use function Sauls\Component\Helper\array_keys_with_value;
17
use function Sauls\Component\Helper\array_remove_key;
18
use Symfony\Component\OptionsResolver\OptionsResolver as SymfonyOptionsResolver;
19
use Sauls\Component\Collection\ArrayCollection;
20
21
class OptionsResolver extends SymfonyOptionsResolver
22
{
23
    /**
24
     * @throws \Symfony\Component\OptionsResolver\Exception\AccessException
25
     * @throws \Exception
26
     */
27 7
    public function setDefaults(array $defaults)
28
    {
29 7
        return parent::setDefaults(array_keys_with_value($defaults));
30
    }
31
32
    /**
33
     * @throws \Exception
34
     */
35 9
    public function resolve(array $options = []): array
36
    {
37 9
        return (new ArrayCollection(
38 9
            $this->processDotNotatedValues(
39 9
                parent::resolve(array_keys_with_value($options))
40
            )
41 4
        ))->all();
42
    }
43
44 4
    private function processDotNotatedValues(array $resolvedValues): array
45
    {
46 4
        foreach ($resolvedValues as $key => $value) {
47 4
            if (array_key_childs_exist($key, $resolvedValues)) {
48 4
                array_remove_key($resolvedValues, $key);
49
            }
50
        }
51
52 4
        return $resolvedValues;
53
    }
54
55
}
56