Completed
Push — master ( 12029f...68e9ab )
by Maxence
02:26
created

MembersController::importFromGroup()   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) {
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
	/**
69
	 * @NoAdminRequired
70
	 * @NoSubAdminRequired
71
	 *
72
	 * @param $id
73
	 * @param string $name
74
	 *
75
	 * @return DataResponse
76
	 */
77 View Code Duplication
	public function importFromGroup($id, $name) {
0 ignored issues
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...
78
79
		try {
80
			$data = $this->membersService->importMembersFromGroup($id, $name);
81
		} catch (\Exception $e) {
82
			return $this->fail(
83
				[
84
					'circle_id' => $id,
85
					'name'      => $name,
86
					'error'     => $e->getMessage()
87
				]
88
			);
89
		}
90
91
		return $this->success(
92
			[
93
				'circle_id' => $id,
94
				'name'      => $name,
95
				'members'   => $data
96
			]
97
		);
98
	}
99
100
101
102
	/**
103
	 * @NoAdminRequired
104
	 * @NoSubAdminRequired
105
	 *
106
	 * @param $id
107
	 * @param $member
108
	 * @param $level
109
	 *
110
	 * @return DataResponse
111
	 * @internal param string $name
112
	 */
113
	public function level($id, $member, $level) {
114
115
		try {
116
			$data = $this->membersService->levelMember($id, $member, $level);
117
		} catch (\Exception $e) {
118
			return
119
				$this->fail(
120
					[
121
						'circle_id' => $id,
122
						'name'      => $member,
123
						'level'     => $level,
124
						'error'     => $e->getMessage()
125
					]
126
				);
127
		}
128
129
		return $this->success(
130
			[
131
				'circle_id' => $id,
132
				'name'      => $member,
133
				'level'     => $level,
134
				'members'   => $data,
135
			]
136
		);
137
	}
138
139
140
	/**
141
	 * @NoAdminRequired
142
	 * @NoSubAdminRequired
143
	 *
144
	 * @param $id
145
	 * @param $member
146
	 *
147
	 * @return DataResponse
148
	 * @internal param string $name
149
	 *
150
	 */
151 View Code Duplication
	public function remove($id, $member) {
152
153
		try {
154
			$data = $this->membersService->removeMember($id, $member);
155
		} catch (\Exception $e) {
156
			return
157
				$this->fail(
158
					[
159
						'circle_id' => $id,
160
						'name'      => $member,
161
						'error'     => $e->getMessage()
162
					]
163
				);
164
		}
165
166
		return $this->success(
167
			[
168
				'circle_id' => $id,
169
				'name'      => $member,
170
				'members'   => $data,
171
			]
172
		);
173
	}
174
175
176
}
177
178