Configuration::addResources()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 29

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 29
rs 9.456
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace PH\Bundle\WebhookBundle\DependencyInjection;
6
7
use PH\Bundle\WebhookBundle\Form\Type\WebhookType;
8
use PH\Component\Webhook\Model\Webhook;
9
use PH\Component\Webhook\Model\WebhookInterface;
10
use Sylius\Bundle\ResourceBundle\Controller\ResourceController;
11
use Sylius\Bundle\ResourceBundle\SyliusResourceBundle;
12
use Sylius\Component\Resource\Factory\Factory;
13
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
14
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
15
use Symfony\Component\Config\Definition\ConfigurationInterface;
16
17
final class Configuration implements ConfigurationInterface
18
{
19
    /**
20
     * {@inheritdoc}
21
     */
22 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...
23
    {
24
        $treeBuilder = new TreeBuilder();
25
        $rootNode = $treeBuilder->root('ph_webhook');
26
        $rootNode
27
            ->addDefaultsIfNotSet()
28
            ->children()
29
                ->scalarNode('driver')->defaultValue(SyliusResourceBundle::DRIVER_DOCTRINE_ORM)->end()
30
            ->end()
31
        ;
32
33
        $this->addResources($rootNode);
34
35
        return $treeBuilder;
36
    }
37
38
    /**
39
     * @param ArrayNodeDefinition $node
40
     */
41
    private function addResources(ArrayNodeDefinition $node)
42
    {
43
        $node
44
            ->children()
45
                ->arrayNode('resources')
46
                    ->addDefaultsIfNotSet()
47
                    ->children()
48
                        ->arrayNode('webhook')
49
                            ->addDefaultsIfNotSet()
50
                            ->children()
51
                                ->variableNode('options')->end()
52
                                ->arrayNode('classes')
53
                                    ->addDefaultsIfNotSet()
54
                                    ->children()
55
                                        ->scalarNode('model')->defaultValue(Webhook::class)->cannotBeEmpty()->end()
56
                                        ->scalarNode('interface')->defaultValue(WebhookInterface::class)->cannotBeEmpty()->end()
57
                                        ->scalarNode('controller')->defaultValue(ResourceController::class)->cannotBeEmpty()->end()
58
                                        ->scalarNode('repository')->cannotBeEmpty()->end()
59
                                        ->scalarNode('factory')->defaultValue(Factory::class)->end()
60
                                        ->scalarNode('form')->defaultValue(WebhookType::class)->cannotBeEmpty()->end()
61
                                    ->end()
62
                                ->end()
63
                            ->end()
64
                        ->end()
65
                    ->end()
66
                ->end()
67
            ->end()
68
        ;
69
    }
70
}
71