@@ -24,7 +24,7 @@ |
||
| 24 | 24 | * |
| 25 | 25 | * @throws MessageTransmissionException |
| 26 | 26 | */ |
| 27 | - public function send(string $identifier, string $message, array $extra = []): void; |
|
| 27 | + public function send(string $identifier, string $message, array $extra = [ ]): void; |
|
| 28 | 28 | |
| 29 | 29 | public function isComplete(?Settings $settings = null): bool; |
| 30 | 30 | |
@@ -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 $this->getProviderId() . '_' . $fieldName; |
|
| 55 | + return $this->getProviderId().'_'.$fieldName; |
|
| 56 | 56 | } |
| 57 | 57 | } |
| 58 | - throw new ConfigurationException('Invalid configuration field: ' . $field->field . ', check SCHEMA at ' . static::class); |
|
| 58 | + throw new ConfigurationException('Invalid configuration field: '.$field->field.', check SCHEMA at '.static::class); |
|
| 59 | 59 | } |
| 60 | 60 | |
| 61 | 61 | /** |
@@ -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; |
@@ -55,16 +55,16 @@ discard block |
||
| 55 | 55 | return $this->settings = $this->createSettings(); |
| 56 | 56 | } |
| 57 | 57 | |
| 58 | - #[\Override] |
|
| 58 | + #[\Override ] |
|
| 59 | 59 | abstract public function cliConfigure(InputInterface $input, OutputInterface $output): int; |
| 60 | 60 | |
| 61 | - #[\Override] |
|
| 61 | + #[\Override ] |
|
| 62 | 62 | public function remove(?Settings $settings = null): void { |
| 63 | 63 | if (!is_object($settings)) { |
| 64 | 64 | $settings = $this->getSettings(); |
| 65 | 65 | } |
| 66 | 66 | foreach ($settings->fields as $field) { |
| 67 | - $method = 'delete' . $this->toCamel($field->field); |
|
| 67 | + $method = 'delete'.$this->toCamel($field->field); |
|
| 68 | 68 | $this->{$method}(); |
| 69 | 69 | } |
| 70 | 70 | } |
@@ -73,11 +73,11 @@ discard block |
||
| 73 | 73 | return str_replace(' ', '', ucwords(str_replace('_', ' ', $field))); |
| 74 | 74 | } |
| 75 | 75 | |
| 76 | - #[\Override] |
|
| 76 | + #[\Override ] |
|
| 77 | 77 | public static function getProviderId(): string { |
| 78 | 78 | $id = self::deriveIdFromFqcn(static::class); |
| 79 | 79 | if ($id === null) { |
| 80 | - throw new \LogicException('Cannot derive gateway id from FQCN: ' . static::class); |
|
| 80 | + throw new \LogicException('Cannot derive gateway id from FQCN: '.static::class); |
|
| 81 | 81 | } |
| 82 | 82 | return $id; |
| 83 | 83 | } |
@@ -60,13 +60,13 @@ |
||
| 60 | 60 | $gateway = $this->gatewayFactory->get($gatewayName); |
| 61 | 61 | try { |
| 62 | 62 | $message = match ($gateway->getSettings()->allow_markdown ?? false) { |
| 63 | - true => $this->l10n->t('`%s` is your verification code.', [$verificationNumber]), |
|
| 64 | - default => $this->l10n->t('%s is your verification code.', [$verificationNumber]), |
|
| 63 | + true => $this->l10n->t('`%s` is your verification code.', [ $verificationNumber ]), |
|
| 64 | + default => $this->l10n->t('%s is your verification code.', [ $verificationNumber ]), |
|
| 65 | 65 | }; |
| 66 | 66 | $gateway->send( |
| 67 | 67 | $identifier, |
| 68 | 68 | $message, |
| 69 | - ['code' => $verificationNumber], |
|
| 69 | + [ 'code' => $verificationNumber ], |
|
| 70 | 70 | ); |
| 71 | 71 | } catch (MessageTransmissionException $ex) { |
| 72 | 72 | throw new VerificationException($ex->getMessage(), $ex->getCode(), $ex); |
@@ -22,7 +22,7 @@ discard block |
||
| 22 | 22 | parent::__construct('twofactorauth:gateway:status'); |
| 23 | 23 | } |
| 24 | 24 | |
| 25 | - #[\Override] |
|
| 25 | + #[\Override ] |
|
| 26 | 26 | protected function execute(InputInterface $input, OutputInterface $output) { |
| 27 | 27 | $fqcn = $this->gatewayFactory->getFqcnList(); |
| 28 | 28 | foreach ($fqcn as $fqcn) { |
@@ -30,7 +30,7 @@ discard block |
||
| 30 | 30 | $gateway = $this->gatewayFactory->get($fqcn); |
| 31 | 31 | $isConfigured = $gateway->isComplete(); |
| 32 | 32 | $settings = $gateway->getSettings(); |
| 33 | - $output->writeln($settings->name . ': ' . ($isConfigured ? 'configured' : 'not configured')); |
|
| 33 | + $output->writeln($settings->name.': '.($isConfigured ? 'configured' : 'not configured')); |
|
| 34 | 34 | } |
| 35 | 35 | return 0; |
| 36 | 36 | } |
@@ -22,11 +22,11 @@ |
||
| 22 | 22 | * |
| 23 | 23 | * @var FieldDefinition[] |
| 24 | 24 | */ |
| 25 | - public array $fields = [], |
|
| 25 | + public array $fields = [ ], |
|
| 26 | 26 | ) { |
| 27 | 27 | } |
| 28 | 28 | |
| 29 | - #[\Override] |
|
| 29 | + #[\Override ] |
|
| 30 | 30 | public function jsonSerialize(): mixed { |
| 31 | 31 | return [ |
| 32 | 32 | 'name' => $this->name, |
@@ -42,7 +42,7 @@ discard block |
||
| 42 | 42 | parent::__construct($appConfig); |
| 43 | 43 | } |
| 44 | 44 | |
| 45 | - #[\Override] |
|
| 45 | + #[\Override ] |
|
| 46 | 46 | public function createSettings(): Settings { |
| 47 | 47 | return new Settings( |
| 48 | 48 | name: 'Signal', |
@@ -61,20 +61,20 @@ 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 | $client = $this->clientService->newClient(); |
| 67 | 67 | // determine type of gateway |
| 68 | 68 | |
| 69 | 69 | // test for native signal-cli JSON RPC. |
| 70 | 70 | $response = $client->post( |
| 71 | - $this->getUrl() . '/api/v1/rpc', |
|
| 71 | + $this->getUrl().'/api/v1/rpc', |
|
| 72 | 72 | [ |
| 73 | 73 | 'http_errors' => false, |
| 74 | 74 | 'json' => [ |
| 75 | 75 | 'jsonrpc' => '2.0', |
| 76 | 76 | 'method' => 'version', |
| 77 | - 'id' => 'version_' . $this->timeFactory->getTime(), |
|
| 77 | + 'id' => 'version_'.$this->timeFactory->getTime(), |
|
| 78 | 78 | ], |
| 79 | 79 | ]); |
| 80 | 80 | if ($response->getStatusCode() === 200 || $response->getStatusCode() === 201) { |
@@ -90,12 +90,12 @@ discard block |
||
| 90 | 90 | 'account' => $this->getAccount(), // mandatory for native RPC API |
| 91 | 91 | ]; |
| 92 | 92 | $response = $response = $client->post( |
| 93 | - $this->getUrl() . '/api/v1/rpc', |
|
| 93 | + $this->getUrl().'/api/v1/rpc', |
|
| 94 | 94 | [ |
| 95 | 95 | 'json' => [ |
| 96 | 96 | 'jsonrpc' => '2.0', |
| 97 | 97 | 'method' => 'send', |
| 98 | - 'id' => 'code_' . $this->timeFactory->getTime(), |
|
| 98 | + 'id' => 'code_'.$this->timeFactory->getTime(), |
|
| 99 | 99 | 'params' => $params, |
| 100 | 100 | ], |
| 101 | 101 | ]); |
@@ -103,12 +103,12 @@ discard block |
||
| 103 | 103 | $json = json_decode($body, true); |
| 104 | 104 | $statusCode = $response->getStatusCode(); |
| 105 | 105 | // The 201 "created" is probably a bug. |
| 106 | - if ($statusCode < 200 || $statusCode >= 300 || is_null($json) || !is_array($json) || ($json['jsonrpc'] ?? null) != '2.0' || !isset($json['result']['timestamp'])) { |
|
| 106 | + if ($statusCode < 200 || $statusCode >= 300 || is_null($json) || !is_array($json) || ($json[ 'jsonrpc' ] ?? null) != '2.0' || !isset($json[ 'result' ][ 'timestamp' ])) { |
|
| 107 | 107 | throw new MessageTransmissionException("error reported by Signal gateway, status=$statusCode, body=$body}"); |
| 108 | 108 | } |
| 109 | 109 | } else { |
| 110 | 110 | // Try gateway in the style of https://gitlab.com/morph027/signal-cli-dbus-rest-api |
| 111 | - $response = $client->get($this->getUrl() . '/v1/about'); |
|
| 111 | + $response = $client->get($this->getUrl().'/v1/about'); |
|
| 112 | 112 | if ($response->getStatusCode() === 200) { |
| 113 | 113 | // Not so "ńew style" gateway, see |
| 114 | 114 | // https://gitlab.com/morph027/signal-cli-dbus-rest-api |
@@ -116,7 +116,7 @@ discard block |
||
| 116 | 116 | // https://github.com/bbernhard/signal-cli-rest-api |
| 117 | 117 | $body = $response->getBody(); |
| 118 | 118 | $json = json_decode($body, true); |
| 119 | - $versions = $json['versions'] ?? []; |
|
| 119 | + $versions = $json[ 'versions' ] ?? [ ]; |
|
| 120 | 120 | if (is_array($versions) && in_array('v2', $versions)) { |
| 121 | 121 | $json = [ |
| 122 | 122 | 'recipients' => $identifier, |
@@ -124,17 +124,17 @@ discard block |
||
| 124 | 124 | ]; |
| 125 | 125 | $account = $this->getAccount(); |
| 126 | 126 | if ($account != self::ACCOUNT_UNNECESSARY) { |
| 127 | - $json['account'] = $account; |
|
| 127 | + $json[ 'account' ] = $account; |
|
| 128 | 128 | } |
| 129 | 129 | $response = $client->post( |
| 130 | - $this->getUrl() . '/v2/send', |
|
| 130 | + $this->getUrl().'/v2/send', |
|
| 131 | 131 | [ |
| 132 | 132 | 'json' => $json, |
| 133 | 133 | ] |
| 134 | 134 | ); |
| 135 | 135 | } else { |
| 136 | 136 | $response = $client->post( |
| 137 | - $this->getUrl() . '/v1/send/' . $identifier, |
|
| 137 | + $this->getUrl().'/v1/send/'.$identifier, |
|
| 138 | 138 | [ |
| 139 | 139 | 'json' => [ 'message' => $message ], |
| 140 | 140 | ] |
@@ -143,13 +143,13 @@ discard block |
||
| 143 | 143 | $body = (string)$response->getBody(); |
| 144 | 144 | $json = json_decode($body, true); |
| 145 | 145 | $status = $response->getStatusCode(); |
| 146 | - if ($status !== 201 || is_null($json) || !is_array($json) || !isset($json['timestamp'])) { |
|
| 146 | + if ($status !== 201 || is_null($json) || !is_array($json) || !isset($json[ 'timestamp' ])) { |
|
| 147 | 147 | throw new MessageTransmissionException("error reported by Signal gateway, status=$status, body=$body}"); |
| 148 | 148 | } |
| 149 | 149 | } else { |
| 150 | 150 | // Try old deprecated gateway https://gitlab.com/morph027/signal-web-gateway |
| 151 | 151 | $response = $client->post( |
| 152 | - $this->getUrl() . '/v1/send/' . $identifier, |
|
| 152 | + $this->getUrl().'/v1/send/'.$identifier, |
|
| 153 | 153 | [ |
| 154 | 154 | 'body' => [ |
| 155 | 155 | 'to' => $identifier, |
@@ -162,24 +162,24 @@ discard block |
||
| 162 | 162 | $json = json_decode($body, true); |
| 163 | 163 | |
| 164 | 164 | $status = $response->getStatusCode(); |
| 165 | - if ($status !== 200 || is_null($json) || !is_array($json) || !isset($json['success']) || $json['success'] !== true) { |
|
| 165 | + if ($status !== 200 || is_null($json) || !is_array($json) || !isset($json[ 'success' ]) || $json[ 'success' ] !== true) { |
|
| 166 | 166 | throw new MessageTransmissionException("error reported by Signal gateway, status=$status, body=$body}"); |
| 167 | 167 | } |
| 168 | 168 | } |
| 169 | 169 | } |
| 170 | 170 | } |
| 171 | 171 | |
| 172 | - #[\Override] |
|
| 172 | + #[\Override ] |
|
| 173 | 173 | public function cliConfigure(InputInterface $input, OutputInterface $output): int { |
| 174 | 174 | $settings = $this->getSettings(); |
| 175 | 175 | $helper = new QuestionHelper(); |
| 176 | - $urlQuestion = new Question($settings->fields[0]->prompt, $settings->fields[0]->default); |
|
| 176 | + $urlQuestion = new Question($settings->fields[ 0 ]->prompt, $settings->fields[ 0 ]->default); |
|
| 177 | 177 | $url = $helper->ask($input, $output, $urlQuestion); |
| 178 | 178 | $output->writeln("Using $url."); |
| 179 | 179 | |
| 180 | 180 | $this->setUrl($url); |
| 181 | 181 | |
| 182 | - $accountQuestion = new Question($settings->fields[1]->prompt, $settings->fields[1]->default); |
|
| 182 | + $accountQuestion = new Question($settings->fields[ 1 ]->prompt, $settings->fields[ 1 ]->default); |
|
| 183 | 183 | $account = $helper->ask($input, $output, $accountQuestion); |
| 184 | 184 | if ($account == '') { |
| 185 | 185 | $account = self::ACCOUNT_UNNECESSARY; |
@@ -51,7 +51,7 @@ discard block |
||
| 51 | 51 | $this->client = $this->clientService->newClient(); |
| 52 | 52 | } |
| 53 | 53 | |
| 54 | - #[\Override] |
|
| 54 | + #[\Override ] |
|
| 55 | 55 | public function createSettings(): Settings { |
| 56 | 56 | return new Settings( |
| 57 | 57 | name: 'WhatsApp', |
@@ -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); |
@@ -15,31 +15,31 @@ |
||
| 15 | 15 | |
| 16 | 16 | /** @extends AFactory<AProvider> */ |
| 17 | 17 | class Factory extends AFactory { |
| 18 | - #[\Override] |
|
| 18 | + #[\Override ] |
|
| 19 | 19 | protected function getPrefix(): string { |
| 20 | 20 | return 'OCA\\TwoFactorGateway\\Provider\\Channel\\SMS\\Provider\\Drivers\\'; |
| 21 | 21 | } |
| 22 | 22 | |
| 23 | - #[\Override] |
|
| 23 | + #[\Override ] |
|
| 24 | 24 | protected function getSuffix(): string { |
| 25 | 25 | return ''; |
| 26 | 26 | } |
| 27 | 27 | |
| 28 | - #[\Override] |
|
| 28 | + #[\Override ] |
|
| 29 | 29 | protected function getBaseClass(): string { |
| 30 | 30 | return AProvider::class; |
| 31 | 31 | } |
| 32 | 32 | |
| 33 | - #[\Override] |
|
| 33 | + #[\Override ] |
|
| 34 | 34 | public function get(string $name): object { |
| 35 | - if (isset($this->instances[$name])) { |
|
| 36 | - return $this->instances[$name]; |
|
| 35 | + if (isset($this->instances[ $name ])) { |
|
| 36 | + return $this->instances[ $name ]; |
|
| 37 | 37 | } |
| 38 | 38 | foreach ($this->getFqcnList() as $fqcn) { |
| 39 | 39 | $instance = \OCP\Server::get($fqcn); |
| 40 | 40 | if ($instance->getSettings()->id === $name) { |
| 41 | 41 | $instance->setAppConfig(\OCP\Server::get(\OCP\IAppConfig::class)); |
| 42 | - $this->instances[$name] = $instance; |
|
| 42 | + $this->instances[ $name ] = $instance; |
|
| 43 | 43 | return $instance; |
| 44 | 44 | } |
| 45 | 45 | } |