Completed
Pull Request — master (#362)
by Maxence
02:10 queued 11s
created

CircleCreate   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 6
dl 0
loc 67
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A verify() 0 2 1
A manage() 0 16 3
A __construct() 0 9 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 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 CircleCreate
44
 *
45
 * @package OCA\Circles\GlobalScale
46
 */
47
class CircleCreate 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
	 * CircleCreate constructor.
64
	 *
65
	 * @param CirclesRequest $circlesRequest
66
	 * @param MembersRequest $membersRequest
67
	 * @param EventsService $eventsService
68
	 * @param MiscService $miscService
69
	 */
70
	public function __construct(
71
		CirclesRequest $circlesRequest, MembersRequest $membersRequest, EventsService $eventsService,
72
		MiscService $miscService
73
	) {
74
		$this->circlesRequest = $circlesRequest;
75
		$this->membersRequest = $membersRequest;
76
		$this->eventsService = $eventsService;
77
		$this->miscService = $miscService;
78
	}
79
80
81
	/**
82
	 * Circles are created on the original instance, so return false;
83
	 *
84
	 * @param GSEvent $event
85
	 */
86
	public function verify(GSEvent $event): void {
87
	}
88
89
90
	/**
91
	 * @param GSEvent $event
92
	 *
93
	 * @throws CircleAlreadyExistsException
94
	 * @throws MemberAlreadyExistsException
95
	 */
96
	public function manage(GSEvent $event): void {
97
		if (!$event->hasCircle()) {
98
			return;
99
		}
100
101
		$circle = $event->getCircle();
102
		$this->circlesRequest->createCircle($circle);
103
104
		$owner = $circle->getOwner();
105
		if ($owner->getInstance() === '') {
106
			$owner->setInstance($event->getSource());
107
		}
108
		$this->membersRequest->createMember($owner);
109
110
		$this->eventsService->onCircleCreation($circle);
111
	}
112
113
}
114
115