| Conditions | 1 |
| Paths | 1 |
| Total Lines | 82 |
| Code Lines | 76 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 0 |
| CRAP Score | 2 |
| 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 |
||
| 30 | public function getConfigTreeBuilder() |
||
| 31 | { |
||
| 32 | $treeBuilder = new TreeBuilder(); |
||
| 33 | $rootNode = $treeBuilder->root('gearman'); |
||
|
|
|||
| 34 | |||
| 35 | $rootNode |
||
| 36 | ->children() |
||
| 37 | ->arrayNode('bundles') |
||
| 38 | ->prototype('array') |
||
| 39 | ->children() |
||
| 40 | ->scalarNode('name') |
||
| 41 | ->isRequired() |
||
| 42 | ->cannotBeEmpty() |
||
| 43 | ->end() |
||
| 44 | ->booleanNode('active') |
||
| 45 | ->defaultFalse() |
||
| 46 | ->end() |
||
| 47 | ->arrayNode('include') |
||
| 48 | ->prototype('scalar')->end() |
||
| 49 | ->end() |
||
| 50 | ->arrayNode('ignore') |
||
| 51 | ->prototype('scalar')->end() |
||
| 52 | ->end() |
||
| 53 | ->end() |
||
| 54 | ->end() |
||
| 55 | ->end() |
||
| 56 | ->arrayNode('servers') |
||
| 57 | ->performNoDeepMerging() |
||
| 58 | ->defaultValue(array( |
||
| 59 | 'localhost' => array( |
||
| 60 | 'host' => '127.0.0.1', |
||
| 61 | 'port' => '4730', |
||
| 62 | ), |
||
| 63 | )) |
||
| 64 | ->prototype('array') |
||
| 65 | ->children() |
||
| 66 | ->scalarNode('host') |
||
| 67 | ->isRequired() |
||
| 68 | ->cannotBeEmpty() |
||
| 69 | ->end() |
||
| 70 | ->integerNode('port') |
||
| 71 | ->defaultValue('4730') |
||
| 72 | ->end() |
||
| 73 | ->end() |
||
| 74 | ->end() |
||
| 75 | ->end() |
||
| 76 | ->arrayNode('defaults') |
||
| 77 | ->addDefaultsIfNotSet() |
||
| 78 | ->children() |
||
| 79 | ->integerNode('iterations') |
||
| 80 | ->min(0) |
||
| 81 | ->defaultValue(0) |
||
| 82 | ->end() |
||
| 83 | ->scalarNode('method') |
||
| 84 | ->defaultValue('doNormal') |
||
| 85 | ->end() |
||
| 86 | ->booleanNode('callbacks') |
||
| 87 | ->defaultTrue() |
||
| 88 | ->end() |
||
| 89 | ->scalarNode('job_prefix') |
||
| 90 | ->defaultNull() |
||
| 91 | ->end() |
||
| 92 | ->booleanNode('generate_unique_key') |
||
| 93 | ->defaultTrue() |
||
| 94 | ->end() |
||
| 95 | ->booleanNode('workers_name_prepend_namespace') |
||
| 96 | ->defaultTrue() |
||
| 97 | ->end() |
||
| 98 | ->integerNode('minimum_execution_time') |
||
| 99 | ->min(0) |
||
| 100 | ->defaultValue(0) |
||
| 101 | ->end() |
||
| 102 | ->integerNode('timeout') |
||
| 103 | ->min(0) |
||
| 104 | ->defaultValue(0) |
||
| 105 | ->end() |
||
| 106 | ->end() |
||
| 107 | ->end() |
||
| 108 | ->end(); |
||
| 109 | |||
| 110 | return $treeBuilder; |
||
| 111 | } |
||
| 112 | } |
||
| 113 |
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.
To visualize
will produce issues in the first and second line, while this second example
will produce no issues.