Completed
Push — master ( bc9f64...507600 )
by Paweł
20s
created

Configuration::addResourcesSection()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 63
Code Lines 60

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 63
rs 9.4347
c 0
b 0
f 0
cc 1
eloc 60
nc 1
nop 1

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
/*
4
 * This file is part of the Sylius package.
5
 *
6
 * (c) Paweł Jędrzejewski
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Sylius\Bundle\PaymentBundle\DependencyInjection;
13
14
use Sylius\Bundle\PaymentBundle\Form\Type\PaymentMethodTranslationType;
15
use Sylius\Bundle\PaymentBundle\Form\Type\PaymentMethodType;
16
use Sylius\Bundle\PaymentBundle\Form\Type\PaymentType;
17
use Sylius\Bundle\ResourceBundle\Controller\ResourceController;
18
use Sylius\Bundle\ResourceBundle\SyliusResourceBundle;
19
use Sylius\Component\Payment\Model\Payment;
20
use Sylius\Component\Payment\Model\PaymentInterface;
21
use Sylius\Component\Payment\Model\PaymentMethod;
22
use Sylius\Component\Payment\Model\PaymentMethodInterface;
23
use Sylius\Component\Payment\Model\PaymentMethodTranslation;
24
use Sylius\Component\Payment\Model\PaymentMethodTranslationInterface;
25
use Sylius\Component\Resource\Factory\Factory;
26
use Sylius\Component\Resource\Factory\TranslatableFactory;
27
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
28
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
29
use Symfony\Component\Config\Definition\ConfigurationInterface;
30
31
/**
32
 * @author Paweł Jędrzejewski <[email protected]>
33
 */
34
final class Configuration implements ConfigurationInterface
35
{
36
    /**
37
     * {@inheritdoc}
38
     */
39
    public function getConfigTreeBuilder()
40
    {
41
        $treeBuilder = new TreeBuilder();
42
        $rootNode = $treeBuilder->root('sylius_payment');
43
44
        $rootNode
45
            ->addDefaultsIfNotSet()
46
            ->children()
47
                ->scalarNode('driver')->defaultValue(SyliusResourceBundle::DRIVER_DOCTRINE_ORM)->end()
48
                ->arrayNode('gateways')
49
                    ->useAttributeAsKey('name')
50
                    ->prototype('scalar')
51
                ->end()
52
            ->end()
53
        ;
54
55
        $this->addResourcesSection($rootNode);
56
57
        return $treeBuilder;
58
    }
59
60
    /**
61
     * @param ArrayNodeDefinition $node
62
     */
63
    private function addResourcesSection(ArrayNodeDefinition $node)
64
    {
65
        $node
66
            ->children()
67
                ->arrayNode('resources')
68
                    ->addDefaultsIfNotSet()
69
                    ->children()
70
                        ->arrayNode('payment_method')
71
                            ->addDefaultsIfNotSet()
72
                            ->children()
73
                                ->variableNode('options')->end()
74
                                ->arrayNode('classes')
75
                                    ->addDefaultsIfNotSet()
76
                                    ->children()
77
                                        ->scalarNode('model')->defaultValue(PaymentMethod::class)->cannotBeEmpty()->end()
78
                                        ->scalarNode('interface')->defaultValue(PaymentMethodInterface::class)->cannotBeEmpty()->end()
79
                                        ->scalarNode('controller')->defaultValue(ResourceController::class)->cannotBeEmpty()->end()
80
                                        ->scalarNode('repository')->cannotBeEmpty()->end()
81
                                        ->scalarNode('factory')->defaultValue(TranslatableFactory::class)->end()
82
                                        ->scalarNode('form')->defaultValue(PaymentMethodType::class)->cannotBeEmpty()->end()
83
                                    ->end()
84
                                ->end()
85
                                ->arrayNode('translation')
86
                                    ->addDefaultsIfNotSet()
87
                                    ->children()
88
                                        ->variableNode('options')->end()
89
                                        ->arrayNode('classes')
90
                                            ->addDefaultsIfNotSet()
91
                                            ->children()
92
                                                ->scalarNode('model')->defaultValue(PaymentMethodTranslation::class)->cannotBeEmpty()->end()
93
                                                ->scalarNode('interface')->defaultValue(PaymentMethodTranslationInterface::class)->cannotBeEmpty()->end()
94
                                                ->scalarNode('controller')->defaultValue(ResourceController::class)->cannotBeEmpty()->end()
95
                                                ->scalarNode('repository')->cannotBeEmpty()->end()
96
                                                ->scalarNode('factory')->defaultValue(Factory::class)->cannotBeEmpty()->end()
97
                                                ->scalarNode('form')->defaultValue(PaymentMethodTranslationType::class)->cannotBeEmpty()->end()
98
                                            ->end()
99
                                        ->end()
100
                                    ->end()
101
                                ->end()
102
                            ->end()
103
                        ->end()
104
                        ->arrayNode('payment')
105
                            ->addDefaultsIfNotSet()
106
                            ->children()
107
                                ->variableNode('options')->end()
108
                                ->arrayNode('classes')
109
                                    ->addDefaultsIfNotSet()
110
                                    ->children()
111
                                        ->scalarNode('model')->defaultValue(Payment::class)->cannotBeEmpty()->end()
112
                                        ->scalarNode('interface')->defaultValue(PaymentInterface::class)->cannotBeEmpty()->end()
113
                                        ->scalarNode('controller')->defaultValue(ResourceController::class)->cannotBeEmpty()->end()
114
                                        ->scalarNode('repository')->cannotBeEmpty()->end()
115
                                        ->scalarNode('factory')->defaultValue(Factory::class)->end()
116
                                        ->scalarNode('form')->defaultValue(PaymentType::class)->cannotBeEmpty()->end()
117
                                    ->end()
118
                                ->end()
119
                            ->end()
120
                        ->end()
121
                    ->end()
122
                ->end()
123
            ->end()
124
        ;
125
    }
126
}
127