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

@@ 281-297 (lines=17) @@
278
	 * @return null|Member
279
	 * @throws \Exception
280
	 */
281
	public function joinCircle($circleUniqueId) {
282
283
		try {
284
			$circle = $this->circlesRequest->getCircle($circleUniqueId, $this->userId);
285
286
			$member = $this->membersRequest->getFreshNewMember($circleUniqueId, $this->userId, Member::TYPE_USER);
287
			$member->hasToBeAbleToJoinTheCircle();
288
			$member->joinCircle($circle->getType());
289
			$this->membersRequest->updateMember($member);
290
291
			$this->eventsService->onMemberNew($circle, $member);
292
		} catch (\Exception $e) {
293
			throw $e;
294
		}
295
296
		return $member;
297
	}
298
299
300
	/**
@@ 308-328 (lines=21) @@
305
	 * @return null|Member
306
	 * @throws \Exception
307
	 */
308
	public function leaveCircle($circleUniqueId) {
309
310
		try {
311
			$circle = $this->circlesRequest->getCircle($circleUniqueId, $this->userId);
312
			$member = $circle->getViewer();
313
314
			$member->hasToBeMemberOrAlmost();
315
			$member->cantBeOwner();
316
317
			$this->eventsService->onMemberLeaving($circle, $member);
318
319
			$member->setStatus(Member::STATUS_NONMEMBER);
320
			$member->setLevel(Member::LEVEL_NONE);
321
			$this->membersRequest->updateMember($member);
322
		} catch (\Exception $e) {
323
			throw $e;
324
		}
325
326
		return $member;
327
	}
328
329
330
	/**
331
	 * destroy a circle.