| Conditions | 1 |
| Paths | 1 |
| Total Lines | 61 |
| Code Lines | 40 |
| 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 |
||
| 62 | public function testInvoke() |
||
| 63 | { |
||
| 64 | $templateRenderer = $this->prophesize(TemplateRendererInterface::class); |
||
| 65 | $contentCreator = $this->prophesize(ContentCreator::class); |
||
| 66 | $markdownDocumentParser = $this->prophesize(MarkdownDocumentParser::class); |
||
| 67 | $markdownCmsConfig = [ |
||
| 68 | 'options' => [ |
||
| 69 | 'content_dir' => __DIR__ . '/_files', |
||
| 70 | ], |
||
| 71 | 'content' => [ |
||
| 72 | 'src' => [ |
||
| 73 | 'testId' => 'test.md' |
||
| 74 | ] |
||
| 75 | ] |
||
| 76 | ]; |
||
| 77 | |||
| 78 | $action = new SingleBlogEntryAction( |
||
| 79 | $templateRenderer->reveal(), $contentCreator->reveal(), $markdownDocumentParser->reveal(), |
||
| 80 | $markdownCmsConfig |
||
| 81 | ); |
||
| 82 | |||
| 83 | $request = $this->prophesize(ServerRequestInterface::class); |
||
| 84 | $request |
||
| 85 | ->getAttribute('id') |
||
| 86 | ->willReturn('testId'); |
||
| 87 | |||
| 88 | $markdownDocument = $this->prophesize(MarkdownDocument::class); |
||
| 89 | |||
| 90 | $markdownDocumentParser |
||
| 91 | ->__invoke('testContent') |
||
| 92 | ->willReturn($markdownDocument->reveal()); |
||
| 93 | |||
| 94 | $contentType = $this->prophesize(ContentTypeInterface::class); |
||
| 95 | $contentType->getTemplate() |
||
| 96 | ->willReturn('testTemplate'); |
||
| 97 | |||
| 98 | $contentCreator |
||
| 99 | ->__invoke($markdownDocument->reveal()) |
||
| 100 | ->willReturn($contentType->reveal()); |
||
| 101 | |||
| 102 | |||
| 103 | |||
| 104 | $serverParams = [ |
||
| 105 | 'REQUEST_SCHEME' => 'http', |
||
| 106 | 'SERVER_NAME' => 'testServerName' |
||
| 107 | ]; |
||
| 108 | $request |
||
| 109 | ->getServerParams() |
||
| 110 | ->willReturn($serverParams); |
||
| 111 | |||
| 112 | $templateRenderer |
||
| 113 | ->render('testTemplate', Argument::type('array')) |
||
| 114 | ->willReturn(''); |
||
| 115 | |||
| 116 | $response = $action( |
||
| 117 | $request->reveal(), |
||
| 118 | $this->prophesize(ResponseInterface::class)->reveal() |
||
| 119 | ); |
||
| 120 | |||
| 121 | $this->assertInstanceOf(HtmlResponse::class, $response); |
||
| 122 | } |
||
| 123 | } |
Only declaring a single property per statement allows you to later on add doc comments more easily.
It is also recommended by PSR2, so it is a common style that many people expect.