Conditions | 2 |
Paths | 1 |
Total Lines | 55 |
Code Lines | 48 |
Lines | 0 |
Ratio | 0 % |
Tests | 48 |
CRAP Score | 2 |
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 |
||
37 | 11 | public function getConfigTreeBuilder() |
|
38 | { |
||
39 | 11 | $treeBuilder = new TreeBuilder(); |
|
40 | 11 | $rootNode = $treeBuilder->root($this->alias); |
|
41 | $rootNode |
||
42 | 11 | ->validate() |
|
43 | ->ifTrue(function($v) { |
||
44 | 11 | return !empty($v['enabled']) && empty($v['pools']); |
|
45 | 11 | }) |
|
46 | 11 | ->thenInvalid('The child node "pools" at path "'.$this->alias.'" must be configured.') |
|
47 | 11 | ->end() |
|
48 | 11 | ->children() |
|
49 | 11 | ->scalarNode('enabled') |
|
50 | 11 | ->defaultTrue() |
|
51 | 11 | ->end() |
|
52 | 11 | ->arrayNode('listeners') |
|
53 | 11 | ->addDefaultsIfNotSet() |
|
54 | 11 | ->children() |
|
55 | 11 | ->booleanNode('clear_entity_managers')->defaultTrue()->end() |
|
56 | 11 | ->booleanNode('clear_logs')->defaultTrue()->end() |
|
57 | 11 | ->end() |
|
58 | 11 | ->end() |
|
59 | 11 | ->arrayNode('pools') |
|
60 | 11 | ->requiresAtLeastOneElement() |
|
61 | 11 | ->validate() |
|
62 | ->ifTrue(function (array $value) { |
||
63 | 9 | return !array_key_exists('default', $value); |
|
64 | 11 | }) |
|
65 | 11 | ->thenInvalid('Default service not present') |
|
66 | 11 | ->end() |
|
67 | 11 | ->prototype('array') |
|
68 | 11 | ->children() |
|
69 | 11 | ->scalarNode('send_driver') |
|
70 | 11 | ->isRequired() |
|
71 | 11 | ->validate() |
|
72 | 11 | ->ifTrue(function ($value) { |
|
73 | 9 | return !preg_match('/^@[a-zA-Z\.\-0-9\_]+$/', $value); |
|
74 | 11 | }) |
|
75 | 11 | ->thenInvalid('Malformed service ID "%s"') |
|
76 | 11 | ->end() |
|
77 | 11 | ->end() |
|
78 | 11 | ->end() |
|
79 | 11 | ->end() |
|
80 | 11 | ->end() |
|
81 | 11 | ->arrayNode('routes') |
|
82 | 11 | ->normalizeKeys(false) |
|
83 | 11 | ->prototype('scalar') |
|
84 | 11 | ->isRequired() |
|
85 | 11 | ->end() |
|
86 | 11 | ->end() |
|
87 | 11 | ->end() |
|
88 | ; |
||
89 | |||
90 | 11 | return $treeBuilder; |
|
91 | } |
||
92 | } |
||
93 |