Completed
Push — master ( 7d6b25...de2ef0 )
by Thomas
14:16
created

ListGroups::execute()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 7

Duplication

Lines 9
Ratio 100 %

Importance

Changes 0
Metric Value
cc 1
eloc 7
nc 1
nop 2
dl 9
loc 9
rs 9.6666
c 0
b 0
f 0
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\Group;
23
24
use OC\Core\Command\Base;
25
use OCP\IGroupManager;
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 ListGroups extends Base {
0 ignored issues
show
Duplication introduced by
This class 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...
31
	/** @var \OCP\IGroupManager */
32
	protected $groupManager;
33
34
	/**
35
	 * @param IGroupManager $groupManager
36
	 */
37
	public function __construct(IGroupManager $groupManager) {
38
		parent::__construct();
39
		$this->groupManager = $groupManager;
40
	}
41
42
	protected function configure() {
43
		parent::configure();
44
45
		$this
46
			->setName('group:list')
47
			->setDescription('list groups')
48
			->addArgument(
49
				'search-pattern',
50
				InputArgument::OPTIONAL,
51
				'Restrict the list to groups whose name contains the string'
52
			)
53
		;
54
	}
55
56
	protected function execute(InputInterface $input, OutputInterface $output) {
57
		$groupNameSubString = $input->getArgument('search-pattern');
58
		$groups = $this->groupManager->search($groupNameSubString, null, null, 'management');
59
		$groups = array_map(function($group) {
60
			/** @var IGroup $group */
61
			return $group->getGID();
62
		}, $groups);
63
		parent::writeArrayInOutputFormat($input, $output, $groups);
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (writeArrayInOutputFormat() instead of execute()). Are you sure this is correct? If so, you might want to change this to $this->writeArrayInOutputFormat().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
64
	}
65
}
66