@@ -20,7 +20,7 @@ |
||
| 20 | 20 | * |
| 21 | 21 | * @var FieldDefinition[] |
| 22 | 22 | */ |
| 23 | - public array $fields = [], |
|
| 23 | + public array $fields = [ ], |
|
| 24 | 24 | ) { |
| 25 | 25 | } |
| 26 | 26 | } |
@@ -65,24 +65,24 @@ discard block |
||
| 65 | 65 | ); |
| 66 | 66 | } |
| 67 | 67 | |
| 68 | - #[\Override] |
|
| 69 | - public function send(string $identifier, string $message, array $extra = []): void { |
|
| 68 | + #[\Override ] |
|
| 69 | + public function send(string $identifier, string $message, array $extra = [ ]): void { |
|
| 70 | 70 | $this->logger->debug("sending whatsapp message to $identifier, message: $message"); |
| 71 | 71 | |
| 72 | 72 | $response = $this->getSessionStatus(); |
| 73 | 73 | if ($response !== 'CONNECTED') { |
| 74 | - throw new MessageTransmissionException('WhatsApp session is not connected. Current status: ' . $response); |
|
| 74 | + throw new MessageTransmissionException('WhatsApp session is not connected. Current status: '.$response); |
|
| 75 | 75 | } |
| 76 | 76 | |
| 77 | 77 | $chatId = $this->getChatIdFromPhoneNumber($identifier); |
| 78 | 78 | |
| 79 | 79 | try { |
| 80 | - $response = $this->client->post($this->getBaseUrl() . '/client/sendMessage/' . $this->instanceId, [ |
|
| 80 | + $response = $this->client->post($this->getBaseUrl().'/client/sendMessage/'.$this->instanceId, [ |
|
| 81 | 81 | 'json' => [ |
| 82 | 82 | 'chatId' => $chatId, |
| 83 | 83 | 'contentType' => 'string', |
| 84 | 84 | 'content' => $message, |
| 85 | - 'options' => [], |
|
| 85 | + 'options' => [ ], |
|
| 86 | 86 | ], |
| 87 | 87 | ]); |
| 88 | 88 | } catch (\Exception $e) { |
@@ -96,10 +96,10 @@ discard block |
||
| 96 | 96 | $this->logger->debug("whatsapp message to chat $identifier sent"); |
| 97 | 97 | } |
| 98 | 98 | |
| 99 | - #[\Override] |
|
| 99 | + #[\Override ] |
|
| 100 | 100 | public function cliConfigure(InputInterface $input, OutputInterface $output): int { |
| 101 | 101 | $helper = new QuestionHelper(); |
| 102 | - $baseUrlQuestion = new Question($this->getSettings()->fields[0]->prompt . ' '); |
|
| 102 | + $baseUrlQuestion = new Question($this->getSettings()->fields[ 0 ]->prompt.' '); |
|
| 103 | 103 | $this->lazyBaseUrl = $helper->ask($input, $output, $baseUrlQuestion); |
| 104 | 104 | $this->lazyBaseUrl = rtrim($this->lazyBaseUrl, '/'); |
| 105 | 105 | |
@@ -108,7 +108,7 @@ discard block |
||
| 108 | 108 | return 1; |
| 109 | 109 | } |
| 110 | 110 | } catch (\Exception $e) { |
| 111 | - $output->writeln('<error>' . $e->getMessage() . '</error>'); |
|
| 111 | + $output->writeln('<error>'.$e->getMessage().'</error>'); |
|
| 112 | 112 | } |
| 113 | 113 | |
| 114 | 114 | $this->setBaseUrl($this->lazyBaseUrl); |
@@ -118,23 +118,23 @@ discard block |
||
| 118 | 118 | |
| 119 | 119 | private function getChatIdFromPhoneNumber(string $phoneNumber): string { |
| 120 | 120 | try { |
| 121 | - $response = $this->client->post($this->getBaseUrl() . '/client/getNumberId/' . $this->instanceId, [ |
|
| 121 | + $response = $this->client->post($this->getBaseUrl().'/client/getNumberId/'.$this->instanceId, [ |
|
| 122 | 122 | 'json' => [ |
| 123 | 123 | 'number' => preg_replace('/\D/', '', $phoneNumber), |
| 124 | 124 | ], |
| 125 | 125 | ]); |
| 126 | 126 | $json = $response->getBody(); |
| 127 | 127 | $data = json_decode($json, true); |
| 128 | - if (empty($data['result'])) { |
|
| 128 | + if (empty($data[ 'result' ])) { |
|
| 129 | 129 | throw new MessageTransmissionException('The phone number is not registered on WhatsApp.'); |
| 130 | 130 | } |
| 131 | - return $data['result']['_serialized']; |
|
| 131 | + return $data[ 'result' ][ '_serialized' ]; |
|
| 132 | 132 | } catch (ServerException $e) { |
| 133 | 133 | $content = $e->getResponse()?->getBody()?->getContents(); |
| 134 | 134 | if ($content === null) { |
| 135 | 135 | throw new MessageTransmissionException('Unknown error'); |
| 136 | 136 | } |
| 137 | - $errorMessage = json_decode($content, true)['error'] ?? 'Unknown error'; |
|
| 137 | + $errorMessage = json_decode($content, true)[ 'error' ] ?? 'Unknown error'; |
|
| 138 | 138 | throw new MessageTransmissionException($errorMessage); |
| 139 | 139 | } |
| 140 | 140 | } |
@@ -148,7 +148,7 @@ discard block |
||
| 148 | 148 | } |
| 149 | 149 | |
| 150 | 150 | /** @var string */ |
| 151 | - $this->lazyBaseUrl = $this->__call(__FUNCTION__, []); |
|
| 151 | + $this->lazyBaseUrl = $this->__call(__FUNCTION__, [ ]); |
|
| 152 | 152 | return $this->lazyBaseUrl; |
| 153 | 153 | } |
| 154 | 154 | |
@@ -164,19 +164,19 @@ discard block |
||
| 164 | 164 | |
| 165 | 165 | $last = null; |
| 166 | 166 | while (true) { |
| 167 | - $response = $this->client->get($this->getBaseUrl() . '/session/qr/' . $this->instanceId); |
|
| 167 | + $response = $this->client->get($this->getBaseUrl().'/session/qr/'.$this->instanceId); |
|
| 168 | 168 | $json = $response->getBody(); |
| 169 | 169 | $data = json_decode($json, true); |
| 170 | - if ($data['success'] === false) { |
|
| 171 | - if ($data['message'] === 'qr code not ready or already scanned') { |
|
| 170 | + if ($data[ 'success' ] === false) { |
|
| 171 | + if ($data[ 'message' ] === 'qr code not ready or already scanned') { |
|
| 172 | 172 | $output->writeln('<error>Session not connected yet, waiting...</error>'); |
| 173 | 173 | sleep(2); |
| 174 | 174 | continue; |
| 175 | 175 | } |
| 176 | - $output->writeln('<error>' . $data['message'] . '</error>'); |
|
| 176 | + $output->writeln('<error>'.$data[ 'message' ].'</error>'); |
|
| 177 | 177 | return 1; |
| 178 | 178 | } |
| 179 | - $qrCodeContent = $data['qr']; |
|
| 179 | + $qrCodeContent = $data[ 'qr' ]; |
|
| 180 | 180 | |
| 181 | 181 | if ($qrCodeContent !== $last) { |
| 182 | 182 | $last = $qrCodeContent; |
@@ -198,7 +198,7 @@ discard block |
||
| 198 | 198 | } |
| 199 | 199 | |
| 200 | 200 | private function getSessionStatus(): string { |
| 201 | - $endpoint = $this->getBaseUrl() . '/session/status/' . $this->instanceId; |
|
| 201 | + $endpoint = $this->getBaseUrl().'/session/status/'.$this->instanceId; |
|
| 202 | 202 | |
| 203 | 203 | try { |
| 204 | 204 | $response = $this->client->get($endpoint); |
@@ -209,18 +209,18 @@ discard block |
||
| 209 | 209 | return 'not_connected'; |
| 210 | 210 | } |
| 211 | 211 | |
| 212 | - if (($responseData['success'] ?? null) === false) { |
|
| 213 | - $msg = $responseData['message'] ?? ''; |
|
| 214 | - return in_array($msg, ['session_not_found', 'session_not_connected'], true) |
|
| 212 | + if (($responseData[ 'success' ] ?? null) === false) { |
|
| 213 | + $msg = $responseData[ 'message' ] ?? ''; |
|
| 214 | + return in_array($msg, [ 'session_not_found', 'session_not_connected' ], true) |
|
| 215 | 215 | ? $msg |
| 216 | 216 | : 'not_connected'; |
| 217 | 217 | } |
| 218 | 218 | |
| 219 | - return (string)($responseData['state'] ?? 'not_connected'); |
|
| 219 | + return (string)($responseData[ 'state' ] ?? 'not_connected'); |
|
| 220 | 220 | } catch (ClientException $e) { |
| 221 | 221 | return 'not_connected'; |
| 222 | 222 | } catch (RequestException $e) { |
| 223 | - $this->logger->info('Could not connect to ' . $endpoint, ['exception' => $e]); |
|
| 223 | + $this->logger->info('Could not connect to '.$endpoint, [ 'exception' => $e ]); |
|
| 224 | 224 | throw new \Exception('Could not connect to the WhatsApp API. Please check the URL.', 1); |
| 225 | 225 | } |
| 226 | 226 | } |
@@ -239,13 +239,13 @@ discard block |
||
| 239 | 239 | } |
| 240 | 240 | |
| 241 | 241 | private function getSessionStart(): int { |
| 242 | - $endpoint = $this->getBaseUrl() . '/session/start/' . $this->instanceId; |
|
| 242 | + $endpoint = $this->getBaseUrl().'/session/start/'.$this->instanceId; |
|
| 243 | 243 | try { |
| 244 | 244 | $this->client->get($endpoint); |
| 245 | 245 | } catch (ClientException $e) { |
| 246 | 246 | return 1; |
| 247 | 247 | } catch (RequestException $e) { |
| 248 | - $this->logger->info('Could not connect to ' . $endpoint, [ |
|
| 248 | + $this->logger->info('Could not connect to '.$endpoint, [ |
|
| 249 | 249 | 'exception' => $e, |
| 250 | 250 | ]); |
| 251 | 251 | throw new \Exception('Could not connect to the WhatsApp API. Please check the URL.', 1); |
@@ -11,17 +11,17 @@ |
||
| 11 | 11 | |
| 12 | 12 | /** @extends AFactory<AProvider> */ |
| 13 | 13 | class Factory extends AFactory { |
| 14 | - #[\Override] |
|
| 14 | + #[\Override ] |
|
| 15 | 15 | protected function getPrefix(): string { |
| 16 | 16 | return 'OCA\\TwoFactorGateway\\Provider\\Channel\\'; |
| 17 | 17 | } |
| 18 | 18 | |
| 19 | - #[\Override] |
|
| 19 | + #[\Override ] |
|
| 20 | 20 | protected function getSuffix(): string { |
| 21 | 21 | return 'Provider'; |
| 22 | 22 | } |
| 23 | 23 | |
| 24 | - #[\Override] |
|
| 24 | + #[\Override ] |
|
| 25 | 25 | protected function getBaseClass(): string { |
| 26 | 26 | return AProvider::class; |
| 27 | 27 | } |
@@ -13,17 +13,17 @@ |
||
| 13 | 13 | |
| 14 | 14 | /** @extends AFactory<AProvider> */ |
| 15 | 15 | class Factory extends AFactory { |
| 16 | - #[\Override] |
|
| 16 | + #[\Override ] |
|
| 17 | 17 | protected function getPrefix(): string { |
| 18 | 18 | return 'OCA\\TwoFactorGateway\\Provider\\Channel\\'; |
| 19 | 19 | } |
| 20 | 20 | |
| 21 | - #[\Override] |
|
| 21 | + #[\Override ] |
|
| 22 | 22 | protected function getSuffix(): string { |
| 23 | 23 | return 'Gateway'; |
| 24 | 24 | } |
| 25 | 25 | |
| 26 | - #[\Override] |
|
| 26 | + #[\Override ] |
|
| 27 | 27 | protected function getBaseClass(): string { |
| 28 | 28 | return IGateway::class; |
| 29 | 29 | } |
@@ -72,8 +72,8 @@ discard block |
||
| 72 | 72 | ); |
| 73 | 73 | } |
| 74 | 74 | |
| 75 | - #[\Override] |
|
| 76 | - public function send(string $identifier, string $message, array $extra = []): void { |
|
| 75 | + #[\Override ] |
|
| 76 | + public function send(string $identifier, string $message, array $extra = [ ]): void { |
|
| 77 | 77 | $this->logger->debug("sending xmpp message to $identifier, message: $message"); |
| 78 | 78 | |
| 79 | 79 | $sender = $this->getSender(); |
@@ -81,7 +81,7 @@ discard block |
||
| 81 | 81 | $server = $this->getServer(); |
| 82 | 82 | $method = $this->getMethod(); |
| 83 | 83 | $user = $this->getUsername(); |
| 84 | - $url = $server . $identifier; |
|
| 84 | + $url = $server.$identifier; |
|
| 85 | 85 | |
| 86 | 86 | if ($method === '1') { |
| 87 | 87 | $from = $user; |
@@ -97,8 +97,8 @@ discard block |
||
| 97 | 97 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); |
| 98 | 98 | curl_setopt($ch, CURLOPT_POST, 1); |
| 99 | 99 | curl_setopt($ch, CURLOPT_POSTFIELDS, $message); |
| 100 | - curl_setopt($ch, CURLOPT_USERPWD, $from . ':' . $password); |
|
| 101 | - curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: text/plain']); |
|
| 100 | + curl_setopt($ch, CURLOPT_USERPWD, $from.':'.$password); |
|
| 101 | + curl_setopt($ch, CURLOPT_HTTPHEADER, [ 'Content-Type: text/plain' ]); |
|
| 102 | 102 | $result = curl_exec($ch); |
| 103 | 103 | curl_close($ch); |
| 104 | 104 | $this->logger->debug("XMPP message to $identifier sent"); |
@@ -107,30 +107,30 @@ discard block |
||
| 107 | 107 | } |
| 108 | 108 | } |
| 109 | 109 | |
| 110 | - #[\Override] |
|
| 110 | + #[\Override ] |
|
| 111 | 111 | public function cliConfigure(InputInterface $input, OutputInterface $output): int { |
| 112 | 112 | $helper = new QuestionHelper(); |
| 113 | 113 | $settings = $this->getSettings(); |
| 114 | - $fields = []; |
|
| 114 | + $fields = [ ]; |
|
| 115 | 115 | foreach ($settings->fields as $field) { |
| 116 | - $fields[$field->field] = $field; |
|
| 116 | + $fields[ $field->field ] = $field; |
|
| 117 | 117 | } |
| 118 | 118 | $sender = ''; |
| 119 | 119 | while (empty($sender) or substr_count($sender, '@') !== 1) { |
| 120 | - $senderQuestion = new Question($fields['sender']->prompt . ' '); |
|
| 120 | + $senderQuestion = new Question($fields[ 'sender' ]->prompt.' '); |
|
| 121 | 121 | $sender = $helper->ask($input, $output, $senderQuestion); |
| 122 | 122 | if (empty($sender)) { |
| 123 | 123 | $output->writeln('XMPP-JID must not be empty!'); |
| 124 | 124 | } elseif (substr_count($sender, '@') !== 1) { |
| 125 | 125 | $output->writeln('XMPP-JID not valid!'); |
| 126 | 126 | } else { |
| 127 | - $username = explode('@', $sender)[0]; |
|
| 127 | + $username = explode('@', $sender)[ 0 ]; |
|
| 128 | 128 | } |
| 129 | 129 | } |
| 130 | 130 | $output->writeln("Using $sender as XMPP-JID.\nUsing $username as username."); |
| 131 | 131 | $password = ''; |
| 132 | 132 | while (empty($password)) { |
| 133 | - $passwordQuestion = new Question($fields['password']->prompt . ' '); |
|
| 133 | + $passwordQuestion = new Question($fields[ 'password' ]->prompt.' '); |
|
| 134 | 134 | $password = $helper->ask($input, $output, $passwordQuestion); |
| 135 | 135 | if (empty($password)) { |
| 136 | 136 | $output->writeln('Password must not be empty!'); |
@@ -139,7 +139,7 @@ discard block |
||
| 139 | 139 | $output->writeln('Password accepted.'); |
| 140 | 140 | $server = ''; |
| 141 | 141 | while (empty($server)) { |
| 142 | - $serverQuestion = new Question($fields['server']->prompt . ' '); |
|
| 142 | + $serverQuestion = new Question($fields[ 'server' ]->prompt.' '); |
|
| 143 | 143 | $server = $helper->ask($input, $output, $serverQuestion); |
| 144 | 144 | if (empty($server)) { |
| 145 | 145 | $output->writeln('API path must not be empty!'); |
@@ -148,7 +148,7 @@ discard block |
||
| 148 | 148 | $output->writeln("Using $server as full URL to access REST/HTTP API."); |
| 149 | 149 | $method = 0; |
| 150 | 150 | while (intval($method) < 1 or intval($method) > 2) { |
| 151 | - echo $fields['method']->prompt . PHP_EOL; |
|
| 151 | + echo $fields[ 'method' ]->prompt.PHP_EOL; |
|
| 152 | 152 | echo "(1) prosody with mod_rest\n"; |
| 153 | 153 | echo "(2) prosody with mod_post_msg\n"; |
| 154 | 154 | $methodQuestion = new Question('Your choice: '); |
@@ -60,20 +60,20 @@ discard block |
||
| 60 | 60 | ); |
| 61 | 61 | } |
| 62 | 62 | |
| 63 | - #[\Override] |
|
| 64 | - public function send(string $identifier, string $message, array $extra = []): void { |
|
| 63 | + #[\Override ] |
|
| 64 | + public function send(string $identifier, string $message, array $extra = [ ]): void { |
|
| 65 | 65 | $client = $this->clientService->newClient(); |
| 66 | 66 | // determine type of gateway |
| 67 | 67 | |
| 68 | 68 | // test for native signal-cli JSON RPC. |
| 69 | 69 | $response = $client->post( |
| 70 | - $this->getUrl() . '/api/v1/rpc', |
|
| 70 | + $this->getUrl().'/api/v1/rpc', |
|
| 71 | 71 | [ |
| 72 | 72 | 'http_errors' => false, |
| 73 | 73 | 'json' => [ |
| 74 | 74 | 'jsonrpc' => '2.0', |
| 75 | 75 | 'method' => 'version', |
| 76 | - 'id' => 'version_' . $this->timeFactory->getTime(), |
|
| 76 | + 'id' => 'version_'.$this->timeFactory->getTime(), |
|
| 77 | 77 | ], |
| 78 | 78 | ]); |
| 79 | 79 | if ($response->getStatusCode() === 200 || $response->getStatusCode() === 201) { |
@@ -89,12 +89,12 @@ discard block |
||
| 89 | 89 | 'account' => $this->getAccount(), // mandatory for native RPC API |
| 90 | 90 | ]; |
| 91 | 91 | $response = $response = $client->post( |
| 92 | - $this->getUrl() . '/api/v1/rpc', |
|
| 92 | + $this->getUrl().'/api/v1/rpc', |
|
| 93 | 93 | [ |
| 94 | 94 | 'json' => [ |
| 95 | 95 | 'jsonrpc' => '2.0', |
| 96 | 96 | 'method' => 'send', |
| 97 | - 'id' => 'code_' . $this->timeFactory->getTime(), |
|
| 97 | + 'id' => 'code_'.$this->timeFactory->getTime(), |
|
| 98 | 98 | 'params' => $params, |
| 99 | 99 | ], |
| 100 | 100 | ]); |
@@ -102,12 +102,12 @@ discard block |
||
| 102 | 102 | $json = json_decode($body, true); |
| 103 | 103 | $statusCode = $response->getStatusCode(); |
| 104 | 104 | // The 201 "created" is probably a bug. |
| 105 | - if ($statusCode < 200 || $statusCode >= 300 || is_null($json) || !is_array($json) || ($json['jsonrpc'] ?? null) != '2.0' || !isset($json['result']['timestamp'])) { |
|
| 105 | + if ($statusCode < 200 || $statusCode >= 300 || is_null($json) || !is_array($json) || ($json[ 'jsonrpc' ] ?? null) != '2.0' || !isset($json[ 'result' ][ 'timestamp' ])) { |
|
| 106 | 106 | throw new MessageTransmissionException("error reported by Signal gateway, status=$statusCode, body=$body}"); |
| 107 | 107 | } |
| 108 | 108 | } else { |
| 109 | 109 | // Try gateway in the style of https://gitlab.com/morph027/signal-cli-dbus-rest-api |
| 110 | - $response = $client->get($this->getUrl() . '/v1/about'); |
|
| 110 | + $response = $client->get($this->getUrl().'/v1/about'); |
|
| 111 | 111 | if ($response->getStatusCode() === 200) { |
| 112 | 112 | // Not so "ńew style" gateway, see |
| 113 | 113 | // https://gitlab.com/morph027/signal-cli-dbus-rest-api |
@@ -115,7 +115,7 @@ discard block |
||
| 115 | 115 | // https://github.com/bbernhard/signal-cli-rest-api |
| 116 | 116 | $body = $response->getBody(); |
| 117 | 117 | $json = json_decode($body, true); |
| 118 | - $versions = $json['versions'] ?? []; |
|
| 118 | + $versions = $json[ 'versions' ] ?? [ ]; |
|
| 119 | 119 | if (is_array($versions) && in_array('v2', $versions)) { |
| 120 | 120 | $json = [ |
| 121 | 121 | 'recipients' => $identifier, |
@@ -123,17 +123,17 @@ discard block |
||
| 123 | 123 | ]; |
| 124 | 124 | $account = $this->getAccount(); |
| 125 | 125 | if ($account != self::ACCOUNT_UNNECESSARY) { |
| 126 | - $json['account'] = $account; |
|
| 126 | + $json[ 'account' ] = $account; |
|
| 127 | 127 | } |
| 128 | 128 | $response = $client->post( |
| 129 | - $this->getUrl() . '/v2/send', |
|
| 129 | + $this->getUrl().'/v2/send', |
|
| 130 | 130 | [ |
| 131 | 131 | 'json' => $json, |
| 132 | 132 | ] |
| 133 | 133 | ); |
| 134 | 134 | } else { |
| 135 | 135 | $response = $client->post( |
| 136 | - $this->getUrl() . '/v1/send/' . $identifier, |
|
| 136 | + $this->getUrl().'/v1/send/'.$identifier, |
|
| 137 | 137 | [ |
| 138 | 138 | 'json' => [ 'message' => $message ], |
| 139 | 139 | ] |
@@ -142,13 +142,13 @@ discard block |
||
| 142 | 142 | $body = (string)$response->getBody(); |
| 143 | 143 | $json = json_decode($body, true); |
| 144 | 144 | $status = $response->getStatusCode(); |
| 145 | - if ($status !== 201 || is_null($json) || !is_array($json) || !isset($json['timestamp'])) { |
|
| 145 | + if ($status !== 201 || is_null($json) || !is_array($json) || !isset($json[ 'timestamp' ])) { |
|
| 146 | 146 | throw new MessageTransmissionException("error reported by Signal gateway, status=$status, body=$body}"); |
| 147 | 147 | } |
| 148 | 148 | } else { |
| 149 | 149 | // Try old deprecated gateway https://gitlab.com/morph027/signal-web-gateway |
| 150 | 150 | $response = $client->post( |
| 151 | - $this->getUrl() . '/v1/send/' . $identifier, |
|
| 151 | + $this->getUrl().'/v1/send/'.$identifier, |
|
| 152 | 152 | [ |
| 153 | 153 | 'body' => [ |
| 154 | 154 | 'to' => $identifier, |
@@ -161,24 +161,24 @@ discard block |
||
| 161 | 161 | $json = json_decode($body, true); |
| 162 | 162 | |
| 163 | 163 | $status = $response->getStatusCode(); |
| 164 | - if ($status !== 200 || is_null($json) || !is_array($json) || !isset($json['success']) || $json['success'] !== true) { |
|
| 164 | + if ($status !== 200 || is_null($json) || !is_array($json) || !isset($json[ 'success' ]) || $json[ 'success' ] !== true) { |
|
| 165 | 165 | throw new MessageTransmissionException("error reported by Signal gateway, status=$status, body=$body}"); |
| 166 | 166 | } |
| 167 | 167 | } |
| 168 | 168 | } |
| 169 | 169 | } |
| 170 | 170 | |
| 171 | - #[\Override] |
|
| 171 | + #[\Override ] |
|
| 172 | 172 | public function cliConfigure(InputInterface $input, OutputInterface $output): int { |
| 173 | 173 | $settings = $this->getSettings(); |
| 174 | 174 | $helper = new QuestionHelper(); |
| 175 | - $urlQuestion = new Question($settings->fields[0]->prompt, $settings->fields[0]->default); |
|
| 175 | + $urlQuestion = new Question($settings->fields[ 0 ]->prompt, $settings->fields[ 0 ]->default); |
|
| 176 | 176 | $url = $helper->ask($input, $output, $urlQuestion); |
| 177 | 177 | $output->writeln("Using $url."); |
| 178 | 178 | |
| 179 | 179 | $this->setUrl($url); |
| 180 | 180 | |
| 181 | - $accountQuestion = new Question($settings->fields[1]->prompt, $settings->fields[1]->default); |
|
| 181 | + $accountQuestion = new Question($settings->fields[ 1 ]->prompt, $settings->fields[ 1 ]->default); |
|
| 182 | 182 | $account = $helper->ask($input, $output, $accountQuestion); |
| 183 | 183 | if ($account == '') { |
| 184 | 184 | $account = self::ACCOUNT_UNNECESSARY; |
@@ -17,32 +17,32 @@ |
||
| 17 | 17 | /** @extends AFactory<AProvider> */ |
| 18 | 18 | class Factory extends AFactory { |
| 19 | 19 | /** @var array<string,IProvider> */ |
| 20 | - protected array $instances = []; |
|
| 21 | - #[\Override] |
|
| 20 | + protected array $instances = [ ]; |
|
| 21 | + #[\Override ] |
|
| 22 | 22 | protected function getPrefix(): string { |
| 23 | 23 | return 'OCA\\TwoFactorGateway\\Provider\\Channel\\Telegram\\Provider\\Drivers\\'; |
| 24 | 24 | } |
| 25 | 25 | |
| 26 | - #[\Override] |
|
| 26 | + #[\Override ] |
|
| 27 | 27 | protected function getSuffix(): string { |
| 28 | 28 | return ''; |
| 29 | 29 | } |
| 30 | 30 | |
| 31 | - #[\Override] |
|
| 31 | + #[\Override ] |
|
| 32 | 32 | protected function getBaseClass(): string { |
| 33 | 33 | return IProvider::class; |
| 34 | 34 | } |
| 35 | 35 | |
| 36 | - #[\Override] |
|
| 36 | + #[\Override ] |
|
| 37 | 37 | public function get(string $name): object { |
| 38 | - if (isset($this->instances[$name])) { |
|
| 39 | - return $this->instances[$name]; |
|
| 38 | + if (isset($this->instances[ $name ])) { |
|
| 39 | + return $this->instances[ $name ]; |
|
| 40 | 40 | } |
| 41 | 41 | foreach ($this->getFqcnList() as $fqcn) { |
| 42 | 42 | if ($fqcn === $name || $fqcn::getProviderId() === $name) { |
| 43 | 43 | $instance = \OCP\Server::get($fqcn); |
| 44 | 44 | $instance->setAppConfig(\OCP\Server::get(\OCP\IAppConfig::class)); |
| 45 | - $this->instances[$name] = $instance; |
|
| 45 | + $this->instances[ $name ] = $instance; |
|
| 46 | 46 | return $instance; |
| 47 | 47 | } |
| 48 | 48 | } |
@@ -61,33 +61,33 @@ discard block |
||
| 61 | 61 | ); |
| 62 | 62 | } |
| 63 | 63 | |
| 64 | - #[\Override] |
|
| 65 | - public function send(string $identifier, string $message, array $extra = []): void { |
|
| 64 | + #[\Override ] |
|
| 65 | + public function send(string $identifier, string $message, array $extra = [ ]): void { |
|
| 66 | 66 | $this->logger->debug("sending telegram message to $identifier, message: $message"); |
| 67 | 67 | |
| 68 | 68 | $sessionFile = $this->getSessionDirectory(); |
| 69 | 69 | |
| 70 | - putenv('TELEGRAM_API_ID=' . $this->getApiId()); |
|
| 71 | - putenv('TELEGRAM_API_HASH=' . $this->getApiHash()); |
|
| 70 | + putenv('TELEGRAM_API_ID='.$this->getApiId()); |
|
| 71 | + putenv('TELEGRAM_API_HASH='.$this->getApiHash()); |
|
| 72 | 72 | |
| 73 | - $path = realpath(__DIR__ . '/ClientCli/Cli.php'); |
|
| 74 | - $cmd = 'php ' . escapeshellarg($path) . ' ' |
|
| 73 | + $path = realpath(__DIR__.'/ClientCli/Cli.php'); |
|
| 74 | + $cmd = 'php '.escapeshellarg($path).' ' |
|
| 75 | 75 | . 'telegram:send-message ' |
| 76 | - . '--session-directory ' . escapeshellarg($sessionFile) |
|
| 77 | - . ' --to ' . escapeshellarg($identifier) |
|
| 78 | - . ' --message ' . escapeshellarg($message); |
|
| 76 | + . '--session-directory '.escapeshellarg($sessionFile) |
|
| 77 | + . ' --to '.escapeshellarg($identifier) |
|
| 78 | + . ' --message '.escapeshellarg($message); |
|
| 79 | 79 | |
| 80 | 80 | exec($cmd, $output, $returnVar); |
| 81 | 81 | |
| 82 | 82 | if ($returnVar !== 0) { |
| 83 | - $this->logger->error('Error sending Telegram message', ['output' => $output, 'returnVar' => $returnVar]); |
|
| 83 | + $this->logger->error('Error sending Telegram message', [ 'output' => $output, 'returnVar' => $returnVar ]); |
|
| 84 | 84 | throw new MessageTransmissionException(); |
| 85 | 85 | } |
| 86 | 86 | |
| 87 | 87 | $this->logger->debug("telegram message to chat $identifier sent"); |
| 88 | 88 | } |
| 89 | 89 | |
| 90 | - #[\Override] |
|
| 90 | + #[\Override ] |
|
| 91 | 91 | public function cliConfigure(InputInterface $input, OutputInterface $output): int { |
| 92 | 92 | if (PHP_VERSION_ID < 80200) { |
| 93 | 93 | $output->writeln('The Telegram Client API provider requires PHP 8.2 or higher.'); |
@@ -103,15 +103,15 @@ discard block |
||
| 103 | 103 | $this->setApiId($apiId); |
| 104 | 104 | $this->setApiHash($apiHash); |
| 105 | 105 | |
| 106 | - putenv('TELEGRAM_API_ID=' . $apiId); |
|
| 107 | - putenv('TELEGRAM_API_HASH=' . $apiHash); |
|
| 106 | + putenv('TELEGRAM_API_ID='.$apiId); |
|
| 107 | + putenv('TELEGRAM_API_HASH='.$apiHash); |
|
| 108 | 108 | |
| 109 | 109 | $sessionFile = $this->getSessionDirectory(); |
| 110 | 110 | |
| 111 | - $path = realpath(__DIR__ . '/ClientCli/Cli.php'); |
|
| 112 | - $cmd = 'php ' . escapeshellarg($path) . ' ' |
|
| 111 | + $path = realpath(__DIR__.'/ClientCli/Cli.php'); |
|
| 112 | + $cmd = 'php '.escapeshellarg($path).' ' |
|
| 113 | 113 | . 'telegram:login ' |
| 114 | - . '--session-directory ' . escapeshellarg($sessionFile); |
|
| 114 | + . '--session-directory '.escapeshellarg($sessionFile); |
|
| 115 | 115 | |
| 116 | 116 | // This is only to create the client session files. |
| 117 | 117 | // The login will be made afterwards. |
@@ -123,7 +123,7 @@ discard block |
||
| 123 | 123 | $output->writeln(''); |
| 124 | 124 | $output->writeln("<comment>$cmd</comment>"); |
| 125 | 125 | $output->writeln(''); |
| 126 | - $output->writeln('Make sure that the user to run the command is the same as the web server user: <info>' . $user['name'] . '</info>.'); |
|
| 126 | + $output->writeln('Make sure that the user to run the command is the same as the web server user: <info>'.$user[ 'name' ].'</info>.'); |
|
| 127 | 127 | $output->writeln(''); |
| 128 | 128 | $output->writeln('Follow the instructions in the command output.'); |
| 129 | 129 | return 0; |
@@ -138,9 +138,9 @@ discard block |
||
| 138 | 138 | } |
| 139 | 139 | |
| 140 | 140 | $instanceId = $this->config->getSystemValueString('instanceid'); |
| 141 | - $appDataFolder = 'appdata_' . $instanceId; |
|
| 142 | - $dataDirectory = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data'); |
|
| 143 | - $fullPath = $dataDirectory . '/' . $appDataFolder . '/' . Application::APP_ID . '/session.madeline'; |
|
| 141 | + $appDataFolder = 'appdata_'.$instanceId; |
|
| 142 | + $dataDirectory = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT.'/data'); |
|
| 143 | + $fullPath = $dataDirectory.'/'.$appDataFolder.'/'.Application::APP_ID.'/session.madeline'; |
|
| 144 | 144 | |
| 145 | 145 | if (is_dir($fullPath) === false) { |
| 146 | 146 | $reflection = new \ReflectionClass($folder); |
@@ -53,10 +53,10 @@ discard block |
||
| 53 | 53 | ); |
| 54 | 54 | } |
| 55 | 55 | |
| 56 | - #[\Override] |
|
| 57 | - public function send(string $identifier, string $message, array $extra = []): void { |
|
| 56 | + #[\Override ] |
|
| 57 | + public function send(string $identifier, string $message, array $extra = [ ]): void { |
|
| 58 | 58 | if (empty($message)) { |
| 59 | - $message = $this->l10n->t('`%s` is your Nextcloud verification code.', [$extra['code']]); |
|
| 59 | + $message = $this->l10n->t('`%s` is your Nextcloud verification code.', [ $extra[ 'code' ] ]); |
|
| 60 | 60 | } |
| 61 | 61 | $this->logger->debug("sending telegram message to $identifier, message: $message"); |
| 62 | 62 | $botToken = $this->getBotToken(); |
@@ -75,11 +75,11 @@ discard block |
||
| 75 | 75 | $this->logger->debug("telegram message to chat $identifier sent"); |
| 76 | 76 | } |
| 77 | 77 | |
| 78 | - #[\Override] |
|
| 78 | + #[\Override ] |
|
| 79 | 79 | public function cliConfigure(InputInterface $input, OutputInterface $output): int { |
| 80 | 80 | $helper = new QuestionHelper(); |
| 81 | 81 | $settings = $this->getSettings(); |
| 82 | - $tokenQuestion = new Question($settings->fields[0]->prompt . ' '); |
|
| 82 | + $tokenQuestion = new Question($settings->fields[ 0 ]->prompt.' '); |
|
| 83 | 83 | $token = $helper->ask($input, $output, $tokenQuestion); |
| 84 | 84 | $this->setBotToken($token); |
| 85 | 85 | $output->writeln("Using $token."); |