| Conditions | 6 |
| Paths | 19 |
| Total Lines | 64 |
| 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 |
||
| 37 | public function processUpdateAction() |
||
| 38 | { |
||
| 39 | // Check current user authorization |
||
| 40 | if (null !== $response = $this->checkAuth(AdminResources::MODULE, Dealer::getModuleCode(), |
||
| 41 | AccessManager::VIEW) |
||
| 42 | ) { |
||
| 43 | return $response; |
||
| 44 | } |
||
| 45 | |||
| 46 | // Error (Default: false) |
||
| 47 | $error_msg = false; |
||
|
|
|||
| 48 | |||
| 49 | // Create the Form from the request |
||
| 50 | $changeForm = $this->getForm($this->getRequest()); |
||
| 51 | |||
| 52 | try { |
||
| 53 | // Check the form against constraints violations |
||
| 54 | $form = $this->validateForm($changeForm, "POST"); |
||
| 55 | |||
| 56 | // Get the form field values |
||
| 57 | $data = $form->getData(); |
||
| 58 | |||
| 59 | $updatedObject = $this->getService()->updateFromArray($data); |
||
| 60 | |||
| 61 | // Check if object exist |
||
| 62 | if (!$updatedObject) { |
||
| 63 | throw new \LogicException( |
||
| 64 | $this->getTranslator()->trans("No %obj was updated.", ['%obj' => 'Dealer']) |
||
| 65 | ); |
||
| 66 | } |
||
| 67 | // If we have to stay on the same page, do not redirect to the successUrl, |
||
| 68 | // just redirect to the edit page again. |
||
| 69 | if ($this->getRequest()->get('save_mode') == 'stay') { |
||
| 70 | $id = $this->getRequest()->query->get("dealer_id"); |
||
| 71 | |||
| 72 | return new RedirectResponse(URL::getInstance()->absoluteUrl("/admin/module/Dealer/dealer/edit", |
||
| 73 | ["dealer_id" => $id, ])); |
||
| 74 | } |
||
| 75 | |||
| 76 | // Redirect to the success URL |
||
| 77 | return $this->generateSuccessRedirect($changeForm); |
||
| 78 | } catch (FormValidationException $ex) { |
||
| 79 | // Form cannot be validated |
||
| 80 | $error_msg = $this->createStandardFormValidationErrorMessage($ex); |
||
| 81 | /*} catch (\Exception $ex) { |
||
| 82 | // Any other error |
||
| 83 | $error_msg = $ex->getMessage();*/ |
||
| 84 | } |
||
| 85 | |||
| 86 | if (false !== $error_msg) { |
||
| 87 | // At this point, the form has errors, and should be redisplayed. |
||
| 88 | $this->setupFormErrorContext( |
||
| 89 | $this->getTranslator()->trans("%obj modification", ['%obj' => 'Dealer']), |
||
| 90 | $error_msg, |
||
| 91 | $changeForm, |
||
| 92 | $ex |
||
| 93 | ); |
||
| 94 | |||
| 95 | $id = $this->getRequest()->query->get("dealer_id"); |
||
| 96 | |||
| 97 | return new RedirectResponse(URL::getInstance()->absoluteUrl("/admin/module/Dealer/dealer/edit", |
||
| 98 | ["dealer_id" => $id, ])); |
||
| 99 | } |
||
| 100 | } |
||
| 101 | |||
| 120 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.