| Conditions | 1 |
| Paths | 1 |
| Total Lines | 98 |
| Code Lines | 85 |
| 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 | $file = 'i am file'; |
||
| 18 | $size = 4.2; |
||
| 19 | $width = 2; |
||
| 20 | $height = 4; |
||
| 21 | $font = m::mock(Font::class) |
||
| 22 | ->shouldReceive('text') |
||
|
|
|||
| 23 | ->with($text) |
||
| 24 | ->once() |
||
| 25 | ->shouldReceive('file') |
||
| 26 | ->with($file) |
||
| 27 | ->once() |
||
| 28 | ->shouldReceive('size') |
||
| 29 | ->with($size) |
||
| 30 | ->once() |
||
| 31 | ->shouldReceive('color') |
||
| 32 | ->with('#000') |
||
| 33 | ->once() |
||
| 34 | ->shouldReceive('valign') |
||
| 35 | ->with('top') |
||
| 36 | ->once() |
||
| 37 | ->shouldReceive('getBoxSize') |
||
| 38 | ->andReturn(['width' => $width, 'height' => $height]) |
||
| 39 | ->once() |
||
| 40 | ->getMock(); |
||
| 41 | $textExpectation = function ($actualClosure) use ($font) { |
||
| 42 | $fontActual = null; |
||
| 43 | $actualClosure($fontActual); |
||
| 44 | return $fontActual == $font; |
||
| 45 | }; |
||
| 46 | |||
| 47 | $canvasLine = m::mock(Image::class) |
||
| 48 | ->shouldReceive('text') |
||
| 49 | ->with('', null, null, m::on($textExpectation)) |
||
| 50 | ->shouldReceive('resize') |
||
| 51 | ->with(round($width * FieldRendererFixedText::LETTER_SPACING_ADJUSTMENT), $height) |
||
| 52 | ->once() |
||
| 53 | ->shouldReceive('getWidth') |
||
| 54 | ->andReturn($width) |
||
| 55 | ->once() |
||
| 56 | ->shouldReceive('getHeight') |
||
| 57 | ->andReturn($height) |
||
| 58 | ->once() |
||
| 59 | ->getMock(); |
||
| 60 | |||
| 61 | $orientation = 90; |
||
| 62 | |||
| 63 | $canvas = m::mock(Image::class) |
||
| 64 | ->shouldReceive('insert') |
||
| 65 | ->with($canvasLine, 'top-left', 0, 0) |
||
| 66 | ->once() |
||
| 67 | ->shouldReceive('rotate') |
||
| 68 | ->with(360 - $orientation) |
||
| 69 | ->once() |
||
| 70 | ->getMock(); |
||
| 71 | |||
| 72 | $imageManager = m::mock(ImageManager::class) |
||
| 73 | ->shouldReceive('canvas') |
||
| 74 | ->with($width, $height) |
||
| 75 | ->andReturn($canvasLine) |
||
| 76 | ->once() |
||
| 77 | ->shouldReceive('canvas') |
||
| 78 | ->with($width, $height) |
||
| 79 | ->andReturn($canvas) |
||
| 80 | ->once() |
||
| 81 | ->getMock(); |
||
| 82 | |||
| 83 | $faceExpected = 'i am face'; |
||
| 84 | $parser = m::mock(FieldParserInterface::class) |
||
| 85 | ->shouldReceive('getText') |
||
| 86 | ->andReturn($text) |
||
| 87 | ->once() |
||
| 88 | ->shouldReceive('getFontFace') |
||
| 89 | ->andReturn($faceExpected) |
||
| 90 | ->once() |
||
| 91 | ->shouldReceive('getFontSize') |
||
| 92 | ->andReturn($size) |
||
| 93 | ->once() |
||
| 94 | ->shouldReceive('getOrientation') |
||
| 95 | ->andReturn($orientation) |
||
| 96 | ->once() |
||
| 97 | ->getMock(); |
||
| 98 | |||
| 99 | $fontResolver = function ($face) use ($faceExpected, $file) { |
||
| 100 | $this->assertEquals($faceExpected, $face); |
||
| 101 | return $file; |
||
| 102 | }; |
||
| 103 | |||
| 104 | $renderer = new FieldRendererFixedText($font); |
||
| 105 | $image = $renderer->render( |
||
| 106 | $imageManager, |
||
| 107 | $parser, |
||
| 108 | $fontResolver |
||
| 109 | ); |
||
| 110 | |||
| 111 | $this->assertEquals($canvas, $image); |
||
| 112 | } |
||
| 114 |
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.