| Conditions | 11 | 
| Paths | 40 | 
| Total Lines | 81 | 
| Code Lines | 47 | 
| 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 | ||
| 47 | public function editAction(Request $request): Response | ||
| 48 |     { | ||
| 49 | $object = $this->assertObjectExists($request, true); | ||
| 50 | $this->checkParentChildAssociation($request, $object); | ||
|  | |||
| 51 | |||
| 52 |         $this->admin->checkAccess('edit', $object); | ||
| 53 | |||
| 54 | $preResponse = $this->preEdit($request, $object); | ||
| 55 |         if (null !== $preResponse) { | ||
| 56 | return $preResponse; | ||
| 57 | } | ||
| 58 | |||
| 59 | $this->admin->setSubject($object); | ||
| 60 | $form = $this->admin->getForm(); | ||
| 61 | $form->setData($object); | ||
| 62 | $form->handleRequest($request); | ||
| 63 | |||
| 64 |         if ($form->isSubmitted()) { | ||
| 65 | $isFormValid = $form->isValid(); | ||
| 66 | |||
| 67 | // Gestion spéciale pour la validation des preuves | ||
| 68 |             if ($isFormValid && $this->isProofValidationSubmission($request, $object)) { | ||
| 69 | $this->handleProofValidation($object, $request); | ||
| 70 | } | ||
| 71 | |||
| 72 | // Validation et redirection si tout est OK | ||
| 73 |             if ($isFormValid) { | ||
| 74 | $submittedObject = $form->getData(); | ||
| 75 | $this->admin->setSubject($submittedObject); | ||
| 76 | |||
| 77 |                 try { | ||
| 78 | $submittedObject = $this->admin->update($submittedObject); | ||
| 79 | |||
| 80 |                     if ($this->isXmlHttpRequest($request)) { | ||
| 81 | return $this->handleXmlHttpRequestSuccessResponse($request, $submittedObject); | ||
| 82 | } | ||
| 83 | |||
| 84 | $this->addFlash( | ||
| 85 | 'sonata_flash_success', | ||
| 86 | $this->getProofValidationMessage($submittedObject) | ||
| 87 | ); | ||
| 88 | |||
| 89 | // Redirection après succès vers la prochaine preuve | ||
| 90 | $nextProofRedirect = $this->getNextProofRedirect($submittedObject); | ||
| 91 |                     if ($nextProofRedirect) { | ||
| 92 | return $nextProofRedirect; | ||
| 93 | } | ||
| 94 | |||
| 95 |                     if (null !== ($response = $this->redirectTo($request, $submittedObject))) { | ||
| 96 | return $response; | ||
| 97 | } | ||
| 98 |                 } catch (\Throwable $e) { | ||
| 99 | $this->handleModelManagerThrowable($e); | ||
| 100 | |||
| 101 | $isFormValid = false; | ||
| 102 | } | ||
| 103 | } | ||
| 104 | |||
| 105 | // Message d'erreur si la validation a échoué | ||
| 106 |             if (!$isFormValid) { | ||
| 107 | $this->addFlash( | ||
| 108 | 'sonata_flash_error', | ||
| 109 | $this->trans( | ||
| 110 | 'flash_edit_error', | ||
| 111 | ['%name%' => $this->escapeHtml($this->admin->toString($object))], | ||
| 112 | 'SonataAdminBundle' | ||
| 113 | ) | ||
| 114 | ); | ||
| 115 | } | ||
| 116 | } | ||
| 117 | |||
| 118 | $formView = $form->createView(); | ||
| 119 | $this->setFormTheme($formView, $this->admin->getFormTheme()); | ||
| 120 | |||
| 121 | return $this->render( | ||
| 122 |             $this->admin->getTemplateRegistry()->getTemplate('edit'), | ||
| 123 | [ | ||
| 124 | 'action' => 'edit', | ||
| 125 | 'form' => $formView, | ||
| 126 | 'object' => $object, | ||
| 127 | 'objectId' => $this->admin->getNormalizedIdentifier($object), | ||
| 128 | ] | ||
| 296 |