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

GlobalScaleController::broadcast()   A

Complexity

Conditions 2
Paths 5

Size

Total Lines 14

Duplication

Lines 14
Ratio 100 %

Importance

Changes 0
Metric Value
dl 14
loc 14
rs 9.7998
c 0
b 0
f 0
cc 2
nc 5
nop 0
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->miscService->log('CONFIRMING ' . json_encode($event));
68
69
//			$this->gsUpstreamService->onNewEvent($event);
70
71
			return $this->success([]);
72
		} catch (Exception $e) {
73
			return $this->fail(['data' => $data, 'error' => $e->getMessage()]);
74
		}
75
	}
76
77
78
	/**
79
	 * @PublicPage
80
	 * @NoCSRFRequired
81
	 *
82
	 * @param string $token
83
	 *
84
	 * @return DataResponse
85
	 */
86
	public function asyncBroadcast(string $token): DataResponse {
87
		try {
88
			$wrapper = $this->gsUpstreamService->getEventByToken($token);
89
90
			$this->async();
91
92
			$this->gsUpstreamService->broadcastEvent($wrapper->getEvent());
93
94
			return $this->success([]);
95
		} catch (Exception $e) {
96
			return $this->fail(['token' => $token, 'error' => $e->getMessage()]);
97
		}
98
	}
99
100
101
	/**
102
	 * @PublicPage
103
	 * @NoCSRFRequired
104
	 *
105
	 * @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...
106
	 *
107
	 * @return DataResponse
108
	 */
109 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...
110
		$data = file_get_contents('php://input');
111
112
		try {
113
			$event = new GSevent();
114
			$event->importFromJson($data);
115
116
			$this->gsDownstreamService->onNewEvent($event);
117
118
			return $this->success([]);
119
		} catch (Exception $e) {
120
			return $this->fail(['data' => $data, 'error' => $e->getMessage()]);
121
		}
122
	}
123
124
}
125
126