Passed
Pull Request — master (#668)
by
unknown
06:08 queued 04:34
created
lib/Provider/Channel/Signal/Gateway.php 1 patch
Spacing   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -33,8 +33,8 @@  discard block
 block discarded – undo
33 33
 		'name' => 'Signal',
34 34
 		'instructions' => 'The gateway can send authentication to your Signal mobile and deskop app.',
35 35
 		'fields' => [
36
-			['field' => 'url', 'prompt' => 'Please enter the URL of the Signal gateway (leave blank to use default):', 'default' => 'http://localhost:5000'],
37
-			['field' => 'account', 'prompt' => 'Please enter the account (phone-number) of the sending signal account (leave blank if a phone-number is not required):', 'default' => ''],
36
+			[ 'field' => 'url', 'prompt' => 'Please enter the URL of the Signal gateway (leave blank to use default):', 'default' => 'http://localhost:5000' ],
37
+			[ 'field' => 'account', 'prompt' => 'Please enter the account (phone-number) of the sending signal account (leave blank if a phone-number is not required):', 'default' => '' ],
38 38
 		],
39 39
 	];
40 40
 	public const ACCOUNT_UNNECESSARY = 'unneccessary';
@@ -48,20 +48,20 @@  discard block
 block discarded – undo
48 48
 		parent::__construct($appConfig);
49 49
 	}
50 50
 
