| Conditions | 10 |
| Paths | 20 |
| Total Lines | 74 |
| Code Lines | 47 |
| Lines | 11 |
| Ratio | 14.86 % |
| Changes | 2 | ||
| Bugs | 1 | Features | 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 |
||
| 70 | public function editAction() |
||
| 71 | { |
||
| 72 | /* @var $user \Auth\Entity\User */ |
||
| 73 | $user = $this->userRepository->find($this->params('id'), \Doctrine\ODM\MongoDB\LockMode::NONE, null, ['allowDeactivated' => true]); |
||
| 74 | |||
| 75 | // check if user is not found |
||
| 76 | if (!$user) { |
||
| 77 | return $this->notFoundAction(); |
||
| 78 | } |
||
| 79 | |||
| 80 | $params = $this->params(); |
||
| 81 | $serviceLocator = $this->getServiceLocator(); |
||
| 82 | $forms = $serviceLocator->get('forms'); |
||
| 83 | /* @var $infoContainer \Auth\Form\UserProfileContainer */ |
||
| 84 | $infoContainer = $forms->get('Auth/userprofilecontainer'); |
||
| 85 | $infoContainer->setEntity($user); |
||
| 86 | $statusContainer = $forms->get('Auth/UserStatusContainer'); |
||
| 87 | $statusContainer->setEntity($user); |
||
| 88 | |||
| 89 | // set selected user to image strategy |
||
| 90 | $imageStrategy = $infoContainer->getForm('info.image') |
||
| 91 | ->getHydrator() |
||
| 92 | ->getStrategy('image'); |
||
| 93 | $fileEntity = $imageStrategy->getFileEntity(); |
||
| 94 | $fileEntity->setUser($user); |
||
| 95 | $imageStrategy->setFileEntity($fileEntity); |
||
| 96 | |||
| 97 | if ($this->request->isPost()) { |
||
| 98 | $formName = $params->fromQuery('form'); |
||
| 99 | $container = $formName === 'status' ? $statusContainer : $infoContainer; |
||
| 100 | $form = $container->getForm($formName); |
||
| 101 | |||
| 102 | if ($form) { |
||
| 103 | $postData = $form->getOption('use_post_array') ? $params->fromPost() : []; |
||
| 104 | $filesData = $form->getOption('use_files_array') ? $params->fromFiles() : []; |
||
| 105 | $form->setData(array_merge($postData, $filesData)); |
||
| 106 | |||
| 107 | if (!$form->isValid()) { |
||
| 108 | return new JsonModel( |
||
| 109 | array( |
||
| 110 | 'valid' => false, |
||
| 111 | 'errors' => $form->getMessages(), |
||
| 112 | ) |
||
| 113 | ); |
||
| 114 | } |
||
| 115 | |||
| 116 | $serviceLocator->get('repositories')->store($user); |
||
| 117 | |||
| 118 | View Code Duplication | if ('file-uri' === $params->fromPost('return')) { |
|
| 119 | $content = $form->getHydrator()->getLastUploadedFile()->getUri(); |
||
| 120 | } else { |
||
| 121 | if ($form instanceof SummaryFormInterface) { |
||
| 122 | $form->setRenderMode(SummaryFormInterface::RENDER_SUMMARY); |
||
| 123 | $viewHelper = 'summaryform'; |
||
| 124 | } else { |
||
| 125 | $viewHelper = 'form'; |
||
| 126 | } |
||
| 127 | $content = $serviceLocator->get('ViewHelperManager')->get($viewHelper)->__invoke($form); |
||
| 128 | } |
||
| 129 | |||
| 130 | return new JsonModel( |
||
| 131 | array( |
||
| 132 | 'valid' => $form->isValid(), |
||
| 133 | 'content' => $content, |
||
| 134 | ) |
||
| 135 | ); |
||
| 136 | } |
||
| 137 | } |
||
| 138 | |||
| 139 | return [ |
||
| 140 | 'infoContainer' => $infoContainer, |
||
| 141 | 'statusContainer' => $statusContainer |
||
| 142 | ]; |
||
| 143 | } |
||
| 144 | } |
||
| 145 |
This check compares the return type specified in the
@returnannotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.