| Conditions | 1 |
| Paths | 1 |
| Total Lines | 52 |
| Code Lines | 36 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 4 | ||
| Bugs | 0 | 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 testRender(): void |
||
| 16 | { |
||
| 17 | $user = new User(); |
||
| 18 | $email = '[email protected]'; |
||
| 19 | $subject = 'my subject'; |
||
| 20 | $type = 'my_type'; |
||
| 21 | $layoutParams = ['fooLayout' => 'barLayout']; |
||
| 22 | $mailParams = ['fooMail' => 'barMail']; |
||
| 23 | |||
| 24 | $viewRenderer = $this->createMock(RendererInterface::class); |
||
| 25 | $matcher = self::exactly(2); |
||
| 26 | $viewRenderer->expects($matcher) |
||
| 27 | ->method('render') |
||
| 28 | ->willReturnCallback(function (ViewModel $viewModel) use ($matcher, $user) { |
||
| 29 | $callback = match ($matcher->getInvocationCount()) { |
||
| 30 | 1 => (function () use ($viewModel, $user) { |
||
| 31 | $variables = [ |
||
| 32 | 'fooMail' => 'barMail', |
||
| 33 | 'email' => '[email protected]', |
||
| 34 | 'user' => $user, |
||
| 35 | 'serverUrl' => 'https://example.com', |
||
| 36 | ]; |
||
| 37 | |||
| 38 | self::assertSame('my-type', $viewModel->getTemplate()); |
||
| 39 | self::assertSame($variables, $viewModel->getVariables()); |
||
| 40 | |||
| 41 | return 'mocked-rendered-view'; |
||
| 42 | }), |
||
| 43 | 2 => (function () use ($viewModel, $user) { |
||
| 44 | $variables = [ |
||
| 45 | 'fooLayout' => 'barLayout', |
||
| 46 | 'content' => 'mocked-rendered-view', |
||
| 47 | 'subject' => 'my subject', |
||
| 48 | 'user' => $user, |
||
| 49 | 'serverUrl' => 'https://example.com', |
||
| 50 | 'hostname' => 'example.com', |
||
| 51 | ]; |
||
| 52 | |||
| 53 | self::assertSame('layout', $viewModel->getTemplate()); |
||
| 54 | self::assertSame($variables, $viewModel->getVariables()); |
||
| 55 | |||
| 56 | return 'mocked-rendered-layout'; |
||
| 57 | }), |
||
| 58 | default => fn () => $this->fail(), |
||
| 59 | }; |
||
| 60 | |||
| 61 | return $callback(); |
||
| 62 | }); |
||
| 63 | |||
| 64 | $messageRenderer = new MessageRenderer($viewRenderer, 'example.com'); |
||
| 65 | |||
| 66 | $messageRenderer->render($user, $email, $subject, $type, $mailParams, $layoutParams); |
||
| 67 | } |
||
| 69 |