Configuration::getConfigTreeBuilder()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 16

Duplication

Lines 16
Ratio 100 %

Importance

Changes 0
Metric Value
dl 16
loc 16
rs 9.7333
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace PH\Bundle\SubscriptionBundle\DependencyInjection;
6
7
use PH\Bundle\SubscriptionBundle\Form\Type\SubscriptionType;
8
use PH\Bundle\SubscriptionBundle\Helper\DateTimeHelper;
9
use PH\Component\Subscription\Model\Metadata;
10
use PH\Component\Subscription\Model\MetadataInterface;
11
use PH\Component\Subscription\Model\Subscription;
12
use PH\Component\Subscription\Model\SubscriptionInterface;
13
use PH\Component\Subscription\Model\SubscriptionItem;
14
use PH\Component\Subscription\Model\SubscriptionItemInterface;
15
use Sylius\Bundle\ResourceBundle\Controller\ResourceController;
16
use Sylius\Bundle\ResourceBundle\SyliusResourceBundle;
17
use Sylius\Component\Resource\Factory\Factory;
18
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
19
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
20
use Symfony\Component\Config\Definition\ConfigurationInterface;
21
22
/**
23
 * This is the class that validates and merges configuration from your app/config files.
24
 *
25
 * To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/configuration.html}
26
 */
27
final class Configuration implements ConfigurationInterface
28
{
29
    /**
30
     * {@inheritdoc}
31
     */
32 View Code Duplication
    public function getConfigTreeBuilder()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
33
    {
34
        $treeBuilder = new TreeBuilder();
35
        $rootNode = $treeBuilder->root('ph_subscription');
36
37
        $rootNode
38
            ->addDefaultsIfNotSet()
39
                ->children()
40
                    ->scalarNode('driver')->defaultValue(SyliusResourceBundle::DRIVER_DOCTRINE_ORM)->end()
41
                ->end()
42
        ;
43
44
        $this->addResources($rootNode);
45
46
        return $treeBuilder;
47
    }
48
49
    /**
50
     * @param ArrayNodeDefinition $node
51
     */
52
    private function addResources(ArrayNodeDefinition $node)
53
    {
54
        $node
55
            ->children()
56
                ->scalarNode('date_time_helper')->defaultValue(DateTimeHelper::class)->cannotBeEmpty()->end()
57
                ->arrayNode('subscription_intervals')
58
                    ->isRequired()
59
                    ->requiresAtLeastOneElement()
60
                    ->useAttributeAsKey('name')
61
                    ->prototype('scalar')->end()
62
                ->end()
63
                ->arrayNode('resources')
64
                ->addDefaultsIfNotSet()
65
                ->children()
66
                    ->arrayNode('subscription')
67
                        ->addDefaultsIfNotSet()
68
                        ->children()
69
                            ->variableNode('options')->end()
70
                            ->arrayNode('classes')
71
                            ->addDefaultsIfNotSet()
72
                                ->children()
73
                                    ->scalarNode('model')->defaultValue(Subscription::class)->cannotBeEmpty()->end()
74
                                    ->scalarNode('interface')->defaultValue(SubscriptionInterface::class)->cannotBeEmpty()->end()
75
                                    ->scalarNode('controller')->defaultValue(ResourceController::class)->cannotBeEmpty()->end()
76
                                    ->scalarNode('repository')->cannotBeEmpty()->end()
77
                                    ->scalarNode('factory')->defaultValue(Factory::class)->end()
78
                                    ->scalarNode('form')->defaultValue(SubscriptionType::class)->cannotBeEmpty()->end()
79
                                ->end()
80
                            ->end()
81
                        ->end()
82
                    ->end()
83
                    ->arrayNode('subscription_item')
84
                        ->addDefaultsIfNotSet()
85
                        ->children()
86
                            ->variableNode('options')->end()
87
                            ->arrayNode('classes')
88
                            ->addDefaultsIfNotSet()
89
                                ->children()
90
                                    ->scalarNode('model')->defaultValue(SubscriptionItem::class)->cannotBeEmpty()->end()
91
                                    ->scalarNode('interface')->defaultValue(SubscriptionItemInterface::class)->cannotBeEmpty()->end()
92
                                    ->scalarNode('controller')->defaultValue(ResourceController::class)->cannotBeEmpty()->end()
93
                                    ->scalarNode('repository')->cannotBeEmpty()->end()
94
                                    ->scalarNode('factory')->defaultValue(Factory::class)->end()
95
                                    ->scalarNode('form')->defaultValue(SubscriptionType::class)->cannotBeEmpty()->end()
96
                                ->end()
97
                            ->end()
98
                        ->end()
99
                    ->end()
100
                    ->arrayNode('subscription_metadata')
101
                        ->addDefaultsIfNotSet()
102
                            ->children()
103
                                ->variableNode('options')->end()
104
                                ->arrayNode('classes')
105
                                ->addDefaultsIfNotSet()
106
                                ->children()
107
                                    ->scalarNode('model')->defaultValue(Metadata::class)->cannotBeEmpty()->end()
108
                                    ->scalarNode('interface')->defaultValue(MetadataInterface::class)->cannotBeEmpty()->end()
109
                                    ->scalarNode('controller')->defaultValue(ResourceController::class)->cannotBeEmpty()->end()
110
                                    ->scalarNode('repository')->cannotBeEmpty()->end()
111
                                    ->scalarNode('factory')->defaultValue(Factory::class)->end()
112
                                ->end()
113
                            ->end()
114
                        ->end()
115
                    ->end()
116
                ->end()
117
            ->end()
118
        ;
119
    }
120
}
121