@@ -66,7 +66,7 @@ discard block |
||
| 66 | 66 | $clone['chat_id'] = $chatId; |
| 67 | 67 | array_push($payload, $clone); |
| 68 | 68 | } |
| 69 | - $dequeue = function (TimerInterface $timer) use (&$payload) { |
|
| 69 | + $dequeue = function(TimerInterface $timer) use (&$payload) { |
|
| 70 | 70 | // if there's no more message to dequeue cancel the timer |
| 71 | 71 | if (!$payload) { |
| 72 | 72 | $this->loop->cancelTimer($timer); |
@@ -76,7 +76,7 @@ discard block |
||
| 76 | 76 | // pop and process |
| 77 | 77 | $params = array_pop($payload); |
| 78 | 78 | $this->telegram->doSendMessage($params) |
| 79 | - ->otherwise(function (TelegramException $error) { |
|
| 79 | + ->otherwise(function(TelegramException $error) { |
|
| 80 | 80 | $this->logger->error("Failed to send message in bulk mode, reason: $error"); |
| 81 | 81 | } |
| 82 | 82 | ); |
@@ -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 | } |
@@ -157,7 +157,7 @@ discard block |
||
| 157 | 157 | } |
| 158 | 158 | |
| 159 | 159 | |
| 160 | - public function deleteItemChatData($key){ |
|
| 160 | + public function deleteItemChatData($key) { |
|
| 161 | 161 | $chatId = $this->update->getEffectiveChat()->getId(); |
| 162 | 162 | $cache = $this->container->get(ZanzaraCache::class); |
| 163 | 163 | return $cache->deleteCacheItemChatData($chatId, $cache); |
@@ -167,7 +167,7 @@ discard block |
||
| 167 | 167 | * Delete all chat data |
| 168 | 168 | * @return PromiseInterface |
| 169 | 169 | */ |
| 170 | - public function deleteAllChatData(){ |
|
| 170 | + public function deleteAllChatData() { |
|
| 171 | 171 | $chatId = $this->update->getEffectiveChat()->getId(); |
| 172 | 172 | $cache = $this->container->get(ZanzaraCache::class); |
| 173 | 173 | return $cache->deleteAllCacheChatData($chatId); |
@@ -187,7 +187,7 @@ discard block |
||
| 187 | 187 | return $cache->setCacheUserData($userId, $key, $data); |
| 188 | 188 | } |
| 189 | 189 | |
| 190 | - public function deleteItemUserData($key){ |
|
| 190 | + public function deleteItemUserData($key) { |
|
| 191 | 191 | $userId = $this->update->getEffectiveChat()->getUsername(); |
| 192 | 192 | $cache = $this->container->get(ZanzaraCache::class); |
| 193 | 193 | return $cache->deleteCacheItemUserData($userId, $cache); |
@@ -197,7 +197,7 @@ discard block |
||
| 197 | 197 | * Delete all chat data |
| 198 | 198 | * @return PromiseInterface |
| 199 | 199 | */ |
| 200 | - public function deleteAllUserData(){ |
|
| 200 | + public function deleteAllUserData() { |
|
| 201 | 201 | $chatId = $this->update->getEffectiveChat()->getUsername(); |
| 202 | 202 | $cache = $this->container->get(ZanzaraCache::class); |
| 203 | 203 | return $cache->deleteAllCacheUserData($chatId); |
@@ -228,12 +228,12 @@ discard block |
||
| 228 | 228 | return $cache->deleteAllCacheGlobalData(); |
| 229 | 229 | } |
| 230 | 230 | |
| 231 | - public function wipeCache(){ |
|
| 231 | + public function wipeCache() { |
|
| 232 | 232 | $cache = $this->container->get(ZanzaraCache::class); |
| 233 | 233 | return $cache->wipeCache(); |
| 234 | 234 | } |
| 235 | 235 | |
| 236 | - public function deleteUserData(){ |
|
| 236 | + public function deleteUserData() { |
|
| 237 | 237 | $userId = $this->update->getEffectiveChat()->getUsername(); |
| 238 | 238 | $cache = $this->container->get(ZanzaraCache::class); |
| 239 | 239 | return $cache->deteleCacheChatData($userId); |
@@ -97,7 +97,7 @@ discard block |
||
| 97 | 97 | |
| 98 | 98 | case Config::REACTPHP_WEBHOOK_MODE: |
| 99 | 99 | $this->telegram->getWebhookInfo()->then( |
| 100 | - function (WebhookInfo $webhookInfo) { |
|
| 100 | + function(WebhookInfo $webhookInfo) { |
|
| 101 | 101 | if (!$webhookInfo->getUrl()) { |
| 102 | 102 | $message = "Your bot doesn't have a webhook set, please set one before running Zanzara in webhook" . |
| 103 | 103 | " mode. See https://github.com/badfarm/zanzara/wiki#set-webhook"; |
@@ -111,7 +111,7 @@ discard block |
||
| 111 | 111 | |
| 112 | 112 | case Config::POLLING_MODE: |
| 113 | 113 | $this->telegram->getWebhookInfo()->then( |
| 114 | - function (WebhookInfo $webhookInfo) { |
|
| 114 | + function(WebhookInfo $webhookInfo) { |
|
| 115 | 115 | if (!$webhookInfo->getUrl()) { |
| 116 | 116 | $this->loop->futureTick([$this, 'polling']); |
| 117 | 117 | echo "Zanzara is listening...\n"; |
@@ -124,7 +124,7 @@ discard block |
||
| 124 | 124 | $answer = readline(); |
| 125 | 125 | if (strtoupper($answer) === "YES") { |
| 126 | 126 | $this->telegram->deleteWebhook()->then( |
| 127 | - function ($res) { |
|
| 127 | + function($res) { |
|
| 128 | 128 | if ($res === true) { |
| 129 | 129 | $this->logger->info("Webhook is deleted, Zanzara is starting in polling ..."); |
| 130 | 130 | $this->loop->futureTick([$this, 'polling']); |
@@ -183,19 +183,19 @@ discard block |
||
| 183 | 183 | private function prepareServer() |
| 184 | 184 | { |
| 185 | 185 | $processingUpdate = null; |
| 186 | - $this->server = new Server(function (ServerRequestInterface $request) use (&$processingUpdate) { |
|
| 186 | + $this->server = new Server(function(ServerRequestInterface $request) use (&$processingUpdate) { |
|
| 187 | 187 | $token = $this->resolveTokenFromPath($request->getUri()->getPath()); |
| 188 | 188 | if (!$this->isWebhookAuthorized($token)) { |
| 189 | 189 | $this->logger->errorNotAuthorized(); |
| 190 | 190 | return new Response(403, [], $this->logger->getNotAuthorizedMessage()); |
| 191 | 191 | } |
| 192 | - $json = (string)$request->getBody(); |
|
| 192 | + $json = (string) $request->getBody(); |
|
| 193 | 193 | /** @var Update $processingUpdate */ |
| 194 | 194 | $processingUpdate = $this->zanzaraMapper->mapJson($json, Update::class); |
| 195 | 195 | $this->processUpdate($processingUpdate); |
| 196 | 196 | return new Response(); |
| 197 | 197 | }); |
| 198 | - $this->server->on('error', function ($e) use (&$processingUpdate) { |
|
| 198 | + $this->server->on('error', function($e) use (&$processingUpdate) { |
|
| 199 | 199 | $this->logger->errorUpdate($e, $processingUpdate); |
| 200 | 200 | $errorHandler = $this->config->getErrorHandler(); |
| 201 | 201 | if ($errorHandler) { |
@@ -225,7 +225,7 @@ discard block |
||
| 225 | 225 | 'limit' => $this->config->getPollingLimit(), |
| 226 | 226 | 'timeout' => $this->config->getPollingTimeout(), |
| 227 | 227 | 'allowed_updates' => $this->config->getPollingAllowedUpdates(), |
| 228 | - ])->then(function (array $updates) use (&$offset, &$processingUpdate) { |
|
| 228 | + ])->then(function(array $updates) use (&$offset, &$processingUpdate) { |
|
| 229 | 229 | if ($offset === 1) { |
| 230 | 230 | //first run I need to get the current updateId from telegram |
| 231 | 231 | $lastUpdate = end($updates); |
@@ -244,10 +244,10 @@ discard block |
||
| 244 | 244 | } |
| 245 | 245 | $this->polling($offset); |
| 246 | 246 | } |
| 247 | - }, function (TelegramException $error) use (&$offset) { |
|
| 247 | + }, function(TelegramException $error) use (&$offset) { |
|
| 248 | 248 | $this->logger->error("Failed to fetch updates from Telegram: $error"); |
| 249 | 249 | $this->polling($offset); // consider place a delay before restarting to poll |
| 250 | - })->otherwise(function ($e) use (&$offset, &$processingUpdate) { |
|
| 250 | + })->otherwise(function($e) use (&$offset, &$processingUpdate) { |
|
| 251 | 251 | $this->logger->errorUpdate($e); |
| 252 | 252 | $errorHandler = $this->config->getErrorHandler(); |
| 253 | 253 | if ($errorHandler) { |
@@ -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); |
@@ -199,14 +199,14 @@ discard block |
||
| 199 | 199 | */ |
| 200 | 200 | public function deleteCacheItem($cacheKey, $key) |
| 201 | 201 | { |
| 202 | - return $this->cache->get($cacheKey)->then(function ($arrayData) use ($cacheKey, $key) { |
|
| 202 | + return $this->cache->get($cacheKey)->then(function($arrayData) use ($cacheKey, $key) { |
|
| 203 | 203 | if (!$arrayData) { |
| 204 | 204 | return true; //there isn't anything so it's deleted |
| 205 | 205 | } else { |
| 206 | 206 | unset($arrayData[$key]); |
| 207 | 207 | } |
| 208 | 208 | |
| 209 | - return $this->cache->set($cacheKey, $arrayData)->then(function ($result) { |
|
| 209 | + return $this->cache->set($cacheKey, $arrayData)->then(function($result) { |
|
| 210 | 210 | if ($result !== true) { |
| 211 | 211 | $this->logger->errorWriteCache($result); |
| 212 | 212 | } |
@@ -223,7 +223,7 @@ discard block |
||
| 223 | 223 | */ |
| 224 | 224 | public function deleteCache(array $keys) |
| 225 | 225 | { |
| 226 | - return $this->cache->deleteMultiple($keys)->then(function ($result) { |
|
| 226 | + return $this->cache->deleteMultiple($keys)->then(function($result) { |
|
| 227 | 227 | if ($result !== true) { |
| 228 | 228 | $this->logger->errorClearCache($result); |
| 229 | 229 | } |
@@ -240,7 +240,7 @@ discard block |
||
| 240 | 240 | */ |
| 241 | 241 | public function getCacheItem($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 { |
@@ -251,7 +251,7 @@ discard block |
||
| 251 | 251 | |
| 252 | 252 | public function getCache($cacheKey) |
| 253 | 253 | { |
| 254 | - return $this->cache->get($cacheKey)->then(function ($arrayData) { |
|
| 254 | + return $this->cache->get($cacheKey)->then(function($arrayData) { |
|
| 255 | 255 | return $arrayData; |
| 256 | 256 | }); |
| 257 | 257 | } |
@@ -262,7 +262,7 @@ discard block |
||
| 262 | 262 | */ |
| 263 | 263 | public function wipeCache() |
| 264 | 264 | { |
| 265 | - return $this->cache->clear()->then(function ($result) { |
|
| 265 | + return $this->cache->clear()->then(function($result) { |
|
| 266 | 266 | return $result; |
| 267 | 267 | }); |
| 268 | 268 | } |
@@ -277,7 +277,7 @@ discard block |
||
| 277 | 277 | */ |
| 278 | 278 | public function setCache($cacheKey, $key, $data) |
| 279 | 279 | { |
| 280 | - return $this->cache->get($cacheKey)->then(function ($arrayData) use ($key, $data, $cacheKey) { |
|
| 280 | + return $this->cache->get($cacheKey)->then(function($arrayData) use ($key, $data, $cacheKey) { |
|
| 281 | 281 | if (!$arrayData) { |
| 282 | 282 | $arrayData = array(); |
| 283 | 283 | $arrayData[$key] = $data; |
@@ -285,7 +285,7 @@ discard block |
||
| 285 | 285 | $arrayData[$key] = $data; |
| 286 | 286 | } |
| 287 | 287 | |
| 288 | - return $this->cache->set($cacheKey, $arrayData)->then(function ($result) { |
|
| 288 | + return $this->cache->set($cacheKey, $arrayData)->then(function($result) { |
|
| 289 | 289 | if ($result !== true) { |
| 290 | 290 | $this->logger->errorWriteCache($result); |
| 291 | 291 | } |
@@ -303,14 +303,14 @@ discard block |
||
| 303 | 303 | */ |
| 304 | 304 | public function callHandlerByChatId($chatId, $update, $container) |
| 305 | 305 | { |
| 306 | - return $this->cache->get($this->getKeyConversation($chatId))->then(function (array $conversation) use ($update, $chatId, $container) { |
|
| 306 | + return $this->cache->get($this->getKeyConversation($chatId))->then(function(array $conversation) use ($update, $chatId, $container) { |
|
| 307 | 307 | if ($conversation) { |
| 308 | 308 | $handler = $conversation["state"]; |
| 309 | 309 | $handler(new Context($update, $container)); |
| 310 | 310 | } |
| 311 | - }, function ($err) use ($container, $update) { |
|
| 311 | + }, function($err) use ($container, $update) { |
|
| 312 | 312 | $this->logger->errorUpdate($update, $err); |
| 313 | - })->otherwise(function ($err, $update, $chatId) { |
|
| 313 | + })->otherwise(function($err, $update, $chatId) { |
|
| 314 | 314 | $this->logger->errorUpdate($err, $update); |
| 315 | 315 | $this->deleteConversationCache($chatId); |
| 316 | 316 | }); |
@@ -50,7 +50,7 @@ |
||
| 50 | 50 | $this->error($message); |
| 51 | 51 | } |
| 52 | 52 | |
| 53 | - public function errorGetCache($error){ |
|
| 53 | + public function errorGetCache($error) { |
|
| 54 | 54 | $message = "Failed to get data from cache, reason: {$error}"; |
| 55 | 55 | $this->error($message); |
| 56 | 56 | } |
@@ -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) use ($value) { |
|
| 1500 | + }, function($error) use ($value) { |
|
| 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) { |
|
| 1513 | - foreach ($files as $key => $value){ |
|
| 1512 | + return all($promises)->then(function($files) use($multipart_data) { |
|
| 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 | }); |
@@ -1563,8 +1563,8 @@ discard block |
||
| 1563 | 1563 | $logger = $this->container->get(ZanzaraLogger::class); |
| 1564 | 1564 | |
| 1565 | 1565 | return $promise |
| 1566 | - ->then(function (ResponseInterface $response) use ($class, $mapper) { |
|
| 1567 | - $json = (string)$response->getBody(); |
|
| 1566 | + ->then(function(ResponseInterface $response) use ($class, $mapper) { |
|
| 1567 | + $json = (string) $response->getBody(); |
|
| 1568 | 1568 | $object = json_decode($json); |
| 1569 | 1569 | |
| 1570 | 1570 | if (is_scalar($object->result) && $class === "Scalar") { |
@@ -1573,8 +1573,8 @@ discard block |
||
| 1573 | 1573 | |
| 1574 | 1574 | return $mapper->mapObject($object->result, $class); |
| 1575 | 1575 | |
| 1576 | - }, function (ResponseException $exception) use ($logger, $mapper) { |
|
| 1577 | - $json = (string)$exception->getResponse()->getBody(); |
|
| 1576 | + }, function(ResponseException $exception) use ($logger, $mapper) { |
|
| 1577 | + $json = (string) $exception->getResponse()->getBody(); |
|
| 1578 | 1578 | $telegramException = $mapper->mapJson($json, TelegramException::class); |
| 1579 | 1579 | $logger->error($telegramException); |
| 1580 | 1580 | throw $telegramException; |