Conditions | 3 |
Paths | 4 |
Total Lines | 60 |
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 |
||
36 | public function getConfigTreeBuilder() |
||
37 | { |
||
38 | $treeBuilder = new TreeBuilder(); |
||
39 | $rootNode = $treeBuilder->root('kunstmaan_node_search'); |
||
40 | |||
41 | $rootNode->children()->booleanNode('enable_update_listener')->defaultTrue(); |
||
42 | $rootNode->children()->booleanNode('use_match_query_for_title')->defaultFalse(); |
||
43 | |||
44 | /** @var ArrayNodeDefinition $properties */ |
||
45 | $properties = $rootNode->children()->arrayNode('mapping')->useAttributeAsKey('name')->prototype('array'); |
||
46 | |||
47 | $types = [ |
||
48 | 'token_count', 'text', 'keyword', |
||
49 | 'float', 'double', 'byte', 'short', 'integer', 'long', |
||
50 | 'date', |
||
51 | 'boolean', |
||
52 | 'binary', |
||
53 | ]; |
||
54 | if (!$this->useElasticSearchVersion6) { |
||
55 | $types[] = 'string'; |
||
56 | } |
||
57 | |||
58 | $properties->children()->scalarNode('type')->beforeNormalization()->ifNotInArray($types)->thenInvalid('type must be one of: ' . implode(', ', $types)); |
||
59 | |||
60 | if ($this->useElasticSearchVersion6) { |
||
61 | $properties->children()->booleanNode('fielddata'); |
||
62 | $properties->children()->booleanNode('doc_values'); |
||
63 | $properties->children() |
||
64 | ->scalarNode('index') |
||
65 | ->beforeNormalization() |
||
66 | ->ifNotInArray(['true', 'false', true, false]) |
||
67 | ->thenInvalid("index must be one of: true, false"); |
||
68 | } else { |
||
69 | $properties->children() |
||
70 | ->scalarNode('index') |
||
71 | ->beforeNormalization() |
||
72 | ->ifNotInArray(['analyzed', 'not_analyzed', 'no']) |
||
73 | ->thenInvalid("index must be one of: analyzed, not_analyzed, no"); |
||
74 | $properties->children()->booleanNode('include_in_all'); |
||
75 | } |
||
76 | |||
77 | $properties->children()->booleanNode('store'); |
||
78 | $properties->children()->floatNode('boost'); |
||
79 | $properties->children()->scalarNode('null_value'); |
||
80 | $properties->children()->scalarNode('analyzer'); |
||
81 | $properties->children()->scalarNode('search_analyzer'); |
||
82 | $properties->children()->scalarNode('index_analyzer'); |
||
83 | $properties->children()->scalarNode('copy_to'); |
||
84 | $properties->children()->scalarNode('term_vector')->beforeNormalization()->ifNotInArray(['yes', 'no', 'with_positions', 'with_offsets', 'with_positions_offsets']) |
||
85 | ->thenInvalid("term_vector must be one of: yes, no, with_positions, with_offsets, with_positions_offsets"); |
||
86 | |||
87 | $rootNode |
||
88 | ->children() |
||
89 | ->arrayNode('contexts') |
||
90 | ->defaultValue([]) |
||
91 | ->prototype('scalar')->end() |
||
92 | ->end(); |
||
93 | |||
94 | return $treeBuilder; |
||
95 | } |
||
96 | } |
||
97 |