Completed
Pull Request — master (#53)
by Rick
02:13
created
src/TgLog.php 3 patches
Indentation   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -174,15 +174,15 @@  discard block
 block discarded – undo
174 174
         return $this;
175 175
     }
176 176
 
177
-	/**
178
-	 * This is the method that actually makes the call, which can be easily overwritten so that our unit tests can work
179
-	 *
180
-	 * @param TelegramMethods $method
181
-	 * @param array $formData
182
-	 *
183
-	 * @return TelegramRawData
184
-	 * @throws \Exception
185
-	 */
177
+ /**
178
+  * This is the method that actually makes the call, which can be easily overwritten so that our unit tests can work
179
+  *
180
+  * @param TelegramMethods $method
181
+  * @param array $formData
182
+  *
183
+  * @return TelegramRawData
184
+  * @throws \Exception
185
+  */
186 186
     protected function sendRequestToTelegram(TelegramMethods $method, array $formData): TelegramRawData
187 187
     {
188 188
         $e = null;
@@ -190,13 +190,13 @@  discard block
 block discarded – undo
190 190
         try {
191 191
             $response = $this->requestHandler->post($this->composeApiMethodUrl($method), $formData);
192 192
             $this->logger->debug('Got response back from Telegram');
193
-	        return $response;
193
+         return $response;
194 194
         } catch (\Exception $e) {
195 195
             // It can happen that we have a network problem, in such case, we can't do nothing about it, so rethrow
196 196
             if (!method_exists($e, 'getResponse') || empty($e->getResponse())) {
197 197
                 throw $e;
198 198
             }
199
-	        return new TelegramRawData((string)$e->getResponse()->getBody(), $e);
199
+         return new TelegramRawData((string)$e->getResponse()->getBody(), $e);
200 200
         }
201 201
     }
202 202
 
@@ -257,9 +257,9 @@  discard block
 block discarded – undo
257 257
             case 'application/x-www-form-urlencoded':
258 258
                 $this->logger->debug('Creating x-www-form-urlencoded form (AKA fast request)');
259 259
                 $formData = [
260
-	                'headers' =>  [
261
-	                	'Content-Type' => 'application/x-www-form-urlencoded',
262
-	                ],
260
+                 'headers' =>  [
261
+                  'Content-Type' => 'application/x-www-form-urlencoded',
262
+                 ],
263 263
                     'body' => http_build_query($method->export(), '', '&'),
264 264
                 ];
265 265
                 break;
@@ -275,8 +275,8 @@  discard block
 block discarded – undo
275 275
                     $this->formType
276 276
                 ]);
