Conditions | 2 |
Paths | 2 |
Total Lines | 55 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
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:
If many parameters/temporary variables are present:
1 | <?php |
||
27 | public function getConfigTreeBuilder() |
||
28 | { |
||
29 | if (\method_exists(TreeBuilder::class, 'getRootNode')) { |
||
30 | // Symfony 4.1+ |
||
31 | $treeBuilder = new TreeBuilder('eo_honeypot'); |
||
32 | $rootNode = $treeBuilder->getRootNode(); |
||
33 | } else { |
||
34 | // Symfony <= 4.0 |
||
35 | $treeBuilder = new TreeBuilder(); |
||
36 | $rootNode = $treeBuilder->root('eo_honeypot'); |
||
37 | } |
||
38 | |||
39 | $rootNode |
||
40 | ->children() |
||
41 | ->arrayNode('redirect') |
||
42 | ->canBeEnabled() |
||
43 | ->addDefaultsIfNotSet() |
||
44 | ->children() |
||
45 | ->scalarNode('url')->defaultNull()->end() |
||
46 | ->scalarNode('route')->defaultNull()->end() |
||
47 | ->arrayNode('route_parameters') |
||
48 | ->useAttributeAsKey('name') |
||
49 | ->prototype('scalar')->end() |
||
50 | ->end() |
||
51 | ->end() |
||
52 | ->end() |
||
53 | ->arrayNode('storage') |
||
54 | ->addDefaultsIfNotSet() |
||
55 | ->children() |
||
56 | ->arrayNode('database') |
||
57 | ->canBeEnabled() |
||
58 | ->children() |
||
59 | ->scalarNode('class')->defaultValue('ApplicationEoHoneypotBundle:HoneypotPrey')->end() |
||
60 | ->scalarNode('driver') |
||
61 | ->defaultValue('mongodb') |
||
62 | ->validate() |
||
63 | ->ifNotInArray(array('orm', 'mongodb')) |
||
64 | ->thenInvalid('Invalid database driver "%s"') |
||
65 | ->end() |
||
66 | ->end() |
||
67 | ->end() |
||
68 | ->end() |
||
69 | ->arrayNode('file') |
||
70 | ->canBeEnabled() |
||
71 | ->children() |
||
72 | ->scalarNode('output')->defaultValue('/var/log/honeypot.log')->end() |
||
73 | ->end() |
||
74 | ->end() |
||
75 | ->end() |
||
76 | ->end() |
||
77 | ->end() |
||
78 | ; |
||
79 | |||
80 | return $treeBuilder; |
||
81 | } |
||
82 | } |
||
83 |