ShareController   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 52
Duplicated Lines 38.46 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 2
Bugs 1 Features 0
Metric Value
wmc 5
c 2
b 1
f 0
lcom 1
cbo 1
dl 20
loc 52
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
B searchUser() 20 28 4

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
2
/**
3
 * @copyright Copyright (c) 2016 Julius Härtl <[email protected]>
4
 *
5
 * @author Julius Härtl <[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\Deck\Controller;
25
26
use OCA\Deck\Db\Acl;
27
28
use OCA\Deck\Service\BoardService;
29
use OCP\IGroupManager;
30
use OCP\IRequest;
31
use OCP\AppFramework\Controller;
32
use OCP\IUserManager;
33
34
class ShareController extends Controller {
35
36
	private $userManager;
37
	private $groupManager;
38
	private $boardService;
39
	private $userId;
40
41
	public function __construct($appName, IRequest $request, IUserManager $userManager, IGroupManager $groupManager, BoardService $boardService, $userId) {
42
		parent::__construct($appName, $request);
43
		$this->userManager = $userManager;
44
		$this->groupManager = $groupManager;
45
		$this->userId = $userId;
46
		$this->boardService = $boardService;
47
48
	}
49
50
	/**
51
	 * @NoAdminRequired
52
	 * @param $search
53
	 * @return array
54
	 */
55
	public function searchUser($search) {
56
		$limit = 3;
57
		$offset = null;
58
		$result = [];
59 View Code Duplication
		foreach ($this->groupManager->search($search, $limit, $offset) as $idx => $group) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
60
			$acl = new Acl();
61
			$acl->setType('group');
62
			$acl->setParticipant($group->getGID());
63
			$acl->setPermissionEdit(true);
64
			$acl->setPermissionShare(true);
65
			$acl->setPermissionManage(true);
66
			$result[] = $acl;
67
		}
68
		$limit = 10;
69 View Code Duplication
		foreach ($this->userManager->searchDisplayName($search, $limit, $offset) as $idx => $user) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
70
			if ($user->getUID() === $this->userId) {
71
							continue;
72
			}
73
			$acl = new Acl();
74
			$acl->setType('user');
75
			$acl->setParticipant($user->getUID());
76
			$acl->setPermissionEdit(true);
77
			$acl->setPermissionShare(true);
78
			$acl->setPermissionManage(true);
79
			$result[] = $acl;
80
		}
81
		return $result;
82
	}
83
84
85
}
86