| Conditions | 1 |
| Paths | 1 |
| Total Lines | 66 |
| 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 |
||
| 13 | public function testFind() |
||
| 14 | { |
||
| 15 | $container = new Container(); |
||
| 16 | |||
| 17 | $container->set('customRenderer1', function() use ($container) { |
||
| 18 | return new FileBasedRenderer( |
||
| 19 | 'tests/customTemplates', |
||
| 20 | new ArrayCache(), |
||
| 21 | $container |
||
| 22 | ); |
||
| 23 | }); |
||
| 24 | $container->set('packageRenderer1', function() use ($container) { |
||
| 25 | return new FileBasedRenderer( |
||
| 26 | 'tests/templates', |
||
| 27 | new ArrayCache(), |
||
| 28 | $container |
||
| 29 | ); |
||
| 30 | }); |
||
| 31 | $container->set('templateRenderer', function() use ($container) { |
||
| 32 | return new FileBasedRenderer( |
||
| 33 | 'tests/templateTemplates', |
||
| 34 | new ArrayCache(), |
||
| 35 | $container |
||
| 36 | ); |
||
| 37 | }); |
||
| 38 | |||
| 39 | $chainRenderer = new ChainRenderer($container, ['customRenderer1'], ['packageRenderer1'], new ArrayCache(), 'uniqueName'); |
||
| 40 | |||
| 41 | ob_start(); |
||
| 42 | $chainRenderer->render(new Foo()); |
||
| 43 | $html = ob_get_clean(); |
||
| 44 | $this->assertSame('Foo', $html); |
||
| 45 | |||
| 46 | // Same test, for cache testing |
||
| 47 | ob_start(); |
||
| 48 | $chainRenderer->render(new Foo()); |
||
| 49 | $html = ob_get_clean(); |
||
| 50 | $this->assertSame('Foo', $html); |
||
| 51 | |||
| 52 | $chainRenderer->setTemplateRendererInstanceName('templateRenderer'); |
||
| 53 | |||
| 54 | ob_start(); |
||
| 55 | $chainRenderer->render(new Foo()); |
||
| 56 | $html = ob_get_clean(); |
||
| 57 | $this->assertSame('FooTemplate', $html); |
||
| 58 | |||
| 59 | $this->expectException(NoRendererFoundException::class); |
||
| 60 | $this->expectExceptionMessage('Renderer not found. Unable to find renderer for object of class \'stdClass\'. Path tested: Testing renderer for directory \'tests/customTemplates\' |
||
| 61 | Tested file: tests/customTemplates/stdClass__context.twig |
||
| 62 | Tested file: tests/customTemplates/stdClass__context.php |
||
| 63 | Tested file: tests/customTemplates/stdClass.twig |
||
| 64 | Tested file: tests/customTemplates/stdClass.php |
||
| 65 | Testing renderer for directory \'tests/templateTemplates\' |
||
| 66 | Tested file: tests/templateTemplates/stdClass__context.twig |
||
| 67 | Tested file: tests/templateTemplates/stdClass__context.php |
||
| 68 | Tested file: tests/templateTemplates/stdClass.twig |
||
| 69 | Tested file: tests/templateTemplates/stdClass.php |
||
| 70 | Testing renderer for directory \'tests/templates\' |
||
| 71 | Tested file: tests/templates/stdClass__context.twig |
||
| 72 | Tested file: tests/templates/stdClass__context.php |
||
| 73 | Tested file: tests/templates/stdClass.twig |
||
| 74 | Tested file: tests/templates/stdClass.php |
||
| 75 | '); |
||
| 76 | $chainRenderer->render(new \stdClass(), 'context'); |
||
| 77 | |||
| 78 | } |
||
| 79 | } |
||
| 80 |