ListCommand   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 27
dl 0
loc 50
rs 10
c 2
b 0
f 0
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A formatTags() 0 10 2
A configure() 0 17 1
A execute() 0 8 1
A __construct() 0 4 1
1
<?php
2
/**
3
 * @copyright Copyright (c) 2021, hosting.de, Johannes Leuker <[email protected]>
4
 *
5
 * @author Johannes Leuker <[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
namespace OC\Core\Command\SystemTag;
24
25
use OC\Core\Command\Base;
26
use OCP\SystemTag\ISystemTag;
27
use OCP\SystemTag\ISystemTagManager;
28
use Symfony\Component\Console\Input\InputInterface;
29
use Symfony\Component\Console\Input\InputOption;
30
use Symfony\Component\Console\Output\OutputInterface;
31
32
class ListCommand extends Base {
33
	public function __construct(
34
		protected ISystemTagManager $systemTagManager,
35
	) {
36
		parent::__construct();
37
	}
38
39
	protected function configure() {
40
		$this
41
			->setName('tag:list')
42
			->setDescription('list tags')
43
			->addOption(
44
				'visibilityFilter',
45
				null,
46
				InputOption::VALUE_OPTIONAL,
47
				'filter by visibility (1,0)'
48
			)
49
			->addOption(
50
				'nameSearchPattern',
51
				null,
52
				InputOption::VALUE_OPTIONAL,
53
				'optional search pattern for the tag name (infix)'
54
			);
55
		parent::configure();
56
	}
57
58
	protected function execute(InputInterface $input, OutputInterface $output): int {
59
		$tags = $this->systemTagManager->getAllTags(
60
			$input->getOption('visibilityFilter'),
61
			$input->getOption('nameSearchPattern')
62
		);
63
64
		$this->writeArrayInOutputFormat($input, $output, $this->formatTags($tags));
65
		return 0;
66
	}
67
68
	/**
69
	 * @param ISystemtag[] $tags
70
	 * @return array
71
	 */
72
	private function formatTags(array $tags): array {
73
		$result = [];
74
75
		foreach ($tags as $tag) {
76
			$result[$tag->getId()] = [
77
				'name' => $tag->getName(),
78
				'access' => ISystemTag::ACCESS_LEVEL_LOOKUP[$tag->getAccessLevel()],
79
			];
80
		}
81
		return $result;
82
	}
83
}
84