Configure   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 1
dl 0
loc 63
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A configure() 0 6 1
A execute() 0 20 4
1
<?php
2
declare(strict_types=1);
3
4
5
/**
6
 * Bookmarks_FullTextSearch - Index bookmarks
7
 *
8
 * This file is licensed under the Affero General Public License version 3 or
9
 * later. See the COPYING file.
10
 *
11
 * @author Maxence Lange <[email protected]>
12
 * @copyright 2018
13
 * @license GNU AGPL version 3 or any later version
14
 *
15
 * This program is free software: you can redistribute it and/or modify
16
 * it under the terms of the GNU Affero General Public License as
17
 * published by the Free Software Foundation, either version 3 of the
18
 * License, or (at your option) any later version.
19
 *
20
 * This program is distributed in the hope that it will be useful,
21
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23
 * GNU Affero General Public License for more details.
24
 *
25
 * You should have received a copy of the GNU Affero General Public License
26
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
27
 *
28
 */
29
30
31
namespace OCA\Bookmarks_FullTextSearch\Command;
32
33
34
use Exception;
35
use OC\Core\Command\Base;
36
use OCA\Bookmarks_FullTextSearch\Service\ConfigService;
37
use OCA\Bookmarks_FullTextSearch\Service\MiscService;
38
use Symfony\Component\Console\Input\InputArgument;
39
use Symfony\Component\Console\Input\InputInterface;
40
use Symfony\Component\Console\Output\OutputInterface;
41
42
43
class Configure extends Base {
44
45
46
	/** @var ConfigService */
47
	private $configService;
48
49
	/** @var MiscService */
50
	private $miscService;
51
52
53
	/**
54
	 * Index constructor.
55
	 *
56
	 * @param ConfigService $configService
57
	 * @param MiscService $miscService
58
	 */
59
	public function __construct(ConfigService $configService, MiscService $miscService) {
60
		parent::__construct();
61
62
		$this->configService = $configService;
63
		$this->miscService = $miscService;
64
	}
65
66
67
	/**
68
	 *
69
	 */
70
	protected function configure() {
71
		parent::configure();
72
		$this->setName('bookmarks_fulltextsearch:configure')
73
			 ->addArgument('json', InputArgument::REQUIRED, 'set config')
74
			 ->setDescription('Configure the installation');
75
	}
76
77
78
	/**
79
	 * @param InputInterface $input
80
	 * @param OutputInterface $output
81
	 *
82
	 * @throws Exception
83
	 */
84
	protected function execute(InputInterface $input, OutputInterface $output) {
85
		$json = $input->getArgument('json');
86
87
		$config = json_decode($json, true);
88
89
		if ($config === null) {
90
			$output->writeln('Invalid JSON');
91
92
			return;
93
		}
94
95
		$ak = array_keys($config);
96
		foreach ($ak as $k) {
97
			if (array_key_exists($k, $this->configService->defaults)) {
98
				$this->configService->setAppValue($k, $config[$k]);
99
			}
100
		}
101
102
		$output->writeln(json_encode($this->configService->getConfig(), JSON_PRETTY_PRINT));
103
	}
104
105
}
106
107