Failed Conditions
Pull Request — master (#1)
by Yo
03:40
created

StepLoggerConfiguration   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 3
dl 0
loc 36
ccs 0
cts 27
cp 0
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B getConfigTreeBuilder() 0 30 2
1
<?php
2
namespace Yoanm\BehatUtilsExtension\ServiceContainer\Configuration;
3
4
use Symfony\Component\Config\Definition\Builder\NodeDefinition;
5
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
6
7
class StepLoggerConfiguration
8
{
9
    /**
10
     * @return NodeDefinition
11
     */
12
    public function getConfigTreeBuilder()
13
    {
14
        $castToBool = function ($value) {
15
            $filtered = filter_var(
16
                $value,
17
                FILTER_VALIDATE_BOOLEAN,
18
                FILTER_NULL_ON_FAILURE
19
            );
20
21
            return (null === $filtered) ? (bool) $value : $filtered;
22
        };
23
24
        $treeBuilder = new TreeBuilder();
25
        $rootNode = $treeBuilder->root('step_logger');
26
        $rootNode
27
            ->addDefaultsIfNotSet()
28
            ->treatFalseLike(array('enabled' => false))
29
            ->treatNullLike(array('enabled' => false))
30
            ->treatTrueLike(array('enabled' => true))
31
            ->children()
32
                ->booleanNode('enabled')
33
                    ->beforeNormalization()
34
                        ->always()
35
                        ->then($castToBool)
36
                    ->end()
37
                    ->defaultFalse()
38
        ;
39
40
        return $rootNode;
41
    }
42
}
43