| Conditions | 7 |
| Paths | 6 |
| Total Lines | 55 |
| Code Lines | 32 |
| 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 |
||
| 65 | public function edit(Trick $trick, Request $request) |
||
| 66 | { |
||
| 67 | |||
| 68 | $form = $this->createForm(TrickTypeForm::class, $trick, [ |
||
| 69 | 'all_tags_json' => $this->tagSerializer->allTagsJson(), |
||
| 70 | 'trick_tags_json' => $trick->getTagsJson(), |
||
| 71 | ]); |
||
| 72 | $form |
||
| 73 | ->add('delete', SubmitType::class, [ |
||
| 74 | 'label' => 'Delete', |
||
| 75 | 'attr' => [ |
||
| 76 | 'class' => 'waves-effect waves-light btn right mr-2', |
||
| 77 | 'onclick' => 'return confirm(\'are you sure?\')', |
||
| 78 | ] |
||
| 79 | ]); |
||
| 80 | |||
| 81 | $form->handleRequest($request); |
||
| 82 | |||
| 83 | $trickImage = new Image(); |
||
| 84 | $imageForm = $this->createForm(ImageTypeForm::class, $trickImage); |
||
| 85 | $imageForm->handleRequest($request); |
||
| 86 | |||
| 87 | if ($imageForm->isSubmitted() && $imageForm->isValid()) { |
||
| 88 | $event = new ImageAddEvent($trickImage, $trick); |
||
| 89 | $this->dispatcher->dispatch(ImageAddEvent::NAME, $event); |
||
| 90 | |||
| 91 | //Forcing the next form shown to be a new image |
||
| 92 | $trickImage = new Image(); |
||
| 93 | $imageForm = $this->createForm(ImageTypeForm::class, $trickImage); |
||
| 94 | } |
||
| 95 | |||
| 96 | |||
| 97 | if ($form->getClickedButton() && $form->getClickedButton()->getName() === 'delete') { |
||
|
|
|||
| 98 | |||
| 99 | $event = new TrickDeletedEvent($trick); |
||
| 100 | $this->dispatcher->dispatch(TrickDeletedEvent::NAME, $event); |
||
| 101 | |||
| 102 | return $this->redirectToRoute('home'); |
||
| 103 | } |
||
| 104 | |||
| 105 | if ($form->isSubmitted() && $form->isValid()) { |
||
| 106 | |||
| 107 | $event = new TrickEditedEvent($trick); |
||
| 108 | $this->dispatcher->dispatch(TrickEditedEvent::NAME, $event); |
||
| 109 | |||
| 110 | return $this->redirectToRoute('trick.show', [ |
||
| 111 | 'id' => $trick->getId(), |
||
| 112 | 'slug' => $trick->getSlug(), |
||
| 113 | ]); |
||
| 114 | } |
||
| 115 | |||
| 116 | return $this->render('trick/admin/edit.html.twig', [ |
||
| 117 | 'trick' => $trick, |
||
| 118 | 'form' => $form->createView(), |
||
| 119 | 'imageForm' => $imageForm->createView(), |
||
| 120 | ]); |
||
| 123 | } |