| Conditions | 6 |
| Paths | 4 |
| Total Lines | 52 |
| Code Lines | 29 |
| 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 |
||
| 44 | public function edit(Trick $trick, Request $request) |
||
| 45 | { |
||
| 46 | |||
| 47 | $form = $this->createForm(TrickType::class, $trick); |
||
| 48 | $form |
||
| 49 | ->add('save', SubmitType::class, [ |
||
| 50 | 'label' => 'Save', |
||
| 51 | 'attr' => [ |
||
| 52 | 'class' => 'waves-effect waves-light btn right mr-2' |
||
| 53 | ] |
||
| 54 | ]) |
||
| 55 | ->add('delete', SubmitType::class, [ |
||
| 56 | 'label' => 'Delete', |
||
| 57 | 'attr' => [ |
||
| 58 | 'class' => 'waves-effect waves-light btn right mr-2', |
||
| 59 | 'onclick' => 'return confirm(\'are you sure?\')', |
||
| 60 | ] |
||
| 61 | ]); |
||
| 62 | |||
| 63 | $form->handleRequest($request); |
||
| 64 | |||
| 65 | |||
| 66 | if ($form->getClickedButton() && $form->getClickedButton()->getName() === 'delete') { |
||
|
|
|||
| 67 | |||
| 68 | $event = new TrickDeletedEvent($trick); |
||
| 69 | $this->dispatcher->dispatch(TrickDeletedEvent::NAME, $event); |
||
| 70 | |||
| 71 | return $this->redirectToRoute('home'); |
||
| 72 | } |
||
| 73 | |||
| 74 | if ($form->isSubmitted() && $form->isValid()) { |
||
| 75 | |||
| 76 | $event = new TrickEditedEvent($trick); |
||
| 77 | $this->dispatcher->dispatch(TrickEditedEvent::NAME, $event); |
||
| 78 | |||
| 79 | return $this->redirectToRoute('trick.show', [ |
||
| 80 | 'id' => $trick->getId(), |
||
| 81 | 'slug' => $trick->getSlug(), |
||
| 82 | ]); |
||
| 83 | } |
||
| 84 | |||
| 85 | $history = array(); |
||
| 86 | //Only load the history if we are admin. Ease the load. |
||
| 87 | if($this->isGranted('ROLE_ADMIN')){ |
||
| 88 | $history = $this->trickHistory->getHistory($trick->getId()); |
||
| 89 | } |
||
| 90 | |||
| 91 | |||
| 92 | return $this->render('trick/admin/edit.html.twig', [ |
||
| 93 | 'trick' => $trick, |
||
| 94 | 'form' => $form->createView(), |
||
| 95 | 'history' => $history, |
||
| 96 | ]); |
||
| 99 | } |