Completed
Push — master ( 8de48f...51cd42 )
by Saulius
11s queued 10s
created

OptionsResolver   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 9
c 2
b 0
f 0
dl 0
loc 32
ccs 12
cts 12
cp 1
rs 10
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A resolve() 0 7 1
A setDefaults() 0 3 1
A processDotNotatedValues() 0 9 3
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 Exception;
16
use Sauls\Component\Collection\ArrayCollection;
17
use Symfony\Component\OptionsResolver\Exception\AccessException;
18
use Symfony\Component\OptionsResolver\OptionsResolver as SymfonyOptionsResolver;
19
20
use function Sauls\Component\Helper\array_key_childs_exist;
21
use function Sauls\Component\Helper\array_keys_with_value;
22
use function Sauls\Component\Helper\array_remove_key;
23
24
class OptionsResolver extends SymfonyOptionsResolver
25
{
26
    /**
27
     * @throws AccessException
28
     * @throws Exception
29
     */
30 7
    public function setDefaults(array $defaults)
31
    {
32 7
        return parent::setDefaults(array_keys_with_value($defaults));
33
    }
34
35
    /**
36
     * @throws Exception
37
     */
38 9
    public function resolve(array $options = []): array
39
    {
40 9
        return (new ArrayCollection(
41 9
            $this->processDotNotatedValues(
42 9
                parent::resolve(array_keys_with_value($options))
43
            )
44 4
        ))->all();
45
    }
46
47 4
    private function processDotNotatedValues(array $resolvedValues): array
48
    {
49 4
        foreach ($resolvedValues as $key => $value) {
50 4
            if (array_key_childs_exist($key, $resolvedValues)) {
51 1
                array_remove_key($resolvedValues, $key);
52
            }
53
        }
54
55 4
        return $resolvedValues;
56
    }
57
}
58