| Conditions | 1 |
| Paths | 1 |
| Total Lines | 73 |
| Code Lines | 63 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | 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 |
||
| 16 | public function testRender() |
||
| 17 | { |
||
| 18 | $posX = 1; |
||
| 19 | $posY = 3; |
||
| 20 | $width = 2; |
||
| 21 | $height = 4; |
||
| 22 | $image = m::mock(Image::class); |
||
| 23 | $canvas = m::mock(Image::class) |
||
| 24 | ->shouldReceive('insert') |
||
| 25 | ->with($image, 'top-left', (int) $posX, (int) $posY) |
||
| 26 | ->once() |
||
| 27 | ->getMock(); |
||
| 28 | $imageManager = m::mock(ImageManager::class) |
||
| 29 | ->shouldReceive('canvas') |
||
| 30 | ->with($width, $height, '#fff') |
||
| 31 | ->once() |
||
| 32 | ->andReturn($canvas) |
||
| 33 | ->getMock(); |
||
| 34 | |||
| 35 | $fieldParser = m::mock(FieldParserInterface::class) |
||
| 36 | ->shouldReceive('isDisplayed') |
||
| 37 | ->andReturn(true) |
||
| 38 | ->once() |
||
| 39 | ->shouldReceive('getPositionX') |
||
| 40 | ->andReturn($posX) |
||
| 41 | ->once() |
||
| 42 | ->shouldReceive('getPositionY') |
||
| 43 | ->andReturn($posY) |
||
| 44 | ->once() |
||
| 45 | ->getMock(); |
||
| 46 | |||
| 47 | $xml = new \SimpleXMLElement('<xml/>'); |
||
| 48 | $parserDocument = m::mock(ParserDocument::class) |
||
| 49 | ->shouldReceive('parse') |
||
| 50 | ->with($xml) |
||
| 51 | ->once() |
||
| 52 | ->shouldReceive('getFieldParsers') |
||
| 53 | ->andReturn([$fieldParser]) |
||
| 54 | ->once() |
||
| 55 | ->shouldReceive('getWidth') |
||
| 56 | ->andReturn($width) |
||
| 57 | ->once() |
||
| 58 | ->shouldReceive('getHeight') |
||
| 59 | ->andReturn($height) |
||
| 60 | ->once() |
||
| 61 | ->getMock(); |
||
| 62 | |||
| 63 | $fontResolver = function () {}; // @codingStandardsIgnoreLine |
||
| 64 | $graphicResolver = function () {}; // @codingStandardsIgnoreLine |
||
| 65 | $fieldRenderer = m::mock(FieldRendererInterface::class) |
||
| 66 | ->shouldReceive('render') |
||
| 67 | ->with($imageManager, $fieldParser, $fontResolver, $graphicResolver) |
||
| 68 | ->andReturn($image) |
||
| 69 | ->once() |
||
| 70 | ->getMock(); |
||
| 71 | |||
| 72 | $fieldRendererFactory = m::mock(FieldRendererFactory::class) |
||
| 73 | ->shouldReceive('getFieldRenderer') |
||
| 74 | ->with($fieldParser) |
||
| 75 | ->andReturn($fieldRenderer) |
||
| 76 | ->once() |
||
| 77 | ->getMock(); |
||
| 78 | |||
| 79 | $rendererDocument = new RendererDocument( |
||
| 80 | $parserDocument, |
||
| 81 | $fieldRendererFactory, |
||
| 82 | $imageManager |
||
| 83 | ); |
||
| 84 | |||
| 85 | $imageActual = $rendererDocument->render($xml, $fontResolver, $graphicResolver); |
||
| 86 | |||
| 87 | $this->assertSame($canvas, $imageActual); |
||
| 88 | } |
||
| 89 | } |
||
| 90 |