51
-	#[\Override]
52
-	public function send(string $identifier, string $message, array $extra = []): void {
51
+	#[\Override ]
52
+	public function send(string $identifier, string $message, array $extra = [ ]): void {
53 53
 		$client = $this->clientService->newClient();
54 54
 		// determine type of gateway
55 55
 
56 56
 		// test for native signal-cli JSON RPC.
57 57
 		$response = $client->post(
58
-			$this->getUrl() . '/api/v1/rpc',
58
+			$this->getUrl().'/api/v1/rpc',
59 59
 			[
60 60
 				'http_errors' => false,
61 61
 				'json' => [
62 62
 					'jsonrpc' => '2.0',
63 63
 					'method' => 'version',
64
-					'id' => 'version_' . $this->timeFactory->getTime(),
64
+					'id' => 'version_'.$this->timeFactory->getTime(),
65 65
 				],
66 66
 			]);
67 67
 		if ($response->getStatusCode() === 200 || $response->getStatusCode() === 201) {
@@ -77,12 +77,12 @@  discard block
 block discarded – undo
77 77
 				'account' => $this->getAccount(), // mandatory for native RPC API
78 78
 			];
79 79
 			$response = $response = $client->post(
80
-				$this->getUrl() . '/api/v1/rpc',
80
+				$this->getUrl().'/api/v1/rpc',
81 81
 				[
82 82
 					'json' => [
83 83
 						'jsonrpc' => '2.0',
84 84
 						'method' => 'send',
85
-						'id' => 'code_' . $this->timeFactory->getTime(),
85
+						'id' => 'code_'.$this->timeFactory->getTime(),
86 86
 						'params' => $params,
87 87
 					],
88 88
 				]);
@@ -90,12 +90,12 @@  discard block
 block discarded – undo
90 90
 			$json = json_decode($body, true);
91 91
 			$statusCode = $response->getStatusCode();
92 92
 			// The 201 "created" is probably a bug.
93
-			if ($statusCode < 200 || $statusCode >= 300 || is_null($json) || !is_array($json) || ($json['jsonrpc'] ?? null) != '2.0' || !isset($json['result']['timestamp'])) {
93
+			if ($statusCode < 200 || $statusCode >= 300 || is_null($json) || !is_array($json) || ($json[ 'jsonrpc' ] ?? null) != '2.0' || !isset($json[ 'result' ][ 'timestamp' ])) {
94 94
 				throw new MessageTransmissionException("error reported by Signal gateway, status=$statusCode, body=$body}");
95 95
 			}
96 96
 		} else {
97 97
 			// Try gateway in the style of https://gitlab.com/morph027/signal-cli-dbus-rest-api
98
-			$response = $client->get($this->getUrl() . '/v1/about');
98
+			$response = $client->get($this->getUrl().'/v1/about');
99 99
 			if ($response->getStatusCode() === 200) {
100 100
 				// Not so "ńew style" gateway, see
101 101
 				// https://gitlab.com/morph027/signal-cli-dbus-rest-api
@@ -103,7 +103,7 @@  discard block
 block discarded – undo
103 103
 				// https://github.com/bbernhard/signal-cli-rest-api
104 104
 				$body = $response->getBody();
105 105
 				$json = json_decode($body, true);
106
-				$versions = $json['versions'] ?? [];
106
+				$versions = $json[ 'versions' ] ?? [ ];
107 107
 				if (is_array($versions) && in_array('v2', $versions)) {
108 108
 					$json = [
109 109
 						'recipients' => $identifier,
@@ -111,17 +111,17 @@  discard block
 block discarded – undo
111 111
 					];
112 112
 					$account = $this->getAccount();
113 113
 					if ($account != self::ACCOUNT_UNNECESSARY) {
114
-						$json['account'] = $account;
114
+						$json[ 'account' ] = $account;
115 115
 					}
116 116
 					$response = $client->post(
117
-						$this->getUrl() . '/v2/send',
117
+						$this->getUrl().'/v2/send',
118 118
 						[
119 119
 							'json' => $json,
120 120
 						]
121 121
 					);
122 122
 				} else {
123 123
 					$response = $client->post(
124
-						$this->getUrl() . '/v1/send/' . $identifier,
124
+						$this->getUrl().'/v1/send/'.$identifier,
125 125
 						[
126 126
 							'json' => [ 'message' => $message ],
127 127
 						]
@@ -130,13 +130,13 @@  discard block
 block discarded – undo
130 130
 				$body = (string)$response->getBody();
131 131
 				$json = json_decode($body, true);
132 132
 				$status = $response->getStatusCode();
133
-				if ($status !== 201 || is_null($json) || !is_array($json) || !isset($json['timestamp'])) {
133
+				if ($status !== 201 || is_null($json) || !is_array($json) || !isset($json[ 'timestamp' ])) {
134 134
 					throw new MessageTransmissionException("error reported by Signal gateway, status=$status, body=$body}");
135 135
 				}
136 136
 			} else {
137 137
 				// Try old deprecated gateway https://gitlab.com/morph027/signal-web-gateway
138 138
 				$response = $client->post(
139
-					$this->getUrl() . '/v1/send/' . $identifier,
139
+					$this->getUrl().'/v1/send/'.$identifier,
140 140
 					[
141 141
 						'body' => [
142 142
 							'to' => $identifier,
@@ -149,23 +149,23 @@  discard block
 block discarded – undo
149 149
 				$json = json_decode($body, true);
150 150
 
151 151
 				$status = $response->getStatusCode();
152
-				if ($status !== 200 || is_null($json) || !is_array($json) || !isset($json['success']) || $json['success'] !== true) {
152
+				if ($status !== 200 || is_null($json) || !is_array($json) || !isset($json[ 'success' ]) || $json[ 'success' ] !== true) {
153 153
 					throw new MessageTransmissionException("error reported by Signal gateway, status=$status, body=$body}");
154 154
 				}
155 155
 			}
156 156
 		}
157 157
 	}
158 158
 
159
-	#[\Override]
159
+	#[\Override ]
160 160
 	public function cliConfigure(InputInterface $input, OutputInterface $output): int {
161 161
 		$helper = new QuestionHelper();
162
-		$urlQuestion = new Question(self::SCHEMA['fields'][0]['prompt'], self::SCHEMA['fields'][0]['default']);
162
+		$urlQuestion = new Question(self::SCHEMA[ 'fields' ][ 0 ][ 'prompt' ], self::SCHEMA[ 'fields' ][ 0 ][ 'default' ]);
163 163
 		$url = $helper->ask($input, $output, $urlQuestion);
164 164
 		$output->writeln("Using $url.");
165 165
 
166 166
 		$this->setUrl($url);
167 167
 
168
-		$accountQuestion = new Question(self::SCHEMA['fields'][1]['prompt'], self::SCHEMA['fields'][1]['default']);
168
+		$accountQuestion = new Question(self::SCHEMA[ 'fields' ][ 1 ][ 'prompt' ], self::SCHEMA[ 'fields' ][ 1 ][ 'default' ]);
169 169
 		$account = $helper->ask($input, $output, $accountQuestion);
170 170
 		if ($account == '') {
171 171
 			$account = self::ACCOUNT_UNNECESSARY;
Please login to merge, or discard this patch.