| Conditions | 18 |
| Paths | 728 |
| Total Lines | 89 |
| Code Lines | 57 |
| 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 |
||
| 83 | public function userpendingAction(Request $request, $action = 'accept', $userid = 0, $gid = 0) |
||
| 84 | { |
||
| 85 | if ($gid < 1 || $userid < 1) { |
||
| 86 | throw new \InvalidArgumentException($this->__('Invalid Group ID or User ID.')); |
||
| 87 | } |
||
| 88 | |||
| 89 | $group = ModUtil::apiFunc('ZikulaGroupsModule', 'user', 'get', ['gid' => $gid]); |
||
| 90 | if (!$group) { |
||
| 91 | throw new NotFoundHttpException($this->__('Sorry! No such group found.')); |
||
| 92 | } |
||
| 93 | |||
| 94 | $appInfo = ModUtil::apiFunc('ZikulaGroupsModule', 'admin', 'getapplicationinfo', ['gid' => $gid, 'userid' => $userid]); |
||
| 95 | |||
| 96 | $formValues = [ |
||
| 97 | 'gid' => $gid, |
||
| 98 | 'userid' => $userid, |
||
| 99 | 'action' => $action, |
||
| 100 | 'userName' => UserUtil::getVar('uname', $userid), |
||
| 101 | 'application' => $appInfo['application'] |
||
| 102 | ]; |
||
| 103 | if ($action == 'deny') { |
||
| 104 | $formValues['reason'] = $this->__('Sorry! This is a message to inform you with regret that your application for membership of the aforementioned private group has been rejected.'); |
||
| 105 | } |
||
| 106 | |||
| 107 | $form = $this->createForm(ManageApplicationType::class, $formValues, [ |
||
| 108 | 'translator' => $this->get('translator.default') |
||
| 109 | ]); |
||
| 110 | |||
| 111 | if ($form->handleRequest($request)->isValid()) { |
||
| 112 | if ($form->get('save')->isClicked()) { |
||
| 113 | $formData = $form->getData(); |
||
| 114 | |||
| 115 | $sendtag = isset($formData['sendtag']) ? $formData['sendtag'] : 0; |
||
| 116 | $reason = isset($formData['reason']) ? $formData['reason'] : ''; |
||
| 117 | |||
| 118 | $reasonTitle = ''; |
||
| 119 | if ($action == 'deny') { |
||
| 120 | $reasonTitle = $this->__f('Concerning your %s group membership application', ['%s' => $group['name']]); |
||
| 121 | if (empty($reason)) { |
||
| 122 | // Get Default TEXT |
||
| 123 | $reason = $this->__('Sorry! This is a message to inform you with regret that your application for membership of the aforementioned private group has been rejected.'); |
||
| 124 | } |
||
| 125 | } elseif ($action == 'accept') { |
||
| 126 | $reasonTitle = $this->__f('Done! The user has been added to the %s group.', ['%s' => $group['name']]); |
||
| 127 | if (empty($reason)) { |
||
| 128 | // Get Default TEXT |
||
| 129 | $reason = $this->__('Done! Your application has been accepted. You have been granted all the privileges assigned to the group of which you are now member.'); |
||
| 130 | } |
||
| 131 | } |
||
| 132 | |||
| 133 | try { |
||
| 134 | $result = ModUtil::apiFunc('ZikulaGroupsModule', 'admin', 'pendingaction', [ |
||
| 135 | 'userid' => $userid, |
||
| 136 | 'gid' => $gid, |
||
| 137 | 'sendtag' => $sendtag, |
||
| 138 | 'reason' => $reason, |
||
| 139 | 'reasontitle' => $reasonTitle, |
||
| 140 | 'action' => $action |
||
| 141 | ]); |
||
| 142 | |||
| 143 | if (!$result) { |
||
| 144 | if ($action == 'deny') { |
||
| 145 | $this->addFlash('error', $this->__("Error! Could not execute 'Reject' action.")); |
||
| 146 | } else { |
||
| 147 | $this->addFlash('error', $this->__("Error! Could not execute 'Accept' action.")); |
||
| 148 | } |
||
| 149 | } else { |
||
| 150 | if ($action == 'accept') { |
||
| 151 | $this->addFlash('status', $this->__('Done! The user was added to the group.')); |
||
| 152 | } else { |
||
| 153 | $this->addFlash('status', $this->__("Done! The user's application for group membership has been rejected.")); |
||
| 154 | } |
||
| 155 | } |
||
| 156 | } catch (\RuntimeException $e) { |
||
| 157 | $this->addFlash('error', $e->getMessage()); |
||
| 158 | } |
||
| 159 | } |
||
| 160 | if ($form->get('cancel')->isClicked()) { |
||
| 161 | $this->addFlash('status', $this->__('Operation cancelled.')); |
||
| 162 | } |
||
| 163 | |||
| 164 | return $this->redirectToRoute('zikulagroupsmodule_group_list'); |
||
| 165 | } |
||
| 166 | |||
| 167 | return [ |
||
| 168 | 'form' => $form->createView(), |
||
| 169 | 'action' => $action |
||
| 170 | ]; |
||
| 171 | } |
||
| 172 | |||
| 233 |
If you suppress an error, we recommend checking for the error condition explicitly: