Completed
Push — master ( 028ddc...8aadd3 )
by Alex
13:57
created

Configuration::getConfigTreeBuilder()   C

Complexity

Conditions 7
Paths 1

Size

Total Lines 83
Code Lines 69

Duplication

Lines 24
Ratio 28.92 %

Importance

Changes 6
Bugs 0 Features 3
Metric Value
c 6
b 0
f 3
dl 24
loc 83
rs 6.5439
cc 7
eloc 69
nc 1
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
/*
4
* This file is part of the OrbitaleCmsBundle package.
5
*
6
* (c) Alexandre Rock Ancelet <[email protected]>
7
*
8
* For the full copyright and license information, please view the LICENSE
9
* file that was distributed with this source code.
10
*/
11
12
namespace Orbitale\Bundle\CmsBundle\DependencyInjection;
13
14
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
15
use Symfony\Component\Config\Definition\ConfigurationInterface;
16
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;
17
18
/**
19
 * This is the class that validates and merges configuration from your app/config files.
20
 *
21
 * To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html#cookbook-bundles-extension-config-class}
22
 */
23
class Configuration implements ConfigurationInterface
24
{
25
    /**
26
     * {@inheritdoc}
27
     */
28
    public function getConfigTreeBuilder()
29
    {
30
        $treeBuilder = new TreeBuilder();
31
        $rootNode = $treeBuilder->root('orbitale_cms');
32
33
        $rootNode
34
            ->children()
35
                ->scalarNode('page_class')
36
                    ->isRequired()
37
                    ->validate()
38
                        ->always()
39 View Code Duplication
                        ->then(function ($value) {
1 ignored issue
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
40
                            if (!$value) {
41
                                return null;
42
                            }
43
                            if (!class_exists($value) || !is_a($value, 'Orbitale\Bundle\CmsBundle\Entity\Page', true)) {
44
                                throw new InvalidConfigurationException(sprintf(
45
                                    'Page class must be a valid class extending %s. "%s" given.',
46
                                    'Orbitale\Bundle\CmsBundle\Entity\Page', $value
47
                                ));
48
                            }
49
                            return $value;
50
                        })
51
                    ->end()
52
                ->end()
53
                ->scalarNode('category_class')
54
                    ->isRequired()
55
                    ->validate()
56
                        ->always()
57 View Code Duplication
                        ->then(function ($value) {
1 ignored issue
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
58
                            if (!$value) {
59
                                return null;
60
                            }
61
                            if (!class_exists($value) || !is_a($value, 'Orbitale\Bundle\CmsBundle\Entity\Category', true)) {
62
                                throw new InvalidConfigurationException(sprintf(
63
                                    'Category class must be a valid class extending %s. "%s" given.',
64
                                    'Orbitale\Bundle\CmsBundle\Entity\Category', $value
65
                                ));
66
                            }
67
                            return $value;
68
                        })
69
                    ->end()
70
                ->end()
71
                ->arrayNode('layouts')
72
                    ->defaultValue(array(
73
                        'front' => array(
74
                            'resource' => 'OrbitaleCmsBundle::default_layout.html.twig',
75
                            'pattern' => '^/',
76
                        ),
77
                    ))
78
                    ->useAttributeAsKey('name')
79
                    ->prototype('array')
80
                        ->children()
81
                            ->scalarNode('name')->end()
82
                            ->scalarNode('resource')->isRequired()->end()
83
                            ->arrayNode('assets_css')->end()
84
                            ->arrayNode('assets_js')->end()
85
                            ->scalarNode('pattern')->end()
86
                            ->scalarNode('host')->end()
87
                        ->end()
88
                    ->end()
89
                ->end()
90
                ->arrayNode('design')
91
                    ->addDefaultsIfNotSet()
92
                    ->children()
93
                        ->scalarNode('breadcrumbs_class')->defaultValue('breadcrumb')->end()
94
                        ->scalarNode('breadcrumbs_link_class')->defaultValue('')->end()
95
                        ->scalarNode('breadcrumbs_current_class')->defaultValue('')->end()
96
                        ->scalarNode('breadcrumbs_separator')->defaultValue('>')->end()
97
                        ->scalarNode('breadcrumbs_separator_class')->defaultValue('breadcrumb-separator')->end()
98
                    ->end()
99
                ->end()
100
                ->arrayNode('cache')
101
                    ->addDefaultsIfNotSet()
102
                    ->children()
103
                        ->booleanNode('enabled')->defaultFalse()->end()
104
                        ->scalarNode('ttl')->defaultValue('300')->end()
105
                    ->end()
106
                ->end()
107
            ->end();
108
109
        return $treeBuilder;
110
    }
111
}
112