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

GSDownstreamService   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 87
Duplicated Lines 19.54 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 2
dl 17
loc 87
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 17 17 1
A requestedEvent() 0 9 1
A onNewEvent() 0 9 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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\GlobalScaleEventException;
37
use OCA\Circles\Exceptions\GSKeyException;
38
use OCA\Circles\Exceptions\GSStatusException;
39
use OCA\Circles\Model\GlobalScale\GSEvent;
40
use OCP\IURLGenerator;
41
42
43
/**
44
 * Class GSDownstreamService
45
 *
46
 * @package OCA\Circles\Service
47
 */
48
class GSDownstreamService {
49
50
51
	/** @var string */
52
	private $userId = '';
53
54
	/** @var IURLGenerator */
55
	private $urlGenerator;
56
57
	/** @var GSEventsRequest */
58
	private $gsEventsRequest;
59
60
	/** @var CirclesRequest */
61
	private $circlesRequest;
62
63
	/** @var GlobalScaleService */
64
	private $globalScaleService;
65
66
	/** @var ConfigService */
67
	private $configService;
68
69
	/** @var MiscService */
70
	private $miscService;
71
72
73
	/**
74
	 * GSUpstreamService constructor.
75
	 *
76
	 * @param $userId
77
	 * @param IURLGenerator $urlGenerator
78
	 * @param GSEventsRequest $gsEventsRequest
79
	 * @param CirclesRequest $circlesRequest
80
	 * @param GlobalScaleService $globalScaleService
81
	 * @param ConfigService $configService
82
	 * @param MiscService $miscService
83
	 */
84 View Code Duplication
	public function __construct(
85
		$userId,
86
		IURLGenerator $urlGenerator,
87
		GSEventsRequest $gsEventsRequest,
88
		CirclesRequest $circlesRequest,
89
		GlobalScaleService $globalScaleService,
90
		ConfigService $configService,
91
		MiscService $miscService
92
	) {
93
		$this->userId = $userId;
94
		$this->urlGenerator = $urlGenerator;
95
		$this->gsEventsRequest = $gsEventsRequest;
96
		$this->circlesRequest = $circlesRequest;
97
		$this->globalScaleService = $globalScaleService;
98
		$this->configService = $configService;
99
		$this->miscService = $miscService;
100
	}
101
102
103
	/**
104
	 * @param GSEvent $event
105
	 *
106
	 * @throws GlobalScaleEventException
107
	 * @throws GSKeyException
108
	 * @throws GSStatusException
109
	 */
110
	public function requestedEvent(GSEvent $event) {
111
		$this->globalScaleService->checkEvent($event);
112
113
		$gs = $this->globalScaleService->getGlobalScaleEvent($event);
114
		$gs->verify($event, true);
115
		$gs->manage($event);
116
117
		$this->globalScaleService->asyncBroadcast($event);
118
	}
119
120
121
	/**
122
	 * @param GSEvent $event
123
	 */
124
	public function onNewEvent(GSEvent $event) {
125
		try {
126
			$this->globalScaleService->checkEvent($event);
127
128
			$gs = $this->globalScaleService->getGlobalScaleEvent($event);
129
			$gs->manage($event);
130
		} catch (Exception $e) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
131
		}
132
	}
133
134
}
135
136