Configuration::getConfigTreeBuilder()   B
last analyzed

Complexity

Conditions 5
Paths 1

Size

Total Lines 81
Code Lines 67

Duplication

Lines 20
Ratio 24.69 %

Importance

Changes 0
Metric Value
dl 20
loc 81
rs 8.3904
c 0
b 0
f 0
cc 5
eloc 67
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
use Orbitale\Bundle\CmsBundle\Entity\Page;
18
use Orbitale\Bundle\CmsBundle\Entity\Category;
19
20
/**
21
 * This is the class that validates and merges configuration from your app/config files.
22
 *
23
 * To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html#cookbook-bundles-extension-config-class}
24
 */
25
class Configuration implements ConfigurationInterface
26
{
27
    /**
28
     * {@inheritdoc}
29
     */
30
    public function getConfigTreeBuilder()
31
    {
32
        $treeBuilder = new TreeBuilder();
33
        $rootNode    = $treeBuilder->root('orbitale_cms');
34
35
        $rootNode
36
            ->addDefaultsIfNotSet()
37
            ->children()
38
                ->scalarNode('page_class')
39
                    ->isRequired()
40
                    ->validate()
41
                        ->ifString()
42 View Code Duplication
                        ->then(function($value) {
0 ignored issues
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...
43
                            if (!class_exists($value) || !is_a($value, Page::class, true)) {
44
                                throw new InvalidConfigurationException(sprintf(
45
                                    'Page class must be a valid class extending %s. "%s" given.',
46
                                    Page::class, $value
47
                                ));
48
                            }
49
50
                            return $value;
51
                        })
52
                    ->end()
53
                ->end()
54
                ->scalarNode('category_class')
55
                    ->isRequired()
56
                    ->validate()
57
                        ->ifString()
58 View Code Duplication
                        ->then(function($value) {
0 ignored issues
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...
59
                            if (!class_exists($value) || !is_a($value, Category::class, true)) {
60
                                throw new InvalidConfigurationException(sprintf(
61
                                    'Category class must be a valid class extending %s. "%s" given.',
62
                                    Category::class, $value
63
                                ));
64
                            }
65
66
                            return $value;
67
                        })
68
                    ->end()
69
                ->end()
70
                ->arrayNode('layouts')
71
                    ->defaultValue([
72
                        'front' => [
73
                            'resource' => '@OrbitaleCms/default_layout.html.twig',
74
                            'pattern' => '',
75
                        ],
76
                    ])
77
                    ->useAttributeAsKey('name')
78
                    ->prototype('array')
79
                        ->addDefaultsIfNotSet()
80
                        ->children()
81
                            ->scalarNode('name')->end()
82
                            ->scalarNode('resource')->isRequired()->end()
83
                            ->arrayNode('assets_css')->prototype('scalar')->end()->end()
84
                            ->arrayNode('assets_js')->prototype('scalar')->end()->end()
85
                            ->scalarNode('pattern')->defaultValue('')->end()
86
                            ->scalarNode('host')->defaultValue('')->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
                        ->integerNode('ttl')->defaultValue(300)->end()
105
                    ->end()
106
                ->end()
107
            ->end();
108
109
        return $treeBuilder;
110
    }
111
}
112