@@ -133,7 +133,7 @@ discard block |
||
| 133 | 133 | public function downloadFile(File $file): TelegramDocument |
| 134 | 134 | { |
| 135 | 135 | $this->logger->debug('Downloading file from Telegram, creating URL'); |
| 136 | - $url = 'https://api.telegram.org/file/bot' . $this->botToken . '/' . $file->file_path; |
|
| 136 | + $url = 'https://api.telegram.org/file/bot'.$this->botToken.'/'.$file->file_path; |
|
| 137 | 137 | $this->logger->debug('About to perform request to begin downloading file'); |
| 138 | 138 | return new TelegramDocument($this->requestHandler->get($url)); |
| 139 | 139 | } |
@@ -146,16 +146,16 @@ discard block |
||
| 146 | 146 | public function downloadFileAsync(File $file): PromiseInterface |
| 147 | 147 | { |
| 148 | 148 | $this->logger->debug('Downloading file async from Telegram, creating URL'); |
| 149 | - $url = 'https://api.telegram.org/file/bot' . $this->botToken . '/' . $file->file_path; |
|
| 149 | + $url = 'https://api.telegram.org/file/bot'.$this->botToken.'/'.$file->file_path; |
|
| 150 | 150 | $this->logger->debug('About to perform request to begin downloading file'); |
| 151 | 151 | |
| 152 | 152 | $deferred = new Promise(); |
| 153 | 153 | |
| 154 | - return $this->requestHandler->requestAsync($url)->then(function (ResponseInterface $response) use ($deferred) |
|
| 154 | + return $this->requestHandler->requestAsync($url)->then(function(ResponseInterface $response) use ($deferred) |
|
| 155 | 155 | { |
| 156 | 156 | $deferred->resolve(new TelegramDocument($response)); |
| 157 | 157 | }, |
| 158 | - function (RequestException $exception) use ($deferred) |
|
| 158 | + function(RequestException $exception) use ($deferred) |
|
| 159 | 159 | { |
| 160 | 160 | if (!empty($exception->getResponse()->getBody())) |
| 161 | 161 | $deferred->resolve(new TelegramDocument($exception->getResponse())); |
@@ -170,7 +170,7 @@ discard block |
||
| 170 | 170 | */ |
| 171 | 171 | final private function constructApiUrl(): TgLog |
| 172 | 172 | { |
| 173 | - $this->apiUrl = 'https://api.telegram.org/bot' . $this->botToken . '/'; |
|
| 173 | + $this->apiUrl = 'https://api.telegram.org/bot'.$this->botToken.'/'; |
|
| 174 | 174 | $this->logger->debug('Built up the API URL'); |
| 175 | 175 | return $this; |
| 176 | 176 | } |
@@ -213,14 +213,14 @@ discard block |
||
| 213 | 213 | $deferred = new Promise(); |
| 214 | 214 | |
| 215 | 215 | $promise = $this->requestHandler->requestAsync($this->composeApiMethodUrl($method), $formData); |
| 216 | - $promise->then(function (ResponseInterface $response) use ($deferred) |
|
| 216 | + $promise->then(function(ResponseInterface $response) use ($deferred) |
|
| 217 | 217 | { |
| 218 | - $deferred->resolve(new TelegramRawData((string) $response->getBody())); |
|
| 218 | + $deferred->resolve(new TelegramRawData((string)$response->getBody())); |
|
| 219 | 219 | }, |
| 220 | - function (RequestException $exception) use ($deferred) |
|
| 220 | + function(RequestException $exception) use ($deferred) |
|
| 221 | 221 | { |
| 222 | 222 | if (!empty($exception->getResponse()->getBody())) |
| 223 | - $deferred->resolve(new TelegramRawData((string) $exception->getResponse()->getBody(), $exception)); |
|
| 223 | + $deferred->resolve(new TelegramRawData((string)$exception->getResponse()->getBody(), $exception)); |
|
| 224 | 224 | else |
| 225 | 225 | $deferred->reject($exception); |
| 226 | 226 | }); |
@@ -328,7 +328,7 @@ discard block |
||
| 328 | 328 | $this->methodName = substr($completeClassName, strrpos($completeClassName, '\\') + 1); |
| 329 | 329 | $this->logger->info('About to perform API request', ['method' => $this->methodName]); |
| 330 | 330 | |
| 331 | - return $this->apiUrl . $this->methodName; |
|
| 331 | + return $this->apiUrl.$this->methodName; |
|
| 332 | 332 | } |
| 333 | 333 | |
| 334 | 334 | /** |
@@ -157,10 +157,11 @@ discard block |
||
| 157 | 157 | }, |
| 158 | 158 | function (RequestException $exception) use ($deferred) |
| 159 | 159 | { |
| 160 | - if (!empty($exception->getResponse()->getBody())) |
|
| 161 | - $deferred->resolve(new TelegramDocument($exception->getResponse())); |
|
| 162 | - else |
|
| 163 | - $deferred->reject($exception); |
|
| 160 | + if (!empty($exception->getResponse()->getBody())) { |
|
| 161 | + $deferred->resolve(new TelegramDocument($exception->getResponse())); |
|
| 162 | + } else { |
|
| 163 | + $deferred->reject($exception); |
|
| 164 | + } |
|
| 164 | 165 | }); |
| 165 | 166 | } |
| 166 | 167 | |
@@ -219,10 +220,11 @@ discard block |
||
| 219 | 220 | }, |
| 220 | 221 | function (RequestException $exception) use ($deferred) |
| 221 | 222 | { |
| 222 | - if (!empty($exception->getResponse()->getBody())) |
|
| 223 | - $deferred->resolve(new TelegramRawData((string) $exception->getResponse()->getBody(), $exception)); |
|
| 224 | - else |
|
| 225 | - $deferred->reject($exception); |
|
| 223 | + if (!empty($exception->getResponse()->getBody())) { |
|
| 224 | + $deferred->resolve(new TelegramRawData((string) $exception->getResponse()->getBody(), $exception)); |
|
| 225 | + } else { |
|
| 226 | + $deferred->reject($exception); |
|
| 227 | + } |
|
| 226 | 228 | }); |
| 227 | 229 | |
| 228 | 230 | return $deferred; |
@@ -1,6 +1,6 @@ discard block |
||
| 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 |
||
| 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 | { |
@@ -78,7 +78,7 @@ discard block |
||
| 78 | 78 | } |
| 79 | 79 | } |
| 80 | 80 | finally { |
| 81 | - return new TelegramRawData((string) $response->getBody(), $e); |
|
| 81 | + return new TelegramRawData((string)$response->getBody(), $e); |
|
| 82 | 82 | } |
| 83 | 83 | } |
| 84 | 84 | |
@@ -94,12 +94,12 @@ discard block |
||
| 94 | 94 | $deferred = new Promise(); |
| 95 | 95 | |
| 96 | 96 | $promise = $this->httpClient->postAsync($uri, $formData); |
| 97 | - $promise->then(function (ResponseInterface $response) use ($deferred) { |
|
| 98 | - $deferred->resolve(new TelegramRawData((string) $response->getBody())); |
|
| 97 | + $promise->then(function(ResponseInterface $response) use ($deferred) { |
|
| 98 | + $deferred->resolve(new TelegramRawData((string)$response->getBody())); |
|
| 99 | 99 | }, |
| 100 | - function (RequestException $exception) use ($deferred) { |
|
| 100 | + function(RequestException $exception) use ($deferred) { |
|
| 101 | 101 | if (!empty($exception->getResponse()->getBody())) |
| 102 | - $deferred->resolve(new TelegramRawData((string) $exception->getResponse()->getBody(), $exception)); |
|
| 102 | + $deferred->resolve(new TelegramRawData((string)$exception->getResponse()->getBody(), $exception)); |
|
| 103 | 103 | else |
| 104 | 104 | $deferred->reject($exception); |
| 105 | 105 | }); |
@@ -69,15 +69,13 @@ discard block |
||
| 69 | 69 | try { |
| 70 | 70 | $response = $this->httpClient->post($uri, $formData); |
| 71 | 71 | $this->logger->debug('Got response back from Telegram, applying json_decode'); |
| 72 | - } |
|
| 73 | - catch (ClientException $e) { |
|
| 72 | + } catch (ClientException $e) { |
|
| 74 | 73 | $response = $e->getResponse(); |
| 75 | 74 | // It can happen that we have a network problem, in such case, we can't do nothing about it, so rethrow |
| 76 | 75 | if (empty($response)) { |
| 77 | 76 | throw $e; |
| 78 | 77 | } |
| 79 | - } |
|
| 80 | - finally { |
|
| 78 | + } finally { |
|
| 81 | 79 | return new TelegramRawData((string) $response->getBody(), $e); |
| 82 | 80 | } |
| 83 | 81 | } |
@@ -98,10 +96,11 @@ discard block |
||
| 98 | 96 | $deferred->resolve(new TelegramRawData((string) $response->getBody())); |
| 99 | 97 | }, |
| 100 | 98 | function (RequestException $exception) use ($deferred) { |
| 101 | - if (!empty($exception->getResponse()->getBody())) |
|
| 102 | - $deferred->resolve(new TelegramRawData((string) $exception->getResponse()->getBody(), $exception)); |
|
| 103 | - else |
|
| 104 | - $deferred->reject($exception); |
|
| 99 | + if (!empty($exception->getResponse()->getBody())) { |
|
| 100 | + $deferred->resolve(new TelegramRawData((string) $exception->getResponse()->getBody(), $exception)); |
|
| 101 | + } else { |
|
| 102 | + $deferred->reject($exception); |
|
| 103 | + } |
|
| 105 | 104 | }); |
| 106 | 105 | |
| 107 | 106 | return $deferred; |