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

GSDownstreamService::requestedEvent()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 14
rs 9.7998
c 0
b 0
f 0
cc 1
nc 1
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\Service;
31
32
33
use Exception;
34
use OCA\Circles\Db\CirclesRequest;
35
use OCA\Circles\Db\GSEventsRequest;
36
use OCA\Circles\Exceptions\CircleDoesNotExistException;
37
use OCA\Circles\Exceptions\ConfigNoCircleAvailableException;
38
use OCA\Circles\Exceptions\GlobalScaleDSyncException;
39
use OCA\Circles\Exceptions\GlobalScaleEventException;
40
use OCA\Circles\Exceptions\GSKeyException;
41
use OCA\Circles\Exceptions\GSStatusException;
42
use OCA\Circles\Model\GlobalScale\GSEvent;
43
use OCP\IURLGenerator;
44
45
46
/**
47
 * Class GSDownstreamService
48
 *
49
 * @package OCA\Circles\Service
50
 */
51
class GSDownstreamService {
52
53
54
	/** @var string */
55
	private $userId = '';
56
57
	/** @var IURLGenerator */
58
	private $urlGenerator;
59
60
	/** @var GSEventsRequest */
61
	private $gsEventsRequest;
62
63
	/** @var CirclesRequest */
64
	private $circlesRequest;
65
66
	/** @var GlobalScaleService */
67
	private $globalScaleService;
68
69
	/** @var ConfigService */
70
	private $configService;
71
72
	/** @var MiscService */
73
	private $miscService;
74
75
76
	/**
77
	 * GSUpstreamService constructor.
78
	 *
79
	 * @param $userId
80
	 * @param IURLGenerator $urlGenerator
81
	 * @param GSEventsRequest $gsEventsRequest
82
	 * @param CirclesRequest $circlesRequest
83
	 * @param GlobalScaleService $globalScaleService
84
	 * @param ConfigService $configService
85
	 * @param MiscService $miscService
86
	 */
87
	public function __construct(
88
		$userId,
89
		IURLGenerator $urlGenerator,
90
		GSEventsRequest $gsEventsRequest,
91
		CirclesRequest $circlesRequest,
92
		GlobalScaleService $globalScaleService,
93
		ConfigService $configService,
94
		MiscService $miscService
95
	) {
96
		$this->userId = $userId;
97
		$this->urlGenerator = $urlGenerator;
98
		$this->gsEventsRequest = $gsEventsRequest;
99
		$this->circlesRequest = $circlesRequest;
100
		$this->globalScaleService = $globalScaleService;
101
		$this->configService = $configService;
102
		$this->miscService = $miscService;
103
	}
104
105
106
	/**
107
	 * @param GSEvent $event
108
	 *
109
	 * @throws GSKeyException
110
	 * @throws GSStatusException
111
	 * @throws GlobalScaleEventException
112
	 * @throws CircleDoesNotExistException
113
	 * @throws ConfigNoCircleAvailableException
114
	 * @throws GlobalScaleDSyncException
115
	 */
116
	public function requestedEvent(GSEvent $event) {
117
		$this->globalScaleService->checkEvent($event);
118
119
		$gs = $this->globalScaleService->getGlobalScaleEvent($event);
120
		$gs->verify($event, true);
121
122
		$this->miscService->log('&&&& 1 ' . json_encode($event));
123
124
		$gs->manage($event);
125
126
		$this->miscService->log('&&&& 2 ' . json_encode($event));
127
128
		$this->globalScaleService->asyncBroadcast($event);
129
	}
130
131
132
	/**
133
	 * @param GSEvent $event
134
	 *
135
	 * @throws CircleDoesNotExistException
136
	 * @throws ConfigNoCircleAvailableException
137
	 * @throws GSKeyException
138
	 * @throws GlobalScaleDSyncException
139
	 * @throws GlobalScaleEventException
140
	 */
141 View Code Duplication
	public function statusEvent(GSEvent $event) {
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...
142
		$this->globalScaleService->checkEvent($event);
143
144
		$gs = $this->globalScaleService->getGlobalScaleEvent($event);
145
		$gs->verify($event, false);
146
		$gs->manage($event);
147
	}
148
149
150
	/**
151
	 * @param GSEvent $event
152
	 */
153 View Code Duplication
	public function onNewEvent(GSEvent $event) {
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...
154
		try {
155
			$this->globalScaleService->checkEvent($event);
156
157
			$gs = $this->globalScaleService->getGlobalScaleEvent($event);
158
			$gs->manage($event);
159
		} catch (Exception $e) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
160
		}
161
	}
162
163
}
164
165