Completed
Pull Request — master (#1038)
by René
04:22
created

SystemController::getSiteUsersAndGroups()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 2
c 0
b 0
f 0
dl 0
loc 12
ccs 0
cts 12
cp 0
rs 10
cc 1
nc 1
nop 8
crap 2

How to fix   Many Parameters   

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

1
<?php
2
/**
3
 * @copyright Copyright (c) 2017 Vinzenz Rosenkranz <[email protected]>
4
 *
5
 * @author René Gieling <[email protected]>
6
 *
7
 * @license GNU AGPL version 3 or any later version
8
 *
9
 *  This program is free software: you can redistribute it and/or modify
10
 *  it under the terms of the GNU Affero General Public License as
11
 *  published by the Free Software Foundation, either version 3 of the
12
 *  License, or (at your option) any later version.
13
 *
14
 *  This program is distributed in the hope that it will be useful,
15
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 *  GNU Affero General Public License for more details.
18
 *
19
 *  You should have received a copy of the GNU Affero General Public License
20
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
21
 *
22
 */
23
24
namespace OCA\Polls\Controller;
25
26
use Exception;
27
use OCP\AppFramework\Controller;
28
use OCP\AppFramework\Http;
29
use OCP\AppFramework\Http\DataResponse;
30
use OCA\Polls\Service\SystemService;
31
32
use OCP\IRequest;
33
34
class SystemController extends Controller {
35
36
	/** @var SystemService */
37
	private $systemService;
38
39
	/**
40
	 * SystemController constructor.
41
	 * @param string $appName
42
	 * @param IRequest $request
43
	 * @param SystemService $systemService
44
	 */
45
46
	public function __construct(
47
		string $appName,
48
		IRequest $request,
49
		SystemService $systemService
50
	) {
51
		parent::__construct($appName, $request);
52
		$this->systemService = $systemService;
53
	}
54
55
	 /**
56
 	 * Get a list of users
57
 	 * @NoAdminRequired
58
 	 * @param string $query
59
 	 * @param array $skipUsers - usernames to skip in return array
60
	 * @return DataResponse
61
 	 */
62
	 public function getSiteUsers($query = '', $skipUsers = array()) {
63
		 return new DataResponse(['users' => $this->systemService->getSiteUsers($query, $skipUsers)], Http::STATUS_OK);
64
	 }
65
66
	 /**
67
 	 * Get a list of user groups
68
 	 * @NoAdminRequired
69
 	 * @param string $query
70
 	 * @param array $skipGroups - group names to skip in return array
71
	 * @return DataResponse
72
 	 */
73
	 public function getSiteGroups($query = '', $skipGroups = array()) {
74
		 return new DataResponse(['groups' => $this->systemService->getSiteGroups($query, $skipGroups)], Http::STATUS_OK);
75
	 }
76
77
	/**
78
	 * Get a list of contacts
79
	 * @NoAdminRequired
80
	 * @param string $query
81
	 * @return DataResponse
82
	 */
83
	public function getContacts($query = '') {
84
		return new DataResponse(['contacts' => $this->systemService->getContacts($query)], Http::STATUS_OK);
85
	}
86
87
	/**
88
	 * Get a list of contact groups
89
	 * @NoAdminRequired
90
	 * @param string $query
91
	 * @return DataResponse
92
	 */
93
	public function getContactsGroups($query = '') {
94
		return new DataResponse(['contactGroups' => $this->systemService->getContactsGroups($query)], Http::STATUS_OK);
95
	}
96
97
98
	/**
99
	 * Get a combined list of NC users, groups and contacts
100
	 * @NoAdminRequired
101
	 * @param string $query
102
	 * @param bool $getGroups - search in groups
103
	 * @param bool $getUsers - search in site users
104
	 * @param bool $getContacts - search in contacs
105
	 * @param bool $getContactGroups - search in contacs
106
	 * @param array $skipGroups - group names to skip in return array
107
	 * @param array $skipUsers - user names to skip in return array
108
	 * @return DataResponse
109
	 */
110
	public function getSiteUsersAndGroups(
111
		$query = '',
112
		$getGroups = true,
113
		$getUsers = true,
114
		$getContacts = true,
115
		$getContactGroups = true,
116
		$getMail = false,
117
		$skipGroups = array(),
118
		$skipUsers = array()
119
	) {
120
		return new DataResponse(['siteusers' => $this->systemService->getSiteUsersAndGroups(
121
			$query, $getGroups, $getUsers, $getContacts, $getContactGroups, $getMail, $skipGroups, $skipUsers )], Http::STATUS_OK);
122
	}
123
124
	/**
125
	 * Validate it the user name is reservrd
126
	 * return false, if this username already exists as a user or as
127
	 * a participant of the poll
128
	 * @NoAdminRequired
129
	 * @PublicPage
130
	 * @return DataResponse
131
	 */
132
	public function validatePublicUsername($pollId, $userName, $token) {
0 ignored issues
show
Unused Code introduced by
The parameter $token is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

132
	public function validatePublicUsername($pollId, $userName, /** @scrutinizer ignore-unused */ $token) {

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

Loading history...
Unused Code introduced by
The parameter $pollId is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

132
	public function validatePublicUsername(/** @scrutinizer ignore-unused */ $pollId, $userName, $token) {

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

Loading history...
133
		return new DataResponse(['result' => true, 'name' => $userName], Http::STATUS_OK);
134
135
	}
136
137
}
138