| Conditions | 3 |
| Paths | 1 |
| Total Lines | 55 |
| Code Lines | 47 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 6 | ||
| Bugs | 1 | 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 |
||
| 27 | public function getConfigTreeBuilder() |
||
| 28 | { |
||
| 29 | $treeBuilder = new TreeBuilder(); |
||
| 30 | $treeBuilder->root('dunglas_action') |
||
| 31 | ->fixXmlConfig('directory', 'directories') |
||
| 32 | ->children() |
||
| 33 | ->arrayNode('methods') |
||
| 34 | ->info('The list of methods to autowire.') |
||
| 35 | ->prototype('scalar')->end() |
||
| 36 | ->defaultValue(['__construct', 'get*', 'set*']) |
||
| 37 | ->end() |
||
| 38 | ->arrayNode('directories') |
||
| 39 | ->info('List of directories relative to the kernel root directory containing classes.') |
||
| 40 | ->prototype('scalar')->end() |
||
| 41 | ->defaultValue([ |
||
| 42 | '../src/*Bundle/Action', |
||
| 43 | '../src/*Bundle/Command', |
||
| 44 | '../src/*Bundle/Controller', |
||
| 45 | '../src/*Bundle/EventSubscriber', |
||
| 46 | '../src/*Bundle/Twig', |
||
| 47 | ]) |
||
| 48 | ->end() |
||
| 49 | ->arrayNode('tags') |
||
| 50 | ->info('List of tags to add when implementing the corresponding class.') |
||
| 51 | ->useAttributeAsKey('class') |
||
| 52 | ->prototype('array') |
||
| 53 | // Converts 'console.command' to ['console.command'] |
||
| 54 | ->beforeNormalization()->ifString()->then(function ($v) { |
||
| 55 | return [$v]; |
||
| 56 | })->end() |
||
| 57 | ->prototype('array') |
||
| 58 | // Converts 'console.command' to ['console.command', []] |
||
| 59 | ->beforeNormalization()->ifString()->then(function ($v) { |
||
| 60 | return [$v, []]; |
||
| 61 | })->end() |
||
| 62 | ->validate() |
||
| 63 | ->ifTrue(function ($v) { |
||
| 64 | return count($v) !== 2 || !is_string($v[0]) || !is_array($v[1]); |
||
| 65 | }) |
||
| 66 | ->thenInvalid('Invalid tag format. They must be as following: [\'my_tag.name\', [\'attribute\' => \'value\']]') |
||
| 67 | ->end() |
||
| 68 | ->prototype('variable')->end() |
||
| 69 | ->end() |
||
| 70 | ->end() |
||
| 71 | ->defaultValue([ |
||
| 72 | Command::class => [['console.command', []]], |
||
| 73 | EventSubscriberInterface::class => [['kernel.event_subscriber', []]], |
||
| 74 | \Twig_ExtensionInterface::class => [['twig.extension', []]], |
||
| 75 | ]) |
||
| 76 | ->end() |
||
| 77 | ->end() |
||
| 78 | ->end(); |
||
| 79 | |||
| 80 | return $treeBuilder; |
||
| 81 | } |
||
| 82 | } |
||
| 83 |