Code Duplication    Length = 17-21 lines in 3 locations

lib/Service/GroupsService.php 1 location

@@ 97-117 (lines=21) @@
94
	 * @return array
95
	 * @throws \Exception
96
	 */
97
	public function linkGroup($circleUniqueId, $groupId) {
98
99
		try {
100
			$circle = $this->circlesRequest->getCircle($circleUniqueId, $this->userId);
101
			$circle->getHigherViewer()
102
				   ->hasToBeAdmin();
103
104
			$group = $this->getFreshNewMember($circleUniqueId, $groupId);
105
		} catch (\Exception $e) {
106
			throw $e;
107
		}
108
109
		$group->setLevel(Member::LEVEL_MEMBER);
110
		$this->membersRequest->updateGroup($group);
111
112
		$this->eventsService->onGroupLink($circle, $group);
113
114
		return $this->membersRequest->getGroupsFromCircle(
115
			$circleUniqueId, $circle->getHigherViewer()
116
		);
117
	}
118
119
120
	/**

lib/Service/CirclesService.php 2 locations

@@ 291-307 (lines=17) @@
288
	 * @return null|Member
289
	 * @throws \Exception
290
	 */
291
	public function joinCircle($circleUniqueId) {
292
293
		try {
294
			$circle = $this->circlesRequest->getCircle($circleUniqueId, $this->userId);
295
296
			$member = $this->membersRequest->getFreshNewMember(
297
				$circleUniqueId, $this->userId, Member::TYPE_USER
298
			);
299
			$member->hasToBeAbleToJoinTheCircle();
300
			$member->joinCircle($circle->getType());
301
			$this->membersRequest->updateMember($member);
302
303
			$this->eventsService->onMemberNew($circle, $member);
304
		} catch (\Exception $e) {
305
			throw $e;
306
		}
307
308
		return $member;
309
	}
310
@@ 320-340 (lines=21) @@
317
	 * @return null|Member
318
	 * @throws \Exception
319
	 */
320
	public function leaveCircle($circleUniqueId) {
321
322
		try {
323
			$circle = $this->circlesRequest->getCircle($circleUniqueId, $this->userId);
324
			$member = $circle->getViewer();
325
326
			$member->hasToBeMemberOrAlmost();
327
			$member->cantBeOwner();
328
329
			$this->eventsService->onMemberLeaving($circle, $member);
330
331
			$member->setStatus(Member::STATUS_NONMEMBER);
332
			$member->setLevel(Member::LEVEL_NONE);
333
			$this->membersRequest->updateMember($member);
334
		} catch (\Exception $e) {
335
			throw $e;
336
		}
337
338
		return $member;
339
	}
340
341
342
	/**
343
	 * destroy a circle.