Completed
Push — master ( 5dca78...92e122 )
by Christoph
28s queued 11s
created

VoipbusterConfig   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 12
eloc 20
c 1
b 0
f 0
dl 0
loc 54
rs 10

10 Methods

Rating   Name   Duplication   Size   Complexity  
A getOrFail() 0 6 2
A setPassword() 0 2 1
A setUser() 0 2 1
A getDid() 0 2 1
A getUser() 0 2 1
A getPassword() 0 2 1
A setDid() 0 2 1
A remove() 0 3 2
A __construct() 0 2 1
A isComplete() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * @author Francois Blackburn <[email protected]>
7
 *
8
 * Nextcloud - Two-factor Gateway for Telegram
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 function array_intersect;
27
use OCA\TwoFactorGateway\AppInfo\Application;
28
use OCA\TwoFactorGateway\Exception\ConfigurationException;
29
use OCP\IConfig;
30
31
class VoipbusterConfig implements IProviderConfig {
32
	private const expected = [
33
		'voipbuster_api_username',
34
		'voipbuster_api_password',
35
		'voipbuster_did',
36
	];
37
38
	/** @var IConfig */
39
	private $config;
40
41
	public function __construct(IConfig $config) {
42
		$this->config = $config;
43
	}
44
45
	private function getOrFail(string $key): string {
46
		$val = $this->config->getAppValue(Application::APP_NAME, $key, null);
47
		if (is_null($val)) {
0 ignored issues
show
introduced by
The condition is_null($val) is always false.
Loading history...
48
			throw new ConfigurationException();
49
		}
50
		return $val;
51
	}
52
53
	public function getUser(): string {
54
		return $this->getOrFail('voipbuster_api_username');
55
	}
56
57
	public function setUser(string $user) {
58
		$this->config->setAppValue(Application::APP_NAME, 'voipbuster_api_username', $user);
59
	}
60
61
	public function getPassword(): string {
62
		return $this->getOrFail('voipbuster_api_password');
63
	}
64
65
	public function setPassword(string $password) {
66
		$this->config->setAppValue(Application::APP_NAME, 'voipbuster_api_password', $password);
67
	}
68
69
	public function getDid(): string {
70
		return $this->getOrFail('voipbuster_did');
71
	}
72
73
	public function setDid(string $did) {
74
		$this->config->setAppValue(Application::APP_NAME, 'voipbuster_did', $did);
75
	}
76
77
	public function isComplete(): bool {
78
		$set = $this->config->getAppKeys(Application::APP_NAME);
79
		return count(array_intersect($set, self::expected)) === count(self::expected);
80
	}
81
82
	public function remove() {
83
		foreach (self::expected as $key) {
84
			$this->config->deleteAppValue(Application::APP_NAME, $key);
85
		}
86
	}
87
}
88