Completed
Push — master ( 80bdb5...459619 )
by Maxence
03:02
created

CirclesManager::createCircle()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 12
rs 9.8666
c 0
b 0
f 0
cc 1
nc 1
nop 4
1
<?php
2
3
declare(strict_types=1);
4
5
6
/**
7
 * Circles - Bring cloud-users closer together.
8
 *
9
 * This file is licensed under the Affero General Public License version 3 or
10
 * later. See the COPYING file.
11
 *
12
 * @author Maxence Lange <[email protected]>
13
 * @copyright 2021
14
 * @license GNU AGPL version 3 or any later version
15
 *
16
 * This program is free software: you can redistribute it and/or modify
17
 * it under the terms of the GNU Affero General Public License as
18
 * published by the Free Software Foundation, either version 3 of the
19
 * License, or (at your option) any later version.
20
 *
21
 * This program is distributed in the hope that it will be useful,
22
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
24
 * GNU Affero General Public License for more details.
25
 *
26
 * You should have received a copy of the GNU Affero General Public License
27
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
28
 *
29
 */
30
31
32
namespace OCA\Circles;
33
34
35
use daita\MySmallPhpTools\Exceptions\InvalidItemException;
36
use OCA\Circles\Exceptions\CircleNotFoundException;
37
use OCA\Circles\Exceptions\FederatedEventException;
38
use OCA\Circles\Exceptions\FederatedItemException;
39
use OCA\Circles\Exceptions\FederatedUserException;
40
use OCA\Circles\Exceptions\FederatedUserNotFoundException;
41
use OCA\Circles\Exceptions\InitiatorNotConfirmedException;
42
use OCA\Circles\Exceptions\InitiatorNotFoundException;
43
use OCA\Circles\Exceptions\InvalidIdException;
44
use OCA\Circles\Exceptions\MemberNotFoundException;
45
use OCA\Circles\Exceptions\OwnerNotFoundException;
46
use OCA\Circles\Exceptions\RemoteInstanceException;
47
use OCA\Circles\Exceptions\RemoteNotFoundException;
48
use OCA\Circles\Exceptions\RemoteResourceNotFoundException;
49
use OCA\Circles\Exceptions\RequestBuilderException;
50
use OCA\Circles\Exceptions\SingleCircleNotFoundException;
51
use OCA\Circles\Exceptions\UnknownRemoteException;
52
use OCA\Circles\Exceptions\UserTypeNotFoundException;
53
use OCA\Circles\Model\Circle;
54
use OCA\Circles\Model\FederatedUser;
55
use OCA\Circles\Model\Member;
56
use OCA\Circles\Service\CircleService;
57
use OCA\Circles\Service\FederatedUserService;
58
use OCA\Circles\Service\MemberService;
59
use OCP\IUserSession;
60
61
62
/**
63
 * Class CirclesManager
64
 *
65
 * @package OCA\Circles
66
 */
