Passed
Push — master ( e6ef09...54cffe )
by Roeland
49:25 queued 37:20
created

Info::execute()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 15
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 12
nc 2
nop 2
dl 0
loc 15
rs 9.8666
c 1
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * @copyright Copyright (c) 2021, hosting.de, Johannes Leuker <[email protected]>
7
 *
8
 * @author Johannes Leuker <[email protected]>
9
 *
10
 * @license GNU AGPL version 3 or any later version
11
 *
12
 * This program is free software: you can redistribute it and/or modify
13
 * it under the terms of the GNU Affero General Public License as
14
 * published by the Free Software Foundation, either version 3 of the
15
 * License, or (at your option) any later version.
16
 *
17
 * This program is distributed in the hope that it will be useful,
18
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
 * GNU Affero General Public License for more details.
21
 *
22
 * You should have received a copy of the GNU Affero General Public License
23
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
24
 *
25
 */
26
27
namespace OC\Core\Command\Group;
28
29
use OC\Core\Command\Base;
30
use OCP\IGroup;
31
use OCP\IGroupManager;
32
use Symfony\Component\Console\Input\InputArgument;
33
use Symfony\Component\Console\Input\InputInterface;
34
use Symfony\Component\Console\Input\InputOption;
35
use Symfony\Component\Console\Output\OutputInterface;
36
37
class Info extends Base {
38
	/** @var IGroupManager */
39
	protected $groupManager;
40
41
	/**
42
	 * @param IGroupManager $groupManager
43
	 */
44
	public function __construct(IGroupManager $groupManager) {
45
		$this->groupManager = $groupManager;
46
		parent::__construct();
47
	}
48
49
	protected function configure() {
50
		$this
51
			->setName('group:info')
52
			->setDescription('Show information about a group')
53
			->addArgument(
54
				'groupid',
55
				InputArgument::REQUIRED,
56
				'Group id'
57
			)->addOption(
58
				'output',
59
				null,
60
				InputOption::VALUE_OPTIONAL,
61
				'Output format (plain, json or json_pretty, default is plain)',
62
				$this->defaultOutputFormat
63
			);
64
	}
65
66
	protected function execute(InputInterface $input, OutputInterface $output): int {
67
		$gid = $input->getArgument('groupid');
68
		$group = $this->groupManager->get($gid);
69
		if (!$group instanceof IGroup) {
70
			$output->writeln('<error>Group "' . $gid . '" does not exist.</error>');
0 ignored issues
show
Bug introduced by
Are you sure $gid of type null|string|string[] can be used in concatenation? ( Ignorable by Annotation )

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

70
			$output->writeln('<error>Group "' . /** @scrutinizer ignore-type */ $gid . '" does not exist.</error>');
Loading history...
71
			return 1;
72
		} else {
73
			$groupOutput = [
74
				'groupID' => $gid,
75
				'displayName' => $group->getDisplayName(),
76
				'backends' => $group->getBackendNames(),
77
			];
78
79
			$this->writeArrayInOutputFormat($input, $output, $groupOutput);
80
			return 0;
81
		}
82
	}
83
}
84