Conditions | 7 |
Paths | 1 |
Total Lines | 92 |
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 |
||
18 | public function getConfigTreeBuilder() |
||
19 | { |
||
20 | $treeBuilder = new TreeBuilder(); |
||
21 | $rootNode = $treeBuilder->root('netgen_open_weather_map'); |
||
22 | |||
23 | $builder = $this->generateScopeBaseNode($rootNode); |
||
24 | |||
25 | $builder |
||
26 | ->arrayNode('api_settings') |
||
27 | ->children() |
||
28 | ->scalarNode('api_key') |
||
29 | ->cannotBeEmpty() |
||
30 | ->info('API key from OpenWeatherMap') |
||
31 | ->end() |
||
32 | ->scalarNode('units') |
||
33 | ->validate() |
||
34 | ->ifNotInArray(array(UnitsConstraints::IMPERIAL, UnitsConstraints::METRIC, UnitsConstraints::STANDARD)) |
||
35 | ->thenInvalid('Invalid units parameter %s') |
||
36 | ->end() |
||
37 | ->info('Standard, metric, and imperial units are available') |
||
38 | ->end() |
||
39 | ->scalarNode('language') |
||
40 | ->cannotBeEmpty() |
||
41 | ->info('You can use lang parameter to get the output in your language') |
||
42 | ->end() |
||
43 | ->scalarNode('type') |
||
44 | ->validate() |
||
45 | ->ifNotInArray(array(SearchAccuracyConstraints::ACCURATE, SearchAccuracyConstraints::LIKE)) |
||
46 | ->thenInvalid('Invalid search accuracy parameter %s') |
||
47 | ->end() |
||
48 | ->info('Search accuracy') |
||
49 | ->end() |
||
50 | ->end() |
||
51 | ->end(); |
||
52 | |||
53 | $builder |
||
54 | ->arrayNode('cache_settings') |
||
55 | ->validate() |
||
56 | ->ifTrue(function ($v) { |
||
57 | if (empty($v)) { |
||
58 | return true; |
||
59 | } |
||
60 | |||
61 | $requiredSettings = array(); |
||
62 | |||
63 | switch ($v['handler']) { |
||
64 | case 'memcached': |
||
65 | $requiredSettings = array('ttl', 'server', 'port'); |
||
66 | break; |
||
67 | case 'stash': |
||
68 | $requiredSettings = array('ttl'); |
||
69 | break; |
||
70 | case 'null': |
||
71 | return false; |
||
72 | } |
||
73 | |||
74 | foreach ($requiredSettings as $setting) { |
||
75 | if (!array_key_exists($setting, $v)) { |
||
76 | return true; |
||
77 | } |
||
78 | } |
||
79 | |||
80 | return false; |
||
81 | }) |
||
82 | ->thenInvalid('Invalid handler configuration') |
||
83 | ->end() |
||
84 | ->children() |
||
85 | ->scalarNode('handler') |
||
86 | ->cannotBeEmpty() |
||
87 | ->info('Cache handler') |
||
88 | ->validate() |
||
89 | ->ifNotInArray(array('stash', 'memcached', 'null')) |
||
90 | ->thenInvalid('Invalid cache handler %s') |
||
91 | ->end() |
||
92 | ->end() |
||
93 | ->scalarNode('ttl') |
||
94 | ->cannotBeEmpty() |
||
95 | ->info('Cache ttl in seconds') |
||
96 | ->end() |
||
97 | ->scalarNode('server') |
||
98 | ->cannotBeEmpty() |
||
99 | ->info('Memcached server IP address') |
||
100 | ->end() |
||
101 | ->scalarNode('port') |
||
102 | ->cannotBeEmpty() |
||
103 | ->info('Memcached server port') |
||
104 | ->end() |
||
105 | ->end() |
||
106 | ->end(); |
||
107 | |||
108 | return $treeBuilder; |
||
109 | } |
||
110 | } |
||
111 |