@@ -20,7 +20,7 @@ discard block |
||
20 | 20 | |
21 | 21 | class Remove extends Command { |
22 | 22 | /** @var AGateway[] */ |
23 | - private array $gateways = []; |
|
23 | + private array $gateways = [ ]; |
|
24 | 24 | |
25 | 25 | public function __construct( |
26 | 26 | private Factory $gatewayFactory, |
@@ -30,24 +30,24 @@ discard block |
||
30 | 30 | $fqcn = $this->gatewayFactory->getFqcnList(); |
31 | 31 | foreach ($fqcn as $fqcn) { |
32 | 32 | $gateway = $this->gatewayFactory->get($fqcn); |
33 | - $this->gateways[$gateway->getSettings()->id] = $gateway; |
|
33 | + $this->gateways[ $gateway->getSettings()->id ] = $gateway; |
|
34 | 34 | } |
35 | 35 | |
36 | 36 | $this->addArgument( |
37 | 37 | 'gateway', |
38 | 38 | InputArgument::OPTIONAL, |
39 | - 'The name of the gateway: ' . implode(', ', array_keys($this->gateways)) |
|
39 | + 'The name of the gateway: '.implode(', ', array_keys($this->gateways)) |
|
40 | 40 | ); |
41 | 41 | } |
42 | 42 | |
43 | - #[\Override] |
|
43 | + #[\Override ] |
|
44 | 44 | protected function execute(InputInterface $input, OutputInterface $output) { |
45 | 45 | $gatewayName = strtolower((string)$input->getArgument('gateway')); |
46 | 46 | if (!array_key_exists($gatewayName, $this->gateways)) { |
47 | 47 | $helper = new QuestionHelper(); |
48 | 48 | $choiceQuestion = new ChoiceQuestion('Please choose a provider:', array_keys($this->gateways)); |
49 | 49 | $selected = $helper->ask($input, $output, $choiceQuestion); |
50 | - $gateway = $this->gateways[$selected]; |
|
50 | + $gateway = $this->gateways[ $selected ]; |
|
51 | 51 | } |
52 | 52 | |
53 | 53 | $gateway->remove(); |
@@ -25,16 +25,16 @@ discard block |
||
25 | 25 | parent::__construct('twofactorauth:gateway:test'); |
26 | 26 | |
27 | 27 | $fqcn = $this->gatewayFactory->getFqcnList(); |
28 | - $gateways = []; |
|
28 | + $gateways = [ ]; |
|
29 | 29 | foreach ($fqcn as $fqcn) { |
30 | 30 | $gateway = $this->gatewayFactory->get($fqcn); |
31 | - $gateways[$gateway->getSettings()->id] = $gateway; |
|
31 | + $gateways[ $gateway->getSettings()->id ] = $gateway; |
|
32 | 32 | } |
33 | 33 | |
34 | 34 | $this->addArgument( |
35 | 35 | 'gateway', |
36 | 36 | InputArgument::REQUIRED, |
37 | - 'The name of the gateway: ' . implode(', ', array_keys($gateways)) |
|
37 | + 'The name of the gateway: '.implode(', ', array_keys($gateways)) |
|
38 | 38 | ); |
39 | 39 | $this->addArgument( |
40 | 40 | 'identifier', |
@@ -43,7 +43,7 @@ discard block |
||
43 | 43 | ); |
44 | 44 | } |
45 | 45 | |
46 | - #[\Override] |
|
46 | + #[\Override ] |
|
47 | 47 | protected function execute(InputInterface $input, OutputInterface $output) { |
48 | 48 | $gatewayName = $input->getArgument('gateway'); |
49 | 49 | $identifier = $input->getArgument('identifier'); |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | return 1; |
56 | 56 | } |
57 | 57 | |
58 | - $gateway->send($identifier, 'Test', ['code' => '123456']); |
|
58 | + $gateway->send($identifier, 'Test', [ 'code' => '123456' ]); |
|
59 | 59 | return 0; |
60 | 60 | } |
61 | 61 | } |
@@ -16,37 +16,37 @@ |
||
16 | 16 | /** @extends AFactory<AProvider> */ |
17 | 17 | class Factory extends AFactory { |
18 | 18 | /** @var array<AProvider> */ |
19 | - private array $instancesByFqcn = []; |
|
20 | - #[\Override] |
|
19 | + private array $instancesByFqcn = [ ]; |
|
20 | + #[\Override ] |
|
21 | 21 | protected function getPrefix(): string { |
22 | 22 | return 'OCA\\TwoFactorGateway\\Provider\\Channel\\SMS\\Provider\\Drivers\\'; |
23 | 23 | } |
24 | 24 | |
25 | - #[\Override] |
|
25 | + #[\Override ] |
|
26 | 26 | protected function getSuffix(): string { |
27 | 27 | return ''; |
28 | 28 | } |
29 | 29 | |
30 | - #[\Override] |
|
30 | + #[\Override ] |
|
31 | 31 | protected function getBaseClass(): string { |
32 | 32 | return AProvider::class; |
33 | 33 | } |
34 | 34 | |
35 | - #[\Override] |
|
35 | + #[\Override ] |
|
36 | 36 | public function get(string $name): object { |
37 | - if (isset($this->instancesByFqcn[$name])) { |
|
38 | - return $this->instancesByFqcn[$name]; |
|
37 | + if (isset($this->instancesByFqcn[ $name ])) { |
|
38 | + return $this->instancesByFqcn[ $name ]; |
|
39 | 39 | } |
40 | - if (isset($this->instances[$name])) { |
|
41 | - return $this->instances[$name]; |
|
40 | + if (isset($this->instances[ $name ])) { |
|
41 | + return $this->instances[ $name ]; |
|
42 | 42 | } |
43 | 43 | foreach ($this->getFqcnList() as $fqcn) { |
44 | 44 | $instance = \OCP\Server::get($fqcn); |
45 | 45 | $settings = $instance->getSettings(); |
46 | 46 | if ($fqcn === $name || $settings->id === $name) { |
47 | 47 | $instance->setAppConfig(\OCP\Server::get(\OCP\IAppConfig::class)); |
48 | - $this->instances[$settings->id] = $instance; |
|
49 | - $this->instancesByFqcn[$fqcn] = $instance; |
|
48 | + $this->instances[ $settings->id ] = $instance; |
|
49 | + $this->instancesByFqcn[ $fqcn ] = $instance; |
|
50 | 50 | return $instance; |
51 | 51 | } |
52 | 52 | } |
@@ -29,20 +29,20 @@ discard block |
||
29 | 29 | parent::__construct($appConfig); |
30 | 30 | } |
31 | 31 | |
32 | - #[\Override] |
|
33 | - public function send(string $identifier, string $message, array $extra = []): void { |
|
32 | + #[\Override ] |
|
33 | + public function send(string $identifier, string $message, array $extra = [ ]): void { |
|
34 | 34 | $this->getProvider()->send($identifier, $message); |
35 | 35 | } |
36 | 36 | |
37 | - #[\Override] |
|
37 | + #[\Override ] |
|
38 | 38 | final public function cliConfigure(InputInterface $input, OutputInterface $output): int { |
39 | 39 | $namespaces = $this->smsProviderFactory->getFqcnList(); |
40 | - $names = []; |
|
41 | - $providers = []; |
|
40 | + $names = [ ]; |
|
41 | + $providers = [ ]; |
|
42 | 42 | foreach ($namespaces as $ns) { |
43 | 43 | $provider = $this->smsProviderFactory->get($ns); |
44 | - $providers[] = $provider; |
|
45 | - $names[] = $provider->getSettings()->name; |
|
44 | + $providers[ ] = $provider; |
|
45 | + $names[ ] = $provider->getSettings()->name; |
|
46 | 46 | } |
47 | 47 | |
48 | 48 | $helper = new QuestionHelper(); |
@@ -50,29 +50,29 @@ discard block |
||
50 | 50 | $name = $helper->ask($input, $output, $choiceQuestion); |
51 | 51 | $selectedIndex = array_search($name, $names); |
52 | 52 | |
53 | - $provider = $providers[$selectedIndex]; |
|
53 | + $provider = $providers[ $selectedIndex ]; |
|
54 | 54 | |
55 | 55 | foreach ($provider->getSettings()->fields as $field) { |
56 | 56 | $id = $field->field; |
57 | - $prompt = $field->prompt . ' '; |
|
57 | + $prompt = $field->prompt.' '; |
|
58 | 58 | $defaultVal = $field->default ?? null; |
59 | 59 | $optional = (bool)($field->optional ?? false); |
60 | 60 | |
61 | 61 | $answer = (string)$helper->ask($input, $output, new Question($prompt, $defaultVal)); |
62 | 62 | |
63 | 63 | if ($optional && $answer === '') { |
64 | - $method = 'delete' . $this->toCamel($id); |
|
64 | + $method = 'delete'.$this->toCamel($id); |
|
65 | 65 | $provider->{$method}(); |
66 | 66 | continue; |
67 | 67 | } |
68 | 68 | |
69 | - $method = 'set' . $this->toCamel($id); |
|
69 | + $method = 'set'.$this->toCamel($id); |
|
70 | 70 | $provider->{$method}($answer); |
71 | 71 | } |
72 | 72 | return 0; |
73 | 73 | } |
74 | 74 | |
75 | - #[\Override] |
|
75 | + #[\Override ] |
|
76 | 76 | public function createSettings(): Settings { |
77 | 77 | try { |
78 | 78 | $settings = $this->getProvider()->getSettings(); |
@@ -84,7 +84,7 @@ discard block |
||
84 | 84 | return $settings; |
85 | 85 | } |
86 | 86 | |
87 | - #[\Override] |
|
87 | + #[\Override ] |
|
88 | 88 | public function isComplete(?Settings $settings = null): bool { |
89 | 89 | if ($settings === null) { |
90 | 90 | try { |
@@ -97,7 +97,7 @@ discard block |
||
97 | 97 | return parent::isComplete($settings); |
98 | 98 | } |
99 | 99 | |
100 | - #[\Override] |
|
100 | + #[\Override ] |
|
101 | 101 | public function remove(?Settings $settings = null): void { |
102 | 102 | foreach ($this->smsProviderFactory->getFqcnList() as $fqcn) { |
103 | 103 | $provider = $this->smsProviderFactory->get($fqcn); |
@@ -15,37 +15,37 @@ |
||
15 | 15 | |
16 | 16 | /** @extends AFactory<AProvider> */ |
17 | 17 | class Factory extends AFactory { |
18 | - private array $instancesByFqcn = []; |
|
19 | - #[\Override] |
|
18 | + private array $instancesByFqcn = [ ]; |
|
19 | + #[\Override ] |
|
20 | 20 | protected function getPrefix(): string { |
21 | 21 | return 'OCA\\TwoFactorGateway\\Provider\\Channel\\Telegram\\Provider\\Drivers\\'; |
22 | 22 | } |
23 | 23 | |
24 | - #[\Override] |
|
24 | + #[\Override ] |
|
25 | 25 | protected function getSuffix(): string { |
26 | 26 | return ''; |
27 | 27 | } |
28 | 28 | |
29 | - #[\Override] |
|
29 | + #[\Override ] |
|
30 | 30 | protected function getBaseClass(): string { |
31 | 31 | return AProvider::class; |
32 | 32 | } |
33 | 33 | |
34 | - #[\Override] |
|
34 | + #[\Override ] |
|
35 | 35 | public function get(string $name): object { |
36 | - if (isset($this->instancesByFqcn[$name])) { |
|
37 | - return $this->instancesByFqcn[$name]; |
|
36 | + if (isset($this->instancesByFqcn[ $name ])) { |
|
37 | + return $this->instancesByFqcn[ $name ]; |
|
38 | 38 | } |
39 | - if (isset($this->instances[$name])) { |
|
40 | - return $this->instances[$name]; |
|
39 | + if (isset($this->instances[ $name ])) { |
|
40 | + return $this->instances[ $name ]; |
|
41 | 41 | } |
42 | 42 | foreach ($this->getFqcnList() as $fqcn) { |
43 | 43 | $instance = \OCP\Server::get($fqcn); |
44 | 44 | $settings = $instance->getSettings(); |
45 | 45 | if ($fqcn === $name || $settings->id === $name) { |
46 | 46 | $instance->setAppConfig(\OCP\Server::get(\OCP\IAppConfig::class)); |
47 | - $this->instances[$name] = $instance; |
|
48 | - $this->instancesByFqcn[$fqcn] = $instance; |
|
47 | + $this->instances[ $name ] = $instance; |
|
48 | + $this->instancesByFqcn[ $fqcn ] = $instance; |
|
49 | 49 | return $instance; |
50 | 50 | } |
51 | 51 | } |
@@ -29,20 +29,20 @@ discard block |
||
29 | 29 | parent::__construct($appConfig); |
30 | 30 | } |
31 | 31 | |
32 | - #[\Override] |
|
33 | - public function send(string $identifier, string $message, array $extra = []): void { |
|
32 | + #[\Override ] |
|
33 | + public function send(string $identifier, string $message, array $extra = [ ]): void { |
|
34 | 34 | $this->getProvider()->send($identifier, $message); |
35 | 35 | } |
36 | 36 | |
37 | - #[\Override] |
|
37 | + #[\Override ] |
|
38 | 38 | final public function cliConfigure(InputInterface $input, OutputInterface $output): int { |
39 | 39 | $namespaces = $this->telegramProviderFactory->getFqcnList(); |
40 | - $names = []; |
|
41 | - $providers = []; |
|
40 | + $names = [ ]; |
|
41 | + $providers = [ ]; |
|
42 | 42 | foreach ($namespaces as $ns) { |
43 | 43 | $provider = $this->telegramProviderFactory->get($ns); |
44 | - $providers[] = $provider; |
|
45 | - $names[] = $provider->getSettings()->name; |
|
44 | + $providers[ ] = $provider; |
|
45 | + $names[ ] = $provider->getSettings()->name; |
|
46 | 46 | } |
47 | 47 | |
48 | 48 | $helper = new QuestionHelper(); |
@@ -50,11 +50,11 @@ discard block |
||
50 | 50 | $name = $helper->ask($input, $output, $choiceQuestion); |
51 | 51 | $selectedIndex = array_search($name, $names); |
52 | 52 | |
53 | - $providers[$selectedIndex]->cliConfigure($input, $output); |
|
53 | + $providers[ $selectedIndex ]->cliConfigure($input, $output); |
|
54 | 54 | return 0; |
55 | 55 | } |
56 | 56 | |
57 | - #[\Override] |
|
57 | + #[\Override ] |
|
58 | 58 | public function createSettings(): Settings { |
59 | 59 | try { |
60 | 60 | $settings = $this->getProvider()->getSettings(); |
@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | return $settings; |
67 | 67 | } |
68 | 68 | |
69 | - #[\Override] |
|
69 | + #[\Override ] |
|
70 | 70 | public function isComplete(?Settings $settings = null): bool { |
71 | 71 | if ($settings === null) { |
72 | 72 | try { |
@@ -79,7 +79,7 @@ discard block |
||
79 | 79 | return parent::isComplete($settings); |
80 | 80 | } |
81 | 81 | |
82 | - #[\Override] |
|
82 | + #[\Override ] |
|
83 | 83 | public function remove(?Settings $settings = null): void { |
84 | 84 | foreach ($this->telegramProviderFactory->getFqcnList() as $fqcn) { |
85 | 85 | $provider = $this->telegramProviderFactory->get($fqcn); |
@@ -54,10 +54,10 @@ discard block |
||
54 | 54 | ); |
55 | 55 | } |
56 | 56 | |
57 | - #[\Override] |
|
58 | - public function send(string $identifier, string $message, array $extra = []): void { |
|
57 | + #[\Override ] |
|
58 | + public function send(string $identifier, string $message, array $extra = [ ]): void { |
|
59 | 59 | if (empty($message)) { |
60 | - $message = $this->l10n->t('`%s` is your Nextcloud verification code.', [$extra['code']]); |
|
60 | + $message = $this->l10n->t('`%s` is your Nextcloud verification code.', [ $extra[ 'code' ] ]); |
|
61 | 61 | } |
62 | 62 | $this->logger->debug("sending telegram message to $identifier, message: $message"); |
63 | 63 | $token = $this->getToken(); |
@@ -76,11 +76,11 @@ discard block |
||
76 | 76 | $this->logger->debug("telegram message to chat $identifier sent"); |
77 | 77 | } |
78 | 78 | |
79 | - #[\Override] |
|
79 | + #[\Override ] |
|
80 | 80 | public function cliConfigure(InputInterface $input, OutputInterface $output): int { |
81 | 81 | $helper = new QuestionHelper(); |
82 | 82 | $settings = $this->getSettings(); |
83 | - $tokenQuestion = new Question($settings->fields[0]->prompt . ' '); |
|
83 | + $tokenQuestion = new Question($settings->fields[ 0 ]->prompt.' '); |
|
84 | 84 | $token = $helper->ask($input, $output, $tokenQuestion); |
85 | 85 | $this->setToken($token); |
86 | 86 | $output->writeln("Using $token."); |
@@ -18,7 +18,7 @@ discard block |
||
18 | 18 | |
19 | 19 | abstract class AGateway implements IGateway { |
20 | 20 | use TConfigurable; |
21 | - public const SCHEMA = []; |
|
21 | + public const SCHEMA = [ ]; |
|
22 | 22 | protected ?Settings $settings = null; |
23 | 23 | |
24 | 24 | public function __construct( |
@@ -29,25 +29,25 @@ discard block |
||
29 | 29 | /** |
30 | 30 | * @throws MessageTransmissionException |
31 | 31 | */ |
32 | - #[\Override] |
|
33 | - abstract public function send(string $identifier, string $message, array $extra = []): void; |
|
32 | + #[\Override ] |
|
33 | + abstract public function send(string $identifier, string $message, array $extra = [ ]): void; |
|
34 | 34 | |
35 | - #[\Override] |
|
35 | + #[\Override ] |
|
36 | 36 | public function isComplete(?Settings $settings = null): bool { |
37 | 37 | if (!is_object($settings)) { |
38 | 38 | $settings = $this->getSettings(); |
39 | 39 | } |
40 | 40 | $savedKeys = $this->appConfig->getKeys(Application::APP_ID); |
41 | 41 | $providerId = $settings->id ?? $this->getProviderId(); |
42 | - $fields = []; |
|
42 | + $fields = [ ]; |
|
43 | 43 | foreach ($settings->fields as $field) { |
44 | - $fields[] = $providerId . '_' . $field->field; |
|
44 | + $fields[ ] = $providerId.'_'.$field->field; |
|
45 | 45 | } |
46 | 46 | $intersect = array_intersect($fields, $savedKeys); |
47 | 47 | return count($intersect) === count($fields); |
48 | 48 | } |
49 | 49 | |
50 | - #[\Override] |
|
50 | + #[\Override ] |
|
51 | 51 | public function getSettings(): Settings { |
52 | 52 | if ($this->settings !== null) { |
53 | 53 | return $this->settings; |
@@ -57,10 +57,10 @@ discard block |
||
57 | 57 | return $this->settings; |
58 | 58 | } |
59 | 59 | |
60 | - #[\Override] |
|
60 | + #[\Override ] |
|
61 | 61 | abstract public function cliConfigure(InputInterface $input, OutputInterface $output): int; |
62 | 62 | |
63 | - #[\Override] |
|
63 | + #[\Override ] |
|
64 | 64 | public function remove(?Settings $settings = null): void { |
65 | 65 | if (!is_object($settings)) { |
66 | 66 | $settings = $this->getSettings(); |
@@ -68,7 +68,7 @@ discard block |
||
68 | 68 | $this->settings = $settings; |
69 | 69 | } |
70 | 70 | foreach ($settings->fields as $field) { |
71 | - $method = 'delete' . $this->toCamel($field->field); |
|
71 | + $method = 'delete'.$this->toCamel($field->field); |
|
72 | 72 | $this->{$method}(); |
73 | 73 | } |
74 | 74 | } |
@@ -77,11 +77,11 @@ discard block |
||
77 | 77 | return str_replace(' ', '', ucwords(str_replace('_', ' ', $field))); |
78 | 78 | } |
79 | 79 | |
80 | - #[\Override] |
|
80 | + #[\Override ] |
|
81 | 81 | public function getProviderId(): string { |
82 | 82 | $id = self::deriveIdFromFqcn(static::class); |
83 | 83 | if ($id === null) { |
84 | - throw new \LogicException('Cannot derive gateway id from FQCN: ' . static::class); |
|
84 | + throw new \LogicException('Cannot derive gateway id from FQCN: '.static::class); |
|
85 | 85 | } |
86 | 86 | return $id; |
87 | 87 | } |
@@ -20,28 +20,28 @@ discard block |
||
20 | 20 | */ |
21 | 21 | public function __call(string $name, array $args) { |
22 | 22 | if (!preg_match('/^(?<operation>get|set|delete)(?<field>[A-Z][A-Za-z0-9_]*)$/', $name, $matches)) { |
23 | - throw new ConfigurationException('Invalid method ' . $name); |
|
23 | + throw new ConfigurationException('Invalid method '.$name); |
|
24 | 24 | } |
25 | - $field = strtolower(preg_replace('/(?<!^)[A-Z]/', '_$0', $matches['field'])); |
|
25 | + $field = strtolower(preg_replace('/(?<!^)[A-Z]/', '_$0', $matches[ 'field' ])); |
|
26 | 26 | $key = $this->keyFromField($field); |
27 | 27 | |
28 | - switch ($matches['operation']) { |
|
28 | + switch ($matches[ 'operation' ]) { |
|
29 | 29 | case 'get': |
30 | 30 | $val = (string)$this->getAppConfig()->getValueString(Application::APP_ID, $key, ''); |
31 | 31 | if ($val === '') { |
32 | - throw new ConfigurationException('No value set for ' . $field); |
|
32 | + throw new ConfigurationException('No value set for '.$field); |
|
33 | 33 | } |
34 | 34 | return $val; |
35 | 35 | |
36 | 36 | case 'set': |
37 | - $this->getAppConfig()->setValueString(Application::APP_ID, $key, (string)($args[0] ?? '')); |
|
37 | + $this->getAppConfig()->setValueString(Application::APP_ID, $key, (string)($args[ 0 ] ?? '')); |
|
38 | 38 | return $this; |
39 | 39 | |
40 | 40 | case 'delete': |
41 | 41 | $this->getAppConfig()->deleteKey(Application::APP_ID, $key); |
42 | 42 | return $this; |
43 | 43 | } |
44 | - throw new ConfigurationException('Invalid operation ' . $matches['operation']); |
|
44 | + throw new ConfigurationException('Invalid operation '.$matches[ 'operation' ]); |
|
45 | 45 | } |
46 | 46 | |
47 | 47 | /** |
@@ -52,10 +52,10 @@ discard block |
||
52 | 52 | $fields = $settings->fields; |
53 | 53 | foreach ($fields as $field) { |
54 | 54 | if ($field->field === $fieldName) { |
55 | - return $settings->id . '_' . $fieldName; |
|
55 | + return $settings->id.'_'.$fieldName; |
|
56 | 56 | } |
57 | 57 | } |
58 | - throw new ConfigurationException('Invalid configuration field: ' . $fieldName . ', check SCHEMA at ' . static::class); |
|
58 | + throw new ConfigurationException('Invalid configuration field: '.$fieldName.', check SCHEMA at '.static::class); |
|
59 | 59 | } |
60 | 60 | |
61 | 61 | /** |