| Conditions | 2 |
| 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 |
||
| 12 | public function testRender() |
||
| 13 | { |
||
| 14 | $fontResolver = function () { |
||
| 15 | }; |
||
| 16 | $text = 'this is some text'; |
||
| 17 | $fontSize = 42; |
||
| 18 | $orientation = 90; |
||
| 19 | $tracerColour = '#ccc'; |
||
| 20 | |||
| 21 | $textExpectation = function ($actualClosure) use ($text, $fontSize) { |
||
| 22 | $actualFont = null; |
||
| 23 | $actualClosure($actualFont); |
||
| 24 | return $actualFont->getText() == $text && $actualFont->getSize() == $fontSize; |
||
|
|
|||
| 25 | }; |
||
| 26 | |||
| 27 | $canvasWidth = 12345; |
||
| 28 | $canvasHeight = 54321; |
||
| 29 | |||
| 30 | $imageText = m::mock(Image::class) |
||
| 31 | ->shouldReceive('text') |
||
| 32 | ->with('', null, null, m::on($textExpectation)) |
||
| 33 | ->shouldReceive('resize') |
||
| 34 | ->shouldReceive('getWidth') |
||
| 35 | ->andReturn($canvasWidth) |
||
| 36 | ->once() |
||
| 37 | ->shouldReceive('getHeight') |
||
| 38 | ->andReturn($canvasHeight) |
||
| 39 | ->once() |
||
| 40 | ->getMock(); |
||
| 41 | |||
| 42 | $imageCanvas = m::mock(Image::class) |
||
| 43 | ->shouldReceive('insert') |
||
| 44 | ->with($imageText, 'top-left', 0, 0) |
||
| 45 | ->once() |
||
| 46 | ->shouldReceive('rotate') |
||
| 47 | ->with(360 - $orientation) |
||
| 48 | ->once() |
||
| 49 | ->getMock(); |
||
| 50 | |||
| 51 | $imageManager = m::mock(ImageManager::class) |
||
| 52 | ->shouldReceive('canvas') |
||
| 53 | ->with(m::type('int'), m::type('int'), $tracerColour) |
||
| 54 | ->andReturn($imageText) |
||
| 55 | ->once() |
||
| 56 | ->shouldReceive('canvas') |
||
| 57 | ->with($canvasWidth, $canvasHeight, $tracerColour) |
||
| 58 | ->andReturn($imageCanvas) |
||
| 59 | ->once() |
||
| 60 | ->getMock(); |
||
| 61 | |||
| 62 | $renderer = m::mock(FixedTextRenderer::class) |
||
| 63 | ->shouldAllowMockingProtectedMethods() |
||
| 64 | ->shouldReceive('getImageManager') |
||
| 65 | ->andReturn($imageManager) |
||
| 66 | ->shouldReceive('getFontResolver') |
||
| 67 | ->andReturn($fontResolver) |
||
| 68 | ->shouldReceive('getFontFace') |
||
| 69 | ->shouldReceive('getFontSize') |
||
| 70 | ->andReturn($fontSize) |
||
| 71 | ->shouldReceive('getText') |
||
| 72 | ->andReturn($text) |
||
| 73 | ->shouldReceive('getOrientation') |
||
| 74 | ->andReturn($orientation) |
||
| 75 | ->shouldReceive('getTracerColour') |
||
| 76 | ->andReturn($tracerColour) |
||
| 77 | ->getMock() |
||
| 78 | ->makePartial(); |
||
| 79 | |||
| 80 | $this->assertSame($imageCanvas, $renderer->render()); |
||
| 81 | } |
||
| 83 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.