| Conditions | 1 |
| Paths | 1 |
| Total Lines | 55 |
| 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 |
||
| 18 | public function testInvoke() |
||
| 19 | { |
||
| 20 | $entity = new TestSimpleEntity(); |
||
| 21 | $request = new Request([], [], []); |
||
| 22 | |||
| 23 | $actionConfiguration = $this->getMockWithoutConstructor(ActionConfiguration::class); |
||
| 24 | $actionConfiguration |
||
| 25 | ->method('getParameter') |
||
| 26 | ->willReturnMap([ |
||
| 27 | ['form', FormType::class], |
||
| 28 | ['form_options', []], |
||
| 29 | ]) |
||
| 30 | ; |
||
| 31 | |||
| 32 | $admin = $this->getMockWithoutConstructor(AdminInterface::class); |
||
| 33 | $admin |
||
| 34 | ->expects($this->once()) |
||
| 35 | ->method('getUniqueEntity') |
||
| 36 | ->willReturn($entity) |
||
| 37 | ; |
||
| 38 | |||
| 39 | $form = $this->getMockWithoutConstructor(FormInterface::class); |
||
| 40 | $form |
||
| 41 | ->method('isSubmitted') |
||
| 42 | ->willReturn(true) |
||
| 43 | ; |
||
| 44 | $form |
||
| 45 | ->method('isValid') |
||
| 46 | ->willReturn(true) |
||
| 47 | ; |
||
| 48 | |||
| 49 | $formFactory = $this->getMockWithoutConstructor(FormFactoryInterface::class); |
||
| 50 | $formFactory |
||
| 51 | ->expects($this->once()) |
||
| 52 | ->method('create') |
||
| 53 | ->with(FormType::class, $entity, []) |
||
| 54 | ->willReturn($form) |
||
| 55 | ; |
||
| 56 | |||
| 57 | $responder = $this->getMockWithoutConstructor(EditResponder::class); |
||
| 58 | $responder |
||
| 59 | ->method('respond') |
||
| 60 | ->with($actionConfiguration, $admin, $form, null) |
||
| 61 | ; |
||
| 62 | |||
| 63 | $action = new EditAction( |
||
| 64 | 'edit', |
||
| 65 | $formFactory, |
||
| 66 | $responder |
||
| 67 | ); |
||
| 68 | $action->setConfiguration($actionConfiguration); |
||
| 69 | $action->setAdmin($admin); |
||
| 70 | |||
| 71 | $action->__invoke($request); |
||
| 72 | } |
||
| 73 | } |
||
| 74 |