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

GSDownstreamService::isLocalEvent()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
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 OCA\Circles\Db\CirclesRequest;
34
use OCA\Circles\Db\GSEventsRequest;
35
use OCA\Circles\Exceptions\GSKeyException;
36
use OCA\Circles\GlobalScale\IGlobalScaleEvent;
37
use OCA\Circles\Model\GlobalScale\GSEvent;
38
use OCP\AppFramework\QueryException;
39
use OCP\IURLGenerator;
40
41
42
/**
43
 * Class GSDownstreamService
44
 *
45
 * @package OCA\Circles\Service
46
 */
47
class GSDownstreamService {
48
49
50
	/** @var string */
51
	private $userId = '';
52
53
	/** @var IURLGenerator */
54
	private $urlGenerator;
55
56
	/** @var GSEventsRequest */
57
	private $gsEventsRequest;
58
59
	/** @var CirclesRequest */
60
	private $circlesRequest;
61
62
	/** @var ConfigService */
63
	private $configService;
64
65
	/** @var MiscService */
66
	private $miscService;
67
68
69
	/**
70
	 * GSUpstreamService constructor.
71
	 *
72
	 * @param $userId
73
	 * @param IURLGenerator $urlGenerator
74
	 * @param GSEventsRequest $gsEventsRequest
75
	 * @param CirclesRequest $circlesRequest
76
	 * @param ConfigService $configService
77
	 * @param MiscService $miscService
78
	 */
79 View Code Duplication
	public function __construct(
80
		$userId,
81
		IURLGenerator $urlGenerator,
82
		GSEventsRequest $gsEventsRequest,
83
		CirclesRequest $circlesRequest,
84
		ConfigService $configService,
85
		MiscService $miscService
86
	) {
87
		$this->userId = $userId;
88
		$this->urlGenerator = $urlGenerator;
89
		$this->gsEventsRequest = $gsEventsRequest;
90
		$this->circlesRequest = $circlesRequest;
91
		$this->configService = $configService;
92
		$this->miscService = $miscService;
93
	}
94
95
96
	/**
97
	 * @param GSEvent $event
98
	 *
99
	 * @throws GSKeyException
100
	 */
101
	public function onNewEvent(GSEvent $event) {
102
		$this->checkEvent($event);
103
104
		$this->manageEvent($event);
105
	}
106
107
108
	/**
109
	 * @param GSEvent $event
110
	 */
111
	private function manageEvent(GSEvent $event) {
112
113
		try {
114
			$gs = \OC::$server->query('\OCA\Circles\\' . $event->getType());
115
		} catch (QueryException $e) {
0 ignored issues
show
Bug introduced by
The class OCP\AppFramework\QueryException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
116
			return;
117
		}
118
119
		if (!$gs instanceof IGlobalScaleEvent) {
120
			return;
121
		}
122
123
		$gs->manage($event);
124
	}
125
126
127
	/**
128
	 * @return string
129
	 */
130
	public function getKey(): string {
131
		return 'abcd';
132
	}
133
134
135
	/**
136
	 * @param string $key
137
	 *
138
	 * @throws GSKeyException
139
	 */
140
	public function checkKey(string $key) {
141
		if ($key !== $this->getKey()) {
142
			throw new GSKeyException('invalid key');
143
		}
144
	}
145
146
147
	/**
148
	 * @param GSEvent $event
149
	 *
150
	 * @throws GSKeyException
151
	 */
152
	private function checkEvent(GSEvent $event) {
153
		$this->checkKey($event->getKey());
154
	}
155
156
157
	/**
158
	 * @param GSEvent $event
159
	 *
160
	 * @return bool
161
	 */
162
	private function isLocalEvent(GSEvent $event): bool {
0 ignored issues
show
Unused Code introduced by
This method is not used, and could be removed.
Loading history...
Unused Code introduced by
The parameter $event is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
163
		return true;
164
	}
165
166
167
//	private function
168
}
169
170