Passed
Push — master ( 1b523e...77e97a )
by Vitor
09:43 queued 05:12
created
lib/Provider/Channel/GoWhatsApp/Gateway.php 1 patch
Spacing   +42 added lines, -42 removed lines patch added patch discarded remove patch
@@ -49,7 +49,7 @@  discard block
 block discarded – undo
49 49
 		$this->client = $this->clientService->newClient();
50 50
 	}
51 51
 
52
-	#[\Override]
52
+	#[\Override ]
53 53
 	public function createSettings(): Settings {
54 54
 		return new Settings(
55 55
 			name: 'GoWhatsApp',
@@ -75,8 +75,8 @@  discard block
 block discarded – undo
75 75
 		);
76 76
 	}
77 77
 
78
-	#[\Override]
79
-	public function send(string $identifier, string $message, array $extra = []): void {
78
+	#[\Override ]
79
+	public function send(string $identifier, string $message, array $extra = [ ]): void {
80 80
 		$this->logger->debug("sending whatsapp message to $identifier, message: $message");
81 81
 
82 82
 		$isOnWhatsApp = $this->checkUserOnWhatsApp($identifier);
@@ -87,7 +87,7 @@  discard block
 block discarded – undo
87 87
 		$phone = $this->formatPhoneNumber($identifier);
88 88
 
89 89
 		try {
90
-			$response = $this->client->post($this->getBaseUrl() . '/send/message', [
90
+			$response = $this->client->post($this->getBaseUrl().'/send/message', [
91 91
 				'json' => [
92 92
 					'phone' => $phone,
93 93
 					'message' => $message,
@@ -98,57 +98,57 @@  discard block
 block discarded – undo
98 98
 			$body = (string)$response->getBody();
99 99
 			$data = json_decode($body, true);
100 100
 
101
-			if (($data['code'] ?? '') !== 'SUCCESS') {
102
-				throw new MessageTransmissionException($data['message'] ?? 'Failed to send message');
101
+			if (($data[ 'code' ] ?? '') !== 'SUCCESS') {
102
+				throw new MessageTransmissionException($data[ 'message' ] ?? 'Failed to send message');
103 103
 			}
104 104
 
105 105
 			$this->logger->debug("whatsapp message to $identifier sent successfully", [
106
-				'message_id' => $data['results']['message_id'] ?? null,
106
+				'message_id' => $data[ 'results' ][ 'message_id' ] ?? null,
107 107
 			]);
108 108
 		} catch (\Exception $e) {
109 109
 			$this->logger->error('Could not send WhatsApp message', [
110 110
 				'identifier' => $identifier,
111 111
 				'exception' => $e,
112 112
 			]);
113
-			throw new MessageTransmissionException('Failed to send WhatsApp message: ' . $e->getMessage());
113
+			throw new MessageTransmissionException('Failed to send WhatsApp message: '.$e->getMessage());
114 114
 		}
115 115
 	}
116 116
 
117
-	#[\Override]
117
+	#[\Override ]
118 118
 	public function cliConfigure(InputInterface $input, OutputInterface $output): int {
119 119
 		$helper = new QuestionHelper();
120 120
 
121
-		$baseUrlQuestion = new Question($this->getSettings()->fields[0]->prompt . ' ');
121
+		$baseUrlQuestion = new Question($this->getSettings()->fields[ 0 ]->prompt.' ');
122 122
 		$this->lazyBaseUrl = $helper->ask($input, $output, $baseUrlQuestion);
123 123
 		$this->lazyBaseUrl = rtrim($this->lazyBaseUrl, '/');
124 124
 
125
-		$usernameQuestion = new Question($this->getSettings()->fields[1]->prompt . ' ');
125
+		$usernameQuestion = new Question($this->getSettings()->fields[ 1 ]->prompt.' ');
126 126
 		$this->lazyUsername = $helper->ask($input, $output, $usernameQuestion);
127 127
 
128
-		$passwordQuestion = new Question($this->getSettings()->fields[2]->prompt . ' ');
128
+		$passwordQuestion = new Question($this->getSettings()->fields[ 2 ]->prompt.' ');
129 129
 		$passwordQuestion->setHidden(true);
130 130
 		$passwordQuestion->setHiddenFallback(false);
131 131
 		$this->lazyPassword = $helper->ask($input, $output, $passwordQuestion);
132 132
 
133
-		$phoneQuestion = new Question($this->getSettings()->fields[3]->prompt . ' ');
133
+		$phoneQuestion = new Question($this->getSettings()->fields[ 3 ]->prompt.' ');
134 134
 		$this->lazyPhone = $helper->ask($input, $output, $phoneQuestion);
135 135
 		$this->lazyPhone = preg_replace('/\D/', '', $this->lazyPhone);
136 136
 
137 137
 		try {
138 138
 			$output->writeln('<info>Requesting pairing code...</info>');
139
-			$response = $this->client->get($this->getBaseUrl() . '/app/login-with-code', [
140
-				'query' => ['phone' => $this->lazyPhone],
139
+			$response = $this->client->get($this->getBaseUrl().'/app/login-with-code', [
140
+				'query' => [ 'phone' => $this->lazyPhone ],
141 141
 			]);
142 142
 
143 143
 			$body = (string)$response->getBody();
144 144
 			$data = json_decode($body, true);
145 145
 
146
-			if (($data['code'] ?? '') !== 'SUCCESS') {
147
-				$output->writeln('<error>' . ($data['message'] ?? 'Failed to get pairing code') . '</error>');
146
+			if (($data[ 'code' ] ?? '') !== 'SUCCESS') {
147
+				$output->writeln('<error>'.($data[ 'message' ] ?? 'Failed to get pairing code').'</error>');
148 148
 				return 1;
149 149
 			}
150 150
 
151
-			$pairCode = $data['results']['pair_code'] ?? '';
151
+			$pairCode = $data[ 'results' ][ 'pair_code' ] ?? '';
152 152
 			if (empty($pairCode)) {
153 153
 				$output->writeln('<error>No pairing code received</error>');
154 154
 				return 1;
@@ -156,7 +156,7 @@  discard block
 block discarded – undo
156 156
 
157 157
 			$output->writeln('');
158 158
 			$output->writeln('<info>════════════════════════════════════</info>');
159
-			$output->writeln('<info>    PAIRING CODE: ' . $pairCode . '</info>');
159
+			$output->writeln('<info>    PAIRING CODE: '.$pairCode.'</info>');
160 160
 			$output->writeln('<info>════════════════════════════════════</info>');
161 161
 			$output->writeln('');
162 162
 			$output->writeln('Open WhatsApp on your phone and enter this code:');
@@ -165,7 +165,7 @@  discard block
 block discarded – undo
165 165
 			$output->writeln('3. Tap Linked Devices');
166 166
 			$output->writeln('4. Tap Link a Device');
167 167
 			$output->writeln('5. Select "Link with phone number instead"');
168
-			$output->writeln('6. Enter the code: <comment>' . $pairCode . '</comment>');
168
+			$output->writeln('6. Enter the code: <comment>'.$pairCode.'</comment>');
169 169
 			$output->writeln('');
170 170
 
171 171
 			$output->writeln('<info>Waiting for confirmation...</info>');
@@ -176,28 +176,28 @@  discard block
 block discarded – undo
176 176
 				sleep(2);
177 177
 
178 178
 				try {
179
-					$userInfoResponse = $this->client->get($this->getBaseUrl() . '/user/info', [
180
-						'query' => ['phone' => $this->lazyPhone . '@s.whatsapp.net'],
179
+					$userInfoResponse = $this->client->get($this->getBaseUrl().'/user/info', [
180
+						'query' => [ 'phone' => $this->lazyPhone.'@s.whatsapp.net' ],
181 181
 					]);
182 182
 
183 183
 					$userInfoBody = (string)$userInfoResponse->getBody();
184 184
 					$userInfoData = json_decode($userInfoBody, true);
185 185
 
186
-					if (($userInfoData['code'] ?? '') === 'SUCCESS') {
186
+					if (($userInfoData[ 'code' ] ?? '') === 'SUCCESS') {
187 187
 						$output->writeln('');
188 188
 						$output->writeln('<info>✓ Successfully connected to WhatsApp!</info>');
189 189
 						$output->writeln('');
190 190
 
191
-						$results = $userInfoData['results'] ?? [];
192
-						if (!empty($results['verified_name'])) {
193
-							$output->writeln('<comment>Verified Name:</comment> ' . $results['verified_name']);
191
+						$results = $userInfoData[ 'results' ] ?? [ ];
192
+						if (!empty($results[ 'verified_name' ])) {
193
+							$output->writeln('<comment>Verified Name:</comment> '.$results[ 'verified_name' ]);
194 194
 						}
195
-						if (!empty($results['status'])) {
196
-							$output->writeln('<comment>Status:</comment> ' . $results['status']);
195
+						if (!empty($results[ 'status' ])) {
196
+							$output->writeln('<comment>Status:</comment> '.$results[ 'status' ]);
197 197
 						}
198
-						if (!empty($results['devices']) && is_array($results['devices'])) {
199
-							$deviceCount = count($results['devices']);
200
-							$output->writeln('<comment>Connected Devices:</comment> ' . $deviceCount);
198
+						if (!empty($results[ 'devices' ]) && is_array($results[ 'devices' ])) {
199
+							$deviceCount = count($results[ 'devices' ]);
200
+							$output->writeln('<comment>Connected Devices:</comment> '.$deviceCount);
201 201
 						}
202 202
 						$output->writeln('');
203 203
 
@@ -222,33 +222,33 @@  discard block
 block discarded – undo
222 222
 
223 223
 		} catch (RequestException $e) {
224 224
 			$output->writeln('<error>Could not connect to the WhatsApp API. Please check the URL.</error>');
225
-			$this->logger->error('API connection error', ['exception' => $e]);
225
+			$this->logger->error('API connection error', [ 'exception' => $e ]);
226 226
 			return 1;
227 227
 		} catch (\Exception $e) {
228
-			$output->writeln('<error>' . $e->getMessage() . '</error>');
229
-			$this->logger->error('Configuration error', ['exception' => $e]);
228
+			$output->writeln('<error>'.$e->getMessage().'</error>');
229
+			$this->logger->error('Configuration error', [ 'exception' => $e ]);
230 230
 			return 1;
231 231
 		}
232 232
 	}
233 233
 
234 234
 	private function formatPhoneNumber(string $phoneNumber): string {
235 235
 		$phone = preg_replace('/\D/', '', $phoneNumber);
236
-		return $phone . '@s.whatsapp.net';
236
+		return $phone.'@s.whatsapp.net';
237 237
 	}
238 238
 
239 239
 	private function checkUserOnWhatsApp(string $phoneNumber): bool {
240 240
 		try {
241 241
 			$phone = preg_replace('/\D/', '', $phoneNumber);
242
-			$response = $this->client->get($this->getBaseUrl() . '/user/check', [
243
-				'query' => ['phone' => $phone],
242
+			$response = $this->client->get($this->getBaseUrl().'/user/check', [
243
+				'query' => [ 'phone' => $phone ],
244 244
 				'auth' => $this->getBasicAuth(),
245 245
 			]);
246 246
 
247 247
 			$body = (string)$response->getBody();
248 248
 			$data = json_decode($body, true);
249 249
 
250
-			return ($data['code'] ?? '') === 'SUCCESS'
251
-				&& ($data['results']['is_on_whatsapp'] ?? false) === true;
250
+			return ($data[ 'code' ] ?? '') === 'SUCCESS'
251
+				&& ($data[ 'results' ][ 'is_on_whatsapp' ] ?? false) === true;
252 252
 		} catch (\Exception $e) {
253 253
 			$this->logger->error('Error checking if user is on WhatsApp', [
254 254
 				'phone' => $phoneNumber,
@@ -262,9 +262,9 @@  discard block
 block discarded – undo
262 262
 		try {
263 263
 			$username = $this->lazyUsername ?: $this->getUsername();
264 264
 			$password = $this->lazyPassword ?: $this->getPassword();
265
-			return [$username, $password];
265
+			return [ $username, $password ];
266 266
 		} catch (\Exception $e) {
267
-			return ['', ''];
267
+			return [ '', '' ];
268 268
 		}
269 269
 	}
270 270
 
@@ -273,7 +273,7 @@  discard block
 block discarded – undo
273 273
 			return $this->lazyBaseUrl;
274 274
 		}
275 275
 		/** @var string */
276
-		$this->lazyBaseUrl = parent::__call('getBaseUrl', []);
276
+		$this->lazyBaseUrl = parent::__call('getBaseUrl', [ ]);
277 277
 		return $this->lazyBaseUrl;
278 278
 	}
279 279
 }
Please login to merge, or discard this patch.
lib/Provider/Channel/GoWhatsApp/Provider.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -13,12 +13,12 @@
 block discarded – undo
13 13
 
14 14
 class Provider extends AProvider {
15 15
 
16
-	#[\Override]
16
+	#[\Override ]
17 17
 	public function getDisplayName(): string {
18 18
 		return $this->l10n->t('WhatsApp verification');
19 19
 	}
20 20
 
21
-	#[\Override]
21
+	#[\Override ]
22 22
 	public function getDescription(): string {
23 23
 		return $this->l10n->t('Authenticate via WhatsApp');
24 24
 	}
Please login to merge, or discard this patch.