Passed
Pull Request — master (#640)
by Vitor
14:24
created
lib/Provider/Channel/Signal/Gateway.php 1 patch
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -31,7 +31,7 @@  discard block
 block discarded – undo
31 31
 		'name' => 'Signal',
32 32
 		'instructions' => 'The gateway can send authentication to your Signal mobile and deskop app.',
33 33
 		'fields' => [
34
-			['field' => 'url', 'prompt' => 'Please enter the URL of the Signal gateway (leave blank to use default):', 'default' => 'http://localhost:5000'],
34
+			[ 'field' => 'url', 'prompt' => 'Please enter the URL of the Signal gateway (leave blank to use default):', 'default' => 'http://localhost:5000' ],
35 35
 		],
36 36
 	];
37 37
 
@@ -43,29 +43,29 @@  discard block
 block discarded – undo
43 43
 		parent::__construct($appConfig);
44 44
 	}
45 45
 
46
-	#[\Override]
47
-	public function send(IUser $user, string $identifier, string $message, array $extra = []): void {
46
+	#[\Override ]
47
+	public function send(IUser $user, string $identifier, string $message, array $extra = [ ]): void {
48 48
 		$client = $this->clientService->newClient();
49 49
 		// determine type of gateway
50
-		$response = $client->get($this->getUrl() . '/v1/about');
50
+		$response = $client->get($this->getUrl().'/v1/about');
51 51
 		if ($response->getStatusCode() === 200) {
52 52
 			// New style gateway https://gitlab.com/morph027/signal-cli-dbus-rest-api
53 53
 			$response = $client->post(
54
-				$this->getUrl() . '/v1/send/' . $identifier,
54
+				$this->getUrl().'/v1/send/'.$identifier,
55 55
 				[
56 56
 					'json' => [ 'message' => $message ],
57 57
 				]
58 58
 			);
59 59
 			$body = $response->getBody();
60 60
 			$json = json_decode($body, true);
61
-			if ($response->getStatusCode() !== 201 || is_null($json) || !is_array($json) || !isset($json['timestamp'])) {
61
+			if ($response->getStatusCode() !== 201 || is_null($json) || !is_array($json) || !isset($json[ 'timestamp' ])) {
62 62
 				$status = $response->getStatusCode();
63 63
 				throw new MessageTransmissionException("error reported by Signal gateway, status=$status, body=$body}");
64 64
 			}
65 65
 		} else {
66 66
 			// Try old deprecated gateway https://gitlab.com/morph027/signal-web-gateway
67 67
 			$response = $client->post(
68
-				$this->getUrl() . '/v1/send/' . $identifier,
68
+				$this->getUrl().'/v1/send/'.$identifier,
69 69
 				[
70 70
 					'body' => [
71 71
 						'to' => $identifier,
@@ -77,17 +77,17 @@  discard block
 block discarded – undo
77 77
 			$body = $response->getBody();
78 78
 			$json = json_decode($body, true);
79 79
 
80
-			if ($response->getStatusCode() !== 200 || is_null($json) || !is_array($json) || !isset($json['success']) || $json['success'] !== true) {
80
+			if ($response->getStatusCode() !== 200 || is_null($json) || !is_array($json) || !isset($json[ 'success' ]) || $json[ 'success' ] !== true) {
81 81
 				$status = $response->getStatusCode();
82 82
 				throw new MessageTransmissionException("error reported by Signal gateway, status=$status, body=$body}");
83 83
 			}
84 84
 		}
85 85
 	}
86 86
 
87
-	#[\Override]
87
+	#[\Override ]
88 88
 	public function cliConfigure(InputInterface $input, OutputInterface $output): int {
89 89
 		$helper = new QuestionHelper();
90
-		$urlQuestion = new Question(self::SCHEMA['fields'][0]['prompt'], self::SCHEMA['fields'][0]['default']);
90
+		$urlQuestion = new Question(self::SCHEMA[ 'fields' ][ 0 ][ 'prompt' ], self::SCHEMA[ 'fields' ][ 0 ][ 'default' ]);
91 91
 		$url = $helper->ask($input, $output, $urlQuestion);
92 92
 		$output->writeln("Using $url.");
93 93
 
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
@@ -14,38 +14,38 @@
 block discarded – undo
14 14
 use OCA\TwoFactorGateway\Provider\Channel\SMS\Provider\IProvider;
15 15
 
16 16
 class Factory extends AFactory {
17
-	#[\Override]
17
+	#[\Override ]
18 18
 	protected function getPrefix(): string {
19 19
 		return 'OCA\\TwoFactorGateway\\Provider\\Channel\\SMS\\Provider\\Drivers\\';
20 20
 	}
21 21
 
22
-	#[\Override]
22
+	#[\Override ]
23 23
 	protected function getSuffix(): string {
24 24
 		return '';
25 25
 	}
26 26
 
27
-	#[\Override]
27
+	#[\Override ]
28 28
 	protected function getBaseClass(): string {
29 29
 		return IProvider::class;
30 30
 	}
31 31
 
32
-	#[\Override]
32
+	#[\Override ]
33 33
 	public function isValid(string $fqcn): bool {
34 34
 		return defined("$fqcn::SCHEMA")
35 35
 			&& is_array($fqcn::SCHEMA);
36 36
 	}
37 37
 
38
-	#[\Override]
38
+	#[\Override ]
39 39
 	public function get(string $name): IProvider {
40
-		if (isset($this->instances[$name])) {
40
+		if (isset($this->instances[ $name ])) {
41 41
 			/** @var IProvider */
42
-			return $this->instances[$name];
42
+			return $this->instances[ $name ];
43 43
 		}
44 44
 		foreach ($this->getFqcnList() as $fqcn) {
45 45
 			if ($fqcn::getProviderId() === $name) {
46 46
 				$instance = \OCP\Server::get($fqcn);
47 47
 				$instance->setAppConfig(\OCP\Server::get(\OCP\IAppConfig::class));
48
-				$this->instances[$name] = $instance;
48
+				$this->instances[ $name ] = $instance;
49 49
 				return $instance;
50 50
 			}
51 51
 		}
Please login to merge, or discard this patch.
lib/Provider/Channel/SMS/Provider/Drivers/ClickatellCentral.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -28,9 +28,9 @@  discard block
 block discarded – undo
28 28
 		'id' => 'clickatell_central',
29 29
 		'name' => 'Clickatell Central',
30 30
 		'fields' => [
31
-			['field' => 'api',      'prompt' => 'Please enter your central.clickatell.com API-ID:'],
32
-			['field' => 'user',     'prompt' => 'Please enter your central.clickatell.com username:'],
33
-			['field' => 'password', 'prompt' => 'Please enter your central.clickatell.com password:'],
31
+			[ 'field' => 'api', 'prompt' => 'Please enter your central.clickatell.com API-ID:' ],
32
+			[ 'field' => 'user', 'prompt' => 'Please enter your central.clickatell.com username:' ],
33
+			[ 'field' => 'password', 'prompt' => 'Please enter your central.clickatell.com password:' ],
34 34
 		],
35 35
 	];
36 36
 
@@ -42,7 +42,7 @@  discard block
 block discarded – undo
42 42
 		$this->client = $clientService->newClient();
43 43
 	}
44 44
 
45
-	#[\Override]
45
+	#[\Override ]
46 46
 	public function send(string $identifier, string $message) {
47 47
 		try {
48 48
 			$response = $this->client->get(vsprintf('https://api.clickatell.com/http/sendmsg?user=%s&password=%s&api_id=%u&to=%s&text=%s', [
Please login to merge, or discard this patch.
lib/Provider/Channel/SMS/Provider/Drivers/SMSGlobal.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -27,9 +27,9 @@  discard block
 block discarded – undo
27 27
 	public const SCHEMA = [
28 28
 		'name' => 'SMSGlobal',
29 29
 		'fields' => [
30
-			['field' => 'url',      'prompt' => 'Please enter your SMSGlobal http-api:', 'default' => 'https://api.smsglobal.com/http-api.php'],
31
-			['field' => 'user',     'prompt' => 'Please enter your SMSGlobal username (for http-api):'],
32
-			['field' => 'password', 'prompt' => 'Please enter your SMSGlobal password (for http-api):'],
30
+			[ 'field' => 'url', 'prompt' => 'Please enter your SMSGlobal http-api:', 'default' => 'https://api.smsglobal.com/http-api.php' ],
31
+			[ 'field' => 'user', 'prompt' => 'Please enter your SMSGlobal username (for http-api):' ],
32
+			[ 'field' => 'password', 'prompt' => 'Please enter your SMSGlobal password (for http-api):' ],
33 33
 		],
34 34
 	];
35 35
 	private IClient $client;
@@ -40,7 +40,7 @@  discard block
 block discarded – undo
40 40
 		$this->client = $clientService->newClient();
41 41
 	}
42 42
 
43
-	#[\Override]
43
+	#[\Override ]
44 44
 	public function send(string $identifier, string $message) {
45 45
 		$to = str_replace('+', '', $identifier);
46 46
 
Please login to merge, or discard this patch.
lib/Provider/Channel/SMS/Provider/Drivers/SpryngSMS.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -23,7 +23,7 @@  discard block
 block discarded – undo
23 23
 	public const SCHEMA = [
24 24
 		'name' => 'Spryng',
25 25
 		'fields' => [
26
-			['field' => 'apitoken', 'prompt' => 'Please enter your Spryng api token:'],
26
+			[ 'field' => 'apitoken', 'prompt' => 'Please enter your Spryng api token:' ],
27 27
 		],
28 28
 	];
29 29
 	private IClient $client;
@@ -34,7 +34,7 @@  discard block
 block discarded – undo
34 34
 		$this->client = $clientService->newClient();
35 35
 	}
36 36
 
37
-	#[\Override]
37
+	#[\Override ]
38 38
 	public function send(string $identifier, string $message) {
39 39
 		try {
40 40
 			$this->client->post(
@@ -42,14 +42,14 @@  discard block
 block discarded – undo
42 42
 				[
43 43
 					'headers' => [
44 44
 						'Accept' => 'application/json',
45
-						'Authorization' => 'Bearer ' . $this->getApitoken(),
45
+						'Authorization' => 'Bearer '.$this->getApitoken(),
46 46
 						'Content-Type' => 'application/json',
47 47
 					],
48 48
 					'json' => [
49 49
 						'body' => $message,
50 50
 						'encoding' => 'plain',
51 51
 						'originator' => 'Nextcloud',
52
-						'recipients' => [$identifier],
52
+						'recipients' => [ $identifier ],
53 53
 						'route' => '1',
54 54
 					],
55 55
 				]
Please login to merge, or discard this patch.
lib/Provider/Channel/SMS/Provider/Drivers/Ovh.php 1 patch
Spacing   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -34,12 +34,12 @@  discard block
 block discarded – undo
34 34
 	public const SCHEMA = [
35 35
 		'name' => 'OVH',
36 36
 		'fields' => [
37
-			['field' => 'endpoint',        'prompt' => 'Please enter the endpoint (ovh-eu, ovh-us, ovh-ca, soyoustart-eu, soyoustart-ca, kimsufi-eu, kimsufi-ca, runabove-ca):'],
38
-			['field' => 'application_key', 'prompt' => 'Please enter your application key:'],
39
-			['field' => 'application_secret','prompt' => 'Please enter your application secret:'],
40
-			['field' => 'consumer_key',    'prompt' => 'Please enter your consumer key:'],
41
-			['field' => 'account',         'prompt' => 'Please enter your account (sms-*****):'],
42
-			['field' => 'sender',          'prompt' => 'Please enter your sender:'],
37
+			[ 'field' => 'endpoint', 'prompt' => 'Please enter the endpoint (ovh-eu, ovh-us, ovh-ca, soyoustart-eu, soyoustart-ca, kimsufi-eu, kimsufi-ca, runabove-ca):' ],
38
+			[ 'field' => 'application_key', 'prompt' => 'Please enter your application key:' ],
39
+			[ 'field' => 'application_secret', 'prompt' => 'Please enter your application secret:' ],
40
+			[ 'field' => 'consumer_key', 'prompt' => 'Please enter your consumer key:' ],
41
+			[ 'field' => 'account', 'prompt' => 'Please enter your account (sms-*****):' ],
42
+			[ 'field' => 'sender', 'prompt' => 'Please enter your sender:' ],
43 43
 		],
44 44
 	];
45 45
 	private IClient $client;
@@ -76,24 +76,24 @@  discard block
 block discarded – undo
76 76
 		$this->client = $clientService->newClient();
77 77
 	}
78 78
 
79
-	#[\Override]
79
+	#[\Override ]
80 80
 	public function send(string $identifier, string $message) {
81 81
 		$endpoint = $this->getEndpoint();
82 82
 		$sender = $this->getSender();
83 83
 		$smsAccount = $this->getAccount();
84 84
 
85
-		$this->attrs['AK'] = $this->getApplicationKey();
86
-		$this->attrs['AS'] = $this->getApplicationSecret();
87
-		$this->attrs['CK'] = $this->getConsumerKey();
88
-		if (!isset($this->endpoints[$endpoint])) {
85
+		$this->attrs[ 'AK' ] = $this->getApplicationKey();
86
+		$this->attrs[ 'AS' ] = $this->getApplicationSecret();
87
+		$this->attrs[ 'CK' ] = $this->getConsumerKey();
88
+		if (!isset($this->endpoints[ $endpoint ])) {
89 89
 			throw new InvalidProviderException("Endpoint $endpoint not found");
90 90
 		}
91
-		$this->attrs['endpoint'] = $this->endpoints[$endpoint];
91
+		$this->attrs[ 'endpoint' ] = $this->endpoints[ $endpoint ];
92 92
 
93 93
 		$this->getTimeDelta();
94 94
 
95
-		$header = $this->getHeader('GET', $this->attrs['endpoint'] . '/sms');
96
-		$response = $this->client->get($this->attrs['endpoint'] . '/sms', [
95
+		$header = $this->getHeader('GET', $this->attrs[ 'endpoint' ].'/sms');
96
+		$response = $this->client->get($this->attrs[ 'endpoint' ].'/sms', [
97 97
 			'headers' => $header,
98 98
 		]);
99 99
 		$smsServices = json_decode($response->getBody(), true);
@@ -120,14 +120,14 @@  discard block
 block discarded – undo
120 120
 		];
121 121
 		$body = json_encode($content);
122 122
 
123
-		$header = $this->getHeader('POST', $this->attrs['endpoint'] . "/sms/$smsAccount/jobs", $body);
124
-		$response = $this->client->post($this->attrs['endpoint'] . "/sms/$smsAccount/jobs", [
123
+		$header = $this->getHeader('POST', $this->attrs[ 'endpoint' ]."/sms/$smsAccount/jobs", $body);
124
+		$response = $this->client->post($this->attrs[ 'endpoint' ]."/sms/$smsAccount/jobs", [
125 125
 			'headers' => $header,
126 126
 			'json' => $content,
127 127
 		]);
128 128
 		$resultPostJob = json_decode($response->getBody(), true);
129 129
 
130
-		if (count($resultPostJob['validReceivers']) === 0) {
130
+		if (count($resultPostJob[ 'validReceivers' ]) === 0) {
131 131
 			throw new MessageTransmissionException("Bad receiver $identifier");
132 132
 		}
133 133
 	}
@@ -138,16 +138,16 @@  discard block
 block discarded – undo
138 138
 	 * @throws InvalidProviderException
139 139
 	 */
140 140
 	private function getTimeDelta(): void {
141
-		if (!isset($this->attrs['timedelta'])) {
142
-			if (!isset($this->attrs['endpoint'])) {
141
+		if (!isset($this->attrs[ 'timedelta' ])) {
142
+			if (!isset($this->attrs[ 'endpoint' ])) {
143 143
 				throw new InvalidProviderException('Need to set the endpoint');
144 144
 			}
145 145
 			try {
146
-				$response = $this->client->get($this->attrs['endpoint'] . '/auth/time');
146
+				$response = $this->client->get($this->attrs[ 'endpoint' ].'/auth/time');
147 147
 				$serverTimestamp = (int)$response->getBody();
148
-				$this->attrs['timedelta'] = $serverTimestamp - time();
148
+				$this->attrs[ 'timedelta' ] = $serverTimestamp - time();
149 149
 			} catch (Exception $ex) {
150
-				throw new InvalidProviderException('Unable to calculate time delta:' . $ex->getMessage());
150
+				throw new InvalidProviderException('Unable to calculate time delta:'.$ex->getMessage());
151 151
 			}
152 152
 		}
153 153
 	}
@@ -160,14 +160,14 @@  discard block
 block discarded – undo
160 160
 	 * @return array $header Contains the data for the request need by OVH
161 161
 	 */
162 162
 	private function getHeader($method, $query, $body = '') {
163
-		$timestamp = time() + $this->attrs['timedelta'];
164
-		$prehash = $this->attrs['AS'] . '+' . $this->attrs['CK'] . '+' . $method . '+' . $query . '+' . $body . '+' . $timestamp;
163
+		$timestamp = time() + $this->attrs[ 'timedelta' ];
164
+		$prehash = $this->attrs[ 'AS' ].'+'.$this->attrs[ 'CK' ].'+'.$method.'+'.$query.'+'.$body.'+'.$timestamp;
165 165
 		$header = [
166 166
 			'Content-Type' => 'application/json; charset=utf-8',
167
-			'X-Ovh-Application' => $this->attrs['AK'],
167
+			'X-Ovh-Application' => $this->attrs[ 'AK' ],
168 168
 			'X-Ovh-Timestamp' => $timestamp,
169
-			'X-Ovh-Signature' => '$1$' . sha1($prehash),
170
-			'X-Ovh-Consumer' => $this->attrs['CK'],
169
+			'X-Ovh-Signature' => '$1$'.sha1($prehash),
170
+			'X-Ovh-Consumer' => $this->attrs[ 'CK' ],
171 171
 		];
172 172
 		return $header;
173 173
 	}
Please login to merge, or discard this patch.
lib/Provider/Channel/SMS/Provider/Drivers/WebSms.php 1 patch
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -26,8 +26,8 @@  discard block
 block discarded – undo
26 26
 		'id' => 'websms_de',
27 27
 		'name' => 'WebSMS.de',
28 28
 		'fields' => [
29
-			['field' => 'user',     'prompt' => 'Please enter your websms.de username:'],
30
-			['field' => 'password', 'prompt' => 'Please enter your websms.de password:'],
29
+			[ 'field' => 'user', 'prompt' => 'Please enter your websms.de username:' ],
30
+			[ 'field' => 'password', 'prompt' => 'Please enter your websms.de password:' ],
31 31
 		],
32 32
 	];
33 33
 	private IClient $client;
@@ -38,20 +38,20 @@  discard block
 block discarded – undo
38 38
 		$this->client = $clientService->newClient();
39 39
 	}
40 40
 
41
-	#[\Override]
41
+	#[\Override ]
42 42
 	public function send(string $identifier, string $message) {
43 43
 		$user = $this->getUser();
44 44
 		$password = $this->getPassword();
45 45
 		try {
46 46
 			$this->client->post('https://api.websms.com/rest/smsmessaging/text', [
47 47
 				'headers' => [
48
-					'Authorization' => 'Basic ' . base64_encode("$user:$password"),
48
+					'Authorization' => 'Basic '.base64_encode("$user:$password"),
49 49
 					'Content-Type' => 'application/json',
50 50
 				],
51 51
 				'json' => [
52 52
 					'messageContent' => $message,
53 53
 					'test' => false,
54
-					'recipientAddressList' => [$identifier],
54
+					'recipientAddressList' => [ $identifier ],
55 55
 				],
56 56
 			]);
57 57
 		} catch (Exception $ex) {
Please login to merge, or discard this patch.
lib/Provider/Channel/SMS/Provider/Drivers/HuaweiE3531.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -24,7 +24,7 @@  discard block
 block discarded – undo
24 24
 		'id' => 'huawei_e3531',
25 25
 		'name' => 'Huawei E3531',
26 26
 		'fields' => [
27
-			['field' => 'api', 'prompt' => 'Please enter the base URL of the Huawei E3531 stick: ', 'default' => 'http://192.168.8.1/api'],
27
+			[ 'field' => 'api', 'prompt' => 'Please enter the base URL of the Huawei E3531 stick: ', 'default' => 'http://192.168.8.1/api' ],
28 28
 		],
29 29
 	];
30 30
 	private IClient $client;
@@ -35,7 +35,7 @@  discard block
 block discarded – undo
35 35
 		$this->client = $clientService->newClient();
36 36
 	}
37 37
 
38
-	#[\Override]
38
+	#[\Override ]
39 39
 	public function send(string $identifier, string $message) {
40 40
 		$url = $this->getApi();
41 41
 
Please login to merge, or discard this patch.
lib/Provider/Channel/SMS/Provider/Drivers/SMSApi.php 1 patch
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -25,8 +25,8 @@  discard block
 block discarded – undo
25 25
 	public const SCHEMA = [
26 26
 		'name' => 'SMSAPI',
27 27
 		'fields' => [
28
-			['field' => 'token', 'prompt' => 'Please enter your SMSApi.com API token:'],
29
-			['field' => 'sender','prompt' => 'Please enter your SMSApi.com sender name:'],
28
+			[ 'field' => 'token', 'prompt' => 'Please enter your SMSApi.com API token:' ],
29
+			[ 'field' => 'sender', 'prompt' => 'Please enter your SMSApi.com sender name:' ],
30 30
 		],
31 31
 	];
32 32
 	private IClient $client;
@@ -37,17 +37,17 @@  discard block
 block discarded – undo
37 37
 		$this->client = $clientService->newClient();
38 38
 	}
39 39
 
40
-	#[\Override]
40
+	#[\Override ]
41 41
 	public function send(string $identifier, string $message) {
42 42
 		$sender = $this->getSender();
43 43
 		$token = $this->getToken();
44 44
 		$url = 'https://api.smsapi.com/sms.do';
45 45
 
46 46
 		$params = [
47
-			'to' => $identifier,         //destination number
48
-			'from' => $sender,             //sendername made in https://ssl.smsapi.com/sms_settings/sendernames
49
-			'message' => $message,    		//message content
50
-			'format' => 'json',           	//get response in json format
47
+			'to' => $identifier, //destination number
48
+			'from' => $sender, //sendername made in https://ssl.smsapi.com/sms_settings/sendernames
49
+			'message' => $message, //message content
50
+			'format' => 'json', //get response in json format
51 51
 		];
52 52
 
53 53
 		try {
@@ -71,7 +71,7 @@  discard block
 block discarded – undo
71 71
 			curl_close($c);
72 72
 			$responseData = json_decode($content, true);
73 73
 
74
-			if ($responseData['count'] !== 1) {
74
+			if ($responseData[ 'count' ] !== 1) {
75 75
 				throw new MessageTransmissionException();
76 76
 			}
77 77
 		} catch (Exception $ex) {
Please login to merge, or discard this patch.