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

MemberCreate   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 8

Importance

Changes 0
Metric Value
wmc 4
lcom 2
cbo 8
dl 0
loc 48
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A verify() 0 11 1
A manage() 0 16 3
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\MemberAlreadyExistsException;
36
use OCA\Circles\Exceptions\MemberIsNotModeratorException;
37
use OCA\Circles\Model\GlobalScale\GSEvent;
38
39
40
/**
41
 * Class MemberCreate
42
 *
43
 * @package OCA\Circles\GlobalScale
44
 */
45
class MemberCreate extends AGlobalScaleEvent {
46
47
48
	/**
49
	 * @param GSEvent $event
50
	 * @param bool $localCheck
51
	 * @param bool $mustBeChecked
52
	 *
53
	 * @throws CircleDoesNotExistException
54
	 * @throws ConfigNoCircleAvailableException
55
	 * @throws MemberIsNotModeratorException
56
	 */
57
	public function verify(GSEvent $event, bool $localCheck = false, bool $mustBeChecked = false): void {
58
		$eventCircle = $event->getCircle();
59
		$viewer = $event->getViewer();
60
		$eventViewer = $viewer->getUserId();
61
		$eventInstance = $viewer->getInstance();
62
63
		$circle =
64
			$this->circlesRequest->getCircle($eventCircle->getUniqueId(), $eventViewer, $eventInstance);
65
		$circle->getHigherViewer()
66
			   ->hasToBeModerator();
67
	}
68
69
70
	/**
71
	 * @param GSEvent $event
72
	 *
73
	 * @throws MemberAlreadyExistsException
74
	 */
75
	public function manage(GSEvent $event): void {
76
		$this->miscService->log('new event; ' . json_encode($event));
77
		if (!$event->hasCircle() || !$event->hasMember()) {
78
			return;
79
		}
80
81
		$member = $event->getMember();
82
		$this->miscService->log('new event; ' . json_encode($member));
83
84
//		if ($member->getInstance() === '') {
85
//			$member->setInstance($event->getSource());
86
//		}
87
88
		$this->membersRequest->createMember($member);
89
		$this->eventsService->onMemberNew($event->getCircle(), $member);
90
	}
91
92
}
93
94