277 277
                 $formData = [
278
-                	'headers' => [
279
-	                    'Content-Type' => $this->formType
278
+                 'headers' => [
279
+                     'Content-Type' => $this->formType
280 280
                     ]
281 281
                 ];
282 282
                 break;
@@ -349,7 +349,7 @@  discard block
 block discarded – undo
349 349
     {
350 350
         $this->logger->debug('Creating multi-part form array data (complex and expensive)');
351 351
         $formData = [
352
-        	'body' => null
352
+         'body' => null
353 353
         ];
354 354
 
355 355
         $multiPartArray = [];
Please login to merge, or discard this patch.
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -132,7 +132,7 @@  discard block
 block discarded – undo
132 132
     public function downloadFile(File $file): TelegramDocument
133 133
     {
134 134
         $this->logger->debug('Downloading file from Telegram, creating URL');
135
-        $url = 'https://api.telegram.org/file/bot' . $this->botToken . '/' . $file->file_path;
135
+        $url = 'https://api.telegram.org/file/bot'.$this->botToken.'/'.$file->file_path;
136 136
         $this->logger->debug('About to perform request to begin downloading file');
137 137
         return new TelegramDocument($this->requestHandler->get($url));
138 138
     }
@@ -145,16 +145,16 @@  discard block
 block discarded – undo
145 145
     public function downloadFileAsync(File $file): PromiseInterface
146 146
     {
147 147
         $this->logger->debug('Downloading file async from Telegram, creating URL');
148
-        $url = 'https://api.telegram.org/file/bot' . $this->botToken . '/' . $file->file_path;
148
+        $url = 'https://api.telegram.org/file/bot'.$this->botToken.'/'.$file->file_path;
149 149
         $this->logger->debug('About to perform request to begin downloading file');
150 150
 
151 151
         $deferred = new Deferred();
152 152
 
153
-        return $this->requestHandler->getAsync($url)->then(function (ResponseInterface $response) use ($deferred)
153
+        return $this->requestHandler->getAsync($url)->then(function(ResponseInterface $response) use ($deferred)
154 154
         {
155 155
             $deferred->resolve(new TelegramDocument($response));
156 156
         },
157
-            function (\Exception $exception) use ($deferred)
157
+            function(\Exception $exception) use ($deferred)
158 158
             {
159 159
                 if (method_exists($exception, 'getResponse') && !empty($exception->getResponse()->getBody()))
160 160
                     $deferred->resolve(new TelegramDocument($exception->getResponse()));
@@ -169,7 +169,7 @@  discard block
 block discarded – undo
169 169
      */
170 170
     final private function constructApiUrl(): TgLog
171 171
     {
172
-        $this->apiUrl = 'https://api.telegram.org/bot' . $this->botToken . '/';
172
+        $this->apiUrl = 'https://api.telegram.org/bot'.$this->botToken.'/';
173 173
         $this->logger->debug('Built up the API URL');
174 174
         return $this;
175 175
     }
@@ -212,14 +212,14 @@  discard block
 block discarded – undo
212 212
         $deferred = new Deferred();
213 213
 
214 214
         $promise = $this->requestHandler->postAsync($this->composeApiMethodUrl($method), $formData);
215
-        $promise->then(function (ResponseInterface $response) use ($deferred)
215
+        $promise->then(function(ResponseInterface $response) use ($deferred)
216 216
         {
217
-            $deferred->resolve(new TelegramRawData((string) $response->getBody()));
217
+            $deferred->resolve(new TelegramRawData((string)$response->getBody()));
218 218
         },
219
-            function (\Exception $exception) use ($deferred)
219
+            function(\Exception $exception) use ($deferred)
220 220
             {
221 221
                 if (method_exists($exception, 'getResponse') && !empty($exception->getResponse()->getBody()))
222
-                    $deferred->resolve(new TelegramRawData((string) $exception->getResponse()->getBody(), $exception));
222
+                    $deferred->resolve(new TelegramRawData((string)$exception->getResponse()->getBody(), $exception));
223 223
                 else
224 224
                     $deferred->reject($exception);
225 225
             });
@@ -334,7 +334,7 @@  discard block
 block discarded – undo
334 334
         $this->methodName = substr($completeClassName, strrpos($completeClassName, '\\') + 1);
335 335
         $this->logger->info('About to perform API request', ['method' => $this->methodName]);
336 336
 
337
-        return $this->apiUrl . $this->methodName;
337
+        return $this->apiUrl.$this->methodName;
338 338
     }
339 339
 
340 340
     /**
Please login to merge, or discard this patch.
Braces   +10 added lines, -8 removed lines patch added patch discarded remove patch
@@ -156,10 +156,11 @@  discard block
 block discarded – undo
156 156
         },
157 157
             function (\Exception $exception) use ($deferred)
158 158
             {
159
-                if (method_exists($exception, 'getResponse') && !empty($exception->getResponse()->getBody()))
160
-                    $deferred->resolve(new TelegramDocument($exception->getResponse()));
161
-                else
162
-                    $deferred->reject($exception);
159
+                if (method_exists($exception, 'getResponse') && !empty($exception->getResponse()->getBody())) {
160
+                                    $deferred->resolve(new TelegramDocument($exception->getResponse()));
161
+                } else {
162
+                                    $deferred->reject($exception);
163
+                }
163 164
             });
164 165
     }
165 166
 
@@ -218,10 +219,11 @@  discard block
 block discarded – undo
218 219
         },
219 220
             function (\Exception $exception) use ($deferred)
220 221
             {
221
-                if (method_exists($exception, 'getResponse') && !empty($exception->getResponse()->getBody()))
222
-                    $deferred->resolve(new TelegramRawData((string) $exception->getResponse()->getBody(), $exception));
223
-                else
224
-                    $deferred->reject($exception);
222
+                if (method_exists($exception, 'getResponse') && !empty($exception->getResponse()->getBody())) {
223
+                                    $deferred->resolve(new TelegramRawData((string) $exception->getResponse()->getBody(), $exception));
224
+                } else {
225
+                                    $deferred->reject($exception);
226
+                }
225 227
             });
226 228
 
227 229
         return $deferred->promise();
Please login to merge, or discard this patch.
src/GuzzleRequestHandler.php 3 patches
Indentation   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -49,11 +49,11 @@  discard block
 block discarded – undo
49 49
         $this->httpClient = $client;
50 50
     }
51 51
 
52
-	/**
53
-	 * @param string $uri
54
-	 *
55
-	 * @return ResponseInterface
56
-	 */
52
+ /**
53
+  * @param string $uri
54
+  *
55
+  * @return ResponseInterface
56
+  */
57 57
     public function get(string $uri): ResponseInterface
58 58
     {
59 59
         return $this->httpClient->get($uri);
@@ -112,27 +112,27 @@  discard block
 block discarded – undo
112 112
         return $deferred->promise();
113 113
     }
114 114
 
115
-	/**
116
-	 * @param string $uri
117
-	 *
118
-	 * @return PromiseInterface
119
-	 */
115
+ /**
116
+  * @param string $uri
117
+  *
118
+  * @return PromiseInterface
119
+  */
120 120
     public function getAsync(string $uri): PromiseInterface
121 121
     {
122
-	    $this->logger->debug('About to perform async HTTP call to Telegram\'s API');
123
-	    $deferred = new Deferred();
124
-
125
-	    $promise = $this->httpClient->getAsync($uri);
126
-	    $promise->then(function (ResponseInterface $response) use ($deferred) {
127
-		    $deferred->resolve(new TelegramRawData((string) $response->getBody()));
128
-	    },
129
-		    function (RequestException $exception) use ($deferred) {
130
-			    if (!empty($exception->getResponse()->getBody()))
131
-				    $deferred->resolve(new TelegramRawData((string) $exception->getResponse()->getBody(), $exception));
132
-			    else
133
-				    $deferred->reject($exception);
134
-		    });
135
-
136
-	    return $deferred->promise();
122
+     $this->logger->debug('About to perform async HTTP call to Telegram\'s API');
123
+     $deferred = new Deferred();
124
+
125
+     $promise = $this->httpClient->getAsync($uri);
126
+     $promise->then(function (ResponseInterface $response) use ($deferred) {
127
+      $deferred->resolve(new TelegramRawData((string) $response->getBody()));
128
+     },
129
+      function (RequestException $exception) use ($deferred) {
130
+       if (!empty($exception->getResponse()->getBody()))
131
+        $deferred->resolve(new TelegramRawData((string) $exception->getResponse()->getBody(), $exception));
132
+       else
133
+        $deferred->reject($exception);
134
+      });
135
+
136
+     return $deferred->promise();
137 137
     }
138 138
 }
139 139
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-declare(strict_types=1);
3
+declare(strict_types = 1);
4 4
 
5 5
 namespace unreal4u\TelegramAPI;
6 6
 
@@ -34,7 +34,7 @@  discard block
 block discarded – undo
34 34
      * @param ClientInterface $client
35 35
      * @param LoggerInterface $logger
36 36
      */
37
-    public function __construct(?ClientInterface $client = null, LoggerInterface $logger = null)
37
+    public function __construct(? ClientInterface $client = null, LoggerInterface $logger = null)
38 38
     {
39 39
         if ($logger === null)
40 40
         {
@@ -83,7 +83,7 @@  discard block
 block discarded – undo
83 83
             }
84 84
         }
85 85
         finally {
86
-            return new TelegramRawData((string) $response->getBody(), $e);
86
+            return new TelegramRawData((string)$response->getBody(), $e);
87 87
         }
88 88
     }
89 89
 
@@ -99,12 +99,12 @@  discard block
 block discarded – undo
99 99
         $deferred = new Deferred();
100 100
 
101 101
         $promise = $this->httpClient->postAsync($uri, $formData);
102
-        $promise->then(function (ResponseInterface $response) use ($deferred) {
103
-            $deferred->resolve(new TelegramRawData((string) $response->getBody()));
102
+        $promise->then(function(ResponseInterface $response) use ($deferred) {
103
+            $deferred->resolve(new TelegramRawData((string)$response->getBody()));
104 104
         },
105
-            function (RequestException $exception) use ($deferred) {
105
+            function(RequestException $exception) use ($deferred) {
106 106
                 if (!empty($exception->getResponse()->getBody()))
107
-                    $deferred->resolve(new TelegramRawData((string) $exception->getResponse()->getBody(), $exception));
107
+                    $deferred->resolve(new TelegramRawData((string)$exception->getResponse()->getBody(), $exception));
108 108
                 else
109 109
                     $deferred->reject($exception);
110 110
             });
@@ -123,12 +123,12 @@  discard block
 block discarded – undo
123 123
 	    $deferred = new Deferred();
124 124
 
125 125
 	    $promise = $this->httpClient->getAsync($uri);
126
-	    $promise->then(function (ResponseInterface $response) use ($deferred) {
127
-		    $deferred->resolve(new TelegramRawData((string) $response->getBody()));
126
+	    $promise->then(function(ResponseInterface $response) use ($deferred) {
127
+		    $deferred->resolve(new TelegramRawData((string)$response->getBody()));
128 128
 	    },
129
-		    function (RequestException $exception) use ($deferred) {
129
+		    function(RequestException $exception) use ($deferred) {
130 130
 			    if (!empty($exception->getResponse()->getBody()))
131
-				    $deferred->resolve(new TelegramRawData((string) $exception->getResponse()->getBody(), $exception));
131
+				    $deferred->resolve(new TelegramRawData((string)$exception->getResponse()->getBody(), $exception));
132 132
 			    else
133 133
 				    $deferred->reject($exception);
134 134
 		    });
Please login to merge, or discard this patch.
Braces   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -74,15 +74,13 @@  discard block
 block discarded – undo
74 74
         try {
75 75
             $response = $this->httpClient->post($uri, $formData);
76 76
             $this->logger->debug('Got response back from Telegram, applying json_decode');
77
-        }
78
-        catch (ClientException $e) {
77
+        } catch (ClientException $e) {
79 78
             $response = $e->getResponse();
80 79
             // It can happen that we have a network problem, in such case, we can't do nothing about it, so rethrow
81 80
             if (empty($response)) {
82 81
                 throw $e;
83 82
             }
84
-        }
85
-        finally {
83
+        } finally {
86 84
             return new TelegramRawData((string) $response->getBody(), $e);
87 85
         }
88 86
     }
@@ -103,10 +101,11 @@  discard block
 block discarded – undo
103 101
             $deferred->resolve(new TelegramRawData((string) $response->getBody()));
104 102
         },
105 103
             function (RequestException $exception) use ($deferred) {
106
-                if (!empty($exception->getResponse()->getBody()))
107
-                    $deferred->resolve(new TelegramRawData((string) $exception->getResponse()->getBody(), $exception));
108
-                else
109
-                    $deferred->reject($exception);
104
+                if (!empty($exception->getResponse()->getBody())) {
105
+                                    $deferred->resolve(new TelegramRawData((string) $exception->getResponse()->getBody(), $exception));
106
+                } else {
107
+                                    $deferred->reject($exception);
108
+                }
110 109
             });
111 110
 
112 111
         return $deferred->promise();
@@ -127,10 +126,11 @@  discard block
 block discarded – undo
127 126
 		    $deferred->resolve(new TelegramRawData((string) $response->getBody()));
128 127
 	    },
129 128
 		    function (RequestException $exception) use ($deferred) {
130
-			    if (!empty($exception->getResponse()->getBody()))
131
-				    $deferred->resolve(new TelegramRawData((string) $exception->getResponse()->getBody(), $exception));
132
-			    else
133
-				    $deferred->reject($exception);
129
+			    if (!empty($exception->getResponse()->getBody())) {
130
+			    				    $deferred->resolve(new TelegramRawData((string) $exception->getResponse()->getBody(), $exception));
131
+			    } else {
132
+			    				    $deferred->reject($exception);
133
+			    }
134 134
 		    });
135 135
 
136 136
 	    return $deferred->promise();
Please login to merge, or discard this patch.
src/RequestHandlerInterface.php 1 patch
Indentation   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -10,15 +10,15 @@  discard block
 block discarded – undo
10 10
 
11 11
 interface RequestHandlerInterface
12 12
 {
13
-	/**
14
-	 * This is the method that actually makes the call, which can be easily overwritten so that our unit tests can work
15
-	 *
16
-	 * @param string $uri
17
-	 * @param array $formFields
18
-	 *
19
-	 * @return TelegramRawData
20
-	 *
21
-	 */
13
+ /**
14
+  * This is the method that actually makes the call, which can be easily overwritten so that our unit tests can work
15
+  *
16
+  * @param string $uri
17
+  * @param array $formFields
18
+  *
19
+  * @return TelegramRawData
20
+  *
21
+  */
22 22
     public function post(string $uri, array $formFields): TelegramRawData;
23 23
 
24 24
     /**
@@ -36,10 +36,10 @@  discard block
 block discarded – undo
36 36
      */
37 37
     public function postAsync(string $uri, array $formFields): PromiseInterface;
38 38
 
39
-	/**
40
-	 * @param string $uri
41
-	 *
42
-	 * @return PromiseInterface
43
-	 */
44
-	public function getAsync(string $uri): PromiseInterface;
39
+ /**
40
+  * @param string $uri
41
+  *
42
+  * @return PromiseInterface
43
+  */
44
+ public function getAsync(string $uri): PromiseInterface;
45 45
 }
46 46
\ No newline at end of file
Please login to merge, or discard this patch.