@@ -12,17 +12,17 @@ |
||
12 | 12 | use OCA\TwoFactorGateway\Provider\AFactory; |
13 | 13 | |
14 | 14 | class Factory extends AFactory { |
15 | - #[\Override] |
|
15 | + #[\Override ] |
|
16 | 16 | protected function getPrefix(): string { |
17 | 17 | return 'OCA\\TwoFactorGateway\\Provider\\Channel\\'; |
18 | 18 | } |
19 | 19 | |
20 | - #[\Override] |
|
20 | + #[\Override ] |
|
21 | 21 | protected function getSuffix(): string { |
22 | 22 | return 'Gateway'; |
23 | 23 | } |
24 | 24 | |
25 | - #[\Override] |
|
25 | + #[\Override ] |
|
26 | 26 | protected function getBaseClass(): string { |
27 | 27 | return IGateway::class; |
28 | 28 | } |
@@ -15,38 +15,38 @@ |
||
15 | 15 | |
16 | 16 | class Factory extends AFactory { |
17 | 17 | /** @var array<string,IProvider> */ |
18 | - protected array $instances = []; |
|
19 | - #[\Override] |
|
18 | + protected array $instances = [ ]; |
|
19 | + #[\Override ] |
|
20 | 20 | protected function getPrefix(): string { |
21 | 21 | return 'OCA\\TwoFactorGateway\\Provider\\Channel\\SMS\\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 IProvider::class; |
32 | 32 | } |
33 | 33 | |
34 | - #[\Override] |
|
34 | + #[\Override ] |
|
35 | 35 | public function isValid(string $fqcn): bool { |
36 | 36 | return defined("$fqcn::SCHEMA") |
37 | 37 | && is_array($fqcn::SCHEMA); |
38 | 38 | } |
39 | 39 | |
40 | - #[\Override] |
|
40 | + #[\Override ] |
|
41 | 41 | public function get(string $name): IProvider { |
42 | - if (isset($this->instances[$name])) { |
|
43 | - return $this->instances[$name]; |
|
42 | + if (isset($this->instances[ $name ])) { |
|
43 | + return $this->instances[ $name ]; |
|
44 | 44 | } |
45 | 45 | foreach ($this->getFqcnList() as $fqcn) { |
46 | 46 | if ($fqcn::getProviderId() === $name) { |
47 | 47 | $instance = \OCP\Server::get($fqcn); |
48 | 48 | $instance->setAppConfig(\OCP\Server::get(\OCP\IAppConfig::class)); |
49 | - $this->instances[$name] = $instance; |
|
49 | + $this->instances[ $name ] = $instance; |
|
50 | 50 | return $instance; |
51 | 51 | } |
52 | 52 | } |
@@ -25,16 +25,16 @@ discard block |
||
25 | 25 | ) { |
26 | 26 | parent::__construct('twofactorauth:gateway:test'); |
27 | 27 | |
28 | - $ids = []; |
|
28 | + $ids = [ ]; |
|
29 | 29 | $fqcn = $this->gatewayFactory->getFqcnList(); |
30 | 30 | foreach ($fqcn as $fqcn) { |
31 | - $ids[] = $fqcn::getProviderId(); |
|
31 | + $ids[ ] = $fqcn::getProviderId(); |
|
32 | 32 | } |
33 | 33 | |
34 | 34 | $this->addArgument( |
35 | 35 | 'gateway', |
36 | 36 | InputArgument::REQUIRED, |
37 | - 'The name of the gateway: ' . implode(', ', $ids) |
|
37 | + 'The name of the gateway: '.implode(', ', $ids) |
|
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 | } |
@@ -33,8 +33,8 @@ discard block |
||
33 | 33 | 'name' => 'Signal', |
34 | 34 | 'instructions' => 'The gateway can send authentication to your Signal mobile and deskop app.', |
35 | 35 | 'fields' => [ |
36 | - ['field' => 'url', 'prompt' => 'Please enter the URL of the Signal gateway (leave blank to use default):', 'default' => 'http://localhost:5000'], |
|
37 | - ['field' => 'account', 'prompt' => 'Please enter the account (phone-number) of the sending signal account (leave blank if a phone-number is not required):', 'default' => ''], |
|
36 | + [ 'field' => 'url', 'prompt' => 'Please enter the URL of the Signal gateway (leave blank to use default):', 'default' => 'http://localhost:5000' ], |
|
37 | + [ 'field' => 'account', 'prompt' => 'Please enter the account (phone-number) of the sending signal account (leave blank if a phone-number is not required):', 'default' => '' ], |
|
38 | 38 | ], |
39 | 39 | ]; |
40 | 40 | public const ACCOUNT_UNNECESSARY = 'unneccessary'; |
@@ -48,20 +48,20 @@ discard block |
||
48 | 48 | parent::__construct($appConfig); |
49 | 49 | } |
50 | 50 | |
51 | - #[\Override] |
|
52 | - public function send(string $identifier, string $message, array $extra = []): void { |
|
51 | + #[\Override ] |
|
52 | + public function send(string $identifier, string $message, array $extra = [ ]): void { |
|
53 | 53 | $client = $this->clientService->newClient(); |
54 | 54 | // determine type of gateway |
55 | 55 | |
56 | 56 | // test for native signal-cli JSON RPC. |
57 | 57 | $response = $client->post( |
58 | - $this->getUrl() . '/api/v1/rpc', |
|
58 | + $this->getUrl().'/api/v1/rpc', |
|
59 | 59 | [ |
60 | 60 | 'http_errors' => false, |
61 | 61 | 'json' => [ |
62 | 62 | 'jsonrpc' => '2.0', |
63 | 63 | 'method' => 'version', |
64 | - 'id' => 'version_' . $this->timeFactory->getTime(), |
|
64 | + 'id' => 'version_'.$this->timeFactory->getTime(), |
|
65 | 65 | ], |
66 | 66 | ]); |
67 | 67 | if ($response->getStatusCode() === 200 || $response->getStatusCode() === 201) { |
@@ -77,12 +77,12 @@ discard block |
||
77 | 77 | 'account' => $this->getAccount(), // mandatory for native RPC API |
78 | 78 | ]; |
79 | 79 | $response = $response = $client->post( |
80 | - $this->getUrl() . '/api/v1/rpc', |
|
80 | + $this->getUrl().'/api/v1/rpc', |
|
81 | 81 | [ |
82 | 82 | 'json' => [ |
83 | 83 | 'jsonrpc' => '2.0', |
84 | 84 | 'method' => 'send', |
85 | - 'id' => 'code_' . $this->timeFactory->getTime(), |
|
85 | + 'id' => 'code_'.$this->timeFactory->getTime(), |
|
86 | 86 | 'params' => $params, |
87 | 87 | ], |
88 | 88 | ]); |
@@ -90,12 +90,12 @@ discard block |
||
90 | 90 | $json = json_decode($body, true); |
91 | 91 | $statusCode = $response->getStatusCode(); |
92 | 92 | // The 201 "created" is probably a bug. |
93 | - if ($statusCode < 200 || $statusCode >= 300 || is_null($json) || !is_array($json) || ($json['jsonrpc'] ?? null) != '2.0' || !isset($json['result']['timestamp'])) { |
|
93 | + if ($statusCode < 200 || $statusCode >= 300 || is_null($json) || !is_array($json) || ($json[ 'jsonrpc' ] ?? null) != '2.0' || !isset($json[ 'result' ][ 'timestamp' ])) { |
|
94 | 94 | throw new MessageTransmissionException("error reported by Signal gateway, status=$statusCode, body=$body}"); |
95 | 95 | } |
96 | 96 | } else { |
97 | 97 | // Try gateway in the style of https://gitlab.com/morph027/signal-cli-dbus-rest-api |
98 | - $response = $client->get($this->getUrl() . '/v1/about'); |
|
98 | + $response = $client->get($this->getUrl().'/v1/about'); |
|
99 | 99 | if ($response->getStatusCode() === 200) { |
100 | 100 | // Not so "ńew style" gateway, see |
101 | 101 | // https://gitlab.com/morph027/signal-cli-dbus-rest-api |
@@ -103,7 +103,7 @@ discard block |
||
103 | 103 | // https://github.com/bbernhard/signal-cli-rest-api |
104 | 104 | $body = $response->getBody(); |
105 | 105 | $json = json_decode($body, true); |
106 | - $versions = $json['versions'] ?? []; |
|
106 | + $versions = $json[ 'versions' ] ?? [ ]; |
|
107 | 107 | if (is_array($versions) && in_array('v2', $versions)) { |
108 | 108 | $json = [ |
109 | 109 | 'recipients' => $identifier, |
@@ -111,17 +111,17 @@ discard block |
||
111 | 111 | ]; |
112 | 112 | $account = $this->getAccount(); |
113 | 113 | if ($account != self::ACCOUNT_UNNECESSARY) { |
114 | - $json['account'] = $account; |
|
114 | + $json[ 'account' ] = $account; |
|
115 | 115 | } |
116 | 116 | $response = $client->post( |
117 | - $this->getUrl() . '/v2/send', |
|
117 | + $this->getUrl().'/v2/send', |
|
118 | 118 | [ |
119 | 119 | 'json' => $json, |
120 | 120 | ] |
121 | 121 | ); |
122 | 122 | } else { |
123 | 123 | $response = $client->post( |
124 | - $this->getUrl() . '/v1/send/' . $identifier, |
|
124 | + $this->getUrl().'/v1/send/'.$identifier, |
|
125 | 125 | [ |
126 | 126 | 'json' => [ 'message' => $message ], |
127 | 127 | ] |
@@ -130,13 +130,13 @@ discard block |
||
130 | 130 | $body = (string)$response->getBody(); |
131 | 131 | $json = json_decode($body, true); |
132 | 132 | $status = $response->getStatusCode(); |
133 | - if ($status !== 201 || is_null($json) || !is_array($json) || !isset($json['timestamp'])) { |
|
133 | + if ($status !== 201 || is_null($json) || !is_array($json) || !isset($json[ 'timestamp' ])) { |
|
134 | 134 | throw new MessageTransmissionException("error reported by Signal gateway, status=$status, body=$body}"); |
135 | 135 | } |
136 | 136 | } else { |
137 | 137 | // Try old deprecated gateway https://gitlab.com/morph027/signal-web-gateway |
138 | 138 | $response = $client->post( |
139 | - $this->getUrl() . '/v1/send/' . $identifier, |
|
139 | + $this->getUrl().'/v1/send/'.$identifier, |
|
140 | 140 | [ |
141 | 141 | 'body' => [ |
142 | 142 | 'to' => $identifier, |
@@ -149,23 +149,23 @@ discard block |
||
149 | 149 | $json = json_decode($body, true); |
150 | 150 | |
151 | 151 | $status = $response->getStatusCode(); |
152 | - if ($status !== 200 || is_null($json) || !is_array($json) || !isset($json['success']) || $json['success'] !== true) { |
|
152 | + if ($status !== 200 || is_null($json) || !is_array($json) || !isset($json[ 'success' ]) || $json[ 'success' ] !== true) { |
|
153 | 153 | throw new MessageTransmissionException("error reported by Signal gateway, status=$status, body=$body}"); |
154 | 154 | } |
155 | 155 | } |
156 | 156 | } |
157 | 157 | } |
158 | 158 | |
159 | - #[\Override] |
|
159 | + #[\Override ] |
|
160 | 160 | public function cliConfigure(InputInterface $input, OutputInterface $output): int { |
161 | 161 | $helper = new QuestionHelper(); |
162 | - $urlQuestion = new Question(self::SCHEMA['fields'][0]['prompt'], self::SCHEMA['fields'][0]['default']); |
|
162 | + $urlQuestion = new Question(self::SCHEMA[ 'fields' ][ 0 ][ 'prompt' ], self::SCHEMA[ 'fields' ][ 0 ][ 'default' ]); |
|
163 | 163 | $url = $helper->ask($input, $output, $urlQuestion); |
164 | 164 | $output->writeln("Using $url."); |
165 | 165 | |
166 | 166 | $this->setUrl($url); |
167 | 167 | |
168 | - $accountQuestion = new Question(self::SCHEMA['fields'][1]['prompt'], self::SCHEMA['fields'][1]['default']); |
|
168 | + $accountQuestion = new Question(self::SCHEMA[ 'fields' ][ 1 ][ 'prompt' ], self::SCHEMA[ 'fields' ][ 1 ][ 'default' ]); |
|
169 | 169 | $account = $helper->ask($input, $output, $accountQuestion); |
170 | 170 | if ($account == '') { |
171 | 171 | $account = self::ACCOUNT_UNNECESSARY; |
@@ -15,38 +15,38 @@ |
||
15 | 15 | |
16 | 16 | class Factory extends AFactory { |
17 | 17 | /** @var array<string,IProvider> */ |
18 | - protected array $instances = []; |
|
19 | - #[\Override] |
|
18 | + protected array $instances = [ ]; |
|
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 IProvider::class; |
32 | 32 | } |
33 | 33 | |
34 | - #[\Override] |
|
34 | + #[\Override ] |
|
35 | 35 | public function isValid(string $fqcn): bool { |
36 | 36 | return defined("$fqcn::SCHEMA") |
37 | 37 | && is_array($fqcn::SCHEMA); |
38 | 38 | } |
39 | 39 | |
40 | - #[\Override] |
|
40 | + #[\Override ] |
|
41 | 41 | public function get(string $name): IProvider { |
42 | - if (isset($this->instances[$name])) { |
|
43 | - return $this->instances[$name]; |
|
42 | + if (isset($this->instances[ $name ])) { |
|
43 | + return $this->instances[ $name ]; |
|
44 | 44 | } |
45 | 45 | foreach ($this->getFqcnList() as $fqcn) { |
46 | 46 | if ($fqcn::getProviderId() === $name) { |
47 | 47 | $instance = \OCP\Server::get($fqcn); |
48 | 48 | $instance->setAppConfig(\OCP\Server::get(\OCP\IAppConfig::class)); |
49 | - $this->instances[$name] = $instance; |
|
49 | + $this->instances[ $name ] = $instance; |
|
50 | 50 | return $instance; |
51 | 51 | } |
52 | 52 | } |
@@ -37,7 +37,7 @@ discard block |
||
37 | 37 | <p>Enter this ID to receive your verification code below.</p> |
38 | 38 | HTML, |
39 | 39 | 'fields' => [ |
40 | - ['field' => 'bot_token', 'prompt' => 'Please enter your Telegram bot token:'], |
|
40 | + [ 'field' => 'bot_token', 'prompt' => 'Please enter your Telegram bot token:' ], |
|
41 | 41 | ], |
42 | 42 | ]; |
43 | 43 | public function __construct( |
@@ -46,10 +46,10 @@ discard block |
||
46 | 46 | ) { |
47 | 47 | } |
48 | 48 | |
49 | - #[\Override] |
|
50 | - public function send(string $identifier, string $message, array $extra = []): void { |
|
49 | + #[\Override ] |
|
50 | + public function send(string $identifier, string $message, array $extra = [ ]): void { |
|
51 | 51 | if (empty($message)) { |
52 | - $message = $this->l10n->t('`%s` is your Nextcloud verification code.', [$extra['code']]); |
|
52 | + $message = $this->l10n->t('`%s` is your Nextcloud verification code.', [ $extra[ 'code' ] ]); |
|
53 | 53 | } |
54 | 54 | $this->logger->debug("sending telegram message to $identifier, message: $message"); |
55 | 55 | $botToken = $this->getBotToken(); |
@@ -68,10 +68,10 @@ discard block |
||
68 | 68 | $this->logger->debug("telegram message to chat $identifier sent"); |
69 | 69 | } |
70 | 70 | |
71 | - #[\Override] |
|
71 | + #[\Override ] |
|
72 | 72 | public function cliConfigure(InputInterface $input, OutputInterface $output): int { |
73 | 73 | $helper = new QuestionHelper(); |
74 | - $tokenQuestion = new Question(self::SCHEMA['fields'][0]['prompt'] . ' '); |
|
74 | + $tokenQuestion = new Question(self::SCHEMA[ 'fields' ][ 0 ][ 'prompt' ].' '); |
|
75 | 75 | $token = $helper->ask($input, $output, $tokenQuestion); |
76 | 76 | $this->setBotToken($token); |
77 | 77 | $output->writeln("Using $token."); |
@@ -15,7 +15,7 @@ |
||
15 | 15 | use Symfony\Component\Console\Output\OutputInterface; |
16 | 16 | |
17 | 17 | interface IProvider { |
18 | - public const SCHEMA = []; |
|
18 | + public const SCHEMA = [ ]; |
|
19 | 19 | |
20 | 20 | /** |
21 | 21 | * @param string $identifier |
@@ -22,32 +22,32 @@ |
||
22 | 22 | /** |
23 | 23 | * @throws MessageTransmissionException |
24 | 24 | */ |
25 | - #[\Override] |
|
25 | + #[\Override ] |
|
26 | 26 | abstract public function send(string $identifier, string $message); |
27 | 27 | |
28 | - #[\Override] |
|
28 | + #[\Override ] |
|
29 | 29 | public function setAppConfig(IAppConfig $appConfig): void { |
30 | 30 | $this->appConfig = $appConfig; |
31 | 31 | } |
32 | 32 | |
33 | - #[\Override] |
|
33 | + #[\Override ] |
|
34 | 34 | public static function idOverride(): ?string { |
35 | 35 | return null; |
36 | 36 | } |
37 | 37 | |
38 | - #[\Override] |
|
38 | + #[\Override ] |
|
39 | 39 | public static function getProviderId(): string { |
40 | - if (static::SCHEMA['id'] ?? null) { |
|
41 | - return static::SCHEMA['id']; |
|
40 | + if (static::SCHEMA[ 'id' ] ?? null) { |
|
41 | + return static::SCHEMA[ 'id' ]; |
|
42 | 42 | } |
43 | 43 | $id = self::getIdFromProviderFqcn(static::class); |
44 | 44 | if ($id === null) { |
45 | - throw new \LogicException('Cannot derive gateway id from FQCN: ' . static::class); |
|
45 | + throw new \LogicException('Cannot derive gateway id from FQCN: '.static::class); |
|
46 | 46 | } |
47 | 47 | return $id; |
48 | 48 | } |
49 | 49 | |
50 | - #[\Override] |
|
50 | + #[\Override ] |
|
51 | 51 | abstract public function cliConfigure(InputInterface $input, OutputInterface $output): int; |
52 | 52 | |
53 | 53 | private static function getIdFromProviderFqcn(string $fqcn): ?string { |
@@ -14,9 +14,9 @@ discard block |
||
14 | 14 | |
15 | 15 | abstract class AFactory { |
16 | 16 | /** @var array<string,AGateway|AProvider|ISMSProvider|ITelegramProvider> */ |
17 | - protected array $instances = []; |
|
17 | + protected array $instances = [ ]; |
|
18 | 18 | /** @var array<string> */ |
19 | - protected array $fqcn = []; |
|
19 | + protected array $fqcn = [ ]; |
|
20 | 20 | |
21 | 21 | abstract protected function getPrefix(): string; |
22 | 22 | abstract protected function getSuffix(): string; |
@@ -29,8 +29,8 @@ discard block |
||
29 | 29 | /** @return AGateway|AProvider|ISMSProvider|ITelegramProvider */ |
30 | 30 | public function get(string $name): object { |
31 | 31 | $needle = strtolower($name); |
32 | - if (isset($this->instances[$needle])) { |
|
33 | - return $this->instances[$needle]; |
|
32 | + if (isset($this->instances[ $needle ])) { |
|
33 | + return $this->instances[ $needle ]; |
|
34 | 34 | } |
35 | 35 | |
36 | 36 | foreach ($this->getFqcnList() as $fqcn) { |
@@ -39,7 +39,7 @@ discard block |
||
39 | 39 | continue; |
40 | 40 | } |
41 | 41 | $instance = \OCP\Server::get($fqcn); |
42 | - $this->instances[$needle] = $instance; |
|
42 | + $this->instances[ $needle ] = $instance; |
|
43 | 43 | return $instance; |
44 | 44 | } |
45 | 45 | |
@@ -52,7 +52,7 @@ discard block |
||
52 | 52 | return $this->fqcn; |
53 | 53 | } |
54 | 54 | |
55 | - $loader = require __DIR__ . '/../../vendor/autoload.php'; |
|
55 | + $loader = require __DIR__.'/../../vendor/autoload.php'; |
|
56 | 56 | foreach ($loader->getClassMap() as $fqcn => $_) { |
57 | 57 | $type = $this->typeFrom($fqcn); |
58 | 58 | if ($type === null) { |
@@ -64,7 +64,7 @@ discard block |
||
64 | 64 | if (!$this->isValid($fqcn)) { |
65 | 65 | continue; |
66 | 66 | } |
67 | - $this->fqcn[] = $fqcn; |
|
67 | + $this->fqcn[ ] = $fqcn; |
|
68 | 68 | } |
69 | 69 | return $this->fqcn; |
70 | 70 | } |
@@ -79,7 +79,7 @@ discard block |
||
79 | 79 | return null; |
80 | 80 | } |
81 | 81 | $type = substr($fqcn, strlen($prefix)); |
82 | - $type = substr($type, 0, -strlen('\\' . $suffix)); |
|
82 | + $type = substr($type, 0, -strlen('\\'.$suffix)); |
|
83 | 83 | if (strpos($type, '\\') !== false || $type === '') { |
84 | 84 | return null; |
85 | 85 | } |