| Conditions | 3 |
| Paths | 1 |
| Total Lines | 54 |
| Code Lines | 32 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 1 | Features | 1 |
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 |
||
| 19 | public function testDefaultBehavior() |
||
| 20 | { |
||
| 21 | $container = $this->getMock('Symfony\Component\DependencyInjection\ContainerBuilder'); |
||
| 22 | |||
| 23 | $container |
||
| 24 | ->expects($this->any()) |
||
| 25 | ->method('getParameter') |
||
| 26 | ->will($this->returnCallback(function($value) { |
||
| 27 | if ($value == 'sonata.admin.configuration.admin_services') { |
||
| 28 | return array( |
||
| 29 | 'my.admin' => array( |
||
| 30 | 'templates' => array( |
||
| 31 | 'form' => array('myform.twig.html'), |
||
| 32 | 'filter' => array('myfilter.twig.html') |
||
| 33 | ) |
||
| 34 | ) |
||
| 35 | ); |
||
| 36 | } |
||
| 37 | |||
| 38 | if ($value == 'sonata_doctrine_orm_admin.templates') { |
||
| 39 | return array( |
||
| 40 | 'form' => array('default_form.twig.html'), |
||
| 41 | 'filter' => array('default_filter.twig.html'), |
||
| 42 | ); |
||
| 43 | } |
||
| 44 | })) |
||
| 45 | ; |
||
| 46 | |||
| 47 | $container |
||
| 48 | ->expects($this->any()) |
||
| 49 | ->method('findTaggedServiceIds') |
||
| 50 | ->will($this->returnValue(array('my.admin' => array(array('manager_type' => 'orm'))))) |
||
| 51 | ; |
||
| 52 | |||
| 53 | $definition = new Definition(null); |
||
| 54 | |||
| 55 | $container |
||
| 56 | ->expects($this->any()) |
||
| 57 | ->method('getDefinition') |
||
| 58 | ->will($this->returnValue($definition)) |
||
| 59 | ; |
||
| 60 | |||
| 61 | $definition->addMethodCall('setFilterTheme', array(array('custom_call.twig.html'))); |
||
| 62 | |||
| 63 | $compilerPass = new AddTemplatesCompilerPass(); |
||
| 64 | $compilerPass->process($container); |
||
| 65 | |||
| 66 | $expected = array( |
||
| 67 | array('setFilterTheme', array(array('custom_call.twig.html', 'myfilter.twig.html',))), |
||
| 68 | array('setFormTheme', array(array('default_form.twig.html', 'myform.twig.html',))), |
||
| 69 | ); |
||
| 70 | |||
| 71 | $this->assertEquals($expected, $definition->getMethodCalls()); |
||
| 72 | } |
||
| 73 | } |
||
| 74 |