Completed
Push — master ( 8aadd3...9420d2 )
by Alex
14:17
created

Configuration::getConfigTreeBuilder()   B

Complexity

Conditions 5
Paths 1

Size

Total Lines 77
Code Lines 65

Duplication

Lines 18
Ratio 23.38 %

Importance

Changes 7
Bugs 0 Features 3
Metric Value
c 7
b 0
f 3
dl 18
loc 77
rs 8.4456
cc 5
eloc 65
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
                        ->ifString()
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 (!class_exists($value) || !is_a($value, 'Orbitale\Bundle\CmsBundle\Entity\Page', true)) {
41
                                throw new InvalidConfigurationException(sprintf(
42
                                    'Page class must be a valid class extending %s. "%s" given.',
43
                                    'Orbitale\Bundle\CmsBundle\Entity\Page', $value
44
                                ));
45
                            }
46
                            return $value;
47
                        })
48
                    ->end()
49
                ->end()
50
                ->scalarNode('category_class')
51
                    ->isRequired()
52
                    ->validate()
53
                        ->ifString()
54 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...
55
                            if (!class_exists($value) || !is_a($value, 'Orbitale\Bundle\CmsBundle\Entity\Category', true)) {
56
                                throw new InvalidConfigurationException(sprintf(
57
                                    'Category class must be a valid class extending %s. "%s" given.',
58
                                    'Orbitale\Bundle\CmsBundle\Entity\Category', $value
59
                                ));
60
                            }
61
                            return $value;
62
                        })
63
                    ->end()
64
                ->end()
65
                ->arrayNode('layouts')
66
                    ->defaultValue(array(
67
                        'front' => array(
68
                            'resource' => 'OrbitaleCmsBundle::default_layout.html.twig',
69
                            'pattern' => '^/',
70
                        ),
71
                    ))
72
                    ->useAttributeAsKey('name')
73
                    ->prototype('array')
74
                        ->children()
75
                            ->scalarNode('name')->end()
76
                            ->scalarNode('resource')->isRequired()->end()
77
                            ->arrayNode('assets_css')->end()
78
                            ->arrayNode('assets_js')->end()
79
                            ->scalarNode('pattern')->end()
80
                            ->scalarNode('host')->end()
81
                        ->end()
82
                    ->end()
83
                ->end()
84
                ->arrayNode('design')
85
                    ->addDefaultsIfNotSet()
86
                    ->children()
87
                        ->scalarNode('breadcrumbs_class')->defaultValue('breadcrumb')->end()
88
                        ->scalarNode('breadcrumbs_link_class')->defaultValue('')->end()
89
                        ->scalarNode('breadcrumbs_current_class')->defaultValue('')->end()
90
                        ->scalarNode('breadcrumbs_separator')->defaultValue('>')->end()
91
                        ->scalarNode('breadcrumbs_separator_class')->defaultValue('breadcrumb-separator')->end()
92
                    ->end()
93
                ->end()
94
                ->arrayNode('cache')
95
                    ->addDefaultsIfNotSet()
96
                    ->children()
97
                        ->booleanNode('enabled')->defaultFalse()->end()
98
                        ->integerNode('ttl')->defaultValue(300)->end()
99
                    ->end()
100
                ->end()
101
            ->end();
102
103
        return $treeBuilder;
104
    }
105
}
106