@@ -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 | } |
@@ -39,19 +39,19 @@ discard block |
||
| 39 | 39 | private function init() |
| 40 | 40 | { |
| 41 | 41 | $processingUpdate = null; |
| 42 | - $server = new Server($this->loop, function (ServerRequestInterface $request) use (&$processingUpdate) { |
|
| 42 | + $server = new Server($this->loop, function(ServerRequestInterface $request) use (&$processingUpdate) { |
|
| 43 | 43 | $token = $this->resolveTokenFromPath($request->getUri()->getPath()); |
| 44 | 44 | if (!$this->isWebhookAuthorized($token)) { |
| 45 | 45 | $this->logger->errorNotAuthorized(); |
| 46 | 46 | return new Response(403, [], $this->logger->getNotAuthorizedMessage()); |
| 47 | 47 | } |
| 48 | - $json = (string)$request->getBody(); |
|
| 48 | + $json = (string) $request->getBody(); |
|
| 49 | 49 | /** @var Update $processingUpdate */ |
| 50 | 50 | $processingUpdate = $this->zanzaraMapper->mapJson($json, Update::class); |
| 51 | 51 | $this->processUpdate($processingUpdate); |
| 52 | 52 | return new Response(); |
| 53 | 53 | }); |
| 54 | - $server->on('error', function ($e) use (&$processingUpdate) { |
|
| 54 | + $server->on('error', function($e) use (&$processingUpdate) { |
|
| 55 | 55 | $this->logger->errorUpdate($e, $processingUpdate); |
| 56 | 56 | $errorHandler = $this->config->getErrorHandler(); |
| 57 | 57 | if ($errorHandler) { |
@@ -67,7 +67,7 @@ discard block |
||
| 67 | 67 | public function run() |
| 68 | 68 | { |
| 69 | 69 | $this->telegram->getWebhookInfo()->then( |
| 70 | - function (WebhookInfo $webhookInfo) { |
|
| 70 | + function(WebhookInfo $webhookInfo) { |
|
| 71 | 71 | if (!$webhookInfo->getUrl()) { |
| 72 | 72 | $message = "Your bot doesn't have a webhook set, please set one before running Zanzara in webhook" . |
| 73 | 73 | " mode. See https://github.com/badfarm/zanzara/wiki#set-webhook"; |
@@ -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); |
@@ -74,7 +74,7 @@ discard block |
||
| 74 | 74 | |
| 75 | 75 | // pop and process |
| 76 | 76 | $params = array_pop($payload); |
| 77 | - $this->telegram->doSendMessage($params)->/** @scrutinizer ignore-call */ otherwise(function (TelegramException $error) { |
|
| 77 | + $this->telegram->doSendMessage($params)->/** @scrutinizer ignore-call */ otherwise(function(TelegramException $error) { |
|
| 78 | 78 | $this->logger->error("Failed to send message in bulk mode, reason: $error"); |
| 79 | 79 | }); |
| 80 | 80 | }; |
@@ -21,7 +21,7 @@ discard block |
||
| 21 | 21 | public function run() |
| 22 | 22 | { |
| 23 | 23 | $this->telegram->getWebhookInfo()->then( |
| 24 | - function (WebhookInfo $webhookInfo) { |
|
| 24 | + function(WebhookInfo $webhookInfo) { |
|
| 25 | 25 | if (!$webhookInfo->getUrl()) { |
| 26 | 26 | $this->loop->futureTick([$this, 'startPolling']); |
| 27 | 27 | $this->logger->logIsListening(); |
@@ -34,7 +34,7 @@ discard block |
||
| 34 | 34 | $answer = readline(); |
| 35 | 35 | if (strtoupper($answer) === "YES") { |
| 36 | 36 | $this->telegram->deleteWebhook()->then( |
| 37 | - function ($res) { |
|
| 37 | + function($res) { |
|
| 38 | 38 | if ($res === true) { |
| 39 | 39 | $this->logger->info("Webhook is deleted, Zanzara is starting in polling ..."); |
| 40 | 40 | $this->loop->futureTick([$this, 'startPolling']); |
@@ -61,7 +61,7 @@ discard block |
||
| 61 | 61 | 'limit' => $this->config->getPollingLimit(), |
| 62 | 62 | 'timeout' => $this->config->getPollingTimeout(), |
| 63 | 63 | 'allowed_updates' => $this->config->getPollingAllowedUpdates(), |
| 64 | - ])->then(function (array $updates) use (&$offset, &$processingUpdate) { |
|
| 64 | + ])->then(function(array $updates) use (&$offset, &$processingUpdate) { |
|
| 65 | 65 | if ($offset === 1) { |
| 66 | 66 | //first run I need to get the current updateId from telegram |
| 67 | 67 | $lastUpdate = end($updates); |
@@ -80,10 +80,10 @@ discard block |
||
| 80 | 80 | } |
| 81 | 81 | $this->startPolling($offset); |
| 82 | 82 | } |
| 83 | - }, function (TelegramException $error) use (&$offset) { |
|
| 83 | + }, function(TelegramException $error) use (&$offset) { |
|
| 84 | 84 | $this->logger->error("Failed to fetch updates from Telegram: $error"); |
| 85 | 85 | $this->startPolling($offset); // consider place a delay before restarting to poll |
| 86 | - })->/** @scrutinizer ignore-call */ otherwise(function ($e) use (&$offset, &$processingUpdate) { |
|
| 86 | + })->/** @scrutinizer ignore-call */ otherwise(function($e) use (&$offset, &$processingUpdate) { |
|
| 87 | 87 | $this->logger->errorUpdate($e); |
| 88 | 88 | $errorHandler = $this->config->getErrorHandler(); |
| 89 | 89 | if ($errorHandler) { |
@@ -1640,7 +1640,7 @@ discard block |
||
| 1640 | 1640 | $async = $this->container->get(Config::class)->isReactFileSystem(); |
| 1641 | 1641 | |
| 1642 | 1642 | if ($async) { |
| 1643 | - return $this->prepareMultipartDataAsync($params)->then(function ($result) use ($class, $params, $method) { |
|
| 1643 | + return $this->prepareMultipartDataAsync($params)->then(function($result) use ($class, $params, $method) { |
|
| 1644 | 1644 | $headers = array("Content-Length" => $result->getSize(), "Content-Type" => "multipart/form-data; boundary={$result->getBoundary()}"); |
| 1645 | 1645 | return $this->wrapPromise($this->browser->post($method, $headers, $result), $method, $params, $class); |
| 1646 | 1646 | }); |
@@ -1669,12 +1669,12 @@ discard block |
||
| 1669 | 1669 | foreach ($params as $key => $value) { |
| 1670 | 1670 | |
| 1671 | 1671 | if ($value instanceof InputFile) { |
| 1672 | - array_push($promises, $filesystem->getContents($value->getPath())->then(function ($contents) use ($value, $key) { |
|
| 1672 | + array_push($promises, $filesystem->getContents($value->getPath())->then(function($contents) use ($value, $key) { |
|
| 1673 | 1673 | $data = ['name' => $key]; |
| 1674 | 1674 | $data['contents'] = $contents; |
| 1675 | 1675 | $data['filename'] = basename($value->getPath()); |
| 1676 | 1676 | return $data; |
| 1677 | - }, function ($error) { |
|
| 1677 | + }, function($error) { |
|
| 1678 | 1678 | $this->container->get(ZanzaraLogger::class)->error($error); |
| 1679 | 1679 | return $error; |
| 1680 | 1680 | })); |
@@ -1686,12 +1686,12 @@ discard block |
||
| 1686 | 1686 | } |
| 1687 | 1687 | } |
| 1688 | 1688 | |
| 1689 | - return all($promises)->then(function ($files) use ($multipart_data) { |
|
| 1689 | + return all($promises)->then(function($files) use ($multipart_data) { |
|
| 1690 | 1690 | foreach ($files as $key => $value) { |
| 1691 | 1691 | array_push($multipart_data, $value); |
| 1692 | 1692 | } |
| 1693 | 1693 | return new MultipartStream($multipart_data); |
| 1694 | - }, function ($error) { |
|
| 1694 | + }, function($error) { |
|
| 1695 | 1695 | $this->container->get(ZanzaraLogger::class)->error($error); |
| 1696 | 1696 | return $error; |
| 1697 | 1697 | }); |
@@ -1741,8 +1741,8 @@ discard block |
||
| 1741 | 1741 | $logger = $this->container->get(ZanzaraLogger::class); |
| 1742 | 1742 | |
| 1743 | 1743 | return $promise |
| 1744 | - ->then(function (ResponseInterface $response) use ($class, $mapper) { |
|
| 1745 | - $json = (string)$response->getBody(); |
|
| 1744 | + ->then(function(ResponseInterface $response) use ($class, $mapper) { |
|
| 1745 | + $json = (string) $response->getBody(); |
|
| 1746 | 1746 | $object = json_decode($json); |
| 1747 | 1747 | |
| 1748 | 1748 | if (is_scalar($object->result) && $class === "Scalar") { |
@@ -1750,13 +1750,13 @@ discard block |
||
| 1750 | 1750 | } |
| 1751 | 1751 | |
| 1752 | 1752 | return $mapper->mapObject($object->result, $class); |
| 1753 | - }, function ($e) use ($method, $params, $logger, $mapper) { |
|
| 1753 | + }, function($e) use ($method, $params, $logger, $mapper) { |
|
| 1754 | 1754 | if ($e instanceof ResponseException) { |
| 1755 | 1755 | // with the introduction of Local Api server (https://core.telegram.org/bots/api#using-a-local-bot-api-server) |
| 1756 | 1756 | // we can no longer assume that the response is with the TelegramException format, so catch any mapping |
| 1757 | 1757 | // exception |
| 1758 | 1758 | try { |
| 1759 | - $json = (string)$e->getResponse()->getBody(); |
|
| 1759 | + $json = (string) $e->getResponse()->getBody(); |
|
| 1760 | 1760 | $e = $mapper->mapJson($json, TelegramException::class); |
| 1761 | 1761 | } catch (\Exception $ignore) { |
| 1762 | 1762 | // ignore |
@@ -49,7 +49,7 @@ |
||
| 49 | 49 | public function getConversationHandler($chatId): PromiseInterface |
| 50 | 50 | { |
| 51 | 51 | return $this->cache->get($this->getConversationKey($chatId)) |
| 52 | - ->then(function ($conversation) { |
|
| 52 | + ->then(function($conversation) { |
|
| 53 | 53 | if (empty($conversation["state"])) { |
| 54 | 54 | return null; |
| 55 | 55 | } |
@@ -199,14 +199,14 @@ discard block |
||
| 199 | 199 | */ |
| 200 | 200 | public function deleteCacheItem(string $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(); |
| 212 | 212 | } |
@@ -222,7 +222,7 @@ discard block |
||
| 222 | 222 | */ |
| 223 | 223 | public function deleteCache(array $keys) |
| 224 | 224 | { |
| 225 | - return $this->cache->deleteMultiple($keys)->then(function ($result) { |
|
| 225 | + return $this->cache->deleteMultiple($keys)->then(function($result) { |
|
| 226 | 226 | if ($result !== true) { |
| 227 | 227 | $this->logger->errorClearCache(); |
| 228 | 228 | } |
@@ -238,7 +238,7 @@ discard block |
||
| 238 | 238 | */ |
| 239 | 239 | public function getCacheItem(string $cacheKey, $key) |
| 240 | 240 | { |
| 241 | - return $this->cache->get($cacheKey)->then(function ($arrayData) use ($key) { |
|
| 241 | + return $this->cache->get($cacheKey)->then(function($arrayData) use ($key) { |
|
| 242 | 242 | if ($arrayData && array_key_exists($key, $arrayData)) { |
| 243 | 243 | return $arrayData[$key]; |
| 244 | 244 | } else { |
@@ -286,7 +286,7 @@ discard block |
||
| 286 | 286 | public function doSet(string $cacheKey, string $key, $data, $ttl = false) |
| 287 | 287 | { |
| 288 | 288 | $ttl = $this->checkTtl($ttl); |
| 289 | - return $this->cache->get($cacheKey)->then(function ($arrayData) use ($ttl, $key, $data, $cacheKey) { |
|
| 289 | + return $this->cache->get($cacheKey)->then(function($arrayData) use ($ttl, $key, $data, $cacheKey) { |
|
| 290 | 290 | if (!$arrayData) { |
| 291 | 291 | $arrayData = array(); |
| 292 | 292 | $arrayData[$key] = $data; |
@@ -294,7 +294,7 @@ discard block |
||
| 294 | 294 | $arrayData[$key] = $data; |
| 295 | 295 | } |
| 296 | 296 | |
| 297 | - return $this->cache->set($cacheKey, $arrayData, $ttl)->then(function ($result) { |
|
| 297 | + return $this->cache->set($cacheKey, $arrayData, $ttl)->then(function($result) { |
|
| 298 | 298 | if ($result !== true) { |
| 299 | 299 | $this->logger->errorWriteCache(); |
| 300 | 300 | } |
@@ -316,10 +316,10 @@ discard block |
||
| 316 | 316 | { |
| 317 | 317 | |
| 318 | 318 | $ttl = $this->checkTtl($ttl); |
| 319 | - return $this->cache->get($cacheKey)->then(function ($arrayData) use ($ttl, $key, $data, $cacheKey) { |
|
| 319 | + return $this->cache->get($cacheKey)->then(function($arrayData) use ($ttl, $key, $data, $cacheKey) { |
|
| 320 | 320 | $arrayData[$key][] = $data; |
| 321 | 321 | |
| 322 | - return $this->cache->set($cacheKey, $arrayData, $ttl)->then(function ($result) { |
|
| 322 | + return $this->cache->set($cacheKey, $arrayData, $ttl)->then(function($result) { |
|
| 323 | 323 | if ($result !== true) { |
| 324 | 324 | $this->logger->errorWriteCache(); |
| 325 | 325 | } |
@@ -84,14 +84,14 @@ |
||
| 84 | 84 | { |
| 85 | 85 | $update->detectUpdateType(); |
| 86 | 86 | $this->zanzara->resolveListeners($update) |
| 87 | - ->then(function ($listeners) use ($update) { |
|
| 87 | + ->then(function($listeners) use ($update) { |
|
| 88 | 88 | /** @var Listener[] $listeners */ |
| 89 | 89 | foreach ($listeners as $listener) { |
| 90 | 90 | $context = new Context($update, $this->container); |
| 91 | 91 | $middlewareTip = $listener->getTip(); |
| 92 | 92 | $middlewareTip($context); |
| 93 | 93 | } |
| 94 | - })->otherwise(function ($e) use ($update) { |
|
| 94 | + })->otherwise(function($e) use ($update) { |
|
| 95 | 95 | $this->logger->error("Unable to resolve listeners for update $update, reason: $e"); |
| 96 | 96 | }); |
| 97 | 97 | } |
@@ -41,7 +41,7 @@ discard block |
||
| 41 | 41 | $callbackQuery = $update->getCallbackQuery(); |
| 42 | 42 | $text = $callbackQuery->getMessage() ? $callbackQuery->getMessage()->getText() : null; |
| 43 | 43 | $this->conversationManager->getConversationHandler($chatId) |
| 44 | - ->then(function ($handlerInfo) use ($deferred, $callbackQuery, $text, &$listeners) { |
|
| 44 | + ->then(function($handlerInfo) use ($deferred, $callbackQuery, $text, &$listeners) { |
|
| 45 | 45 | if (!$handlerInfo) { // if we are not in a conversation, call the listeners as usual |
| 46 | 46 | if ($text) { |
| 47 | 47 | $this->findListenerAndPush($listeners, 'cb_query_texts', $text); |
@@ -53,7 +53,7 @@ discard block |
||
| 53 | 53 | $listeners[] = new Listener($handlerInfo[0], $this->container); |
| 54 | 54 | } |
| 55 | 55 | $deferred->resolve($listeners); |
| 56 | - })->otherwise(function ($e) use ($deferred) { |
|
| 56 | + })->otherwise(function($e) use ($deferred) { |
|
| 57 | 57 | // if something goes wrong, reject the promise |
| 58 | 58 | $deferred->reject($e); |
| 59 | 59 | }); |
@@ -63,7 +63,7 @@ discard block |
||
| 63 | 63 | $text = $update->getMessage()->getText(); |
| 64 | 64 | $chatId = $update->getEffectiveChat()->getId(); |
| 65 | 65 | $this->conversationManager->getConversationHandler($chatId) |
| 66 | - ->then(function ($handlerInfo) use ($chatId, $text, $deferred, &$listeners) { |
|
| 66 | + ->then(function($handlerInfo) use ($chatId, $text, $deferred, &$listeners) { |
|
| 67 | 67 | if (!$handlerInfo) { // if we are not in a conversation, call the listeners as usual |
| 68 | 68 | $this->findListenerAndPush($listeners, 'messages', $text); |
| 69 | 69 | } elseif (!$handlerInfo[1] && $text) { |
@@ -83,7 +83,7 @@ discard block |
||
| 83 | 83 | $listeners[] = new Listener($handlerInfo[0], $this->container); |
| 84 | 84 | } |
| 85 | 85 | $deferred->resolve($listeners); |
| 86 | - })->otherwise(function ($e) use ($deferred) { |
|
| 86 | + })->otherwise(function($e) use ($deferred) { |
|
| 87 | 87 | // if something goes wrong, reject the promise |
| 88 | 88 | $deferred->reject($e); |
| 89 | 89 | }); |