Passed
Pull Request — master (#665)
by Vitor
04:08 queued 15s
created
lib/Provider/Channel/WhatsApp/Gateway.php 1 patch
Spacing   +28 added lines, -28 removed lines patch added patch discarded remove patch
@@ -37,7 +37,7 @@  discard block
 block discarded – undo
37 37
 	public const SCHEMA = [
38 38
 		'name' => 'WhatsApp',
39 39
 		'fields' => [
40
-			['field' => 'base_url', 'prompt' => 'Base URL to your WhatsApp API endpoint:'],
40
+			[ 'field' => 'base_url', 'prompt' => 'Base URL to your WhatsApp API endpoint:' ],
41 41
 		],
42 42
 	];
43 43
 	private string $instanceId;
@@ -55,27 +55,27 @@  discard block
 block discarded – undo
55 55
 		$this->client = $this->clientService->newClient();
56 56
 	}
57 57
 
58
-	#[\Override]
59
-	public function send(string $identifier, string $message, array $extra = []): void {
58
+	#[\Override ]
59
+	public function send(string $identifier, string $message, array $extra = [ ]): void {
60 60
 		if (empty($message)) {
61
-			$message = $this->l10n->t('`%s` is your Nextcloud verification code.', [$extra['code']]);
61
+			$message = $this->l10n->t('`%s` is your Nextcloud verification code.', [ $extra[ 'code' ] ]);
62 62
 		}
63 63
 		$this->logger->debug("sending whatsapp message to $identifier, message: $message");
64 64
 
65 65
 		$response = $this->getSessionStatus();
66 66
 		if ($response !== 'CONNECTED') {
67
-			throw new MessageTransmissionException('WhatsApp session is not connected. Current status: ' . $response);
67
+			throw new MessageTransmissionException('WhatsApp session is not connected. Current status: '.$response);
68 68
 		}
69 69
 
70 70
 		$chatId = $this->getChatIdFromPhoneNumber($identifier);
71 71
 
72 72
 		try {
73
-			$response = $this->client->post($this->getBaseUrl() . '/client/sendMessage/' . $this->instanceId, [
73
+			$response = $this->client->post($this->getBaseUrl().'/client/sendMessage/'.$this->instanceId, [
74 74
 				'json' => [
75 75
 					'chatId' => $chatId,
76 76
 					'contentType' => 'string',
77 77
 					'content' => $message,
78
-					'options' => [],
78
+					'options' => [ ],
79 79
 				],
80 80
 			]);
81 81
 		} catch (\Exception $e) {
@@ -89,10 +89,10 @@  discard block
 block discarded – undo
89 89
 		$this->logger->debug("whatsapp message to chat $identifier sent");
90 90
 	}
91 91
 
92
-	#[\Override]
92
+	#[\Override ]
93 93
 	public function cliConfigure(InputInterface $input, OutputInterface $output): int {
94 94
 		$helper = new QuestionHelper();
95
-		$baseUrlQuestion = new Question(self::SCHEMA['fields'][0]['prompt'] . ' ');
95
+		$baseUrlQuestion = new Question(self::SCHEMA[ 'fields' ][ 0 ][ 'prompt' ].' ');
96 96
 		$this->lazyBaseUrl = $helper->ask($input, $output, $baseUrlQuestion);
97 97
 		$this->lazyBaseUrl = rtrim($this->lazyBaseUrl, '/');
98 98
 
@@ -101,7 +101,7 @@  discard block
 block discarded – undo
101 101
 				return 1;
102 102
 			}
103 103
 		} catch (\Exception $e) {
104
-			$output->writeln('<error>' . $e->getMessage() . '</error>');
104
+			$output->writeln('<error>'.$e->getMessage().'</error>');
105 105
 		}
106 106
 
107 107
 		$this->setBaseUrl($this->lazyBaseUrl);
@@ -111,23 +111,23 @@  discard block
 block discarded – undo
111 111
 
112 112
 	private function getChatIdFromPhoneNumber(string $phoneNumber): string {
113 113
 		try {
114
-			$response = $this->client->post($this->getBaseUrl() . '/client/getNumberId/' . $this->instanceId, [
114
+			$response = $this->client->post($this->getBaseUrl().'/client/getNumberId/'.$this->instanceId, [
115 115
 				'json' => [
116 116
 					'number' => preg_replace('/\D/', '', $phoneNumber),
117 117
 				],
118 118
 			]);
119 119
 			$json = $response->getBody();
120 120
 			$data = json_decode($json, true);
121
-			if (empty($data['result'])) {
121
+			if (empty($data[ 'result' ])) {
122 122
 				throw new MessageTransmissionException('The phone number is not registered on WhatsApp.');
123 123
 			}
124
-			return $data['result']['_serialized'];
124
+			return $data[ 'result' ][ '_serialized' ];
125 125
 		} catch (ServerException $e) {
126 126
 			$content = $e->getResponse()?->getBody()?->getContents();
127 127
 			if ($content === null) {
128 128
 				throw new MessageTransmissionException('Unknown error');
129 129
 			}
130
-			$errorMessage = json_decode($content, true)['error'] ?? 'Unknown error';
130
+			$errorMessage = json_decode($content, true)[ 'error' ] ?? 'Unknown error';
131 131
 			throw new MessageTransmissionException($errorMessage);
132 132
 		}
133 133
 	}
@@ -141,7 +141,7 @@  discard block
 block discarded – undo
141 141
 		}
142 142
 
143 143
 		/** @var string */
144
-		$this->lazyBaseUrl = $this->__call(__FUNCTION__, []);
144
+		$this->lazyBaseUrl = $this->__call(__FUNCTION__, [ ]);
145 145
 		return $this->lazyBaseUrl;
146 146
 	}
147 147
 
@@ -157,19 +157,19 @@  discard block
 block discarded – undo
157 157
 
158 158
 		$last = null;
159 159
 		while (true) {
160
-			$response = $this->client->get($this->getBaseUrl() . '/session/qr/' . $this->instanceId);
160
+			$response = $this->client->get($this->getBaseUrl().'/session/qr/'.$this->instanceId);
161 161
 			$json = $response->getBody();
162 162
 			$data = json_decode($json, true);
163
-			if ($data['success'] === false) {
164
-				if ($data['message'] === 'qr code not ready or already scanned') {
163
+			if ($data[ 'success' ] === false) {
164
+				if ($data[ 'message' ] === 'qr code not ready or already scanned') {
165 165
 					$output->writeln('<error>Session not connected yet, waiting...</error>');
166 166
 					sleep(2);
167 167
 					continue;
168 168
 				}
169
-				$output->writeln('<error>' . $data['message'] . '</error>');
169
+				$output->writeln('<error>'.$data[ 'message' ].'</error>');
170 170
 				return 1;
171 171
 			}
172
-			$qrCodeContent = $data['qr'];
172
+			$qrCodeContent = $data[ 'qr' ];
173 173
 
174 174
 			if ($qrCodeContent !== $last) {
175 175
 				$last = $qrCodeContent;
@@ -191,7 +191,7 @@  discard block
 block discarded – undo
191 191
 	}
192 192
 
193 193
 	private function getSessionStatus(): string {
194
-		$endpoint = $this->getBaseUrl() . '/session/status/' . $this->instanceId;
194
+		$endpoint = $this->getBaseUrl().'/session/status/'.$this->instanceId;
195 195
 
196 196
 		try {
197 197
 			$response = $this->client->get($endpoint);
@@ -202,18 +202,18 @@  discard block
 block discarded – undo
202 202
 				return 'not_connected';
203 203
 			}
204 204
 
205
-			if (($responseData['success'] ?? null) === false) {
206
-				$msg = $responseData['message'] ?? '';
207
-				return in_array($msg, ['session_not_found', 'session_not_connected'], true)
205
+			if (($responseData[ 'success' ] ?? null) === false) {
206
+				$msg = $responseData[ 'message' ] ?? '';
207
+				return in_array($msg, [ 'session_not_found', 'session_not_connected' ], true)
208 208
 					? $msg
209 209
 					: 'not_connected';
210 210
 			}
211 211
 
212
-			return (string)($responseData['state'] ?? 'not_connected');
212
+			return (string)($responseData[ 'state' ] ?? 'not_connected');
213 213
 		} catch (ClientException $e) {
214 214
 			return 'not_connected';
215 215
 		} catch (RequestException $e) {
216
-			$this->logger->info('Could not connect to ' . $endpoint, ['exception' => $e]);
216
+			$this->logger->info('Could not connect to '.$endpoint, [ 'exception' => $e ]);
217 217
 			throw new \Exception('Could not connect to the WhatsApp API. Please check the URL.', 1);
218 218
 		}
219 219
 	}
@@ -232,13 +232,13 @@  discard block
 block discarded – undo
232 232
 	}
233 233
 
234 234
 	private function getSessionStart(): int {
235
-		$endpoint = $this->getBaseUrl() . '/session/start/' . $this->instanceId;
235
+		$endpoint = $this->getBaseUrl().'/session/start/'.$this->instanceId;
236 236
 		try {
237 237
 			$this->client->get($endpoint);
238 238
 		} catch (ClientException $e) {
239 239
 			return 1;
240 240
 		} catch (RequestException $e) {
241
-			$this->logger->info('Could not connect to ' . $endpoint, [
241
+			$this->logger->info('Could not connect to '.$endpoint, [
242 242
 				'exception' => $e,
243 243
 			]);
244 244
 			throw new \Exception('Could not connect to the WhatsApp API. Please check the URL.', 1);
Please login to merge, or discard this patch.
lib/Provider/Channel/Telegram/Gateway.php 1 patch
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -38,7 +38,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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.");
Please login to merge, or discard this patch.