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

Configuration   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 83
Duplicated Lines 21.69 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 7
Bugs 0 Features 3
Metric Value
wmc 5
c 7
b 0
f 3
lcom 0
cbo 4
dl 18
loc 83
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B getConfigTreeBuilder() 18 77 5

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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