Conditions | 8 |
Paths | 8 |
Total Lines | 61 |
Code Lines | 38 |
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 |
||
39 | public function editAction(int $id): Response |
||
40 | { |
||
41 | $resource = $this->getManager()->getRepository()->find($id); |
||
42 | if (!$resource instanceof Order) { |
||
43 | return $this->redirectToAction('index'); |
||
44 | } |
||
45 | |||
46 | $this->getOrderProvider()->setCurrentOrder($resource); |
||
47 | |||
48 | $form = $this->formBuilder->createForm($resource, [ |
||
49 | 'class' => 'editOrder', |
||
50 | ]); |
||
51 | |||
52 | if ($form->handleRequest()->isSubmitted()) { |
||
53 | if ($form->isValid()) { |
||
54 | $this->getManager()->updateResource($resource); |
||
55 | } |
||
56 | |||
57 | return $this->createFormDefaultJsonResponse($form); |
||
58 | } |
||
59 | |||
60 | $orderStatusHistory = $this->createOrderStatusHistoryResource($resource); |
||
61 | $orderStatusHistoryForm = $this->createOrderStatusHistoryForm($orderStatusHistory); |
||
62 | $orderNote = $this->createOrderNoteResource($resource); |
||
63 | $orderNoteForm = $this->createOrderNoteForm($orderNote); |
||
64 | |||
65 | if ($orderStatusHistoryForm->handleRequest()->isSubmitted()) { |
||
66 | if ($orderStatusHistoryForm->isValid()) { |
||
67 | $this->get('order_status_history.manager')->createResource($orderStatusHistory); |
||
68 | } |
||
69 | |||
70 | return $this->jsonResponse([ |
||
71 | 'valid' => $orderStatusHistoryForm->isValid(), |
||
72 | 'next' => false, |
||
73 | 'continue' => false, |
||
74 | 'redirectTo' => $this->getRedirectToActionUrl('edit', ['id' => $resource->getId()]), |
||
75 | 'error' => $orderStatusHistoryForm->getError(), |
||
76 | ]); |
||
77 | } |
||
78 | |||
79 | if ($orderNoteForm->handleRequest()->isSubmitted()) { |
||
80 | if ($orderNoteForm->isValid()) { |
||
81 | $this->get('order_note.manager')->createResource($orderNote); |
||
82 | } |
||
83 | |||
84 | return $this->jsonResponse([ |
||
85 | 'valid' => $orderNoteForm->isValid(), |
||
86 | 'next' => false, |
||
87 | 'continue' => false, |
||
88 | 'redirectTo' => $this->getRedirectToActionUrl('edit', ['id' => $resource->getId()]), |
||
89 | 'error' => $orderNoteForm->getError(), |
||
90 | ]); |
||
91 | } |
||
92 | |||
93 | return $this->displayTemplate('edit', [ |
||
94 | 'form' => $form, |
||
95 | 'orderStatusHistoryForm' => $orderStatusHistoryForm, |
||
96 | 'orderNoteForm' => $orderNoteForm, |
||
97 | 'resource' => $resource, |
||
98 | ]); |
||
99 | } |
||
100 | |||
194 |