Configuration::getConfigTreeBuilder()   B
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 67

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 67
rs 8.72
c 0
b 0
f 0
cc 3
nc 2
nop 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace Knp\Bundle\SnappyBundle\DependencyInjection;
4
5
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
6
use Symfony\Component\Config\Definition\ConfigurationInterface;
7
8
/**
9
 * Configuration for the emailing bundle.
10
 */
11
class Configuration implements ConfigurationInterface
12
{
13
    /**
14
     * {@inheritdoc}
15
     */
16
    public function getConfigTreeBuilder()
17
    {
18
        $fixOptionKeys = function ($options) {
19
            $fixedOptions = [];
20
            foreach ($options as $key => $value) {
21
                $fixedOptions[str_replace('_', '-', $key)] = $value;
22
            }
23
24
            return $fixedOptions;
25
        };
26
27
        $treeBuilder = new TreeBuilder('knp_snappy');
28
        if (method_exists($treeBuilder, 'getRootNode')) {
29
            $rootNode = $treeBuilder->getRootNode();
30
        } else {
31
            // BC for symfony/config < 4.2
32
            $rootNode = $treeBuilder->root('knp_snappy');
0 ignored issues
show
Bug introduced by
The method root() does not seem to exist on object<Symfony\Component...on\Builder\TreeBuilder>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
33
        }
34
35
        $rootNode
36
            ->children()
37
                ->scalarNode('temporary_folder')->end()
38
                ->integerNode('process_timeout')
39
                    ->min(1)
40
                    ->info('Generator process timeout in seconds.')
41
                ->end()
42
                ->arrayNode('pdf')
43
                    ->addDefaultsIfNotSet()
44
                    ->children()
45
                        ->booleanNode('enabled')->defaultTrue()->end()
46
                        ->scalarNode('binary')->defaultValue('wkhtmltopdf')->end()
47
                        ->arrayNode('options')
48
                            ->performNoDeepMerging()
49
                            ->useAttributeAsKey('name')
50
                            ->beforeNormalization()
51
                                ->always($fixOptionKeys)
52
                            ->end()
53
                            ->prototype('scalar')->end()
54
                        ->end()
55
                        ->arrayNode('env')
56
                            ->prototype('scalar')->end()
57
                        ->end()
58
                    ->end()
59
                ->end()
60
                ->arrayNode('image')
61
                    ->addDefaultsIfNotSet()
62
                    ->children()
63
                        ->booleanNode('enabled')->defaultTrue()->end()
64
                        ->scalarNode('binary')->defaultValue('wkhtmltoimage')->end()
65
                        ->arrayNode('options')
66
                            ->performNoDeepMerging()
67
                            ->useAttributeAsKey('name')
68
                            ->beforeNormalization()
69
                                ->always($fixOptionKeys)
70
                            ->end()
71
                            ->prototype('scalar')->end()
72
                        ->end()
73
                        ->arrayNode('env')
74
                            ->prototype('scalar')->end()
75
                        ->end()
76
                    ->end()
77
                ->end()
78
            ->end()
79
        ;
80
81
        return $treeBuilder;
82
    }
83
}
84