| Conditions | 12 |
| Paths | 16 |
| Total Lines | 54 |
| Code Lines | 37 |
| 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 |
||
| 96 | public function createAction(Request $request, GroupEntity $group) |
||
| 97 | { |
||
| 98 | if (!$this->hasPermission('ZikulaGroupsModule::', '::', ACCESS_OVERVIEW)) { |
||
| 99 | throw new AccessDeniedException(); |
||
| 100 | } |
||
| 101 | $currentUserApi = $this->get('zikula_users_module.current_user'); |
||
| 102 | if (!$currentUserApi->isLoggedIn()) { |
||
| 103 | throw new AccessDeniedException($this->__('Error! You must register for a user account on this site before you can apply for membership of a group.')); |
||
| 104 | } |
||
| 105 | $userEntity = $this->get('zikula_users_module.user_repository')->find($currentUserApi->get('uid')); |
||
| 106 | $groupTypeIsCore = $group->getGtype() == CommonHelper::GTYPE_CORE; |
||
| 107 | $groupStateIsClosed = $group->getState() == CommonHelper::STATE_CLOSED; |
||
| 108 | $groupCountIsLimit = $group->getNbumax() > 0 && $group->getUsers()->count() > $group->getNbumax(); |
||
| 109 | $alreadyGroupMember = $group->getUsers()->contains($userEntity); |
||
| 110 | if ($groupTypeIsCore || $groupStateIsClosed || $groupCountIsLimit || $alreadyGroupMember) { |
||
| 111 | $this->addFlash('error', $this->getSpecificGroupMessage($groupTypeIsCore, $groupStateIsClosed, $groupCountIsLimit, $alreadyGroupMember)); |
||
| 112 | |||
| 113 | return $this->redirectToRoute('zikulagroupsmodule_group_list'); |
||
| 114 | } |
||
| 115 | $existingApplication = $this->get('zikula_groups_module.group_application_repository')->findOneBy(['group' => $group, 'user' => $userEntity]); |
||
| 116 | if ($existingApplication) { |
||
| 117 | $this->addFlash('info', $this->__('You already have a pending application. Please wait until the administrator notifies you.')); |
||
| 118 | |||
| 119 | return $this->redirectToRoute('zikulagroupsmodule_group_list'); |
||
| 120 | } |
||
| 121 | |||
| 122 | $groupApplicationEntity = new GroupApplicationEntity(); |
||
| 123 | $groupApplicationEntity->setGroup($group); |
||
| 124 | $groupApplicationEntity->setUser($userEntity); |
||
| 125 | $form = $this->createForm('Zikula\GroupsModule\Form\Type\MembershipApplicationType', $groupApplicationEntity, [ |
||
| 126 | 'translator' => $this->get('translator.default'), |
||
| 127 | ] |
||
| 128 | ); |
||
| 129 | if ($form->handleRequest($request)->isValid()) { |
||
| 130 | if ($form->get('apply')->isClicked()) { |
||
| 131 | $groupApplicationEntity = $form->getData(); |
||
| 132 | $this->get('doctrine')->getManager()->persist($groupApplicationEntity); |
||
| 133 | $this->get('doctrine')->getManager()->flush(); |
||
| 134 | $newApplicationEvent = new GenericEvent($groupApplicationEntity); |
||
| 135 | $this->get('event_dispatcher')->dispatch(GroupEvents::GROUP_NEW_APPLICATION, $newApplicationEvent); |
||
| 136 | $this->addFlash('status', $this->__('Done! The application has been sent. You will be notified by email when the application is processed.')); |
||
| 137 | } |
||
| 138 | if ($form->get('cancel')->isClicked()) { |
||
| 139 | $this->addFlash('status', $this->__('Application cancelled.')); |
||
| 140 | } |
||
| 141 | |||
| 142 | return $this->redirectToRoute('zikulagroupsmodule_group_list'); |
||
| 143 | } |
||
| 144 | |||
| 145 | return [ |
||
| 146 | 'form' => $form->createView(), |
||
| 147 | 'group' => $group, |
||
| 148 | ]; |
||
| 149 | } |
||
| 150 | |||
| 171 |