Completed
Push — master ( 8024bc...f8f0d2 )
by Vitor
14s
created

Test::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 22
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 16
CRAP Score 2

Importance

Changes 3
Bugs 0 Features 1
Metric Value
eloc 14
dl 0
loc 22
ccs 16
cts 16
cp 1
rs 9.7998
c 3
b 0
f 1
cc 2
nc 2
nop 2
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * SPDX-FileCopyrightText: 2024 Christoph Wurst <[email protected]>
7
 * SPDX-License-Identifier: AGPL-3.0-or-later
8
 */
9
10
namespace OCA\TwoFactorGateway\Command;
11
12
use OCA\TwoFactorGateway\Exception\InvalidProviderException;
13
use OCA\TwoFactorGateway\Provider\Gateway\Factory;
14
use OCP\IUserManager;
15
use Symfony\Component\Console\Command\Command;
16
use Symfony\Component\Console\Input\InputArgument;
17
use Symfony\Component\Console\Input\InputInterface;
18
use Symfony\Component\Console\Output\OutputInterface;
19
20
class Test extends Command {
21 1
	public function __construct(
22
		private IUserManager $userManager,
23
		private Factory $gatewayFactory,
24
	) {
25 1
		parent::__construct('twofactorauth:gateway:test');
26
27 1
		$fqcn = $this->gatewayFactory->getFqcnList();
28 1
		$gateways = [];
29 1
		foreach ($fqcn as $fqcn) {
30 1
			$gateway = $this->gatewayFactory->get($fqcn);
31 1
			$gateways[$gateway->getSettings()->id] = $gateway;
32
		}
33
34 1
		$this->addArgument(
35 1
			'gateway',
36 1
			InputArgument::REQUIRED,
37 1
			'The name of the gateway: ' . implode(', ', array_keys($gateways))
38 1
		);
39 1
		$this->addArgument(
40 1
			'identifier',
41 1
			InputArgument::REQUIRED,
42 1
			'The identifier of the recipient , e.g. phone number, user id, etc.'
43 1
		);
44
	}
45
46
	#[\Override]
47
	protected function execute(InputInterface $input, OutputInterface $output) {
48
		$gatewayName = $input->getArgument('gateway');
49
		$identifier = $input->getArgument('identifier');
50
51
		try {
52
			$gateway = $this->gatewayFactory->get($gatewayName);
53
		} catch (InvalidProviderException $e) {
54
			$output->writeln("<error>{$e->getMessage()}</error>");
55
			return 1;
56
		}
57
58
		$gateway->send($identifier, 'Test', ['code' => '123456']);
59
		return 0;
60
	}
61
}
62