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

GSDownstreamService::statusEvent()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7

Duplication

Lines 7
Ratio 100 %

Importance

Changes 0
Metric Value
dl 7
loc 7
rs 10
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 View Code Duplication
	public function requestedEvent(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...
117
		$this->globalScaleService->checkEvent($event);
118
119
		$gs = $this->globalScaleService->getGlobalScaleEvent($event);
120
		$gs->verify($event, true);
121
		$gs->manage($event);
122
123
		$this->globalScaleService->asyncBroadcast($event);
124
	}
125
126
127
	/**
128
	 * @param GSEvent $event
129
	 *
130
	 * @throws CircleDoesNotExistException
131
	 * @throws ConfigNoCircleAvailableException
132
	 * @throws GSKeyException
133
	 * @throws GlobalScaleDSyncException
134
	 * @throws GlobalScaleEventException
135
	 */
136 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...
137
		$this->globalScaleService->checkEvent($event);
138
139
		$gs = $this->globalScaleService->getGlobalScaleEvent($event);
140
		$gs->verify($event, false);
141
		$gs->manage($event);
142
	}
143
144
145
	/**
146
	 * @param GSEvent $event
147
	 */
148 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...
149
		try {
150
			$this->globalScaleService->checkEvent($event);
151
152
			$gs = $this->globalScaleService->getGlobalScaleEvent($event);
153
			$gs->manage($event);
154
		} catch (Exception $e) {
155
			$this->miscService->log('issue onNewEvent - ' . $e->getMessage());
156
		}
157
	}
158
159
}
160
161