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

MemberAdd   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 84
Duplicated Lines 13.1 %

Coupling/Cohesion

Components 1
Dependencies 8

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 8
dl 11
loc 84
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A verify() 0 32 3
A manage() 11 11 2
A result() 0 7 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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 OC\User\NoUserException;
35
use OCA\Circles\Exceptions\CircleDoesNotExistException;
36
use OCA\Circles\Exceptions\CircleTypeNotValidException;
37
use OCA\Circles\Exceptions\ConfigNoCircleAvailableException;
38
use OCA\Circles\Exceptions\EmailAccountInvalidFormatException;
39
use OCA\Circles\Exceptions\GlobalScaleDSyncException;
40
use OCA\Circles\Exceptions\GlobalScaleEventException;
41
use OCA\Circles\Exceptions\MemberAlreadyExistsException;
42
use OCA\Circles\Exceptions\MemberCantJoinCircleException;
43
use OCA\Circles\Exceptions\MemberIsNotModeratorException;
44
use OCA\Circles\Exceptions\MembersLimitException;
45
use OCA\Circles\Model\GlobalScale\GSEvent;
46
47
48
/**
49
 * Class MemberAdd
50
 *
51
 * @package OCA\Circles\GlobalScale
52
 */
53
class MemberAdd extends AGlobalScaleEvent {
54
55
56
	/**
57
	 * @param GSEvent $event
58
	 * @param bool $localCheck
59
	 * @param bool $mustBeChecked
60
	 *
61
	 * @throws CircleDoesNotExistException
62
	 * @throws ConfigNoCircleAvailableException
63
	 * @throws EmailAccountInvalidFormatException
64
	 * @throws GlobalScaleDSyncException
65
	 * @throws GlobalScaleEventException
66
	 * @throws MemberAlreadyExistsException
67
	 * @throws MemberCantJoinCircleException
68
	 * @throws MembersLimitException
69
	 * @throws NoUserException
70
	 * @throws CircleTypeNotValidException
71
	 * @throws MemberIsNotModeratorException
72
	 */
73
	public function verify(GSEvent $event, bool $localCheck = false, bool $mustBeChecked = false): void {
74
		parent::verify($event, $localCheck, true);
75
76
		$eventMember = $event->getMember();
77
		$this->cleanMember($eventMember);
78
79
		if ($eventMember->getInstance() === '') {
80
			$eventMember->setInstance($event->getSource());
81
		}
82
83
		$ident = $eventMember->getUserId();
84
		$this->membersService->verifyIdentBasedOnItsType(
85
			$ident, $eventMember->getType(), $eventMember->getInstance()
86
		);
87
88
		$circle = $event->getCircle();
89
		if (!$event->isForced()) {
90
			$circle->getHigherViewer()
91
				   ->hasToBeModerator();
92
		}
93
94
		$member = $this->membersRequest->getFreshNewMember(
95
			$circle->getUniqueId(), $ident, $eventMember->getType(), $eventMember->getInstance()
96
		);
97
		$member->hasToBeInviteAble();
98
99
		$this->circlesService->checkThatCircleIsNotFull($circle);
100
		$this->membersService->addMemberBasedOnItsType($circle, $member);
101
102
		$event->setMember($member);
103
104
	}
105
106
107
	/**
108
	 * @param GSEvent $event
109
	 *
110
	 * @throws MemberAlreadyExistsException
111
	 */
112 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...
113
		$circle = $event->getCircle();
114
		$member = $event->getMember();
115
		if ($member->getJoined() === '') {
116
			$this->membersRequest->createMember($member);
117
		} else {
118
			$this->membersRequest->updateMember($member);
119
		}
120
121
		$this->eventsService->onMemberNew($circle, $member);
122
	}
123
124
125
	/**
126
	 * @param GSEvent[] $events
127
	 */
128
	public function result(array $events): void {
129
		//		$instances = array_keys($events);
130
//		foreach ($instances as $instance) {
131
//			$event = $events[$instance];
132
//			$this->miscService->log('---- ' . $instance . ' -- ' . json_encode($event->getResult()));
133
//		}
134
	}
135
136
}
137
138