Completed
Push — master ( 2813c1...14a1cb )
by Maxence
01:59
created

parseSubjectMemberRemoveNotYetMember()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 18
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 18
rs 9.4285
cc 3
eloc 12
nc 2
nop 3
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
28
namespace OCA\Circles\Activity;
29
30
31
use OCA\Circles\Exceptions\FakeException;
32
use OCA\Circles\Model\Circle;
33
use OCA\Circles\Model\Member;
34
use OCP\Activity\IEvent;
35
36
class ProviderSubjectMember extends ProviderParser {
37
38
	/**
39
	 * Parse on Subject 'member_join'.
40
	 * If circle is closed, we say that user accepted his invitation.
41
	 *
42
	 * @param IEvent $event
43
	 * @param Circle $circle
44
	 * @param Member $member
45
	 *
46
	 * @throws FakeException
47
	 */
48
	public function parseSubjectMemberJoin(IEvent &$event, Circle $circle, Member $member) {
49
		if ($event->getSubject() !== 'member_request_invitation') {
50
			return;
51
		}
52
53
		$this->parseSubjectMemberJoinClosedCircle($event, $circle, $member);
54
		$this->parseCircleMemberEvent(
55
			$event, $circle, $member, $this->l10n->t('You joined {circle}'),
56
			$this->l10n->t('{member} joined {circle}')
57
		);
58
59
		throw new FakeException();
60
	}
61
62
63
	/**
64
	 * @param IEvent $event
65
	 * @param Circle $circle
66
	 * @param Member $member
67
	 *
68
	 * @throws FakeException
69
	 */
70
	private function parseSubjectMemberJoinClosedCircle(IEvent &$event, Circle $circle, Member $member) {
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 100 characters; contains 102 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
71
		if ($circle->getType() !== Circle::CIRCLES_CLOSED) {
72
			return;
73
		}
74
75
		$this->parseCircleMemberEvent(
76
			$event, $circle, $member,
77
			$this->l10n->t('You accepted the invitation to join {circle}'),
78
			$this->l10n->t('{member} accepted the invitation to join {circle}')
79
		);
80
81
		throw new FakeException();
82
	}
83
84
85
	/**
86
	 * Parse on Subject 'member_add'.
87
	 * If circle is closed, we say that user's invitation was accepted.
88
	 *
89
	 * @param IEvent $event
90
	 * @param Circle $circle
91
	 * @param Member $member
92
	 *
93
	 * @throws FakeException
94
	 */
95 View Code Duplication
	public function parseSubjectMemberAdd(IEvent &$event, Circle $circle, Member $member) {
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...
96
		if ($event->getSubject() !== 'member_add') {
97
			return;
98
		}
99
100
		$this->parseSubjectMemberAddNotLocalMember($event, $circle, $member);
101
		$this->parseSubjectMemberAddClosedCircle($event, $circle, $member);
102
		$this->parseCircleMemberAdvancedEvent(
103
			$event, $circle, $member,
104
			$this->l10n->t('You added {member} as member to {circle}'),
105
			$this->l10n->t('You have been added as member to {circle} by {author}'),
106
			$this->l10n->t('{member} has been added as member to {circle} by {author}')
107
		);
108
109
		throw new FakeException();
110
	}
111
112
113
	/**
114
	 * @param IEvent $event
115
	 * @param Circle $circle
116
	 * @param Member $member
117
	 *
118
	 * @throws FakeException
119
	 */
120 View Code Duplication
	private function parseSubjectMemberAddNotLocalMember(IEvent &$event, Circle $circle, Member $member
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...
121
	) {
122
		if ($member->getType() === Member::TYPE_USER) {
123
			return;
124
		}
125
126
		$this->parseCircleMemberEvent(
127
			$event, $circle, $member,
128
			$this->l10n->t('You added {external} to {circle}'),
129
			$this->l10n->t('{external} has been added to {circle} by {author}')
130
		);
131
132
		throw new FakeException();
133
	}
134
135
136
	/**
137
	 * @param IEvent $event
138
	 * @param Circle $circle
139
	 * @param Member $member
140
	 *
141
	 * @throws FakeException
142
	 */
143
	private function parseSubjectMemberAddClosedCircle(IEvent &$event, Circle $circle, Member $member) {
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 100 characters; contains 101 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
144
		if ($circle->getType() !== Circle::CIRCLES_CLOSED) {
145
			return;
146
		}
147
148
		$this->parseCircleMemberAdvancedEvent(
149
			$event, $circle, $member,
150
			$this->l10n->t("You accepted {member}'s request to join {circle}"),
151
			$this->l10n->t('Your request to join {circle} has been accepted by {author}'),
152
			$this->l10n->t("{member}'s request to join {circle} has been accepted by {author}")
153
		);
154
155
		throw new FakeException();
156
	}
157
158
159
	/**
160
	 * Parse on Subject 'member_left'.
161
	 * If circle is closed and member was not a real member, we send him to
162
	 * parseSubjectNonMemberLeftClosedCircle();
163
	 *
164
	 * @param IEvent $event
165
	 * @param Circle $circle
166
	 * @param Member $member
167
	 *
168
	 * @throws FakeException
169
	 */
170
	public function parseSubjectMemberLeft(IEvent &$event, Circle $circle, Member $member) {
171
172
		if ($event->getSubject() !== 'member_left') {
173
			return;
174
		}
175
176
		$this->parseSubjectNonMemberLeftClosedCircle($event, $circle, $member);
177
		$this->parseCircleMemberEvent(
178
			$event, $circle, $member,
179
			$this->l10n->t('You left {circle}'),
180
			$this->l10n->t('{member} left {circle}')
181
		);
182
183
		throw new FakeException();
184
	}
185
186
187
	/**
188
	 * Parse on Subject 'member_left' on a closed circle when user were not yet a member.
189
	 * If status is Invited we say that member rejected his invitation.
190
	 * If status is Requested we say he dismissed his request.
191
	 *
192
	 * @param IEvent $event
193
	 * @param Circle $circle
194
	 * @param Member $member
195
	 *
196
	 * @throws FakeException
197
	 */
198
	private function parseSubjectNonMemberLeftClosedCircle(IEvent &$event, Circle $circle, Member $member
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 100 characters; contains 102 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
199
	) {
200
		if ($circle->getType() !== Circle::CIRCLES_CLOSED
201
			|| $member->getLevel() !== Member::LEVEL_NONE) {
202
			return;
203
		}
204
205
		if ($member->getStatus() === Member::STATUS_INVITED) {
206
			$this->parseCircleMemberEvent(
207
				$event, $circle, $member,
208
				$this->l10n->t("You declined the invitation to join {circle}"),
209
				$this->l10n->t("{member} declined an invitation to join {circle}")
210
			);
211
		} else {
212
			$this->parseCircleMemberEvent(
213
				$event, $circle, $member,
214
				$this->l10n->t("You cancelled your request to join {circle}"),
215
				$this->l10n->t("{member} cancelled his request to join {circle}")
216
			);
217
		}
218
219
		throw new FakeException();
220
	}
221
222
223
	/**
224
	 * Parse on Subject 'member_remove'.
225
	 * If circle is closed and member was not a real member, we send him to
226
	 * parseSubjectNonMemberRemoveClosedCircle();
227
	 *
228
	 * @param IEvent $event
229
	 * @param Circle $circle
230
	 * @param Member $member
231
	 *
232
	 * @throws FakeException
233
	 */
234 View Code Duplication
	public function parseSubjectMemberRemove(IEvent &$event, Circle $circle, Member $member) {
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...
235
236
		if ($event->getSubject() !== 'member_remove') {
237
			return;
238
		}
239
240
		$this->parseSubjectMemberRemoveNotLocalMember($event, $circle, $member);
241
		$this->parseSubjectMemberRemoveNotYetMember($event, $circle, $member);
242
		$this->parseCircleMemberAdvancedEvent(
243
			$event, $circle, $member,
244
			$this->l10n->t('You removed {member} from {circle}'),
245
			$this->l10n->t('You have been removed from {circle} by {author}'),
246
			$this->l10n->t('{member} has been removed from {circle} by {author}')
247
		);
248
249
		throw new FakeException();
250
	}
251
252
253
	/**
254
	 * @param IEvent $event
255
	 * @param Circle $circle
256
	 * @param Member $member
257
	 *
258
	 * @throws FakeException
259
	 */
260 View Code Duplication
	private function parseSubjectMemberRemoveNotLocalMember(
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...
261
		IEvent &$event, Circle $circle, Member $member
262
	) {
263
		if ($member->getType() === Member::TYPE_USER) {
264
			return;
265
		}
266
267
		$this->parseCircleMemberEvent(
268
			$event, $circle, $member,
269
			$this->l10n->t('You removed {external} from {circle}'),
270
			$this->l10n->t('{external} has been removed from {circle} by {author}')
271
		);
272
273
		throw new FakeException();
274
	}
275
276
277
	/**
278
	 * Parse on Subject 'member_remove' on a closed circle when user were not yet a member.
279
	 * If status is Invited we say that author cancelled his invitation.
280
	 * If status is Requested we say that his invitation was rejected.
281
	 *
282
	 * @param IEvent $event
283
	 * @param Circle $circle
284
	 * @param Member $member
285
	 *
286
	 * @throws FakeException
287
	 */
288
	private function parseSubjectMemberRemoveNotYetMember(
289
		IEvent &$event, Circle $circle, Member $member
290
	) {
291
		if ($circle->getType() !== Circle::CIRCLES_CLOSED
292
			|| $member->getLevel() !== Member::LEVEL_NONE) {
293
			return;
294
		}
295
296
		$this->parseSubjectMemberRemoveNotYetMemberRequesting($event, $circle, $member);
297
		$this->parseCircleMemberAdvancedEvent(
298
			$event, $circle, $member,
299
			$this->l10n->t("You cancelled {member}'s invitation to join {circle}"),
300
			$this->l10n->t('Your invitation to join {circle} has been cancelled by {author}'),
301
			$this->l10n->t("{author} cancelled {member}'s invitation to join {circle}")
302
		);
303
304
		throw new FakeException();
305
	}
306
307
308 View Code Duplication
	private function parseSubjectMemberRemoveNotYetMemberRequesting(
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...
309
		IEvent &$event, Circle $circle, Member $member
310
	) {
311
		if ($member->getStatus() !== Member::STATUS_REQUEST) {
312
			return;
313
		}
314
315
		$this->parseCircleMemberAdvancedEvent(
316
			$event, $circle, $member,
317
			$this->l10n->t("You dismissed {member}'s request to join {circle}"),
318
			$this->l10n->t('Your request to join {circle} has been dismissed by {author}'),
319
			$this->l10n->t("{member}'s request to join {circle} has been dismissed by {author}")
320
		);
321
322
		throw new FakeException();
323
	}
324
325
326
	/**
327
	 * @param IEvent $event
328
	 * @param Circle $circle
329
	 * @param Member $member
330
	 *
331
	 * @throws FakeException
332
	 */
333 View Code Duplication
	public function parseMemberInvited(IEvent &$event, Circle $circle, Member $member) {
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...
334
		if ($event->getSubject() !== 'member_invited') {
335
			return;
336
		}
337
338
		$this->parseCircleMemberAdvancedEvent(
339
			$event, $circle, $member,
340
			$this->l10n->t('You invited {member} to join {circle}'),
341
			$this->l10n->t('You have been invited to join {circle} by {author}'),
342
			$this->l10n->t('{member} has been invited to join {circle} by {author}')
343
		);
344
345
		throw new FakeException();
346
	}
347
348
349
	/**
350
	 * @param IEvent $event
351
	 * @param Circle $circle
352
	 * @param Member $member
353
	 *
354
	 * @throws FakeException
355
	 */
356 View Code Duplication
	public function parseMemberLevel(IEvent &$event, Circle $circle, Member $member) {
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...
357
		if ($event->getSubject() !== 'member_level') {
358
			return;
359
		}
360
361
		$level = [$this->l10n->t($member->getLevelString())];
362
		$this->parseCircleMemberAdvancedEvent(
363
			$event, $circle, $member,
364
			$this->l10n->t('You changed {member}\'s level in {circle} to %1$s', $level),
365
			$this->l10n->t('{author} changed your level in {circle} to %1$s', $level),
366
			$this->l10n->t('{author} changed {member}\'s level in {circle} to %1$s', $level)
367
		);
368
369
		throw new FakeException();
370
	}
371
372
373
	/**
374
	 * @param IEvent $event
375
	 * @param Circle $circle
376
	 * @param Member $member
377
	 *
378
	 * @throws FakeException
379
	 */
380 View Code Duplication
	public function parseMemberRequestInvitation(IEvent &$event, Circle $circle, Member $member) {
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...
381
		if ($event->getSubject() !== 'member_request_invitation') {
382
			return;
383
		}
384
385
		$this->parseMemberEvent(
386
			$event, $circle, $member,
387
			$this->l10n->t('You sent a request to join {circle}'),
388
			$this->l10n->t('{member} sent a request to join {circle}')
389
		);
390
391
		throw new FakeException();
392
	}
393
394
395
	/**
396
	 * @param IEvent $event
397
	 * @param Circle $circle
398
	 * @param Member $member
399
	 *
400
	 * @throws FakeException
401
	 */
402 View Code Duplication
	public function parseMemberOwner(IEvent &$event, Circle $circle, Member $member) {
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...
403
		if ($event->getSubject() !== 'member_owner') {
404
			return;
405
		}
406
407
		$this->parseMemberEvent(
408
			$event, $circle, $member,
409
			$this->l10n->t('You are the new owner of {circle}'),
410
			$this->l10n->t('{member} is the new owner of {circle}')
411
		);
412
		throw new FakeException();
413
	}
414
}