|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @author Phil Davis <[email protected]> |
|
4
|
|
|
* |
|
5
|
|
|
* @copyright Copyright (c) 2017, ownCloud GmbH |
|
6
|
|
|
* @license AGPL-3.0 |
|
7
|
|
|
* |
|
8
|
|
|
* This code is free software: you can redistribute it and/or modify |
|
9
|
|
|
* it under the terms of the GNU Affero General Public License, version 3, |
|
10
|
|
|
* as published by the Free Software Foundation. |
|
11
|
|
|
* |
|
12
|
|
|
* This program is distributed in the hope that it will be useful, |
|
13
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
14
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
15
|
|
|
* GNU Affero General Public License for more details. |
|
16
|
|
|
* |
|
17
|
|
|
* You should have received a copy of the GNU Affero General Public License, version 3, |
|
18
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/> |
|
19
|
|
|
* |
|
20
|
|
|
*/ |
|
21
|
|
|
|
|
22
|
|
|
namespace OC\Core\Command\User; |
|
23
|
|
|
|
|
24
|
|
|
use OC\Core\Command\Base; |
|
25
|
|
|
use OCP\IUserManager; |
|
26
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
27
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
28
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
|
29
|
|
|
|
|
30
|
|
View Code Duplication |
class ListUsers extends Base { |
|
|
|
|
|
|
31
|
|
|
/** @var \OCP\IUserManager */ |
|
32
|
|
|
protected $userManager; |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* @param IUserManager $userManager |
|
36
|
|
|
*/ |
|
37
|
|
|
public function __construct(IUserManager $userManager) { |
|
38
|
|
|
parent::__construct(); |
|
39
|
|
|
$this->userManager = $userManager; |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
protected function configure() { |
|
43
|
|
|
parent::configure(); |
|
44
|
|
|
|
|
45
|
|
|
$this |
|
46
|
|
|
->setName('user:list') |
|
47
|
|
|
->setDescription('list users') |
|
48
|
|
|
->addArgument( |
|
49
|
|
|
'search-pattern', |
|
50
|
|
|
InputArgument::OPTIONAL, |
|
51
|
|
|
'Restrict the list to users whose User ID contains the string' |
|
52
|
|
|
) |
|
53
|
|
|
; |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) { |
|
57
|
|
|
$userNameSubString = $input->getArgument('search-pattern'); |
|
58
|
|
|
$users = $this->userManager->search($userNameSubString); |
|
59
|
|
|
$users = array_map(function($user) { |
|
60
|
|
|
/** @var IUser $user */ |
|
61
|
|
|
return $user->getDisplayName(); |
|
62
|
|
|
}, $users); |
|
63
|
|
|
parent::writeArrayInOutputFormat($input, $output, $users); |
|
|
|
|
|
|
64
|
|
|
} |
|
65
|
|
|
} |
|
66
|
|
|
|
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.