Passed
Pull Request — master (#686)
by Vitor
04:24
created
lib/Provider/Settings.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -20,7 +20,7 @@
 block discarded – undo
20 20
 		 *
21 21
 		 * @var FieldDefinition[]
22 22
 		 */
23
-		public array $fields = [],
23
+		public array $fields = [ ],
24 24
 	) {
25 25
 	}
26 26
 }
Please login to merge, or discard this patch.
lib/Provider/Channel/WhatsApp/Gateway.php 1 patch
Spacing   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -65,24 +65,24 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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);
Please login to merge, or discard this patch.
lib/Provider/Channel/SMS/Factory.php 1 patch
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -16,22 +16,22 @@  discard block
 block discarded – undo
16 16
 
17 17
 /** @extends AFactory<AProvider> */
18 18
 class Factory extends AFactory {
19
-	#[\Override]
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);
@@ -41,16 +41,16 @@  discard block
 block discarded – undo
41 41
 	 * @param class-string<AProvider> $name
42 42
 	 * @return AProvider
43 43
 	 */
44
-	#[\Override]
44
+	#[\Override ]
45 45
 	public function get(string $name): object {
46
-		if (isset($this->instances[$name])) {
47
-			return $this->instances[$name];
46
+		if (isset($this->instances[ $name ])) {
47
+			return $this->instances[ $name ];
48 48
 		}
49 49
 		foreach ($this->getFqcnList() as $fqcn) {
50 50
 			if ($fqcn::getProviderId() === $name) {
51 51
 				$instance = \OCP\Server::get($fqcn);
52 52
 				$instance->setAppConfig(\OCP\Server::get(\OCP\IAppConfig::class));
53
-				$this->instances[$name] = $instance;
53
+				$this->instances[ $name ] = $instance;
54 54
 				return $instance;
55 55
 			}
56 56
 		}
Please login to merge, or discard this patch.
lib/Provider/Channel/Telegram/Factory.php 1 patch
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -16,38 +16,38 @@
 block discarded – undo
16 16
 /** @extends AFactory<IProvider> */
17 17
 class Factory extends AFactory {
18 18
 	/** @var array<string,IProvider> */
19
-	protected array $instances = [];
20
-	#[\Override]
19
+	protected array $instances = [ ];
20
+	#[\Override ]
21 21
 	protected function getPrefix(): string {
22 22
 		return 'OCA\\TwoFactorGateway\\Provider\\Channel\\Telegram\\Provider\\Drivers\\';
23 23
 	}
24 24
 
25
-	#[\Override]
25
+	#[\Override ]
26 26
 	protected function getSuffix(): string {
27 27
 		return '';
28 28
 	}
29 29
 
30
-	#[\Override]
30
+	#[\Override ]
31 31
 	protected function getBaseClass(): string {
32 32
 		return IProvider::class;
33 33
 	}
34 34
 
35
-	#[\Override]
35
+	#[\Override ]
36 36
 	public function isValid(string $fqcn): bool {
37 37
 		return defined("$fqcn::SCHEMA")
38 38
 			&& is_array($fqcn::SCHEMA);
39 39
 	}
40 40
 
41
-	#[\Override]
41
+	#[\Override ]
42 42
 	public function get(string $name): IProvider {
43
-		if (isset($this->instances[$name])) {
44
-			return $this->instances[$name];
43
+		if (isset($this->instances[ $name ])) {
44
+			return $this->instances[ $name ];
45 45
 		}
46 46
 		foreach ($this->getFqcnList() as $fqcn) {
47 47
 			if ($fqcn::getProviderId() === $name) {
48 48
 				$instance = \OCP\Server::get($fqcn);
49 49
 				$instance->setAppConfig(\OCP\Server::get(\OCP\IAppConfig::class));
50
-				$this->instances[$name] = $instance;
50
+				$this->instances[ $name ] = $instance;
51 51
 				return $instance;
52 52
 			}
53 53
 		}
Please login to merge, or discard this patch.
lib/Provider/Channel/Telegram/Gateway.php 1 patch
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -29,17 +29,17 @@  discard block
 block discarded – undo
29 29
 		parent::__construct($appConfig);
30 30
 	}
31 31
 
32
-	#[\Override]
33
-	public function send(string $identifier, string $message, array $extra = []): void {
32
+	#[\Override ]
33
+	public function send(string $identifier, string $message, array $extra = [ ]): void {
34 34
 		$this->getProvider()->send($identifier, $message);
35 35
 	}
36 36
 
37
-	#[\Override]
37
+	#[\Override ]
38 38
 	final public function cliConfigure(InputInterface $input, OutputInterface $output): int {
39 39
 		$namespaces = $this->telegramProviderFactory->getFqcnList();
40
-		$schemas = [];
40
+		$schemas = [ ];
41 41
 		foreach ($namespaces as $ns) {
42
-			$schemas[] = $ns::SCHEMA;
42
+			$schemas[ ] = $ns::SCHEMA;
43 43
 		}
44 44
 		$names = array_column($schemas, 'name');
45 45
 
@@ -47,15 +47,15 @@  discard block
 block discarded – undo
47 47
 		$choiceQuestion = new ChoiceQuestion('Please choose a Telegram provider:', $names);
48 48
 		$name = $helper->ask($input, $output, $choiceQuestion);
49 49
 		$selectedIndex = array_search($name, $names);
50
-		$schema = $schemas[$selectedIndex];
50
+		$schema = $schemas[ $selectedIndex ];
51 51
 
52
-		$provider = $this->getProvider($namespaces[$selectedIndex]::getProviderId());
52
+		$provider = $this->getProvider($namespaces[ $selectedIndex ]::getProviderId());
53 53
 
54 54
 		$provider->cliConfigure($input, $output);
55 55
 		return 0;
56 56
 	}
57 57
 
58
-	#[\Override]
58
+	#[\Override ]
59 59
 	public function createSettings(): Settings
60 60
 	{
61 61
 		$settings = $this->getProvider()->getSettings();
@@ -65,8 +65,8 @@  discard block
 block discarded – undo
65 65
 		return $settings;
66 66
 	}
67 67
 
68
-	#[\Override]
69
-	public function isComplete(array $schema = []): bool {
68
+	#[\Override ]
69
+	public function isComplete(array $schema = [ ]): bool {
70 70
 		if (empty($schema)) {
71 71
 			try {
72 72
 				$provider = $this->getProvider();
@@ -78,8 +78,8 @@  discard block
 block discarded – undo
78 78
 		return parent::isComplete($schema);
79 79
 	}
80 80
 
81
-	#[\Override]
82
-	public function remove(array $schema = []): void {
81
+	#[\Override ]
82
+	public function remove(array $schema = [ ]): void {
83 83
 		if (empty($schema)) {
84 84
 			$schema = static::SCHEMA;
85 85
 		}
Please login to merge, or discard this patch.
lib/Provider/Factory.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -11,17 +11,17 @@
 block discarded – undo
11 11
 
12 12
 /** @extends AFactory<AProvider> */
13 13
 class Factory extends AFactory {
14
-	#[\Override]
14
+	#[\Override ]
15 15
 	protected function getPrefix(): string {
16 16
 		return 'OCA\\TwoFactorGateway\\Provider\\Channel\\';
17 17
 	}
18 18
 
19
-	#[\Override]
19
+	#[\Override ]
20 20
 	protected function getSuffix(): string {
21 21
 		return 'Provider';
22 22
 	}
23 23
 
24
-	#[\Override]
24
+	#[\Override ]
25 25
 	protected function getBaseClass(): string {
26 26
 		return AProvider::class;
27 27
 	}
Please login to merge, or discard this patch.
lib/Provider/AFactory.php 1 patch
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -17,9 +17,9 @@  discard block
 block discarded – undo
17 17
  */
18 18
 abstract class AFactory {
19 19
 	/** @var array<string, T> */
20
-	protected array $instances = [];
20
+	protected array $instances = [ ];
21 21
 	/** @var array<string> */
22
-	protected array $fqcn = [];
22
+	protected array $fqcn = [ ];
23 23
 
24 24
 	abstract protected function getPrefix(): string;
25 25
 
@@ -38,8 +38,8 @@  discard block
 block discarded – undo
38 38
 	 */
39 39
 	public function get(string $name): object {
40 40
 		$needle = strtolower($name);
41
-		if (isset($this->instances[$needle])) {
42
-			return $this->instances[$needle];
41
+		if (isset($this->instances[ $needle ])) {
42
+			return $this->instances[ $needle ];
43 43
 		}
44 44
 
45 45
 		foreach ($this->getFqcnList() as $fqcn) {
@@ -48,7 +48,7 @@  discard block
 block discarded – undo
48 48
 				continue;
49 49
 			}
50 50
 			$instance = \OCP\Server::get($fqcn);
51
-			$this->instances[$needle] = $instance;
51
+			$this->instances[ $needle ] = $instance;
52 52
 			return $instance;
53 53
 		}
54 54
 
@@ -61,7 +61,7 @@  discard block
 block discarded – undo
61 61
 			return $this->fqcn;
62 62
 		}
63 63
 
64
-		$loader = require __DIR__ . '/../../vendor/autoload.php';
64
+		$loader = require __DIR__.'/../../vendor/autoload.php';
65 65
 		foreach ($loader->getClassMap() as $fqcn => $_) {
66 66
 			$type = $this->typeFrom($fqcn);
67 67
 			if ($type === null) {
@@ -73,7 +73,7 @@  discard block
 block discarded – undo
73 73
 			if (!$this->isValid($fqcn)) {
74 74
 				continue;
75 75
 			}
76
-			$this->fqcn[] = $fqcn;
76
+			$this->fqcn[ ] = $fqcn;
77 77
 		}
78 78
 		return $this->fqcn;
79 79
 	}
@@ -88,7 +88,7 @@  discard block
 block discarded – undo
88 88
 			return null;
89 89
 		}
90 90
 		$type = substr($fqcn, strlen($prefix));
91
-		$type = substr($type, 0, -strlen('\\' . $suffix));
91
+		$type = substr($type, 0, -strlen('\\'.$suffix));
92 92
 		if (strpos($type, '\\') !== false || $type === '') {
93 93
 			return null;
94 94
 		}
Please login to merge, or discard this patch.
lib/Provider/Gateway/Factory.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -13,17 +13,17 @@
 block discarded – undo
13 13
 
14 14
 /** @extends AFactory<AProvider> */
15 15
 class Factory extends AFactory {
16
-	#[\Override]
16
+	#[\Override ]
17 17
 	protected function getPrefix(): string {
18 18
 		return 'OCA\\TwoFactorGateway\\Provider\\Channel\\';
19 19
 	}
20 20
 
21
-	#[\Override]
21
+	#[\Override ]
22 22
 	protected function getSuffix(): string {
23 23
 		return 'Gateway';
24 24
 	}
25 25
 
26
-	#[\Override]
26
+	#[\Override ]
27 27
 	protected function getBaseClass(): string {
28 28
 		return IGateway::class;
29 29
 	}
Please login to merge, or discard this patch.
lib/Provider/Gateway/IGateway.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -24,9 +24,9 @@  discard block
 block discarded – undo
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
-	public function isComplete(array $schema = []): bool;
29
+	public function isComplete(array $schema = [ ]): bool;
30 30
 
31 31
 	public function createSettings(): Settings;
32 32
 
@@ -34,7 +34,7 @@  discard block
 block discarded – undo
34 34
 
35 35
 	public function cliConfigure(InputInterface $input, OutputInterface $output): int;
36 36
 
37
-	public function remove(array $schema = []): void;
37
+	public function remove(array $schema = [ ]): void;
38 38
 
39 39
 	public static function getProviderId(): string;
40 40
 }
Please login to merge, or discard this patch.