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

GatewayConfig::remove()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
c 0
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 Christoph Wurst <[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;
25
26
use OCA\TwoFactorGateway\AppInfo\Application;
27
use OCA\TwoFactorGateway\Exception\ConfigurationException;
28
use OCA\TwoFactorGateway\Service\Gateway\IGatewayConfig;
29
use OCA\TwoFactorGateway\Service\Gateway\SMS\Provider\IProvider;
30
use OCA\TwoFactorGateway\Service\Gateway\SMS\Provider\ProviderFactory;
31
use OCP\IConfig;
32
33
class GatewayConfig implements IGatewayConfig {
34
35
	/** @var IConfig */
36
	private $config;
37
38
	/** @var ProviderFactory */
39
	private $providerFactory;
40
41
	public function __construct(IConfig $config,
42
								ProviderFactory $providerFactory) {
43
		$this->config = $config;
44
		$this->providerFactory = $providerFactory;
45
	}
46
47
	public function getProvider(): IProvider {
48
		$providerName = $this->config->getAppValue(Application::APP_NAME, 'sms_provider_name');
49
		if ($providerName === '') {
50
			throw new ConfigurationException();
51
		}
52
53
		return $this->providerFactory->getProvider($providerName);
54
	}
55
56
	public function setProvider(string $provider) {
57
		$this->config->setAppValue(Application::APP_NAME, 'sms_provider_name', $provider);
58
	}
59
60
	public function isComplete(): bool {
61
		try {
62
			$provider = $this->getProvider();
63
			return $provider->getConfig()->isComplete();
64
		} catch (ConfigurationException $ex) {
65
			return false;
66
		}
67
	}
68
69
	public function remove() {
70
		$this->getProvider()->getConfig()->remove();
0 ignored issues
show
Bug introduced by
The method remove() does not exist on OCA\TwoFactorGateway\Ser...rovider\IProviderConfig. It seems like you code against a sub-type of said class. However, the method does not exist in OCA\TwoFactorGateway\Ser...rovider\ClickSendConfig. Are you sure you never get one of those? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

70
		$this->getProvider()->getConfig()->/** @scrutinizer ignore-call */ remove();
Loading history...
71
	}
72
}
73