Code Duplication    Length = 7-8 lines in 3 locations

src/system/GroupsModule/Controller/MembershipController.php 3 locations

@@ 120-127 (lines=8) @@
117
118
        if ($userEntity->getGroups()->contains($group)) {
119
            $this->addFlash('warning', $this->__('The selected user is already a member of this group.'));
120
        } else {
121
            $userEntity->addGroup($group);
122
            $this->get('doctrine')->getManager()->flush();
123
            $this->addFlash('status', $this->__('Done! The user was added to the group.'));
124
            // Let other modules know that we have updated a group.
125
            $addUserEvent = new GenericEvent(['gid' => $group->getGid(), 'uid' => $userEntity->getUid()]);
126
            $this->get('event_dispatcher')->dispatch(GroupEvents::GROUP_ADD_USER, $addUserEvent);
127
        }
128
129
        return $this->redirectToRoute('zikulagroupsmodule_membership_adminlist', ['gid' => $group->getGid()]);
130
    }
@@ 155-162 (lines=8) @@
152
            || ($group->getNbumax() > 0 && $group->getUsers()->count() > $group->getNbumax())
153
            || ($group->getUsers()->contains($userEntity))) {
154
            $this->addFlash('error', $this->__('Cannot join the requested group')); // @todo more specific info would be better
155
        } else {
156
            $userEntity->addGroup($group);
157
            $this->get('doctrine')->getManager()->flush();
158
            $this->addFlash('success', $this->__f('Joined the "%group" group', ['%group' => $group->getName()]));
159
            // Let other modules know that we have updated a group.
160
            $addUserEvent = new GenericEvent(['gid' => $group->getGid(), 'uid' => $userEntity->getUid()]);
161
            $this->get('event_dispatcher')->dispatch(GroupEvents::GROUP_ADD_USER, $addUserEvent);
162
        }
163
164
        return $this->redirectToRoute('zikulagroupsmodule_group_list');
165
    }
@@ 209-215 (lines=7) @@
206
        ]);
207
208
        if ($form->handleRequest($request)->isValid()) {
209
            if ($form->get('remove')->isClicked()) {
210
                $user->removeGroup($group);
211
                $this->get('doctrine')->getManager()->flush();
212
                $this->addFlash('status', $this->__('Done! The user was removed from the group.'));
213
                $removeUserEvent = new GenericEvent(null, ['gid' => $gid, 'uid' => $uid]);
214
                $this->get('event_dispatcher')->dispatch(GroupEvents::GROUP_REMOVE_USER, $removeUserEvent);
215
            }
216
            if ($form->get('cancel')->isClicked()) {
217
                $this->addFlash('status', $this->__('Operation cancelled.'));
218
            }