| Conditions | 3 |
| Paths | 1 |
| Total Lines | 54 |
| Lines | 0 |
| Ratio | 0 % |
| 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 |
||
| 23 | public function testDefaultBehavior(): void |
||
| 24 | { |
||
| 25 | $container = $this->createMock(ContainerBuilder::class); |
||
| 26 | |||
| 27 | $container |
||
| 28 | ->expects($this->any()) |
||
| 29 | ->method('getParameter') |
||
| 30 | ->willReturnCallback(static function ($value) { |
||
| 31 | if ('sonata.admin.configuration.admin_services' === $value) { |
||
| 32 | return [ |
||
| 33 | 'my.admin' => [ |
||
| 34 | 'templates' => [ |
||
| 35 | 'form' => ['myform.twig.html'], |
||
| 36 | 'filter' => ['myfilter.twig.html'], |
||
| 37 | ], |
||
| 38 | ], |
||
| 39 | ]; |
||
| 40 | } |
||
| 41 | |||
| 42 | if ('sonata_doctrine_orm_admin.templates' === $value) { |
||
| 43 | return [ |
||
| 44 | 'form' => ['default_form.twig.html'], |
||
| 45 | 'filter' => ['default_filter.twig.html'], |
||
| 46 | ]; |
||
| 47 | } |
||
| 48 | }) |
||
| 49 | ; |
||
| 50 | |||
| 51 | $container |
||
| 52 | ->expects($this->any()) |
||
| 53 | ->method('findTaggedServiceIds') |
||
| 54 | ->willReturn(['my.admin' => [['manager_type' => 'orm']]]) |
||
| 55 | ; |
||
| 56 | |||
| 57 | $definition = new Definition(null); |
||
| 58 | |||
| 59 | $container |
||
| 60 | ->expects($this->any()) |
||
| 61 | ->method('getDefinition') |
||
| 62 | ->willReturn($definition) |
||
| 63 | ; |
||
| 64 | |||
| 65 | $definition->addMethodCall('setFilterTheme', [['custom_call.twig.html']]); |
||
| 66 | |||
| 67 | $compilerPass = new AddTemplatesCompilerPass(); |
||
| 68 | $compilerPass->process($container); |
||
| 69 | |||
| 70 | $expected = [ |
||
| 71 | ['setFilterTheme', [['custom_call.twig.html', 'myfilter.twig.html']]], |
||
| 72 | ['setFormTheme', [['default_form.twig.html', 'myform.twig.html']]], |
||
| 73 | ]; |
||
| 74 | |||
| 75 | $this->assertSame($expected, $definition->getMethodCalls()); |
||
| 76 | } |
||
| 77 | } |
||
| 78 |