Completed
Pull Request — master (#2609)
by
unknown
13:04
created

Configuration::getConfigTreeBuilder()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 77

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 22
CRAP Score 2.0003

Importance

Changes 0
Metric Value
dl 0
loc 77
ccs 22
cts 23
cp 0.9565
rs 8.5018
c 0
b 0
f 0
cc 2
nc 2
nop 0
crap 2.0003

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
namespace Kunstmaan\MediaBundle\DependencyInjection;
4
5
use Kunstmaan\MediaBundle\Utils\SymfonyVersion;
6
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
7
use Symfony\Component\Config\Definition\ConfigurationInterface;
8
9
/**
10
 * This is the class that validates and merges configuration from your app/config files
11
 *
12
 * To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html#cookbook-bundles-extension-config-class}
13
 */
14
class Configuration implements ConfigurationInterface
15
{
16
    private const DEFAULT_CROPPING_VIEWS_CONFIG = [
17
        ['name' => 'desktop', 'width' => 1, 'height' => 1, 'lock_ratio' => true],
18
        ['name' => 'tablet', 'width' => 1, 'height' => 1, 'lock_ratio' => true],
19
        ['name' => 'phone', 'width' => 1, 'height' => 1, 'lock_ratio' => true],
20
    ];
21 6
    private const DEFAULT_FOCUS_POINT_CLASSES = ['top-left', 'top-center', 'top-right', 'center-left', 'center', 'center-right', 'bottom-left', 'bottom-center', 'bottom-right'];
22
23 6
    /**
24 6
     * Generates the configuration tree.
25 6
     *
26
     * @return TreeBuilder
27
     */
28
    public function getConfigTreeBuilder()
29
    {
30
        $treeBuilder = new TreeBuilder('kunstmaan_media');
31
        if (method_exists($treeBuilder, 'getRootNode')) {
32 6
            $rootNode = $treeBuilder->getRootNode();
33 6
        } else {
34 6
            // BC layer for symfony/config 4.1 and older
35 6
            $rootNode = $treeBuilder->root('kunstmaan_media');
0 ignored issues
show
Deprecated Code introduced by
The method Symfony\Component\Config...der\TreeBuilder::root() has been deprecated with message: since Symfony 4.3, pass the root name to the constructor instead

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
36 6
        }
37 6
38 6
        $rootNode
39 6
            ->children()
40 6
                ->scalarNode('soundcloud_api_key')->defaultValue('YOUR_CLIENT_ID')->end()
41 6
                ->scalarNode('aviary_api_key')->setDeprecated('The child node "%node%" at path "%path%" is deprecated. Because the aviary service is discontinued.')->defaultNull()->end()
42 6
                ->arrayNode('remote_video')
43 6
                    ->addDefaultsIfNotSet()
44 6
                    ->children()
45 6
                        ->booleanNode('vimeo')->defaultTrue()->end()
46 6
                        ->booleanNode('youtube')->defaultTrue()->end()
47 6
                        ->booleanNode('dailymotion')->defaultTrue()->end()
48 6
                    ->end()
49 6
                ->end()
50 6
                ->booleanNode('enable_pdf_preview')->defaultFalse()->end()
51 6
                ->arrayNode('blacklisted_extensions')
52 6
                    ->defaultValue(['php', 'htaccess'])
53
                    ->prototype('scalar')->end()
54 6
                ->end()
55
                ->scalarNode('web_root')
56
                    ->defaultValue(SymfonyVersion::getRootWebPath())
57
                    ->cannotBeEmpty()
58
                ->end()
59
                ->arrayNode('cropping_views')
60
                    ->addDefaultsIfNotSet()
61
                    ->children()
62
                        ->arrayNode('default')
63
                            ->defaultValue(self::DEFAULT_CROPPING_VIEWS_CONFIG)
64
                            ->arrayPrototype()
65
                                ->addDefaultsIfNotSet()
66
                                ->children()
67
                                    ->scalarNode('name')->end()
68
                                    ->integerNode('width')->end()
69
                                    ->integerNode('height')->end()
70
                                    ->booleanNode('lock_ratio')->defaultTrue()->end()
71
                                ->end()
72
                            ->end()
73
                        ->end()
74
                        ->arrayNode('focus_point_classes')
75
                            ->defaultValue(self::DEFAULT_FOCUS_POINT_CLASSES)
76
                            ->prototype('array')->end()
77
                        ->end()
78
                        ->arrayNode('custom_views')
79
                            ->useAttributeAsKey('groupName')
80
                            ->arrayPrototype()
81
                                ->addDefaultsIfNotSet()
82
                                ->children()
83
                                    ->booleanNode('use_focus_point')->defaultFalse()->end()
84
                                    ->booleanNode('use_cropping')->defaultTrue()->end()
85
                                    ->arrayNode('views')
86
                                        ->arrayPrototype()
87
                                            ->addDefaultsIfNotSet()
88
                                            ->children()
89
                                                ->scalarNode('name')->end()
90
                                                ->integerNode('width')->end()
91
                                                ->integerNode('height')->end()
92
                                                ->booleanNode('lock_ratio')->defaultTrue()->end()
93
                                            ->end()
94
                                        ->end()
95
                                    ->end()
96
                                ->end()
97
                            ->end()
98
                        ->end()
99
                    ->end()
100
                ->end()
101
            ->end();
102
103
        return $treeBuilder;
104
    }
105
}
106