Passed
Pull Request — master (#1)
by Kevin
12:50
created

Configuration::getConfigTreeBuilder()   B

Complexity

Conditions 5
Paths 1

Size

Total Lines 73
Code Lines 64

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 65
CRAP Score 5

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 5
eloc 64
c 1
b 0
f 1
nc 1
nop 0
dl 0
loc 73
rs 8.4743
ccs 65
cts 65
cp 1
crap 5

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
namespace Zenstruck\Foundry\Bundle\DependencyInjection;
4
5
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
6
use Symfony\Component\Config\Definition\ConfigurationInterface;
7
8
/**
9
 * @author Kevin Bond <[email protected]>
10
 */
11
final class Configuration implements ConfigurationInterface
12
{
13 36
    public function getConfigTreeBuilder(): TreeBuilder
14
    {
15 36
        $treeBuilder = new TreeBuilder('zenstruck_foundry');
16
17 36
        $treeBuilder->getRootNode()
18 36
            ->children()
19 36
                ->arrayNode('faker')
20 36
                    ->addDefaultsIfNotSet()
21 36
                    ->info('Configure faker to be used by your factories.')
22 36
                    ->validate()
23
                        ->ifTrue(static function(array $v) {
24 12
                            return $v['locale'] && $v['service'];
25 36
                        })
26 36
                        ->thenInvalid('Cannot set faker locale when using custom service.')
27 36
                    ->end()
28 36
                    ->children()
29 36
                        ->scalarNode('locale')
30 36
                            ->defaultNull()
31 36
                            ->info('Change the default faker locale.')
32 36
                            ->example('fr_FR')
33 36
                        ->end()
34 36
                        ->scalarNode('service')
35 36
                            ->defaultNull()
36 36
                            ->info('Customize the faker service.')
37 36
                            ->example('my_faker')
38 36
                        ->end()
39 36
                    ->end()
40 36
                ->end()
41 36
                ->arrayNode('instantiator')
42 36
                    ->addDefaultsIfNotSet()
43 36
                    ->info('Configure the default instantiator used by your factories.')
44 36
                    ->validate()
45
                        ->ifTrue(static function(array $v) {
46 20
                            return $v['service'] && $v['without_constructor'];
47 36
                        })
48 36
                        ->thenInvalid('Cannot set "without_constructor" when using custom service.')
49 36
                    ->end()
50 36
                    ->validate()
51
                        ->ifTrue(static function(array $v) {
52 16
                            return $v['service'] && $v['allow_extra_attributes'];
53 36
                        })
54 36
                        ->thenInvalid('Cannot set "allow_extra_attributes" when using custom service.')
55 36
                    ->end()
56 36
                    ->validate()
57
                        ->ifTrue(static function(array $v) {
58 12
                            return $v['service'] && $v['always_force_properties'];
59 36
                        })
60 36
                        ->thenInvalid('Cannot set "always_force_properties" when using custom service.')
61 36
                    ->end()
62 36
                    ->children()
63 36
                        ->booleanNode('without_constructor')
64 36
                            ->defaultNull()
65 36
                            ->info('Whether or not to call an object\'s constructor during instantiation.')
66 36
                        ->end()
67 36
                        ->booleanNode('allow_extra_attributes')
68 36
                            ->defaultNull()
69 36
                            ->info('Whether or not to allow extra attributes.')
70 36
                        ->end()
71 36
                        ->booleanNode('always_force_properties')
72 36
                            ->defaultNull()
73 36
                            ->info('Whether or not to skip setters and force set object properties (public/private/protected) directly.')
74 36
                        ->end()
75 36
                        ->scalarNode('service')
76 36
                            ->defaultNull()
77 36
                            ->info('Customize the instantiator service.')
78 36
                            ->example('my_instantiator')
79 36
                        ->end()
80 36
                    ->end()
81 36
                ->end()
82 36
            ->end()
83
        ;
84
85 36
        return $treeBuilder;
86
    }
87
}
88