| Conditions | 1 |
| Paths | 1 |
| Total Lines | 62 |
| Code Lines | 56 |
| Lines | 0 |
| Ratio | 0 % |
| 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 |
||
| 16 | public function getConfigTreeBuilder() |
||
| 17 | { |
||
| 18 | $treeBuilder = new TreeBuilder(); |
||
| 19 | $rootNode = $treeBuilder->root('browscap'); |
||
| 20 | |||
| 21 | $supportedMethods = array( |
||
| 22 | 'URL-wrapper', |
||
| 23 | 'socket', |
||
| 24 | 'cURL', |
||
| 25 | 'local', |
||
| 26 | ); |
||
| 27 | |||
| 28 | $rootNode |
||
| 29 | ->children() |
||
| 30 | ->scalarNode('cache_dir') |
||
| 31 | ->defaultValue(null) |
||
| 32 | ->end() |
||
| 33 | ->scalarNode('local_file') |
||
| 34 | ->defaultValue(null) |
||
| 35 | ->end() |
||
| 36 | ->scalarNode('cache_filename') |
||
| 37 | ->defaultValue('cache.php') |
||
| 38 | ->end() |
||
| 39 | ->scalarNode('ini_filename') |
||
| 40 | ->defaultValue('browscap.ini') |
||
| 41 | ->end() |
||
| 42 | ->scalarNode('remote_ini_url') |
||
| 43 | ->defaultValue('http://browscap.org/stream?q=Full_PHP_BrowsCapINI') |
||
| 44 | ->end() |
||
| 45 | ->scalarNode('remote_ver_url') |
||
| 46 | ->defaultValue('http://browscap.org/version') |
||
| 47 | ->end() |
||
| 48 | ->booleanNode('lowercase') |
||
| 49 | ->defaultValue(false) |
||
| 50 | ->end() |
||
| 51 | ->booleanNode('silent') |
||
| 52 | ->defaultValue(false) |
||
| 53 | ->end() |
||
| 54 | ->scalarNode('timeout') |
||
| 55 | ->defaultValue(5) |
||
| 56 | ->end() |
||
| 57 | ->scalarNode('update_interval') |
||
| 58 | ->defaultValue(432000) |
||
| 59 | ->end() |
||
| 60 | ->scalarNode('error_interval') |
||
| 61 | ->defaultValue(7200) |
||
| 62 | ->end() |
||
| 63 | ->booleanNode('do_auto_update') |
||
| 64 | ->defaultValue(true) |
||
| 65 | ->end() |
||
| 66 | ->scalarNode('update_method') |
||
| 67 | ->validate() |
||
| 68 | ->ifNotInArray($supportedMethods) |
||
| 69 | ->thenInvalid('The method "%s" is not supported. Please choose one of ' . json_encode($supportedMethods)) |
||
| 70 | ->end() |
||
| 71 | ->cannotBeOverwritten() |
||
| 72 | ->defaultValue('cURL') |
||
| 73 | ->end() |
||
| 74 | ->end(); |
||
| 75 | |||
| 76 | return $treeBuilder; |
||
| 77 | } |
||
| 78 | } |
||
| 79 |