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

MemberJoin::manage()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12

Duplication

Lines 12
Ratio 100 %

Importance

Changes 0
Metric Value
dl 12
loc 12
rs 9.8666
c 0
b 0
f 0
cc 2
nc 2
nop 1
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 daita\MySmallPhpTools\Model\SimpleDataStore;
34
use OCA\Circles\Exceptions\CircleDoesNotExistException;
35
use OCA\Circles\Exceptions\ConfigNoCircleAvailableException;
36
use OCA\Circles\Exceptions\GlobalScaleDSyncException;
37
use OCA\Circles\Exceptions\GlobalScaleEventException;
38
use OCA\Circles\Exceptions\MemberAlreadyExistsException;
39
use OCA\Circles\Exceptions\MemberCantJoinCircleException;
40
use OCA\Circles\Exceptions\MemberIsBlockedException;
41
use OCA\Circles\Exceptions\MembersLimitException;
42
use OCA\Circles\Model\GlobalScale\GSEvent;
43
use OCA\Circles\Model\Member;
44
45
46
/**
47
 * Class MemberJoin
48
 *
49
 * @package OCA\Circles\GlobalScale
50
 */
51
class MemberJoin extends AGlobalScaleEvent {
52
53
54
	/**
55
	 * @param GSEvent $event
56
	 * @param bool $localCheck
57
	 * @param bool $mustBeChecked
58
	 *
59
	 * @throws MemberAlreadyExistsException
60
	 * @throws MemberCantJoinCircleException
61
	 * @throws MemberIsBlockedException
62
	 * @throws MembersLimitException
63
	 * @throws CircleDoesNotExistException
64
	 * @throws ConfigNoCircleAvailableException
65
	 * @throws GlobalScaleDSyncException
66
	 * @throws GlobalScaleEventException
67
	 */
68
	public function verify(GSEvent $event, bool $localCheck = false, bool $mustBeChecked = false): void {
69
		parent::verify($event, false, false);
70
71
		$circle = $event->getCircle();
72
		$eventMember = $event->getMember();
73
74
		$member = $this->membersRequest->getFreshNewMember(
75
			$circle->getUniqueId(), $eventMember->getUserId(), Member::TYPE_USER, $eventMember->getInstance()
76
		);
77
		$member->hasToBeAbleToJoinTheCircle();
78
		$member->joinCircle($circle->getType());
79
80
		$this->circlesService->checkThatCircleIsNotFull($circle);
81
		$event->setMember($member);
82
	}
83
84
85
	/**
86
	 * @param GSEvent $event
87
	 *
88
	 * @throws MemberAlreadyExistsException
89
	 */
90 View Code Duplication
	public function manage(GSEvent $event): void {
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...
91
		$circle = $event->getCircle();
92
		$member = $event->getMember();
93
94
		if ($member->getJoined() === '') {
95
			$this->membersRequest->createMember($member);
96
		} else {
97
			$this->membersRequest->updateMember($member);
98
		}
99
100
		$this->eventsService->onMemberNew($circle, $member);
101
	}
102
103
104
	/**
105
	 * @param GSEvent[] $events
106
	 */
107
	public function result(array $events): void {
108
//		$instances = array_keys($events);
109
//		foreach ($instances as $instance) {
110
//			$event = $events[$instance];
111
//			$this->miscService->log('---- ' . $instance . ' -- ' . json_encode($event->getResult()));
112
//		}
113
	}
114
115
}
116
117