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

CirclesController::details()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 21
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 21
rs 9.3142
c 0
b 0
f 0
cc 2
eloc 11
nc 2
nop 1
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 OCA\Circles\Exceptions\CircleDoesNotExistException;
30
use OCA\Circles\Exceptions\CircleTypeDisabledException;
31
use \OCA\Circles\Service\MiscService;
32
use \OCA\Circles\Service\ConfigService;
33
use \OCA\Circles\Service\CirclesService;
34
use \OCA\Circles\Model\Member;
35
36
37
use OCP\AppFramework\Http\DataResponse;
38
39
class CirclesController extends BaseController {
40
41
//	/** @var string */
0 ignored issues
show
Unused Code Comprehensibility introduced by
38% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
42
//	private $userId;
43
//	/** @var IL10N */
44
//	private $l10n;
45
//	/** @var ConfigService */
46
//	private $configService;
47
//
48
//	/** @var MiscService */
49
//	private $miscService;
50
//
51
//	public function __construct(
52
//		$appName,
53
//		IRequest $request,
54
//		$userId,
55
//		IL10N $l10n,
56
//		ConfigService $configService,
57
//		CirclesService $circlesService,
58
//		MiscService $miscService
59
//	) {
60
//		parent::__construct($appName, $request);
61
//
62
//		$this->userId = $userId;
63
//		$this->l10n = $l10n;
64
//		$this->configService = $configService;
65
//		$this->circlesService = $circlesService;
66
//		$this->miscService = $miscService;
67
//	}
68
69
70
	/**
71
	 * @NoAdminRequired
72
	 * @NoSubAdminRequired
73
	 *
74
	 * @param $type
75
	 * @param string $name
76
	 *
77
	 * @return DataResponse
78
	 */
79
	public function create($type, $name) {
80
81
		$data = null;
82
		if (substr($name, 0, 1) === '_') {
83
			return $this->fail(
84
				[
85
					'type'  => $type,
86
					'name'  => $name,
87
					'error' => "The name of your circle cannot start with this character"
88
				]
89
90
			);
91
		}
92
93
94
		try {
95
			$data = $this->circlesService->createCircle($type, $name);
96
		} catch (\Exception $e) {
97
			return $this->fail(
98
				[
99
					'type'  => $type,
100
					'name'  => $name,
101
					'error' => $e->getMessage()
102
				]
103
			);
104
105
		}
106
107
		return $this->success(
108
			[
109
				'name'   => $name,
110
				'circle' => $data,
111
				'type'   => $type
112
			]
113
		);
114
	}
115
116
117
	/**
118
	 * @NoAdminRequired
119
	 * @NoSubAdminRequired
120
	 *
121
	 * @param $type
122
	 * @param string $name
123
	 *
124
	 * @return DataResponse
125
	 */
126
	public function list($type, $name = '') {
127
128
		try {
129
			$data = $this->circlesService->listCircles($type, $name, Member::LEVEL_NONE);
130
		} catch (CircleTypeDisabledException $e) {
131
			return
132
				$this->fail(
133
					[
134
						'type'  => $type,
135
						'error' => $e->getMessage()
136
					]
137
				);
138
		}
139
140
		return $this->success(
141
			[
142
				'type' => $type,
143
				'data' => $data
144
			]
145
		);
146
	}
147
148
149
	/**
150
	 * @NoAdminRequired
151
	 * @NoSubAdminRequired
152
	 *
153
	 * @param $id
154
	 *
155
	 * @return DataResponse
156
	 * @internal param string $name
157
	 *
158
	 */
159
	public function details($id) {
160
161
		try {
162
			$data = $this->circlesService->detailsCircle($id);
163
		} catch (CircleDoesNotExistException $e) {
164
			return
165
				$this->fail(
166
					[
167
						'circle_id' => $id,
168
						'error'     => $e->getMessage()
169
					]
170
				);
171
		}
172
173
		return $this->success(
174
			[
175
				'circle_id' => $id,
176
				'details'   => $data
177
			]
178
		);
179
	}
180
181
182
	/**
183
	 * @NoAdminRequired
184
	 * @NoSubAdminRequired
185
	 *
186
	 * @param $id
187
	 *
188
	 * @return DataResponse
189
	 * @internal param string $name
190
	 *
191
	 */
192 View Code Duplication
	public function join($id) {
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...
193
194
		try {
195
			$data = $this->circlesService->joinCircle($id);
196
		} catch (\Exception $e) {
197
			return $this->fail(
198
				[
199
					'circle_id' => $id,
200
					'error'     => $e->getMessage()
201
				]
202
			);
203
		}
204
205
		return $this->success(
206
			[
207
				'circle_id' => $id,
208
				'member'    => $data
209
			]
210
		);
211
	}
212
213
214
	/**
215
	 * @NoAdminRequired
216
	 * @NoSubAdminRequired
217
	 *
218
	 * @param $id
219
	 *
220
	 * @return DataResponse
221
	 * @internal param string $name
222
	 *
223
	 */
224 View Code Duplication
	public function leave($id) {
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...
225
		try {
226
			$data = $this->circlesService->leaveCircle($id);
227
		} catch (\Exception $e) {
228
			return $this->fail(
229
				[
230
					'circle_id' => $id,
231
					'error'     => $e->getMessage()
232
				]
233
			);
234
		}
235
236
		return $this->success(
237
			[
238
				'circle_id' => $id,
239
				'member'    => $data
240
			]
241
		);
242
	}
243
244
245
}
246
247