Remove   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
eloc 35
c 1
b 0
f 0
dl 0
loc 57
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 14 1
A execute() 0 26 5
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * @author Christoph Wurst <[email protected]>
7
 * @author Simon Spannagel <[email protected]>
8
 *
9
 * Nextcloud - Two-factor Gateway
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\Command;
26
27
use OCA\TwoFactorGateway\Service\Gateway\Signal\Gateway as SignalGateway;
28
use OCA\TwoFactorGateway\Service\Gateway\SMS\Gateway as SMSGateway;
29
use OCA\TwoFactorGateway\Service\Gateway\Telegram\Gateway as TelegramGateway;
30
use OCA\TwoFactorGateway\Service\Gateway\XMPP\Gateway as XMPPGateway;
31
use Symfony\Component\Console\Command\Command;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Console\Command\Command was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
32
use Symfony\Component\Console\Input\InputArgument;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Console\Input\InputArgument was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
33
use Symfony\Component\Console\Input\InputInterface;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Console\Input\InputInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
34
use Symfony\Component\Console\Output\OutputInterface;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Console\Output\OutputInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
35
36
class Remove extends Command {
37
38
	/** @var SignalGateway */
39
	private $signalGateway;
40
41
	/** @var SMSGateway */
42
	private $smsGateway;
43
44
	/** @var TelegramGateway */
45
	private $telegramGateway;
46
47
	/** @var XMPPGateway */
48
	private $xmppGateway;
49
50
	public function __construct(SignalGateway $signalGateway,
51
		SMSGateway $smsGateway,
52
		TelegramGateway $telegramGateway,
53
		XMPPGateway $xmppGateway) {
54
		parent::__construct('twofactorauth:gateway:remove');
55
		$this->signalGateway = $signalGateway;
56
		$this->smsGateway = $smsGateway;
57
		$this->telegramGateway = $telegramGateway;
58
		$this->xmppGateway = $xmppGateway;
59
60
		$this->addArgument(
61
			'gateway',
62
			InputArgument::REQUIRED,
63
			'The name of the gateway, e.g. sms, signal, telegram, xmpp, etc.'
64
		);
65
	}
66
67
	protected function execute(InputInterface $input, OutputInterface $output) {
68
		$gatewayName = $input->getArgument('gateway');
69
70
		/** @var IGateway $gateway */
71
		$gateway = null;
72
		switch ($gatewayName) {
73
			case 'signal':
74
				$gateway = $this->signalGateway;
75
				break;
76
			case 'sms':
77
				$gateway = $this->smsGateway;
78
				break;
79
			case 'telegram':
80
				$gateway = $this->telegramGateway;
81
				break;
82
			case 'xmpp':
83
				$gateway = $this->xmppGateway;
84
				break;
85
			default:
86
				$output->writeln("<error>Invalid gateway $gatewayName</error>");
87
				return 1;
88
		}
89
90
		$gateway->getConfig()->remove();
91
		$output->writeln("Removed configuration for gateway $gatewayName");
92
		return 0;
93
	}
94
}
95