| Conditions | 10 |
| Paths | 20 |
| Total Lines | 71 |
| Code Lines | 45 |
| 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 |
||
| 76 | public function editAction() |
||
| 77 | { |
||
| 78 | /* @var $user \Auth\Entity\User */ |
||
| 79 | $user = $this->userRepository->find($this->params('id'), \Doctrine\ODM\MongoDB\LockMode::NONE, null, ['allowDeactivated' => true]); |
||
| 80 | |||
| 81 | // check if user is not found |
||
| 82 | if (!$user) { |
||
| 83 | return $this->notFoundAction(); |
||
| 84 | } |
||
| 85 | |||
| 86 | $params = $this->params(); |
||
| 87 | $forms = $this->formManager; |
||
| 88 | /* @var $infoContainer \Auth\Form\UserProfileContainer */ |
||
| 89 | $infoContainer = $forms->get('Auth/UserProfileContainer'); |
||
| 90 | $infoContainer->setEntity($user); |
||
| 91 | $statusContainer = $forms->get('Auth/UserStatusContainer'); |
||
| 92 | $statusContainer->setEntity($user); |
||
| 93 | |||
| 94 | // set selected user to image strategy |
||
| 95 | $imageStrategy = $infoContainer->getForm('info.image') |
||
| 96 | ->getHydrator() |
||
| 97 | ->getStrategy('image'); |
||
| 98 | $fileEntity = $imageStrategy->getFileEntity(); |
||
| 99 | $fileEntity->setUser($user); |
||
| 100 | $imageStrategy->setFileEntity($fileEntity); |
||
| 101 | |||
| 102 | if ($this->request->isPost()) { |
||
| 103 | $formName = $params->fromQuery('form'); |
||
| 104 | $container = $formName === 'status' ? $statusContainer : $infoContainer; |
||
| 105 | $form = $container->getForm($formName); |
||
| 106 | |||
| 107 | if ($form) { |
||
| 108 | $postData = $form->getOption('use_post_array') ? $params->fromPost() : []; |
||
| 109 | $filesData = $form->getOption('use_files_array') ? $params->fromFiles() : []; |
||
| 110 | $form->setData(array_merge($postData, $filesData)); |
||
| 111 | |||
| 112 | if (!$form->isValid()) { |
||
| 113 | return new JsonModel( |
||
| 114 | array( |
||
| 115 | 'valid' => false, |
||
| 116 | 'errors' => $form->getMessages(), |
||
| 117 | ) |
||
| 118 | ); |
||
| 119 | } |
||
| 120 | |||
| 121 | $this->userRepository->store($user); |
||
| 122 | |||
| 123 | if ('file-uri' === $params->fromPost('return')) { |
||
| 124 | $content = $form->getHydrator()->getLastUploadedFile()->getUri(); |
||
| 125 | } else { |
||
| 126 | if ($form instanceof SummaryFormInterface) { |
||
| 127 | $form->setRenderMode(SummaryFormInterface::RENDER_SUMMARY); |
||
| 128 | $viewHelper = 'summaryForm'; |
||
| 129 | } else { |
||
| 130 | $viewHelper = 'form'; |
||
| 131 | } |
||
| 132 | $content = $this->viewHelper->get($viewHelper)->__invoke($form); |
||
| 133 | } |
||
| 134 | |||
| 135 | return new JsonModel( |
||
| 136 | array( |
||
| 137 | 'valid' => $form->isValid(), |
||
| 138 | 'content' => $content, |
||
| 139 | ) |
||
| 140 | ); |
||
| 141 | } |
||
| 142 | } |
||
| 143 | |||
| 144 | return [ |
||
| 145 | 'infoContainer' => $infoContainer, |
||
| 146 | 'statusContainer' => $statusContainer |
||
| 147 | ]; |
||
| 194 |