Completed
Pull Request — master (#362)
by Maxence
01:52
created

MemberCreate::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9

Duplication

Lines 9
Ratio 100 %

Importance

Changes 0
Metric Value
dl 9
loc 9
rs 9.9666
c 0
b 0
f 0
cc 1
nc 1
nop 4
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\Db\CirclesRequest;
34
use OCA\Circles\Db\MembersRequest;
35
use OCA\Circles\Exceptions\CircleAlreadyExistsException;
36
use OCA\Circles\Exceptions\MemberAlreadyExistsException;
37
use OCA\Circles\Model\GlobalScale\GSEvent;
38
use OCA\Circles\Service\EventsService;
39
use OCA\Circles\Service\MiscService;
40
41
42
/**
43
 * Class MemberCreate
44
 *
45
 * @package OCA\Circles\GlobalScale
46
 */
47
class MemberCreate implements IGlobalScaleEvent {
48
49
50
	/** @var CirclesRequest */
51
	private $circlesRequest;
52
53
	/** @var MembersRequest */
54
	private $membersRequest;
55
56
	/** @var EventsService */
57
	private $eventsService;
58
59
	/** @var MiscService */
60
	private $miscService;
61
62
63
	/**
64
	 * MemberCreate constructor.
65
	 *
66
	 * @param CirclesRequest $circlesRequest
67
	 * @param MembersRequest $membersRequest
68
	 * @param EventsService $eventsService
69
	 * @param MiscService $miscService
70
	 */
71 View Code Duplication
	public function __construct(
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...
72
		CirclesRequest $circlesRequest, MembersRequest $membersRequest, EventsService $eventsService,
73
		MiscService $miscService
74
	) {
75
		$this->circlesRequest = $circlesRequest;
76
		$this->membersRequest = $membersRequest;
77
		$this->eventsService = $eventsService;
78
		$this->miscService = $miscService;
79
	}
80
81
82
	/**
83
	 * @param GSEvent $event
84
	 *
85
	 * @return bool
86
	 * @throws MemberAlreadyExistsException
87
	 */
88
	public function manage(GSEvent $event): bool {
89
		$this->miscService->log('new event; ' . json_encode($event));
90
		if (!$event->hasCircle() || !$event->hasMember()) {
91
			return false;
92
		}
93
94
		$member = $event->getMember();
95
		$this->miscService->log('new event; ' . json_encode($member));
96
97
		if ($member->getInstance() === '') {
98
			$member->setInstance($event->getSource());
99
		}
100
101
		$this->membersRequest->createMember($member);
102
		$this->eventsService->onMemberNew($event->getCircle(), $member);
103
104
		return true;
105
	}
106
107
}
108
109