Completed
Push — master ( 4c1af7...741b75 )
by Ruud
21:53
created

Configuration::getConfigTreeBuilder()   B

Complexity

Conditions 5
Paths 2

Size

Total Lines 39

Duplication

Lines 3
Ratio 7.69 %

Importance

Changes 0
Metric Value
dl 3
loc 39
rs 8.9848
c 0
b 0
f 0
cc 5
nc 2
nop 0
1
<?php
2
3
namespace Kunstmaan\ConfigBundle\DependencyInjection;
4
5
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
6
use Symfony\Component\Config\Definition\ConfigurationInterface;
7
use Kunstmaan\ConfigBundle\Entity\ConfigurationInterface as KunstmaanConfigurationInterface;
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
    /**
17
     * {@inheritdoc}
18
     */
19
    public function getConfigTreeBuilder()
20
    {
21
        $treeBuilder = new TreeBuilder('kunstmaan_config');
22
        if (method_exists($treeBuilder, 'getRootNode')) {
23
            $rootNode = $treeBuilder->getRootNode();
24
        } else {
25
            // BC layer for symfony/config 4.1 and older
26
            $rootNode = $treeBuilder->root('kunstmaan_config');
27
        }
28
29
        $rootNode
30
            ->children()
31
                ->arrayNode('entities')
32
                    ->defaultValue([])
33
                    ->normalizeKeys(false)
34
                    ->info('The list of entities to manage in the settings zone')
35
                    ->prototype('scalar')->end()
36
                    ->beforeNormalization()
37
                        ->always()
38
                        ->then(function ($entities) {
39
                            foreach ($entities as $entity) {
40
                                if (!class_exists($entity)) {
41
                                    throw new \InvalidArgumentException(sprintf('Entity "%s" does not exist', $entity));
42
                                }
43
44
                                // Check if entity implements the ConfigurationInterface.
45 View Code Duplication
                                if (!in_array(KunstmaanConfigurationInterface::class, class_implements($entity))) {
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...
46
                                    throw new \RuntimeException(sprintf('The entity class "%s" needs to implement the %s', $entity, KunstmaanConfigurationInterface::class));
47
                                }
48
                            }
49
50
                            return $entities;
51
                        })
52
                    ->end()
53
                ->end()
54
            ->end();
55
56
        return $treeBuilder;
57
    }
58
}
59