@@ -13,9 +13,9 @@ discard block |
||
| 13 | 13 | |
| 14 | 14 | abstract class AFactory { |
| 15 | 15 | /** @var array<string,AGateway|AProvider|ISMSProvider> */ |
| 16 | - protected array $instances = []; |
|
| 16 | + protected array $instances = [ ]; |
|
| 17 | 17 | /** @var array<string> */ |
| 18 | - protected array $fqcn = []; |
|
| 18 | + protected array $fqcn = [ ]; |
|
| 19 | 19 | |
| 20 | 20 | abstract protected function getPrefix(): string; |
| 21 | 21 | abstract protected function getSuffix(): string; |
@@ -28,8 +28,8 @@ discard block |
||
| 28 | 28 | /** @return AGateway|AProvider|ISMSProvider */ |
| 29 | 29 | public function get(string $name): object { |
| 30 | 30 | $needle = strtolower($name); |
| 31 | - if (isset($this->instances[$needle])) { |
|
| 32 | - return $this->instances[$needle]; |
|
| 31 | + if (isset($this->instances[ $needle ])) { |
|
| 32 | + return $this->instances[ $needle ]; |
|
| 33 | 33 | } |
| 34 | 34 | |
| 35 | 35 | foreach ($this->getFqcnList() as $fqcn) { |
@@ -38,7 +38,7 @@ discard block |
||
| 38 | 38 | continue; |
| 39 | 39 | } |
| 40 | 40 | $instance = \OCP\Server::get($fqcn); |
| 41 | - $this->instances[$needle] = $instance; |
|
| 41 | + $this->instances[ $needle ] = $instance; |
|
| 42 | 42 | return $instance; |
| 43 | 43 | } |
| 44 | 44 | |
@@ -51,7 +51,7 @@ discard block |
||
| 51 | 51 | return $this->fqcn; |
| 52 | 52 | } |
| 53 | 53 | |
| 54 | - $loader = require __DIR__ . '/../../vendor/autoload.php'; |
|
| 54 | + $loader = require __DIR__.'/../../vendor/autoload.php'; |
|
| 55 | 55 | foreach ($loader->getClassMap() as $fqcn => $_) { |
| 56 | 56 | $type = $this->typeFrom($fqcn); |
| 57 | 57 | if ($type === null) { |
@@ -63,7 +63,7 @@ discard block |
||
| 63 | 63 | if (!$this->isValid($fqcn)) { |
| 64 | 64 | continue; |
| 65 | 65 | } |
| 66 | - $this->fqcn[] = $fqcn; |
|
| 66 | + $this->fqcn[ ] = $fqcn; |
|
| 67 | 67 | } |
| 68 | 68 | return $this->fqcn; |
| 69 | 69 | } |
@@ -78,7 +78,7 @@ discard block |
||
| 78 | 78 | return null; |
| 79 | 79 | } |
| 80 | 80 | $type = substr($fqcn, strlen($prefix)); |
| 81 | - $type = substr($type, 0, -strlen('\\' . $suffix)); |
|
| 81 | + $type = substr($type, 0, -strlen('\\'.$suffix)); |
|
| 82 | 82 | if (strpos($type, '\\') !== false || $type === '') { |
| 83 | 83 | return null; |
| 84 | 84 | } |
@@ -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 | } |
@@ -38,7 +38,7 @@ discard block |
||
| 38 | 38 | <p>Enter this ID to receive your verification code below.</p> |
| 39 | 39 | HTML, |
| 40 | 40 | 'fields' => [ |
| 41 | - ['field' => 'bot_token', 'prompt' => 'Please enter your Telegram bot token:'], |
|
| 41 | + [ 'field' => 'bot_token', 'prompt' => 'Please enter your Telegram bot token:' ], |
|
| 42 | 42 | ], |
| 43 | 43 | ]; |
| 44 | 44 | public function __construct( |
@@ -49,10 +49,10 @@ discard block |
||
| 49 | 49 | parent::__construct($appConfig); |
| 50 | 50 | } |
| 51 | 51 | |
| 52 | - #[\Override] |
|
| 53 | - public function send(string $identifier, string $message, array $extra = []): void { |
|
| 52 | + #[\Override ] |
|
| 53 | + public function send(string $identifier, string $message, array $extra = [ ]): void { |
|
| 54 | 54 | if (empty($message)) { |
| 55 | - $message = $this->l10n->t('`%s` is your Nextcloud verification code.', [$extra['code']]); |
|
| 55 | + $message = $this->l10n->t('`%s` is your Nextcloud verification code.', [ $extra[ 'code' ] ]); |
|
| 56 | 56 | } |
| 57 | 57 | $this->logger->debug("sending telegram message to $identifier, message: $message"); |
| 58 | 58 | $botToken = $this->getBotToken(); |
@@ -71,10 +71,10 @@ discard block |
||
| 71 | 71 | $this->logger->debug("telegram message to chat $identifier sent"); |
| 72 | 72 | } |
| 73 | 73 | |
| 74 | - #[\Override] |
|
| 74 | + #[\Override ] |
|
| 75 | 75 | public function cliConfigure(InputInterface $input, OutputInterface $output): int { |
| 76 | 76 | $helper = new QuestionHelper(); |
| 77 | - $tokenQuestion = new Question(self::SCHEMA['fields'][0]['prompt'] . ' '); |
|
| 77 | + $tokenQuestion = new Question(self::SCHEMA[ 'fields' ][ 0 ][ 'prompt' ].' '); |
|
| 78 | 78 | $token = $helper->ask($input, $output, $tokenQuestion); |
| 79 | 79 | $this->setBotToken($token); |
| 80 | 80 | $output->writeln("Using $token."); |
@@ -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; |
@@ -38,7 +38,7 @@ discard block |
||
| 38 | 38 | 'name' => 'WhatsApp', |
| 39 | 39 | 'allow_markdown' => true, |
| 40 | 40 | 'fields' => [ |
| 41 | - ['field' => 'base_url', 'prompt' => 'Base URL to your WhatsApp API endpoint:'], |
|
| 41 | + [ 'field' => 'base_url', 'prompt' => 'Base URL to your WhatsApp API endpoint:' ], |
|
| 42 | 42 | ], |
| 43 | 43 | ]; |
| 44 | 44 | private string $instanceId; |
@@ -56,24 +56,24 @@ discard block |
||
| 56 | 56 | $this->client = $this->clientService->newClient(); |
| 57 | 57 | } |
| 58 | 58 | |
| 59 | - #[\Override] |
|
| 60 | - public function send(string $identifier, string $message, array $extra = []): void { |
|
| 59 | + #[\Override ] |
|
| 60 | + public function send(string $identifier, string $message, array $extra = [ ]): void { |
|
| 61 | 61 | $this->logger->debug("sending whatsapp message to $identifier, message: $message"); |
| 62 | 62 | |
| 63 | 63 | $response = $this->getSessionStatus(); |
| 64 | 64 | if ($response !== 'CONNECTED') { |
| 65 | - throw new MessageTransmissionException('WhatsApp session is not connected. Current status: ' . $response); |
|
| 65 | + throw new MessageTransmissionException('WhatsApp session is not connected. Current status: '.$response); |
|
| 66 | 66 | } |
| 67 | 67 | |
| 68 | 68 | $chatId = $this->getChatIdFromPhoneNumber($identifier); |
| 69 | 69 | |
| 70 | 70 | try { |
| 71 | - $response = $this->client->post($this->getBaseUrl() . '/client/sendMessage/' . $this->instanceId, [ |
|
| 71 | + $response = $this->client->post($this->getBaseUrl().'/client/sendMessage/'.$this->instanceId, [ |
|
| 72 | 72 | 'json' => [ |
| 73 | 73 | 'chatId' => $chatId, |
| 74 | 74 | 'contentType' => 'string', |
| 75 | 75 | 'content' => $message, |
| 76 | - 'options' => [], |
|
| 76 | + 'options' => [ ], |
|
| 77 | 77 | ], |
| 78 | 78 | ]); |
| 79 | 79 | } catch (\Exception $e) { |
@@ -87,10 +87,10 @@ discard block |
||
| 87 | 87 | $this->logger->debug("whatsapp 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 | $helper = new QuestionHelper(); |
| 93 | - $baseUrlQuestion = new Question(self::SCHEMA['fields'][0]['prompt'] . ' '); |
|
| 93 | + $baseUrlQuestion = new Question(self::SCHEMA[ 'fields' ][ 0 ][ 'prompt' ].' '); |
|
| 94 | 94 | $this->lazyBaseUrl = $helper->ask($input, $output, $baseUrlQuestion); |
| 95 | 95 | $this->lazyBaseUrl = rtrim($this->lazyBaseUrl, '/'); |
| 96 | 96 | |
@@ -99,7 +99,7 @@ discard block |
||
| 99 | 99 | return 1; |
| 100 | 100 | } |
| 101 | 101 | } catch (\Exception $e) { |
| 102 | - $output->writeln('<error>' . $e->getMessage() . '</error>'); |
|
| 102 | + $output->writeln('<error>'.$e->getMessage().'</error>'); |
|
| 103 | 103 | } |
| 104 | 104 | |
| 105 | 105 | $this->setBaseUrl($this->lazyBaseUrl); |
@@ -109,23 +109,23 @@ discard block |
||
| 109 | 109 | |
| 110 | 110 | private function getChatIdFromPhoneNumber(string $phoneNumber): string { |
| 111 | 111 | try { |
| 112 | - $response = $this->client->post($this->getBaseUrl() . '/client/getNumberId/' . $this->instanceId, [ |
|
| 112 | + $response = $this->client->post($this->getBaseUrl().'/client/getNumberId/'.$this->instanceId, [ |
|
| 113 | 113 | 'json' => [ |
| 114 | 114 | 'number' => preg_replace('/\D/', '', $phoneNumber), |
| 115 | 115 | ], |
| 116 | 116 | ]); |
| 117 | 117 | $json = $response->getBody(); |
| 118 | 118 | $data = json_decode($json, true); |
| 119 | - if (empty($data['result'])) { |
|
| 119 | + if (empty($data[ 'result' ])) { |
|
| 120 | 120 | throw new MessageTransmissionException('The phone number is not registered on WhatsApp.'); |
| 121 | 121 | } |
| 122 | - return $data['result']['_serialized']; |
|
| 122 | + return $data[ 'result' ][ '_serialized' ]; |
|
| 123 | 123 | } catch (ServerException $e) { |
| 124 | 124 | $content = $e->getResponse()?->getBody()?->getContents(); |
| 125 | 125 | if ($content === null) { |
| 126 | 126 | throw new MessageTransmissionException('Unknown error'); |
| 127 | 127 | } |
| 128 | - $errorMessage = json_decode($content, true)['error'] ?? 'Unknown error'; |
|
| 128 | + $errorMessage = json_decode($content, true)[ 'error' ] ?? 'Unknown error'; |
|
| 129 | 129 | throw new MessageTransmissionException($errorMessage); |
| 130 | 130 | } |
| 131 | 131 | } |
@@ -139,7 +139,7 @@ discard block |
||
| 139 | 139 | } |
| 140 | 140 | |
| 141 | 141 | /** @var string */ |
| 142 | - $this->lazyBaseUrl = $this->__call(__FUNCTION__, []); |
|
| 142 | + $this->lazyBaseUrl = $this->__call(__FUNCTION__, [ ]); |
|
| 143 | 143 | return $this->lazyBaseUrl; |
| 144 | 144 | } |
| 145 | 145 | |
@@ -155,19 +155,19 @@ discard block |
||
| 155 | 155 | |
| 156 | 156 | $last = null; |
| 157 | 157 | while (true) { |
| 158 | - $response = $this->client->get($this->getBaseUrl() . '/session/qr/' . $this->instanceId); |
|
| 158 | + $response = $this->client->get($this->getBaseUrl().'/session/qr/'.$this->instanceId); |
|
| 159 | 159 | $json = $response->getBody(); |
| 160 | 160 | $data = json_decode($json, true); |
| 161 | - if ($data['success'] === false) { |
|
| 162 | - if ($data['message'] === 'qr code not ready or already scanned') { |
|
| 161 | + if ($data[ 'success' ] === false) { |
|
| 162 | + if ($data[ 'message' ] === 'qr code not ready or already scanned') { |
|
| 163 | 163 | $output->writeln('<error>Session not connected yet, waiting...</error>'); |
| 164 | 164 | sleep(2); |
| 165 | 165 | continue; |
| 166 | 166 | } |
| 167 | - $output->writeln('<error>' . $data['message'] . '</error>'); |
|
| 167 | + $output->writeln('<error>'.$data[ 'message' ].'</error>'); |
|
| 168 | 168 | return 1; |
| 169 | 169 | } |
| 170 | - $qrCodeContent = $data['qr']; |
|
| 170 | + $qrCodeContent = $data[ 'qr' ]; |
|
| 171 | 171 | |
| 172 | 172 | if ($qrCodeContent !== $last) { |
| 173 | 173 | $last = $qrCodeContent; |
@@ -189,7 +189,7 @@ discard block |
||
| 189 | 189 | } |
| 190 | 190 | |
| 191 | 191 | private function getSessionStatus(): string { |
| 192 | - $endpoint = $this->getBaseUrl() . '/session/status/' . $this->instanceId; |
|
| 192 | + $endpoint = $this->getBaseUrl().'/session/status/'.$this->instanceId; |
|
| 193 | 193 | |
| 194 | 194 | try { |
| 195 | 195 | $response = $this->client->get($endpoint); |
@@ -200,18 +200,18 @@ discard block |
||
| 200 | 200 | return 'not_connected'; |
| 201 | 201 | } |
| 202 | 202 | |
| 203 | - if (($responseData['success'] ?? null) === false) { |
|
| 204 | - $msg = $responseData['message'] ?? ''; |
|
| 205 | - return in_array($msg, ['session_not_found', 'session_not_connected'], true) |
|
| 203 | + if (($responseData[ 'success' ] ?? null) === false) { |
|
| 204 | + $msg = $responseData[ 'message' ] ?? ''; |
|
| 205 | + return in_array($msg, [ 'session_not_found', 'session_not_connected' ], true) |
|
| 206 | 206 | ? $msg |
| 207 | 207 | : 'not_connected'; |
| 208 | 208 | } |
| 209 | 209 | |
| 210 | - return (string)($responseData['state'] ?? 'not_connected'); |
|
| 210 | + return (string)($responseData[ 'state' ] ?? 'not_connected'); |
|
| 211 | 211 | } catch (ClientException $e) { |
| 212 | 212 | return 'not_connected'; |
| 213 | 213 | } catch (RequestException $e) { |
| 214 | - $this->logger->info('Could not connect to ' . $endpoint, ['exception' => $e]); |
|
| 214 | + $this->logger->info('Could not connect to '.$endpoint, [ 'exception' => $e ]); |
|
| 215 | 215 | throw new \Exception('Could not connect to the WhatsApp API. Please check the URL.', 1); |
| 216 | 216 | } |
| 217 | 217 | } |
@@ -230,13 +230,13 @@ discard block |
||
| 230 | 230 | } |
| 231 | 231 | |
| 232 | 232 | private function getSessionStart(): int { |
| 233 | - $endpoint = $this->getBaseUrl() . '/session/start/' . $this->instanceId; |
|
| 233 | + $endpoint = $this->getBaseUrl().'/session/start/'.$this->instanceId; |
|
| 234 | 234 | try { |
| 235 | 235 | $this->client->get($endpoint); |
| 236 | 236 | } catch (ClientException $e) { |
| 237 | 237 | return 1; |
| 238 | 238 | } catch (RequestException $e) { |
| 239 | - $this->logger->info('Could not connect to ' . $endpoint, [ |
|
| 239 | + $this->logger->info('Could not connect to '.$endpoint, [ |
|
| 240 | 240 | 'exception' => $e, |
| 241 | 241 | ]); |
| 242 | 242 | throw new \Exception('Could not connect to the WhatsApp API. Please check the URL.', 1); |
@@ -32,17 +32,17 @@ discard block |
||
| 32 | 32 | parent::__construct($appConfig); |
| 33 | 33 | } |
| 34 | 34 | |
| 35 | - #[\Override] |
|
| 36 | - public function send(string $identifier, string $message, array $extra = []): void { |
|
| 35 | + #[\Override ] |
|
| 36 | + public function send(string $identifier, string $message, array $extra = [ ]): void { |
|
| 37 | 37 | $this->getProvider()->send($identifier, $message); |
| 38 | 38 | } |
| 39 | 39 | |
| 40 | - #[\Override] |
|
| 40 | + #[\Override ] |
|
| 41 | 41 | final public function cliConfigure(InputInterface $input, OutputInterface $output): int { |
| 42 | 42 | $namespaces = $this->providerFactory->getFqcnList(); |
| 43 | - $schemas = []; |
|
| 43 | + $schemas = [ ]; |
|
| 44 | 44 | foreach ($namespaces as $ns) { |
| 45 | - $schemas[] = $ns::SCHEMA; |
|
| 45 | + $schemas[ ] = $ns::SCHEMA; |
|
| 46 | 46 | } |
| 47 | 47 | $names = array_column($schemas, 'name'); |
| 48 | 48 | |
@@ -50,31 +50,31 @@ discard block |
||
| 50 | 50 | $choiceQuestion = new ChoiceQuestion('Please choose a SMS provider:', $names); |
| 51 | 51 | $name = $helper->ask($input, $output, $choiceQuestion); |
| 52 | 52 | $selectedIndex = array_search($name, $names); |
| 53 | - $schema = $schemas[$selectedIndex]; |
|
| 53 | + $schema = $schemas[ $selectedIndex ]; |
|
| 54 | 54 | |
| 55 | - $provider = $this->getProvider($namespaces[$selectedIndex]::getProviderId()); |
|
| 55 | + $provider = $this->getProvider($namespaces[ $selectedIndex ]::getProviderId()); |
|
| 56 | 56 | |
| 57 | - foreach ($schema['fields'] as $field) { |
|
| 58 | - $id = $field['field']; |
|
| 59 | - $prompt = $field['prompt'] . ' '; |
|
| 60 | - $defaultVal = $field['default'] ?? null; |
|
| 61 | - $optional = (bool)($field['optional'] ?? false); |
|
| 57 | + foreach ($schema[ 'fields' ] as $field) { |
|
| 58 | + $id = $field[ 'field' ]; |
|
| 59 | + $prompt = $field[ 'prompt' ].' '; |
|
| 60 | + $defaultVal = $field[ 'default' ] ?? null; |
|
| 61 | + $optional = (bool)($field[ 'optional' ] ?? false); |
|
| 62 | 62 | |
| 63 | 63 | $answer = (string)$helper->ask($input, $output, new Question($prompt, $defaultVal)); |
| 64 | 64 | |
| 65 | 65 | if ($optional && $answer === '') { |
| 66 | - $method = 'delete' . $this->toCamel($id); |
|
| 66 | + $method = 'delete'.$this->toCamel($id); |
|
| 67 | 67 | $provider->{$method}(); |
| 68 | 68 | continue; |
| 69 | 69 | } |
| 70 | 70 | |
| 71 | - $method = 'set' . $this->toCamel($id); |
|
| 71 | + $method = 'set'.$this->toCamel($id); |
|
| 72 | 72 | $provider->{$method}($answer); |
| 73 | 73 | } |
| 74 | 74 | return 0; |
| 75 | 75 | } |
| 76 | 76 | |
| 77 | - #[\Override] |
|
| 77 | + #[\Override ] |
|
| 78 | 78 | public function getSettings(): array { |
| 79 | 79 | try { |
| 80 | 80 | $provider = $this->getProvider(); |
@@ -84,8 +84,8 @@ discard block |
||
| 84 | 84 | return $provider::SCHEMA; |
| 85 | 85 | } |
| 86 | 86 | |
| 87 | - #[\Override] |
|
| 88 | - public function isComplete(array $schema = []): bool { |
|
| 87 | + #[\Override ] |
|
| 88 | + public function isComplete(array $schema = [ ]): bool { |
|
| 89 | 89 | if (empty($schema)) { |
| 90 | 90 | try { |
| 91 | 91 | $provider = $this->getProvider(); |
@@ -97,8 +97,8 @@ discard block |
||
| 97 | 97 | return parent::isComplete($schema); |
| 98 | 98 | } |
| 99 | 99 | |
| 100 | - #[\Override] |
|
| 101 | - public function remove(array $schema = []): void { |
|
| 100 | + #[\Override ] |
|
| 101 | + public function remove(array $schema = [ ]): void { |
|
| 102 | 102 | if (empty($schema)) { |
| 103 | 103 | $schema = static::SCHEMA; |
| 104 | 104 | } |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | |
| 18 | 18 | abstract class AGateway implements IGateway { |
| 19 | 19 | use TConfigurable; |
| 20 | - public const SCHEMA = []; |
|
| 20 | + public const SCHEMA = [ ]; |
|
| 21 | 21 | |
| 22 | 22 | public function __construct( |
| 23 | 23 | public IAppConfig $appConfig, |
@@ -27,42 +27,42 @@ discard block |
||
| 27 | 27 | /** |
| 28 | 28 | * @throws MessageTransmissionException |
| 29 | 29 | */ |
| 30 | - #[\Override] |
|
| 31 | - abstract public function send(string $identifier, string $message, array $extra = []): void; |
|
| 30 | + #[\Override ] |
|
| 31 | + abstract public function send(string $identifier, string $message, array $extra = [ ]): void; |
|
| 32 | 32 | |
| 33 | - #[\Override] |
|
| 34 | - public function isComplete(array $schema = []): bool { |
|
| 33 | + #[\Override ] |
|
| 34 | + public function isComplete(array $schema = [ ]): bool { |
|
| 35 | 35 | if (empty($schema)) { |
| 36 | 36 | $schema = static::SCHEMA; |
| 37 | 37 | } |
| 38 | 38 | $set = $this->appConfig->getKeys(Application::APP_ID); |
| 39 | - $fields = array_column($schema['fields'], 'field'); |
|
| 40 | - $providerId = $schema['id'] ?? $this->getProviderId(); |
|
| 41 | - $fields = array_map(fn ($f) => $providerId . '_' . $f, $fields); |
|
| 39 | + $fields = array_column($schema[ 'fields' ], 'field'); |
|
| 40 | + $providerId = $schema[ 'id' ] ?? $this->getProviderId(); |
|
| 41 | + $fields = array_map(fn ($f) => $providerId.'_'.$f, $fields); |
|
| 42 | 42 | $intersect = array_intersect($fields, $set); |
| 43 | 43 | return count($intersect) === count($fields); |
| 44 | 44 | } |
| 45 | 45 | |
| 46 | - #[\Override] |
|
| 46 | + #[\Override ] |
|
| 47 | 47 | public function getSettings(): array { |
| 48 | - $settings = []; |
|
| 49 | - if (isset(static::SCHEMA['instructions'])) { |
|
| 50 | - $settings['instructions'] = static::SCHEMA['instructions']; |
|
| 48 | + $settings = [ ]; |
|
| 49 | + if (isset(static::SCHEMA[ 'instructions' ])) { |
|
| 50 | + $settings[ 'instructions' ] = static::SCHEMA[ 'instructions' ]; |
|
| 51 | 51 | } |
| 52 | - $settings['name'] = static::SCHEMA['name']; |
|
| 52 | + $settings[ 'name' ] = static::SCHEMA[ 'name' ]; |
|
| 53 | 53 | return $settings; |
| 54 | 54 | } |
| 55 | 55 | |
| 56 | - #[\Override] |
|
| 56 | + #[\Override ] |
|
| 57 | 57 | abstract public function cliConfigure(InputInterface $input, OutputInterface $output): int; |
| 58 | 58 | |
| 59 | - #[\Override] |
|
| 60 | - public function remove(array $schema = []): void { |
|
| 59 | + #[\Override ] |
|
| 60 | + public function remove(array $schema = [ ]): void { |
|
| 61 | 61 | if (empty($schema)) { |
| 62 | 62 | $schema = static::SCHEMA; |
| 63 | 63 | } |
| 64 | - foreach ($schema['fields'] as $field) { |
|
| 65 | - $method = 'delete' . $this->toCamel($field['field']); |
|
| 64 | + foreach ($schema[ 'fields' ] as $field) { |
|
| 65 | + $method = 'delete'.$this->toCamel($field[ 'field' ]); |
|
| 66 | 66 | $this->{$method}(); |
| 67 | 67 | } |
| 68 | 68 | } |
@@ -71,11 +71,11 @@ discard block |
||
| 71 | 71 | return str_replace(' ', '', ucwords(str_replace('_', ' ', $field))); |
| 72 | 72 | } |
| 73 | 73 | |
| 74 | - #[\Override] |
|
| 74 | + #[\Override ] |
|
| 75 | 75 | public static function getProviderId(): string { |
| 76 | 76 | $id = self::deriveIdFromFqcn(static::class); |
| 77 | 77 | if ($id === null) { |
| 78 | - throw new \LogicException('Cannot derive gateway id from FQCN: ' . static::class); |
|
| 78 | + throw new \LogicException('Cannot derive gateway id from FQCN: '.static::class); |
|
| 79 | 79 | } |
| 80 | 80 | return $id; |
| 81 | 81 | } |