@@ -38,8 +38,7 @@ discard block |
||
| 38 | 38 | { |
| 39 | 39 | $decoded = json_decode($json); |
| 40 | 40 | return is_array($decoded) ? |
| 41 | - $this->jsonMapper->mapArray($decoded, [], $class) : |
|
| 42 | - $this->jsonMapper->map($decoded, new $class); |
|
| 41 | + $this->jsonMapper->mapArray($decoded, [], $class) : $this->jsonMapper->map($decoded, new $class); |
|
| 43 | 42 | } |
| 44 | 43 | |
| 45 | 44 | /** |
@@ -51,8 +50,7 @@ discard block |
||
| 51 | 50 | public function mapObject($object, $class) |
| 52 | 51 | { |
| 53 | 52 | return is_array($object) ? |
| 54 | - $this->jsonMapper->mapArray($object, [], $class) : |
|
| 55 | - $this->jsonMapper->map($object, new $class); |
|
| 53 | + $this->jsonMapper->mapArray($object, [], $class) : $this->jsonMapper->map($object, new $class); |
|
| 56 | 54 | } |
| 57 | 55 | |
| 58 | 56 | } |
@@ -368,7 +368,7 @@ |
||
| 368 | 368 | */ |
| 369 | 369 | protected function feedMiddlewareStack() |
| 370 | 370 | { |
| 371 | - array_walk_recursive($this->listeners, function ($value) { |
|
| 371 | + array_walk_recursive($this->listeners, function($value) { |
|
| 372 | 372 | if ($value instanceof Listener) { |
| 373 | 373 | foreach ($this->middleware as $m) { |
| 374 | 374 | $value->middleware($m); |
@@ -65,7 +65,7 @@ discard block |
||
| 65 | 65 | $clone['chat_id'] = $chatId; |
| 66 | 66 | array_push($payload, $clone); |
| 67 | 67 | } |
| 68 | - $dequeue = function (TimerInterface $timer) use (&$payload) { |
|
| 68 | + $dequeue = function(TimerInterface $timer) use (&$payload) { |
|
| 69 | 69 | // if there's no more message to dequeue cancel the timer |
| 70 | 70 | if (!$payload) { |
| 71 | 71 | $this->loop->cancelTimer($timer); |
@@ -75,7 +75,7 @@ discard block |
||
| 75 | 75 | // pop and process |
| 76 | 76 | $params = array_pop($payload); |
| 77 | 77 | $this->telegram->doSendMessage($params) |
| 78 | - ->otherwise(function (TelegramException $error) { |
|
| 78 | + ->otherwise(function(TelegramException $error) { |
|
| 79 | 79 | $this->logger->error("Failed to send message in bulk mode, reason: $error"); |
| 80 | 80 | } |
| 81 | 81 | ); |
@@ -1463,7 +1463,7 @@ discard block |
||
| 1463 | 1463 | $async = $this->container->get(Config::class)->isReactFileSystem(); |
| 1464 | 1464 | |
| 1465 | 1465 | if ($async) { |
| 1466 | - return $this->prepareMultipartDataAsync($params)->then(function ($result) use ($method) { |
|
| 1466 | + return $this->prepareMultipartDataAsync($params)->then(function($result) use ($method) { |
|
| 1467 | 1467 | $headers = array("Content-Length" => $result->getSize(), "Content-Type" => "multipart/form-data; boundary={$result->getBoundary()}"); |
| 1468 | 1468 | return $this->browser->post($method, $headers, $result); |
| 1469 | 1469 | }); |
@@ -1492,12 +1492,12 @@ discard block |
||
| 1492 | 1492 | foreach ($params as $key => $value) { |
| 1493 | 1493 | |
| 1494 | 1494 | if ($value instanceof InputFile) { |
| 1495 | - array_push($promises, $filesystem->getContents($value->getPath())->then(function ($contents) use ($value, $multipart_data, $key) { |
|
| 1495 | + array_push($promises, $filesystem->getContents($value->getPath())->then(function($contents) use ($value, $multipart_data, $key) { |
|
| 1496 | 1496 | $data = ['name' => $key]; |
| 1497 | 1497 | $data['contents'] = $contents; |
| 1498 | 1498 | $data['filename'] = basename($value->getPath()); |
| 1499 | 1499 | return $data; |
| 1500 | - }, function ($error) { |
|
| 1500 | + }, function($error) { |
|
| 1501 | 1501 | $this->container->get(ZanzaraLogger::class)->error($error); |
| 1502 | 1502 | return $error; |
| 1503 | 1503 | })); |
@@ -1509,12 +1509,12 @@ discard block |
||
| 1509 | 1509 | } |
| 1510 | 1510 | } |
| 1511 | 1511 | |
| 1512 | - return all($promises)->then(function ($files) use ($multipart_data) { |
|
| 1512 | + return all($promises)->then(function($files) use ($multipart_data) { |
|
| 1513 | 1513 | foreach ($files as $key => $value) { |
| 1514 | 1514 | array_push($multipart_data, $value); |
| 1515 | 1515 | } |
| 1516 | 1516 | return new MultipartStream($multipart_data); |
| 1517 | - }, function ($error) { |
|
| 1517 | + }, function($error) { |
|
| 1518 | 1518 | $this->container->get(ZanzaraLogger::class)->error($error); |
| 1519 | 1519 | return $error; |
| 1520 | 1520 | }); |
@@ -1562,8 +1562,8 @@ discard block |
||
| 1562 | 1562 | $logger = $this->container->get(ZanzaraLogger::class); |
| 1563 | 1563 | |
| 1564 | 1564 | return $promise |
| 1565 | - ->then(function (ResponseInterface $response) use ($class, $mapper) { |
|
| 1566 | - $json = (string)$response->getBody(); |
|
| 1565 | + ->then(function(ResponseInterface $response) use ($class, $mapper) { |
|
| 1566 | + $json = (string) $response->getBody(); |
|
| 1567 | 1567 | $object = json_decode($json); |
| 1568 | 1568 | |
| 1569 | 1569 | if (is_scalar($object->result) && $class === "Scalar") { |
@@ -1572,8 +1572,8 @@ discard block |
||
| 1572 | 1572 | |
| 1573 | 1573 | return $mapper->mapObject($object->result, $class); |
| 1574 | 1574 | |
| 1575 | - }, function (ResponseException $exception) use ($logger, $mapper) { |
|
| 1576 | - $json = (string)$exception->getResponse()->getBody(); |
|
| 1575 | + }, function(ResponseException $exception) use ($logger, $mapper) { |
|
| 1576 | + $json = (string) $exception->getResponse()->getBody(); |
|
| 1577 | 1577 | $telegramException = $mapper->mapJson($json, TelegramException::class); |
| 1578 | 1578 | $logger->error($telegramException); |
| 1579 | 1579 | throw $telegramException; |
@@ -100,7 +100,7 @@ discard block |
||
| 100 | 100 | |
| 101 | 101 | case Config::REACTPHP_WEBHOOK_MODE: |
| 102 | 102 | $this->telegram->getWebhookInfo()->then( |
| 103 | - function (WebhookInfo $webhookInfo) { |
|
| 103 | + function(WebhookInfo $webhookInfo) { |
|
| 104 | 104 | if (!$webhookInfo->getUrl()) { |
| 105 | 105 | $message = "Your bot doesn't have a webhook set, please set one before running Zanzara in webhook" . |
| 106 | 106 | " mode. See https://github.com/badfarm/zanzara/wiki#set-webhook"; |
@@ -114,7 +114,7 @@ discard block |
||
| 114 | 114 | |
| 115 | 115 | case Config::POLLING_MODE: |
| 116 | 116 | $this->telegram->getWebhookInfo()->then( |
| 117 | - function (WebhookInfo $webhookInfo) { |
|
| 117 | + function(WebhookInfo $webhookInfo) { |
|
| 118 | 118 | if (!$webhookInfo->getUrl()) { |
| 119 | 119 | $this->loop->futureTick([$this, 'polling']); |
| 120 | 120 | $this->logger->info("Zanzara is listening..."); |
@@ -127,7 +127,7 @@ discard block |
||
| 127 | 127 | $answer = readline(); |
| 128 | 128 | if (strtoupper($answer) === "YES") { |
| 129 | 129 | $this->telegram->deleteWebhook()->then( |
| 130 | - function ($res) { |
|
| 130 | + function($res) { |
|
| 131 | 131 | if ($res === true) { |
| 132 | 132 | $this->logger->info("Webhook is deleted, Zanzara is starting in polling ..."); |
| 133 | 133 | $this->loop->futureTick([$this, 'polling']); |
@@ -186,19 +186,19 @@ discard block |
||
| 186 | 186 | private function prepareServer() |
| 187 | 187 | { |
| 188 | 188 | $processingUpdate = null; |
| 189 | - $this->server = new Server(function (ServerRequestInterface $request) use (&$processingUpdate) { |
|
| 189 | + $this->server = new Server(function(ServerRequestInterface $request) use (&$processingUpdate) { |
|
| 190 | 190 | $token = $this->resolveTokenFromPath($request->getUri()->getPath()); |
| 191 | 191 | if (!$this->isWebhookAuthorized($token)) { |
| 192 | 192 | $this->logger->errorNotAuthorized(); |
| 193 | 193 | return new Response(403, [], $this->logger->getNotAuthorizedMessage()); |
| 194 | 194 | } |
| 195 | - $json = (string)$request->getBody(); |
|
| 195 | + $json = (string) $request->getBody(); |
|
| 196 | 196 | /** @var Update $processingUpdate */ |
| 197 | 197 | $processingUpdate = $this->zanzaraMapper->mapJson($json, Update::class); |
| 198 | 198 | $this->processUpdate($processingUpdate); |
| 199 | 199 | return new Response(); |
| 200 | 200 | }); |
| 201 | - $this->server->on('error', function ($e) use (&$processingUpdate) { |
|
| 201 | + $this->server->on('error', function($e) use (&$processingUpdate) { |
|
| 202 | 202 | $this->logger->errorUpdate($e, $processingUpdate); |
| 203 | 203 | $errorHandler = $this->config->getErrorHandler(); |
| 204 | 204 | if ($errorHandler) { |
@@ -228,7 +228,7 @@ discard block |
||
| 228 | 228 | 'limit' => $this->config->getPollingLimit(), |
| 229 | 229 | 'timeout' => $this->config->getPollingTimeout(), |
| 230 | 230 | 'allowed_updates' => $this->config->getPollingAllowedUpdates(), |
| 231 | - ])->then(function (array $updates) use (&$offset, &$processingUpdate) { |
|
| 231 | + ])->then(function(array $updates) use (&$offset, &$processingUpdate) { |
|
| 232 | 232 | if ($offset === 1) { |
| 233 | 233 | //first run I need to get the current updateId from telegram |
| 234 | 234 | $lastUpdate = end($updates); |
@@ -247,10 +247,10 @@ discard block |
||
| 247 | 247 | } |
| 248 | 248 | $this->polling($offset); |
| 249 | 249 | } |
| 250 | - }, function (TelegramException $error) use (&$offset) { |
|
| 250 | + }, function(TelegramException $error) use (&$offset) { |
|
| 251 | 251 | $this->logger->error("Failed to fetch updates from Telegram: $error"); |
| 252 | 252 | $this->polling($offset); // consider place a delay before restarting to poll |
| 253 | - })->otherwise(function ($e) use (&$offset, &$processingUpdate) { |
|
| 253 | + })->otherwise(function($e) use (&$offset, &$processingUpdate) { |
|
| 254 | 254 | $this->logger->errorUpdate($e); |
| 255 | 255 | $errorHandler = $this->config->getErrorHandler(); |
| 256 | 256 | if ($errorHandler) { |
@@ -201,14 +201,14 @@ discard block |
||
| 201 | 201 | */ |
| 202 | 202 | public function deleteCacheItem(string $cacheKey, $key) |
| 203 | 203 | { |
| 204 | - return $this->cache->get($cacheKey)->then(function ($arrayData) use ($cacheKey, $key) { |
|
| 204 | + return $this->cache->get($cacheKey)->then(function($arrayData) use ($cacheKey, $key) { |
|
| 205 | 205 | if (!$arrayData) { |
| 206 | 206 | return true; //there isn't anything so it's deleted |
| 207 | 207 | } else { |
| 208 | 208 | unset($arrayData[$key]); |
| 209 | 209 | } |
| 210 | 210 | |
| 211 | - return $this->cache->set($cacheKey, $arrayData)->then(function ($result) { |
|
| 211 | + return $this->cache->set($cacheKey, $arrayData)->then(function($result) { |
|
| 212 | 212 | if ($result !== true) { |
| 213 | 213 | $this->logger->errorWriteCache($result); |
| 214 | 214 | } |
@@ -224,7 +224,7 @@ discard block |
||
| 224 | 224 | */ |
| 225 | 225 | public function deleteCache(array $keys) |
| 226 | 226 | { |
| 227 | - return $this->cache->deleteMultiple($keys)->then(function ($result) { |
|
| 227 | + return $this->cache->deleteMultiple($keys)->then(function($result) { |
|
| 228 | 228 | if ($result !== true) { |
| 229 | 229 | $this->logger->errorClearCache($result); |
| 230 | 230 | } |
@@ -240,7 +240,7 @@ discard block |
||
| 240 | 240 | */ |
| 241 | 241 | public function getCacheItem(string $cacheKey, $key) |
| 242 | 242 | { |
| 243 | - return $this->cache->get($cacheKey)->then(function ($arrayData) use ($key) { |
|
| 243 | + return $this->cache->get($cacheKey)->then(function($arrayData) use ($key) { |
|
| 244 | 244 | if ($arrayData && array_key_exists($key, $arrayData)) { |
| 245 | 245 | return $arrayData[$key]; |
| 246 | 246 | } else { |
@@ -272,7 +272,7 @@ discard block |
||
| 272 | 272 | */ |
| 273 | 273 | public function doSet(string $cacheKey, string $key, $data) |
| 274 | 274 | { |
| 275 | - return $this->cache->get($cacheKey)->then(function ($arrayData) use ($key, $data, $cacheKey) { |
|
| 275 | + return $this->cache->get($cacheKey)->then(function($arrayData) use ($key, $data, $cacheKey) { |
|
| 276 | 276 | if (!$arrayData) { |
| 277 | 277 | $arrayData = array(); |
| 278 | 278 | $arrayData[$key] = $data; |
@@ -280,7 +280,7 @@ discard block |
||
| 280 | 280 | $arrayData[$key] = $data; |
| 281 | 281 | } |
| 282 | 282 | |
| 283 | - return $this->cache->set($cacheKey, $arrayData)->then(function ($result) { |
|
| 283 | + return $this->cache->set($cacheKey, $arrayData)->then(function($result) { |
|
| 284 | 284 | if ($result !== true) { |
| 285 | 285 | $this->logger->errorWriteCache($result); |
| 286 | 286 | } |
@@ -298,14 +298,14 @@ discard block |
||
| 298 | 298 | */ |
| 299 | 299 | public function callHandlerByChatId(int $chatId, $update, $container) |
| 300 | 300 | { |
| 301 | - return $this->cache->get($this->getConversationKey($chatId))->then(function (array $conversation) use ($update, $chatId, $container) { |
|
| 301 | + return $this->cache->get($this->getConversationKey($chatId))->then(function(array $conversation) use ($update, $chatId, $container) { |
|
| 302 | 302 | if (!empty($conversation)) { |
| 303 | 303 | $handler = $conversation["state"]; |
| 304 | 304 | $handler(new Context($update, $container)); |
| 305 | 305 | } |
| 306 | - }, function ($err) use ($container, $update) { |
|
| 306 | + }, function($err) use ($container, $update) { |
|
| 307 | 307 | $this->logger->errorUpdate($update, $err); |
| 308 | - })->otherwise(function ($err, $update, $chatId) { |
|
| 308 | + })->otherwise(function($err, $update, $chatId) { |
|
| 309 | 309 | $this->logger->errorUpdate($err, $update); |
| 310 | 310 | $this->deleteConversationCache($chatId); |
| 311 | 311 | }); |