Completed
Pull Request — master (#362)
by Maxence
02:25
created

MemberJoin   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 7

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 7
dl 0
loc 53
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A verify() 0 15 1
A manage() 0 12 2
1
<?php declare(strict_types=1);
2
3
4
/**
5
 * Circles - Bring cloud-users closer together.
6
 *
7
 * This file is licensed under the Affero General Public License version 3 or
8
 * later. See the COPYING file.
9
 *
10
 * @author Maxence Lange <[email protected]>
11
 * @copyright 2017
12
 * @license GNU AGPL version 3 or any later version
13
 *
14
 * This program is free software: you can redistribute it and/or modify
15
 * it under the terms of the GNU Affero General Public License as
16
 * published by the Free Software Foundation, either version 3 of the
17
 * License, or (at your option) any later version.
18
 *
19
 * This program is distributed in the hope that it will be useful,
20
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22
 * GNU Affero General Public License for more details.
23
 *
24
 * You should have received a copy of the GNU Affero General Public License
25
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
26
 *
27
 */
28
29
30
namespace OCA\Circles\GlobalScale;
31
32
33
use OCA\Circles\Exceptions\CircleDoesNotExistException;
34
use OCA\Circles\Exceptions\ConfigNoCircleAvailableException;
35
use OCA\Circles\Exceptions\GlobalScaleDSyncException;
36
use OCA\Circles\Exceptions\GlobalScaleEventException;
37
use OCA\Circles\Exceptions\MemberAlreadyExistsException;
38
use OCA\Circles\Exceptions\MemberCantJoinCircleException;
39
use OCA\Circles\Exceptions\MemberIsBlockedException;
40
use OCA\Circles\Exceptions\MembersLimitException;
41
use OCA\Circles\Model\GlobalScale\GSEvent;
42
use OCA\Circles\Model\Member;
43
44
45
/**
46
 * Class MemberJoin
47
 *
48
 * @package OCA\Circles\GlobalScale
49
 */
50
class MemberJoin extends AGlobalScaleEvent {
51
52
53
	/**
54
	 * @param GSEvent $event
55
	 * @param bool $localCheck
56
	 * @param bool $mustBeChecked
57
	 *
58
	 * @throws MemberAlreadyExistsException
59
	 * @throws MemberCantJoinCircleException
60
	 * @throws MemberIsBlockedException
61
	 * @throws MembersLimitException
62
	 * @throws CircleDoesNotExistException
63
	 * @throws ConfigNoCircleAvailableException
64
	 * @throws GlobalScaleDSyncException
65
	 * @throws GlobalScaleEventException
66
	 */
67
	public function verify(GSEvent $event, bool $localCheck = false, bool $mustBeChecked = false): void {
68
		parent::verify($event, false, false);
69
70
		$circle = $event->getCircle();
71
		$eventMember = $event->getMember();
72
73
		$member = $this->membersRequest->getFreshNewMember(
74
			$circle->getUniqueId(), $eventMember->getUserId(), Member::TYPE_USER, $eventMember->getInstance()
75
		);
76
		$member->hasToBeAbleToJoinTheCircle();
77
		$member->joinCircle($circle->getType());
78
79
		$this->circlesService->checkThatCircleIsNotFull($circle);
80
		$event->setMember($member);
81
	}
82
83
84
	/**
85
	 * @param GSEvent $event
86
	 *
87
	 * @throws MemberAlreadyExistsException
88
	 */
89
	public function manage(GSEvent $event): void {
90
		$circle = $event->getCircle();
91
		$member = $event->getMember();
92
93
		if ($member->getJoined() === '') {
94
			$this->membersRequest->createMember($member);
95
		} else {
96
			$this->membersRequest->updateMember($member);
97
		}
98
99
		$this->eventsService->onMemberNew($circle, $member);
100
	}
101
102
}
103
104