Configuration   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 87
Duplicated Lines 22.99 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 4
dl 20
loc 87
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B getConfigTreeBuilder() 20 81 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
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