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