Conditions | 5 |
Paths | 1 |
Total Lines | 73 |
Code Lines | 60 |
Lines | 0 |
Ratio | 0 % |
Tests | 53 |
CRAP Score | 5 |
Changes | 1 | ||
Bugs | 0 | Features | 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 |
||
20 | 2 | public function getConfigTreeBuilder() |
|
21 | { |
||
22 | 2 | $treeBuilder = new TreeBuilder(); |
|
23 | |||
24 | 2 | $rootNode = $treeBuilder->root('runopencode_traitor'); |
|
25 | |||
26 | $rootNode |
||
27 | 2 | ->addDefaultsIfNotSet() |
|
28 | 2 | ->children() |
|
29 | 2 | ->booleanNode('use_common_traits') |
|
30 | 2 | ->defaultFalse() |
|
31 | 2 | ->info('For sake of productivity, some of the common Symfony and vendor traits, as well as traits from this library, can be automatically added to "inject" definition.') |
|
32 | 2 | ->end() |
|
33 | 2 | ->arrayNode('inject') |
|
34 | 2 | ->useAttributeAsKey('trait') |
|
35 | 2 | ->prototype('array') |
|
36 | 2 | ->validate() |
|
37 | 2 | ->ifTrue(function($value) { |
|
38 | |||
39 | if (!is_array($value) || 2 !== count($value)) { |
||
40 | return true; |
||
41 | } |
||
42 | |||
43 | if (!is_string($value[0])) { |
||
44 | return true; |
||
45 | } |
||
46 | |||
47 | if (!is_array($value[1])) { |
||
48 | return true; |
||
49 | } |
||
50 | |||
51 | return false; |
||
52 | 2 | }) |
|
53 | 2 | ->thenInvalid('Expected proper setter injection definition.') |
|
54 | 2 | ->end() |
|
55 | 2 | ->prototype('variable') |
|
56 | 2 | ->end() |
|
57 | 2 | ->end() |
|
58 | 2 | ->end() |
|
59 | 2 | ->arrayNode('filters') |
|
60 | 2 | ->info('Analyse services for injection which matches filter criteria.') |
|
61 | 2 | ->children() |
|
62 | 2 | ->arrayNode('tags') |
|
63 | 2 | ->prototype('scalar') |
|
64 | 2 | ->end() |
|
65 | 2 | ->end() |
|
66 | 2 | ->arrayNode('namespaces') |
|
67 | 2 | ->prototype('scalar') |
|
68 | 2 | ->end() |
|
69 | 2 | ->end() |
|
70 | 2 | ->end() |
|
71 | 2 | ->end() |
|
72 | 2 | ->arrayNode('exclude') |
|
73 | 2 | ->info('Exclude services from injection which matches filter criteria.') |
|
74 | 2 | ->children() |
|
75 | 2 | ->arrayNode('services') |
|
76 | 2 | ->prototype('scalar') |
|
77 | 2 | ->end() |
|
78 | 2 | ->end() |
|
79 | 2 | ->arrayNode('namespaces') |
|
80 | 2 | ->prototype('scalar') |
|
81 | 2 | ->end() |
|
82 | 2 | ->end() |
|
83 | 2 | ->arrayNode('classes') |
|
84 | 2 | ->prototype('scalar') |
|
85 | 2 | ->end() |
|
86 | 2 | ->end() |
|
87 | 2 | ->end() |
|
88 | 2 | ->end() |
|
89 | 2 | ->end(); |
|
90 | |||
91 | 2 | return $treeBuilder; |
|
92 | } |
||
93 | } |
||
94 |