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

MesstoSmsConfig::getUser()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 2
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * @author Juho Ylikorpi <[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 OCA\TwoFactorGateway\AppInfo\Application;
27
use OCA\TwoFactorGateway\Exception\ConfigurationException;
28
use OCP\IConfig;
29
30
class MesstoSmsConfig implements IProviderConfig {
31
32
	/** @var IConfig */
33
	private $config;
34
35
	public function __construct(IConfig $config) {
36
		$this->config = $config;
37
	}
38
39
	private function getOrFail(string $key): string {
40
		$val = $this->config->getAppValue(Application::APP_NAME, $key, null);
41
		if (is_null($val)) {
0 ignored issues
show
introduced by
The condition is_null($val) is always false.
Loading history...
42
			throw new ConfigurationException();
43
		}
44
		return $val;
45
	}
46
47
	public function getUser(): string {
48
		return $this->getOrFail('messto_user');
49
	}
50
51
	public function setUser(string $user) {
52
		$this->config->setAppValue(Application::APP_NAME, 'messto_user', $user);
53
	}
54
55
	public function getPassword(): string {
56
		return $this->getOrFail('messto_password');
57
	}
58
59
	public function setPassword(string $password) {
60
		$this->config->setAppValue(Application::APP_NAME, 'messto_password', $password);
61
	}
62
63
	public function isComplete(): bool {
64
		$set = $this->config->getAppKeys(Application::APP_NAME);
65
		$expected = [
66
			'messto_user',
67
			'messto_password',
68
		];
69
		return count(array_intersect($set, $expected)) === count($expected);
70
	}
71
72
}
73