Conditions | 3 |
Paths | 4 |
Total Lines | 60 |
Code Lines | 46 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 1 |
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 |
||
21 | public function getConfigTreeBuilder() |
||
22 | { |
||
23 | $treeBuilder = new TreeBuilder(); |
||
24 | $rootNode = $treeBuilder->root('kunstmaan_node_search'); |
||
25 | |||
26 | $rootNode->children()->booleanNode('enable_update_listener')->defaultTrue(); |
||
27 | $rootNode->children()->booleanNode('use_match_query_for_title')->defaultFalse(); |
||
28 | |||
29 | /** @var ArrayNodeDefinition $properties */ |
||
30 | $properties = $rootNode->children()->arrayNode('mapping')->useAttributeAsKey('name')->prototype('array'); |
||
31 | |||
32 | $types = [ |
||
33 | 'token_count', 'text', 'keyword', |
||
34 | 'float', 'double', 'byte', 'short', 'integer', 'long', |
||
35 | 'date', |
||
36 | 'boolean', |
||
37 | 'binary', |
||
38 | ]; |
||
39 | if (!ElasticSearchUtil::useVersion6()) { |
||
40 | $types[] = 'string'; |
||
41 | } |
||
42 | |||
43 | $properties->children()->scalarNode('type')->beforeNormalization()->ifNotInArray($types)->thenInvalid('type must be one of: ' . implode(', ', $types)); |
||
44 | |||
45 | if (ElasticSearchUtil::useVersion6()) { |
||
46 | $properties->children()->booleanNode('fielddata'); |
||
47 | $properties->children()->booleanNode('doc_values'); |
||
48 | $properties->children() |
||
49 | ->scalarNode('index') |
||
50 | ->beforeNormalization() |
||
51 | ->ifNotInArray(['true', 'false', true, false]) |
||
52 | ->thenInvalid("index must be one of: true, false"); |
||
53 | } else { |
||
54 | $properties->children() |
||
55 | ->scalarNode('index') |
||
56 | ->beforeNormalization() |
||
57 | ->ifNotInArray(['analyzed', 'not_analyzed', 'no']) |
||
58 | ->thenInvalid("index must be one of: analyzed, not_analyzed, no"); |
||
59 | $properties->children()->booleanNode('include_in_all'); |
||
60 | } |
||
61 | |||
62 | $properties->children()->booleanNode('store'); |
||
63 | $properties->children()->floatNode('boost'); |
||
64 | $properties->children()->scalarNode('null_value'); |
||
65 | $properties->children()->scalarNode('analyzer'); |
||
66 | $properties->children()->scalarNode('search_analyzer'); |
||
67 | $properties->children()->scalarNode('index_analyzer'); |
||
68 | $properties->children()->scalarNode('copy_to'); |
||
69 | $properties->children()->scalarNode('term_vector')->beforeNormalization()->ifNotInArray(['yes', 'no', 'with_positions', 'with_offsets', 'with_positions_offsets']) |
||
70 | ->thenInvalid("term_vector must be one of: yes, no, with_positions, with_offsets, with_positions_offsets"); |
||
71 | |||
72 | $rootNode |
||
73 | ->children() |
||
74 | ->arrayNode('contexts') |
||
75 | ->defaultValue([]) |
||
76 | ->prototype('scalar')->end() |
||
77 | ->end(); |
||
78 | |||
79 | return $treeBuilder; |
||
80 | } |
||
81 | } |
||
82 |