| Conditions | 1 |
| Paths | 1 |
| Total Lines | 69 |
| Code Lines | 58 |
| 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 |
||
| 14 | public function testRender() |
||
| 15 | { |
||
| 16 | $text = 'i am text'; |
||
| 17 | $size = 12; |
||
| 18 | $width = 104; |
||
| 19 | $height = 102; |
||
| 20 | $path = '/path/to/font'; |
||
| 21 | $font = m::mock(Font::class) |
||
| 22 | ->shouldReceive('file') |
||
| 23 | ->with($path) |
||
| 24 | ->once() |
||
| 25 | ->shouldReceive('size') |
||
| 26 | ->with($size * FieldRendererBarcode::FONT_SIZE_MULTIPLIER) |
||
| 27 | ->once() |
||
| 28 | ->shouldReceive('color') |
||
| 29 | ->with('#fff') |
||
| 30 | ->once() |
||
| 31 | ->shouldReceive('align') |
||
| 32 | ->with('center') |
||
| 33 | ->once() |
||
| 34 | ->shouldReceive('valign') |
||
| 35 | ->with('middle') |
||
| 36 | ->once() |
||
| 37 | ->getMock(); |
||
| 38 | $textExpectation = function ($actualClosure) use ($font) { |
||
| 39 | $actualClosure($font); |
||
| 40 | return true; |
||
| 41 | }; |
||
| 42 | |||
| 43 | $parser = m::mock(FieldParserInterface::class) |
||
| 44 | ->shouldReceive('getWidth') |
||
| 45 | ->andReturn($width) |
||
| 46 | ->twice() |
||
| 47 | ->shouldReceive('getHeight') |
||
| 48 | ->andReturn($height) |
||
| 49 | ->twice() |
||
| 50 | ->shouldReceive('getFontSize') |
||
| 51 | ->andReturn($size) |
||
| 52 | ->once() |
||
| 53 | ->shouldReceive('getText') |
||
| 54 | ->andReturn($text) |
||
| 55 | ->once() |
||
| 56 | ->getMock(); |
||
| 57 | |||
| 58 | $image = m::mock(Image::class) |
||
| 59 | ->shouldReceive('text') |
||
| 60 | ->with($text, $width / 2, $height, m::on($textExpectation)) |
||
| 61 | ->shouldReceive('resize') |
||
| 62 | ->getMock(); |
||
| 63 | |||
| 64 | $imageManager = m::mock(ImageManager::class) |
||
| 65 | ->shouldReceive('canvas') |
||
| 66 | ->with($width, $height, '#000') |
||
| 67 | ->andReturn($image) |
||
| 68 | ->getMock(); |
||
| 69 | |||
| 70 | $fontResolver = function () use ($path) { |
||
| 71 | return $path; |
||
| 72 | }; |
||
| 73 | |||
| 74 | $renderer = new FieldRendererBarcode(); |
||
| 75 | $imageActual = $renderer->render( |
||
| 76 | $imageManager, |
||
| 77 | $parser, |
||
| 78 | $fontResolver |
||
| 79 | ); |
||
| 80 | |||
| 81 | $this->assertSame($image, $imageActual); |
||
| 82 | } |
||
| 83 | } |
||
| 84 |