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

GlobalScaleController   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 78
Duplicated Lines 35.9 %

Coupling/Cohesion

Components 1
Dependencies 7

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 7
dl 28
loc 78
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A event() 14 14 2
A asyncBroadcast() 0 13 2
A broadcast() 14 14 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\Controller;
31
32
33
use daita\MySmallPhpTools\Traits\TAsync;
34
use daita\MySmallPhpTools\Traits\TStringTools;
35
use Exception;
36
use OCA\Circles\Model\GlobalScale\GSEvent;
37
use OCP\AppFramework\Http\DataResponse;
38
39
40
/**
41
 * Class GlobalScaleController
42
 *
43
 * @package OCA\Circles\Controller
44
 */
45
class GlobalScaleController extends BaseController {
46
47
48
	use TStringTools;
49
	use TAsync;
50
51
52
	/**
53
	 * @PublicPage
54
	 * @NoCSRFRequired
55
	 *
56
	 * @param string $data
0 ignored issues
show
Bug introduced by
There is no parameter named $data. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
57
	 *
58
	 * @return DataResponse
59
	 */
60 View Code Duplication
	public function event(): DataResponse {
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...
61
		$data = file_get_contents('php://input');
62
63
		try {
64
			$event = new GSevent();
65
			$event->importFromJson($data);
66
67
//			$this->gsUpstreamService->onNewEvent($event);
68
69
			return $this->success([]);
70
		} catch (Exception $e) {
71
			return $this->fail(['data' => $data, 'error' => $e->getMessage()]);
72
		}
73
	}
74
75
76
	/**
77
	 * @PublicPage
78
	 * @NoCSRFRequired
79
	 *
80
	 * @param string $token
81
	 *
82
	 * @return DataResponse
83
	 */
84
	public function asyncBroadcast(string $token): DataResponse {
85
		try {
86
			$wrapper = $this->gsUpstreamService->getEventByToken($token);
87
88
			$this->async();
89
90
			$this->gsUpstreamService->broadcastEvent($wrapper->getEvent());
91
92
			return $this->success([]);
93
		} catch (Exception $e) {
94
			return $this->fail(['token' => $token, 'error' => $e->getMessage()]);
95
		}
96
	}
97
98
99
	/**
100
	 * @PublicPage
101
	 * @NoCSRFRequired
102
	 *
103
	 * @param string $data
0 ignored issues
show
Bug introduced by
There is no parameter named $data. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
104
	 *
105
	 * @return DataResponse
106
	 */
107 View Code Duplication
	public function broadcast(): DataResponse {
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...
108
		$data = file_get_contents('php://input');
109
110
		try {
111
			$event = new GSevent();
112
			$event->importFromJson($data);
113
114
			$this->gsDownstreamService->onNewEvent($event);
115
116
			return $this->success([]);
117
		} catch (Exception $e) {
118
			return $this->fail(['data' => $data, 'error' => $e->getMessage()]);
119
		}
120
	}
121
122
}
123
124