Completed
Pull Request — master (#253)
by
unknown
04:02
created

GatewayApiSmsConfig   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 8
eloc 16
c 1
b 0
f 0
dl 0
loc 40
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 2 1
A getAuthToken() 0 2 1
A getOrFail() 0 6 2
A setAuthToken() 0 2 1
A getSenderId() 0 2 1
A isComplete() 0 7 1
A setSenderId() 0 2 1
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * @author Christoph Wurst <[email protected]>
7
 * @author André Fondse <[email protected]>
8
 *
9
 * Nextcloud - Two-factor Gateway for Telegram
10
 *
11
 * This code is free software: you can redistribute it and/or modify
12
 * it under the terms of the GNU Affero General Public License, version 3,
13
 * as published by the Free Software Foundation.
14
 *
15
 * This program is distributed in the hope that it will be useful,
16
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
 * GNU Affero General Public License for more details.
19
 *
20
 * You should have received a copy of the GNU Affero General Public License, version 3,
21
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
22
 *
23
 */
24
25
namespace OCA\TwoFactorGateway\Service\Gateway\SMS\Provider;
26
27
use OCA\TwoFactorGateway\AppInfo\Application;
28
use OCA\TwoFactorGateway\Exception\ConfigurationException;
29
use OCP\IConfig;
30
31
class GatewayApiSmsConfig implements IProviderConfig {
32
33
	/** @var IConfig */
34
	private $config;
35
36
	public function __construct(IConfig $config) {
37
		$this->config = $config;
38
	}
39
40
	private function getOrFail(string $key): string {
41
		$val = $this->config->getAppValue(Application::APP_NAME, $key, null);
42
		if (is_null($val)) {
0 ignored issues
show
introduced by
The condition is_null($val) is always false.
Loading history...
43
			throw new ConfigurationException();
44
		}
45
		return $val;
46
	}
47
48
	public function getAuthToken(): string {
49
		return $this->getOrFail('gatewayapisms_authtoken');
50
	}
51
52
	public function setAuthToken(string $authtoken) {
53
		$this->config->setAppValue(Application::APP_NAME, 'gatewayapisms_authtoken', $authtoken);
54
	}
55
56
	public function getSenderId(): string {
57
		return $this->getOrFail('gatewayapisms_senderid');
58
	}
59
60
	public function setSenderId(string $senderId) {
61
		$this->config->setAppValue(Application::APP_NAME, 'gatewayapisms_senderid', $senderId);
62
	}
63
64
	public function isComplete(): bool {
65
		$set = $this->config->getAppKeys(Application::APP_NAME);
66
		$expected = [
67
			'gatewayapisms_authtoken',
68
			'gatewayapisms_senderid',
69
		];
70
		return count(array_intersect($set, $expected)) === count($expected);
71
	}
72
73
}
74