| Conditions | 2 |
| Paths | 1 |
| Total Lines | 77 |
| Code Lines | 70 |
| 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 |
||
| 18 | public function getConfigTreeBuilder() |
||
| 19 | { |
||
| 20 | $treeBuilder = new TreeBuilder(); |
||
| 21 | $rootNode = $treeBuilder->root('resque'); |
||
| 22 | |||
| 23 | $rootNode |
||
| 24 | ->addDefaultsIfNotSet() |
||
| 25 | ->children() |
||
| 26 | ->scalarNode('vendor_dir') |
||
| 27 | ->defaultValue('%kernel.root_dir%/../vendor') |
||
| 28 | ->cannotBeEmpty() |
||
| 29 | ->info('Set the vendor dir') |
||
| 30 | ->end() |
||
| 31 | ->scalarNode('app_include') |
||
| 32 | ->defaultValue('%kernel.root_dir%/../var/bootstrap.php.cache') |
||
| 33 | ->cannotBeEmpty() |
||
| 34 | ->info('Set the APP_INCLUDE for php-resque') |
||
| 35 | ->end() |
||
| 36 | ->scalarNode('prefix') |
||
| 37 | ->defaultNull() |
||
| 38 | ->end() |
||
| 39 | ->scalarNode('class') |
||
| 40 | ->defaultValue('Mpclarkson\ResqueBundle\Resque') |
||
| 41 | ->cannotBeEmpty() |
||
| 42 | ->info('Set the resque class dir') |
||
| 43 | ->end() |
||
| 44 | ->arrayNode('auto_retry') |
||
| 45 | ->beforeNormalization() |
||
| 46 | ->ifArray() |
||
| 47 | ->then(function($var) { |
||
| 48 | if (array_key_exists(0, $var)) { |
||
| 49 | return [$var]; |
||
| 50 | } |
||
| 51 | return $var; |
||
| 52 | }) |
||
| 53 | ->end() |
||
| 54 | ->prototype('array') |
||
| 55 | ->prototype('scalar')->end() |
||
| 56 | ->end() |
||
| 57 | ->info('Set auto retry strategy') |
||
| 58 | ->end() |
||
| 59 | ->arrayNode('redis') |
||
| 60 | ->info('Redis configuration') |
||
| 61 | ->addDefaultsIfNotSet() |
||
| 62 | ->children() |
||
| 63 | ->scalarNode('host') |
||
| 64 | ->defaultValue('localhost') |
||
| 65 | ->cannotBeEmpty() |
||
| 66 | ->info('The redis hostname') |
||
| 67 | ->end() |
||
| 68 | ->scalarNode('port') |
||
| 69 | ->defaultValue(6379) |
||
| 70 | ->cannotBeEmpty() |
||
| 71 | ->info('The redis port') |
||
| 72 | ->end() |
||
| 73 | ->scalarNode('database') |
||
| 74 | ->defaultValue(0) |
||
| 75 | ->info('The redis database') |
||
| 76 | ->end() |
||
| 77 | ->end() |
||
| 78 | ->end() |
||
| 79 | ->arrayNode('worker') |
||
| 80 | ->info('Worker Server configuration') |
||
| 81 | ->addDefaultsIfNotSet() |
||
| 82 | ->children() |
||
| 83 | ->scalarNode('root_dir') |
||
| 84 | ->defaultValue('%kernel.root_dir%') |
||
| 85 | ->cannotBeEmpty() |
||
| 86 | ->info('The root dir of worker registered app') |
||
| 87 | ->end() |
||
| 88 | ->end() |
||
| 89 | ->end() |
||
| 90 | ->end() |
||
| 91 | ; |
||
| 92 | |||
| 93 | return $treeBuilder; |
||
| 94 | } |
||
| 95 | } |
||
| 96 |