Completed
Push — master ( bf38a8...6247cb )
by Maxence
02:42
created

CirclesManager::startOccSession()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 3
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
	 * $userId - userId to emulate as initiator (can be empty)
156
	 * $userType - specify if userIs not a singleId
157
	 * $circleId - if no userId specified, will use the owner of the Circle as initiator
158
	 *
159
	 * @param string $userId
160
	 * @param int $userType
161
	 * @param string $circleId
162
	 *
163
	 * @throws CircleNotFoundException
164
	 * @throws FederatedItemException
165
	 * @throws FederatedUserException
166
	 * @throws FederatedUserNotFoundException
167
	 * @throws InvalidIdException
168
	 * @throws MemberNotFoundException
169
	 * @throws OwnerNotFoundException
170
	 * @throws RemoteInstanceException
171
	 * @throws RemoteNotFoundException
172
	 * @throws RemoteResourceNotFoundException
173
	 * @throws RequestBuilderException
174
	 * @throws SingleCircleNotFoundException
175
	 * @throws UnknownRemoteException
176
	 * @throws UserTypeNotFoundException
177
	 */
178
	public function startOccSession(
179
		string $userId,
180
		int $userType = Member::TYPE_SINGLE,
181
		string $circleId = ''
182
	): void {
183
		$this->federatedUserService->commandLineInitiator($userId, $userType, $circleId);
184
	}
185
186
187
	/**
188
	 *
189
	 */
190
	public function stopSession(): void {
191
		$this->federatedUserService->unsetCurrentUser();
192
		$this->federatedUserService->bypassCurrentUserCondition(false);
193
	}
194
195
196
	/**
197
	 * @return IFederatedUser
198
	 */
199
	public function getCurrentFederatedUser(): IFederatedUser {
200
		return $this->federatedUserService->getCurrentUser();
201
	}
202
203
204
	/**
205
	 * @return CirclesQueryHelper
206
	 */
207
	public function getQueryHelper(): CirclesQueryHelper {
208
		return $this->circlesQueryHelper;
209
	}
210
211
212
	/**
213
	 * @param string $name
214
	 * @param FederatedUser|null $owner
215
	 * @param bool $personal
216
	 * @param bool $local
217
	 *
218
	 * @return Circle
219
	 * @throws FederatedEventException
220
	 * @throws InitiatorNotConfirmedException
221
	 * @throws FederatedItemException
222
	 * @throws InitiatorNotFoundException
223
	 * @throws InvalidItemException
224
	 * @throws OwnerNotFoundException
225
	 * @throws RemoteInstanceException
226
	 * @throws RemoteNotFoundException
227
	 * @throws RemoteResourceNotFoundException
228
	 * @throws RequestBuilderException
229
	 * @throws UnknownRemoteException
230
	 */
231
	public function createCircle(
232
		string $name,
233
		?FederatedUser $owner = null,
234
		bool $personal = false,
235
		bool $local = false
236
	): Circle {
237
		$outcome = $this->circleService->create($name, $owner, $personal, $local);
238
		$circle = new Circle();
239
		$circle->import($outcome);
240
241
		return $circle;
242
	}
243
244
245
	/**
246
	 * @param string $singleId
247
	 *
248
	 * @throws CircleNotFoundException
249
	 * @throws FederatedEventException
250
	 * @throws FederatedItemException
251
	 * @throws InitiatorNotConfirmedException
252
	 * @throws InitiatorNotFoundException
253
	 * @throws OwnerNotFoundException
254
	 * @throws RemoteInstanceException
255
	 * @throws RemoteNotFoundException
256
	 * @throws RemoteResourceNotFoundException
257
	 * @throws RequestBuilderException
258
	 * @throws UnknownRemoteException
259
	 */
260
	public function destroyCircle(string $singleId): void {
261
		$this->circleService->destroy($singleId);
262
	}
263
264
265
	/**
266
	 * returns Circles available, based on current session
267
	 *
268
	 * @return Circle[]
269
	 * @throws InitiatorNotFoundException
270
	 * @throws RequestBuilderException
271
	 */
272
	public function getCircles(): array {
273
		return $this->circleService->getCircles();
274
	}
275
276
277
	/**
278
	 * @param string $singleId
279
	 *
280
	 * @return Circle
281
	 * @throws CircleNotFoundException
282
	 * @throws InitiatorNotFoundException
283
	 * @throws RequestBuilderException
284
	 */
285
	public function getCircle(string $singleId): Circle {
286
		return $this->circleService->getCircle($singleId);
287
	}
288
289
290
291
	/**
292
	 * WIP
293
	 *
294
	 * @return Circle[]
295
	 * @throws InitiatorNotFoundException
296
	 * @throws RequestBuilderException
297
	 */
298
//	public function getAllCircles(): array {
299
//		$this->federatedUserService->bypassCurrentUserCondition(true);
300
//		$this->circleService->getCircles();
301
//	}
302
303
304
	/**
305
	 * WIP
306
	 *
307
	 * @param string $circleId
308
	 * @param string $singleId
309
	 *
310
	 * @return Member
311
	 * @throws InitiatorNotFoundException
312
	 * @throws MemberNotFoundException
313
	 * @throws RequestBuilderException
314
	 */
315
//	public function getMember(string $circleId, string $singleId): Member {
316
//		$this->federatedUserService->bypassCurrentUserCondition(true);
317
//		$this->memberService->getMemberById($circleId, $singleId);
318
//	}
319
320
321
	/**
322
	 * WIP
323
	 *
324
	 * @param string $memberId
325
	 *
326
	 * @return Member
327
	 */
328
//	public function getMemberById(string $memberId): Member {
329
330
331
}
332
333