| Conditions | 1 |
| Paths | 1 |
| Total Lines | 56 |
| Code Lines | 47 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 3 | ||
| Bugs | 1 | 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 |
||
| 15 | public function testBuild() |
||
| 16 | { |
||
| 17 | $parserManager = m::mock(ParserManager::class); |
||
| 18 | $imageManager = m::mock(ImageManager::class); |
||
| 19 | $xmlField = new SimpleXMLElement('<a/>'); |
||
| 20 | $xmlHeader = new SimpleXMLElement('<b name="test"/>'); |
||
| 21 | $scale = 10; |
||
| 22 | $tracerColour = '#ccc'; |
||
| 23 | $fontResolver = function () { |
||
| 24 | }; |
||
| 25 | |||
| 26 | $parser = m::mock(OffsetDateParser::class) |
||
| 27 | ->shouldReceive('setXmlField') |
||
| 28 | ->with($xmlField) |
||
| 29 | ->shouldReceive('setParserManager') |
||
| 30 | ->with($parserManager) |
||
| 31 | ->shouldReceive('setXmlHeader') |
||
| 32 | ->with($xmlHeader) |
||
| 33 | ->getMock(); |
||
| 34 | |||
| 35 | $parserManager |
||
| 36 | ->shouldReceive('addParser') |
||
| 37 | ->with($parser); |
||
| 38 | |||
| 39 | $renderer = m::mock(FixedTextRenderer::class) |
||
| 40 | ->shouldReceive('setParser') |
||
| 41 | ->with($parser) |
||
| 42 | ->shouldReceive('setImageManager') |
||
| 43 | ->with($imageManager) |
||
| 44 | ->shouldReceive('setScale') |
||
| 45 | ->with($scale) |
||
| 46 | ->shouldReceive('setTracerColour') |
||
| 47 | ->with($tracerColour) |
||
| 48 | ->shouldReceive('setFontResolver') |
||
| 49 | ->with($fontResolver) |
||
| 50 | ->getMock(); |
||
| 51 | |||
| 52 | $builder = m::mock(OffsetDateBuilder::class) |
||
| 53 | ->shouldAllowMockingProtectedMethods() |
||
| 54 | ->shouldReceive('instantiateParser') |
||
| 55 | ->andReturn($parser) |
||
| 56 | ->shouldReceive('instantiateRenderer') |
||
| 57 | ->andReturn($renderer) |
||
| 58 | ->getMock() |
||
| 59 | ->makePartial(); |
||
| 60 | |||
| 61 | $builder->setParserManager($parserManager); |
||
| 62 | $builder->setImageManager($imageManager); |
||
| 63 | $builder->setXmlField($xmlField); |
||
| 64 | $builder->setXmlHeader($xmlHeader); |
||
| 65 | $builder->setScale($scale); |
||
| 66 | $builder->setTracerColour($tracerColour); |
||
| 67 | $builder->setFontResolver($fontResolver); |
||
| 68 | |||
| 69 | $this->assertSame($renderer, $builder->build()); |
||
| 70 | } |
||
| 71 | } |
||
| 72 |