67
class CirclesManager {
68
69
70
	/** @var CirclesQueryHelper */
71
	private $circlesQueryHelper;
72
73
	/** @var FederatedUserService */
74
	private $federatedUserService;
75
76
	/** @var CircleService */
77
	private $circleService;
78
79
	/** @var MemberService */
80
	private $memberService;
81
82
83
	/**
84
	 * CirclesManager constructor.
85
	 *
86
	 * @param IUserSession $userSession
0 ignored issues
show
Bug introduced by
There is no parameter named $userSession. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
87
	 * @param FederatedUserService $federatedUserService
88
	 * @param CircleService $circleService
89
	 * @param MemberService $memberService
90
	 * @param CirclesQueryHelper $circlesQueryHelper
91
	 */
92
	public function __construct(
93
		FederatedUserService $federatedUserService,
94
		CircleService $circleService,
95
		MemberService $memberService,
96
		CirclesQueryHelper $circlesQueryHelper
97
	) {
98
		$this->federatedUserService = $federatedUserService;
99
		$this->circleService = $circleService;
100
		$this->memberService = $memberService;
101
		$this->circlesQueryHelper = $circlesQueryHelper;
102
	}
103
104
105
	/**
106
	 * @param string $federatedId
107
	 * @param int $type
108
	 *
109
	 * @return FederatedUser
110
	 * @throws CircleNotFoundException
111
	 * @throws FederatedItemException
112
	 * @throws FederatedUserException
113
	 * @throws FederatedUserNotFoundException
114
	 * @throws InvalidIdException
115
	 * @throws MemberNotFoundException
116
	 * @throws OwnerNotFoundException
117
	 * @throws RemoteInstanceException
118
	 * @throws RemoteNotFoundException
119
	 * @throws RemoteResourceNotFoundException
120
	 * @throws RequestBuilderException
121
	 * @throws SingleCircleNotFoundException
122
	 * @throws UnknownRemoteException
123
	 * @throws UserTypeNotFoundException
124
	 */
125
	public function getFederatedUser(string $federatedId, int $type = Member::TYPE_SINGLE): FederatedUser {
126
		return $this->federatedUserService->getFederatedUser($federatedId, $type);
127
	}
128
129
130
	/**
131
	 * @throws FederatedUserNotFoundException
132
	 * @throws SingleCircleNotFoundException
133
	 * @throws RequestBuilderException
134
	 * @throws InvalidIdException
135
	 * @throws FederatedUserException
136
	 */
137
	public function startSession(?FederatedUser $federatedUser = null): void {
138
		if (is_null($federatedUser)) {
139
			$this->federatedUserService->initCurrentUser();
140
		} else {
141
			$this->federatedUserService->setCurrentUser($federatedUser);
142
		}
143
	}
144
145
	/**
146
	 *
147
	 */
148
	public function startSuperSession(): void {
149
		$this->federatedUserService->unsetCurrentUser();
150
		$this->federatedUserService->bypassCurrentUserCondition(true);
151
	}
152
153
	/**
154
	 *
155
	 */
156
	public function stopSession(): void {
157
		$this->federatedUserService->unsetCurrentUser();
158
		$this->federatedUserService->bypassCurrentUserCondition(false);
159
	}
160
161
162
	/**
163
	 * @return IFederatedUser
164
	 * @throws FederatedUserException
165
	 * @throws FederatedUserNotFoundException
166
	 * @throws InvalidIdException
167
	 * @throws RequestBuilderException
168
	 * @throws SingleCircleNotFoundException
169
	 */
170
	public function getCurrentFederatedUser(): IFederatedUser {
171
		return $this->federatedUserService->getCurrentUser();
172
	}
173
174
175
	/**
176
	 * @return CirclesQueryHelper
177
	 */
178
	public function getQueryHelper(): CirclesQueryHelper {
179
		return $this->circlesQueryHelper;
180
	}
181
182
183
	/**
184
	 * @param string $name
185
	 * @param FederatedUser|null $owner
186
	 * @param bool $personal
187
	 * @param bool $local
188
	 *
189
	 * @return Circle
190
	 * @throws FederatedEventException
191
	 * @throws InitiatorNotConfirmedException
192
	 * @throws FederatedItemException
193
	 * @throws InitiatorNotFoundException
194
	 * @throws InvalidItemException
195
	 * @throws OwnerNotFoundException
196
	 * @throws RemoteInstanceException
197
	 * @throws RemoteNotFoundException
198
	 * @throws RemoteResourceNotFoundException
199
	 * @throws RequestBuilderException
200
	 * @throws UnknownRemoteException
201
	 */
202
	public function createCircle(
203
		string $name,
204
		?FederatedUser $owner = null,
205
		bool $personal = false,
206
		bool $local = false
207
	): Circle {
208
		$outcome = $this->circleService->create($name, $owner, $personal, $local);
209
		$circle = new Circle();
210
		$circle->import($outcome);
211
212
		return $circle;
213
	}
214
215
216
	/**
217
	 * @param string $singleId
218
	 *
219
	 * @throws CircleNotFoundException
220
	 * @throws FederatedEventException
221
	 * @throws FederatedItemException
222
	 * @throws InitiatorNotConfirmedException
223
	 * @throws InitiatorNotFoundException
224
	 * @throws OwnerNotFoundException
225
	 * @throws RemoteInstanceException
226
	 * @throws RemoteNotFoundException
227
	 * @throws RemoteResourceNotFoundException
228
	 * @throws RequestBuilderException
229
	 * @throws UnknownRemoteException
230
	 */
231
	public function destroyCircle(string $singleId): void {
232
		$this->circleService->destroy($singleId);
233
	}
234
235
236
	/**
237
	 * returns Circles available, based on current session
238
	 *
239
	 * @return Circle[]
240
	 * @throws InitiatorNotFoundException
241
	 * @throws RequestBuilderException
242
	 */
243
	public function getCircles(): array {
244
		return $this->circleService->getCircles();
245
	}
246
247
248
	/**
249
	 * @param string $singleId
250
	 *
251
	 * @return Circle
252
	 * @throws CircleNotFoundException
253
	 * @throws InitiatorNotFoundException
254
	 * @throws RequestBuilderException
255
	 */
256
	public function getCircle(string $singleId): Circle {
257
		return $this->circleService->getCircle($singleId);
258
	}
259
260
261
262
	/**
263
	 * WIP
264
	 *
265
	 * @return Circle[]
266
	 * @throws InitiatorNotFoundException
267
	 * @throws RequestBuilderException
268
	 */
269
//	public function getAllCircles(): array {
270
//		$this->federatedUserService->bypassCurrentUserCondition(true);
271
//		$this->circleService->getCircles();
272
//	}
273
274
275
	/**
276
	 * WIP
277
	 *
278
	 * @param string $circleId
279
	 * @param string $singleId
280
	 *
281
	 * @return Member
282
	 * @throws InitiatorNotFoundException
283
	 * @throws MemberNotFoundException
284
	 * @throws RequestBuilderException
285
	 */
286
//	public function getMember(string $circleId, string $singleId): Member {
287
//		$this->federatedUserService->bypassCurrentUserCondition(true);
288
//		$this->memberService->getMemberById($circleId, $singleId);
289
//	}
290
291
292
	/**
293
	 * WIP
294
	 *
295
	 * @param string $memberId
296
	 *
297
	 * @return Member
298
	 */
299
//	public function getMemberById(string $memberId): Member {
300
301
302
}
303
304