Completed
Push — master ( 6bfb4d...93218d )
by Christoph
19s queued 14s
created

ClickatellCentralConfig::remove()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 2
c 0
b 0
f 0
dl 0
loc 3
rs 10
cc 2
nc 2
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * @author Christian Schrötter <[email protected]>
7
 * @author Christoph Wurst <[email protected]>
8
 * @author André Fondse <[email protected]>
9
 *
10
 * Nextcloud - Two-factor Gateway for Telegram
11
 *
12
 * This code is free software: you can redistribute it and/or modify
13
 * it under the terms of the GNU Affero General Public License, version 3,
14
 * as published by the Free Software Foundation.
15
 *
16
 * This program is distributed in the hope that it will be useful,
17
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19
 * GNU Affero General Public License for more details.
20
 *
21
 * You should have received a copy of the GNU Affero General Public License, version 3,
22
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
23
 *
24
 */
25
26
namespace OCA\TwoFactorGateway\Service\Gateway\SMS\Provider;
27
28
use OCA\TwoFactorGateway\AppInfo\Application;
29
use OCA\TwoFactorGateway\Exception\ConfigurationException;
30
use OCP\IConfig;
31
32
class ClickatellCentralConfig implements IProviderConfig {
33
34
	const expected = [
35
		'clickatell_central_api',
36
		'clickatell_central_user',
37
		'clickatell_central_password',
38
	];
39
40
	/** @var IConfig */
41
	private $config;
42
43
	public function __construct(IConfig $config) {
44
		$this->config = $config;
45
	}
46
47
	private function getOrFail(string $key): string {
48
		$val = $this->config->getAppValue(Application::APP_NAME, $key, null);
49
		if (is_null($val)) {
0 ignored issues
show
introduced by
The condition is_null($val) is always false.
Loading history...
50
			throw new ConfigurationException();
51
		}
52
		return $val;
53
	}
54
55
	public function getApi(): string {
56
		return $this->getOrFail('clickatell_central_api');
57
	}
58
59
	public function setApi(string $api) {
60
		$this->config->setAppValue(Application::APP_NAME, 'clickatell_central_api', $api);
61
	}
62
63
	public function getUser(): string {
64
		return $this->getOrFail('clickatell_central_user');
65
	}
66
67
	public function setUser(string $user) {
68
		$this->config->setAppValue(Application::APP_NAME, 'clickatell_central_user', $user);
69
	}
70
71
	public function getPassword(): string {
72
		return $this->getOrFail('clickatell_central_password');
73
	}
74
75
	public function setPassword(string $password) {
76
		$this->config->setAppValue(Application::APP_NAME, 'clickatell_central_password', $password);
77
	}
78
79
	public function isComplete(): bool {
80
		$set = $this->config->getAppKeys(Application::APP_NAME);
81
		return count(array_intersect($set, self::expected)) === count(self::expected);
82
	}
83
84
	public function remove() {
85
		foreach(self::expected as $key) {
86
			$this->config->deleteAppValue(Application::APP_NAME, $key);
87
		}
88
	}
89
}
90