| Conditions | 1 |
| Paths | 1 |
| Total Lines | 56 |
| Code Lines | 49 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 7 | ||
| Bugs | 1 | Features | 2 |
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 |
||
| 52 | public function getConnectionsNode() |
||
| 53 | { |
||
| 54 | $treeBuilder = new TreeBuilder(); |
||
| 55 | $node = $treeBuilder->root('connections'); |
||
| 56 | |||
| 57 | $node |
||
| 58 | ->requiresAtLeastOneElement() |
||
| 59 | ->useAttributeAsKey('name') |
||
| 60 | ->fixXmlConfig('sub_url') |
||
| 61 | ->fixXmlConfig('filter') |
||
| 62 | ->performNoDeepMerging() |
||
| 63 | ->prototype('array') |
||
| 64 | ->children() |
||
| 65 | ->scalarNode('pub_url') |
||
| 66 | ->isRequired() |
||
| 67 | ->example('http://example.com/pub/?id={token}') |
||
| 68 | ->end() |
||
| 69 | ->arrayNode('sub_urls') |
||
| 70 | ->isRequired() |
||
| 71 | ->prototype('scalar') |
||
| 72 | ->end() |
||
| 73 | ->example(array( |
||
| 74 | 'polling' => 'http://example.com/sub-p/{tokens}', |
||
| 75 | 'long-polling' => 'http://example.com/sub-lp/{tokens}', |
||
| 76 | 'streaming' => 'http://example.com/sub-s/{tokens}', |
||
| 77 | 'eventsource' => 'http://example.com/sub-ev/{tokens}', |
||
| 78 | )) |
||
| 79 | ->end() |
||
| 80 | ->scalarNode('id_generator') |
||
| 81 | ->defaultValue(true) |
||
| 82 | ->example(true) |
||
| 83 | ->end() |
||
| 84 | ->scalarNode('sender') |
||
| 85 | ->defaultValue(true) |
||
| 86 | ->example(true) |
||
| 87 | ->end() |
||
| 88 | ->arrayNode('filters') |
||
| 89 | ->performNoDeepMerging() |
||
| 90 | ->useAttributeAsKey('id') |
||
| 91 | ->prototype('array') |
||
| 92 | ->prototype('scalar') |
||
| 93 | ->end() |
||
| 94 | ->children() |
||
| 95 | ->scalarNode('class')->end() |
||
| 96 | ->end() |
||
| 97 | ->end() |
||
| 98 | ->example(array( |
||
| 99 | 'hash' => array('class' => 'hash', 'secret' => 'mysecret', 'algo' => 'md5'), |
||
| 100 | 'prefix' => array('class' => 'prefix', 'prefix' => 'myapp_'), |
||
| 101 | )) |
||
| 102 | ->end() |
||
| 103 | ->end() |
||
| 104 | ; |
||
| 105 | |||
| 106 | return $node; |
||
| 107 | } |
||
| 108 | } |
||
| 109 |