RestConfiguration::getConfigTreeBuilder()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 51
Code Lines 47

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 46
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 51
ccs 46
cts 46
cp 1
rs 9.4109
cc 1
eloc 47
nc 1
nop 0
crap 1

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 Alchemy\RestBundle\DependencyInjection;
4
5
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
6
use Symfony\Component\Config\Definition\ConfigurationInterface;
7
8
class RestConfiguration implements ConfigurationInterface
9
{
10
11
    /**
12
     * Generates the configuration tree builder.
13
     *
14
     * @return \Symfony\Component\Config\Definition\Builder\TreeBuilder The tree builder
15
     */
16 14
    public function getConfigTreeBuilder()
17
    {
18 14
        $builder = new TreeBuilder();
19
20
        $builder
21 14
            ->root('alchemy_rest')
22 14
                ->children()
23 14
                    ->arrayNode('exceptions')
24 14
                        ->addDefaultsIfNotSet()
25 14
                        ->children()
26 14
                            ->arrayNode('content_types')
27 14
                                ->fixXmlConfig('content_type')
28 14
                                ->addDefaultChildrenIfNoneSet()
29 14
                                ->prototype('scalar')
30 14
                                    ->defaultValue('application/json')
31 14
                                ->end()
32 14
                            ->end()
33 14
                            ->scalarNode('enabled')->defaultTrue()->end()
34 14
                            ->scalarNode('transformer')->defaultNull()->end()
35 14
                        ->end()
36 14
                    ->end()
37 14
                    ->arrayNode('dates')
38 14
                        ->addDefaultsIfNotSet()
39 14
                        ->children()
40 14
                            ->scalarNode('enabled')->defaultTrue()->end()
41 14
                            ->scalarNode('format')->defaultValue('Y-m-d H:i:s')->end()
42 14
                            ->scalarNode('timezone')->defaultValue('UTC')->end()
43 14
                        ->end()
44 14
                    ->end()
45 14
                    ->arrayNode('pagination')
46 14
                        ->addDefaultsIfNotSet()
47 14
                        ->children()
48 14
                            ->scalarNode('enabled')->defaultTrue()->end()
49 14
                            ->scalarNode('limit_parameter')->defaultValue('limit')->end()
50 14
                            ->scalarNode('offset_parameter')->defaultValue('offset')->end()
51 14
                        ->end()
52 14
                    ->end()
53 14
                    ->arrayNode('sort')
54 14
                        ->addDefaultsIfNotSet()
55 14
                        ->children()
56 14
                            ->scalarNode('enabled')->defaultTrue()->end()
57 14
                            ->scalarNode('sort_parameter')->defaultValue('sort')->end()
58 14
                            ->scalarNode('direction_parameter')->defaultValue('dir')->end()
59 14
                            ->scalarNode('multi_sort_parameter')->defaultValue('sorts')->end()
60 14
                        ->end()
61 14
                    ->end()
62 14
                ->end()
63 14
            ->end();
64
65 14
        return $builder;
66
    }
67
}
68