Completed
Push — testscrut1 ( 4c635a...887503 )
by Maxence
02:34
created

MembersController::add()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 22
Code Lines 12

Duplication

Lines 22
Ratio 100 %

Importance

Changes 0
Metric Value
dl 22
loc 22
rs 9.2
c 0
b 0
f 0
cc 2
eloc 12
nc 2
nop 2
1
<?php
2
/**
3
 * Circles - Bring cloud-users closer together.
4
 *
5
 * This file is licensed under the Affero General Public License version 3 or
6
 * later. See the COPYING file.
7
 *
8
 * @author Maxence Lange <[email protected]>
9
 * @copyright 2017
10
 * @license GNU AGPL version 3 or any later version
11
 *
12
 * This program is free software: you can redistribute it and/or modify
13
 * it under the terms of the GNU Affero General Public License as
14
 * published by the Free Software Foundation, either version 3 of the
15
 * License, or (at your option) any later version.
16
 *
17
 * This program is distributed in the hope that it will be useful,
18
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
 * GNU Affero General Public License for more details.
21
 *
22
 * You should have received a copy of the GNU Affero General Public License
23
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
24
 *
25
 */
26
27
namespace OCA\Circles\Controller;
28
29
use OCP\AppFramework\Http\DataResponse;
30
31
class MembersController extends BaseController {
32
33
34
	/**
35
	 * @NoAdminRequired
36
	 * @NoSubAdminRequired
37
	 *
38
	 * @param $id
39
	 * @param string $name
40
	 *
41
	 * @return DataResponse
42
	 */
43 View Code Duplication
	public function add($id, $name) {
1 ignored issue
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
44
45
		try {
46
			$data = $this->membersService->addMember($id, $name);
47
		} catch (\Exception $e) {
48
			return $this->fail(
49
				[
50
					'circle_id' => $id,
51
					'name'      => $name,
52
					'error'     => $e->getMessage()
53
				]
54
			);
55
		}
56
57
		return $this->success(
58
			[
59
				'circle_id' => $id,
60
				'name'      => $name,
61
				'members'   => $data
62
			]
63
		);
64
	}
65
66
67
	/**
68
	 * @NoAdminRequired
69
	 * @NoSubAdminRequired
70
	 *
71
	 * @param $id
72
	 * @param $member
73
	 *
74
	 * @return DataResponse
75
	 * @internal param string $name
76
	 *
77
	 */
78 View Code Duplication
	public function remove($id, $member) {
1 ignored issue
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
79
80
		try {
81
			$data = $this->membersService->removeMember($id, $member);
82
		} catch (\Exception $e) {
83
			return
84
				$this->fail(
85
					[
86
						'circle_id' => $id,
87
						'name'      => $member,
88
						'error'     => $e->getMessage()
89
					]
90
				);
91
		}
92
93
		return $this->success(
94
			[
95
				'circle_id' => $id,
96
				'name'      => $member,
97
				'members'   => $data,
98
			]
99
		);
100
	}
101
102
103
}
104
105