Code Duplication    Length = 28-32 lines in 2 locations

lib/Service/GroupsService.php 1 location

@@ 162-193 (lines=32) @@
159
	 * @return array
160
	 * @throws \Exception
161
	 */
162
	public function levelGroup($circleUniqueId, $groupId, $level) {
163
164
		$level = (int)$level;
165
		try {
166
			$circle = $this->circlesRequest->getCircle($circleUniqueId, $this->userId);
167
			if ($circle->getType() === Circle::CIRCLES_PERSONAL) {
168
				throw new CircleTypeNotValidException(
169
					$this->l10n->t('You cannot edit level in a personal circle')
170
				);
171
			}
172
173
			$group = $this->membersRequest->forceGetGroup($circle->getUniqueId(), $groupId);
174
			if ($group->getLevel() !== $level) {
175
				if ($level === Member::LEVEL_OWNER) {
176
					throw new GroupCannotBeOwnerException(
177
						$this->l10n->t('Group cannot be set as owner of a circle')
178
					);
179
				} else {
180
					$this->editGroupLevel($circle, $group, $level);
181
				}
182
183
				$this->eventsService->onGroupLevel($circle, $group);
184
			}
185
186
			return $this->membersRequest->getGroupsFromCircle(
187
				$circle->getUniqueId(), $circle->getHigherViewer()
188
			);
189
		} catch (\Exception $e) {
190
			throw $e;
191
		}
192
193
	}
194
195
196
	/**

lib/Service/MembersService.php 1 location

@@ 283-310 (lines=28) @@
280
	 * @return array
281
	 * @throws \Exception
282
	 */
283
	public function levelMember($circleUniqueId, $name, $level) {
284
285
		$level = (int)$level;
286
		try {
287
			$circle = $this->circlesRequest->getCircle($circleUniqueId, $this->userId);
288
			if ($circle->getType() === Circle::CIRCLES_PERSONAL) {
289
				throw new CircleTypeNotValidException(
290
					$this->l10n->t('You cannot edit level in a personal circle')
291
				);
292
			}
293
294
			$member = $this->membersRequest->forceGetMember($circle->getUniqueId(), $name);
295
			if ($member->getLevel() !== $level) {
296
				if ($level === Member::LEVEL_OWNER) {
297
					$this->switchOwner($circle, $member);
298
				} else {
299
					$this->editMemberLevel($circle, $member, $level);
300
				}
301
302
				$this->eventsService->onMemberLevel($circle, $member);
303
			}
304
305
			return $this->membersRequest->getMembers(
306
				$circle->getUniqueId(), $circle->getHigherViewer()
307
			);
308
		} catch (\Exception $e) {
309
			throw $e;
310
		}
311
312
	}
313