Passed
Push — master ( 29c3ff...12a478 )
by Vitor
05:59 queued 01:59
created
lib/Provider/Channel/WhatsApp/Gateway.php 1 patch
Spacing   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -38,7 +38,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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);
Please login to merge, or discard this patch.
lib/Provider/Channel/SMS/Gateway.php 1 patch
Spacing   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -32,17 +32,17 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 		}
Please login to merge, or discard this patch.
lib/Provider/Gateway/AGateway.php 1 patch
Spacing   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -17,7 +17,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 	}
Please login to merge, or discard this patch.
lib/Provider/AProvider.php 1 patch
Spacing   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -37,7 +37,7 @@  discard block
 block discarded – undo
37 37
 	protected IGateway $gateway;
38 38
 
39 39
 	private function getSessionKey(): string {
40
-		return 'twofactor_gateway_' . $this->getGatewayName() . '_secret';
40
+		return 'twofactor_gateway_'.$this->getGatewayName().'_secret';
41 41
 	}
42 42
 
43 43
 	public function __construct(
@@ -58,14 +58,14 @@  discard block
 block discarded – undo
58 58
 		}
59 59
 		$fqcn = static::class;
60 60
 		$parts = explode('\\', $fqcn);
61
-		[$name] = array_slice($parts, -2, 1);
61
+		[ $name ] = array_slice($parts, -2, 1);
62 62
 		$this->gatewayName = strtolower($name);
63 63
 		return $this->gatewayName;
64 64
 	}
65 65
 
66
-	#[\Override]
66
+	#[\Override ]
67 67
 	public function getId(): string {
68
-		return 'gateway_' . $this->getGatewayName();
68
+		return 'gateway_'.$this->getGatewayName();
69 69
 	}
70 70
 
71 71
 	private function getSecret(): string {
@@ -79,21 +79,21 @@  discard block
 block discarded – undo
79 79
 		return $secret;
80 80
 	}
81 81
 
82
-	#[\Override]
82
+	#[\Override ]
83 83
 	public function getTemplate(IUser $user): ITemplate {
84 84
 		$secret = $this->getSecret();
85 85
 
86 86
 		try {
87 87
 			$identifier = $this->stateStorage->get($user, $this->getGatewayName())->getIdentifier() ?? '';
88 88
 
89
-			$message = $this->gateway->getSettings()['allow_markdown'] ?? false
90
-				? $this->l10n->t('`%s` is your Nextcloud authentication code', [$secret])
91
-				: $this->l10n->t('%s is your Nextcloud authentication code', [$secret]);
89
+			$message = $this->gateway->getSettings()[ 'allow_markdown' ] ?? false
90
+				? $this->l10n->t('`%s` is your Nextcloud authentication code', [ $secret ])
91
+				: $this->l10n->t('%s is your Nextcloud authentication code', [ $secret ]);
92 92
 
93 93
 			$this->gateway->send(
94 94
 				$identifier,
95 95
 				$message,
96
-				['code' => $secret],
96
+				[ 'code' => $secret ],
97 97
 			);
98 98
 		} catch (MessageTransmissionException) {
99 99
 			return $this->templateManager->getTemplate('twofactor_gateway', 'error');
@@ -104,7 +104,7 @@  discard block
 block discarded – undo
104 104
 		return $tmpl;
105 105
 	}
106 106
 
107
-	#[\Override]
107
+	#[\Override ]
108 108
 	public function verifyChallenge(IUser $user, string $challenge): bool {
109 109
 		$valid = $this->session->exists($this->getSessionKey())
110 110
 			&& $this->session->get($this->getSessionKey()) === $challenge;
@@ -116,31 +116,31 @@  discard block
 block discarded – undo
116 116
 		return $valid;
117 117
 	}
118 118
 
119
-	#[\Override]
119
+	#[\Override ]
120 120
 	public function isTwoFactorAuthEnabledForUser(IUser $user): bool {
121 121
 		return $this->stateStorage->get($user, $this->getGatewayName())->getState() === StateStorage::STATE_ENABLED;
122 122
 	}
123 123
 
124
-	#[\Override]
124
+	#[\Override ]
125 125
 	public function getPersonalSettings(IUser $user): IPersonalProviderSettings {
126
-		$this->initialState->provideInitialState('settings-' . $this->gateway->getProviderId(), $this->gateway->getSettings());
126
+		$this->initialState->provideInitialState('settings-'.$this->gateway->getProviderId(), $this->gateway->getSettings());
127 127
 		return new PersonalSettings(
128 128
 			$this->getGatewayName(),
129 129
 			$this->gateway->isComplete(),
130 130
 		);
131 131
 	}
132 132
 
133
-	#[\Override]
133
+	#[\Override ]
134 134
 	public function getLightIcon(): String {
135 135
 		return Server::get(IURLGenerator::class)->imagePath(Application::APP_ID, 'app.svg');
136 136
 	}
137 137
 
138
-	#[\Override]
138
+	#[\Override ]
139 139
 	public function getDarkIcon(): String {
140 140
 		return Server::get(IURLGenerator::class)->imagePath(Application::APP_ID, 'app-dark.svg');
141 141
 	}
142 142
 
143
-	#[\Override]
143
+	#[\Override ]
144 144
 	public function disableFor(IUser $user) {
145 145
 		$state = $this->stateStorage->get($user, $this->getGatewayName());
146 146
 		if ($state->getState() === StateStorage::STATE_ENABLED) {
Please login to merge, or discard this patch.
lib/Service/SetupService.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -59,14 +59,14 @@
 block discarded – undo
59 59
 		$verificationNumber = $this->random->generate(6, ISecureRandom::CHAR_DIGITS);
60 60
 		$gateway = $this->gatewayFactory->get($gatewayName);
61 61
 		try {
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]),
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 ]),
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);
Please login to merge, or discard this patch.