Completed
Pull Request — master (#2680)
by
unknown
06:45
created

Configuration::getConfigTreeBuilder()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 40

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 31
CRAP Score 2.0001

Importance

Changes 0
Metric Value
dl 0
loc 40
ccs 31
cts 32
cp 0.9688
rs 9.28
c 0
b 0
f 0
cc 2
nc 2
nop 0
crap 2.0001
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_ALLOWED_EXTENSIONS = [
17
        'bmp', 'csv', 'doc', 'docx', 'gif',
18
        'ico', 'jpeg', 'jpg', 'mkv', 'mp3',
19
        'mp4', 'mpeg', 'ogg', 'pdf', 'png',
20
        'pps', 'ppsx', 'ppt', 'pptx', 'tif',
21
        'tiff', 'txt', 'wav', 'webm', 'webp',
22
        'xlsx', 'svg', 'zip', 'docm', 'xlsm',
23
        'xls',
24
    ];
25
26
    /**
27
     * Generates the configuration tree.
28
     *
29
     * @return TreeBuilder
30
     */
31 5
    public function getConfigTreeBuilder()
32
    {
33 5
        $treeBuilder = new TreeBuilder('kunstmaan_media');
34 5
        if (method_exists($treeBuilder, 'getRootNode')) {
35 5
            $rootNode = $treeBuilder->getRootNode();
36
        } else {
37
            // BC layer for symfony/config 4.1 and older
38
            $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...
39
        }
40
41
        $rootNode
42 5
            ->children()
43 5
                ->scalarNode('soundcloud_api_key')->defaultValue('YOUR_CLIENT_ID')->end()
44 5
                ->scalarNode('aviary_api_key')->defaultNull()->end()
45 5
                ->arrayNode('remote_video')
46 5
                    ->addDefaultsIfNotSet()
47 5
                    ->children()
48 5
                        ->booleanNode('vimeo')->defaultTrue()->end()
49 5
                        ->booleanNode('youtube')->defaultTrue()->end()
50 5
                        ->booleanNode('dailymotion')->defaultTrue()->end()
51 5
                    ->end()
52 5
                ->end()
53 5
                ->booleanNode('enable_pdf_preview')->defaultFalse()->end()
54 5
                ->booleanNode('limit_allowed_extensions')->defaultTrue()->end()
55 5
                ->arrayNode('allowed_extensions')
56 5
                    ->defaultValue(self::DEFAULT_ALLOWED_EXTENSIONS)
57 5
                    ->prototype('scalar')->end()
58 5
                ->end()
59 5
                ->arrayNode('blacklisted_extensions')
60 5
                    ->defaultValue(['php', 'htaccess'])
61 5
                    ->prototype('scalar')->end()
62 5
                ->end()
63 5
                ->scalarNode('web_root')
64 5
                    ->defaultValue(SymfonyVersion::getRootWebPath())
65 5
                    ->cannotBeEmpty()
66 5
                ->end()
67 5
            ->end();
68
69 5
        return $treeBuilder;
70
    }
71
}
72