PuzzelSMSConfig::getUrl()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 2
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * @author Kim Syversen <[email protected]>
7
 *
8
 * Nextcloud - Two-factor Gateway
9
 *
10
 * This code is free software: you can redistribute it and/or modify
11
 * it under the terms of the GNU Affero General Public License, version 3,
12
 * as published by the Free Software Foundation.
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, version 3,
20
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
21
 *
22
 */
23
24
namespace OCA\TwoFactorGateway\Service\Gateway\SMS\Provider;
25
26
use OCA\TwoFactorGateway\AppInfo\Application;
27
use OCA\TwoFactorGateway\Exception\ConfigurationException;
28
use OCP\IConfig;
29
use function array_intersect;
30
31
class PuzzelSMSConfig implements IProviderConfig {
32
	private const expected = [
33
		'puzzel_url',
34
		'puzzel_user',
35
		'puzzel_password',
36
		'puzzel_serviceid',
37
	];
38
39
	/** @var IConfig */
40
	private $config;
41
42
	public function __construct(IConfig $config) {
43
		$this->config = $config;
44
	}
45
46
	private function getOrFail(string $key): string {
47
		$val = $this->config->getAppValue(Application::APP_ID, $key, null);
48
		if (is_null($val)) {
0 ignored issues
show
introduced by
The condition is_null($val) is always false.
Loading history...
49
			throw new ConfigurationException();
50
		}
51
		return $val;
52
	}
53
54
	public function getUrl(): string {
55
		return $this->getOrFail('puzzel_url');
56
	}
57
58
	public function setUrl(string $url) {
59
		$this->config->setAppValue(Application::APP_ID, 'puzzel_url', $url);
60
	}
61
62
	public function getUser(): string {
63
		return $this->getOrFail('puzzel_user');
64
	}
65
66
	public function setUser(string $user) {
67
		$this->config->setAppValue(Application::APP_ID, 'puzzel_user', $user);
68
	}
69
70
	public function getPassword(): string {
71
		return $this->getOrFail('puzzel_password');
72
	}
73
74
	public function setPassword(string $password) {
75
		$this->config->setAppValue(Application::APP_ID, 'puzzel_password', $password);
76
	}
77
78
	public function getServiceId() {
79
		return $this->getOrFail('puzzel_serviceid');
80
	}
81
82
	public function setServiceId(string $serviceid) {
83
		$this->config->setAppValue(Application::APP_ID, 'puzzel_serviceid', $serviceid);
84
	}
85
86
	public function isComplete(): bool {
87
		$set = $this->config->getAppKeys(Application::APP_ID);
88
		return count(array_intersect($set, self::expected)) === count(self::expected);
89
	}
90
	
91
	public function remove() {
92
		foreach (self::expected as $key) {
93
			$this->config->deleteAppValue(Application::APP_ID, $key);
94
		}
95
	}
96
}
97