Completed
Pull Request — develop (#23)
by Michele
02:25
created
src/Zanzara/ZanzaraMapper.php 1 patch
Spacing   +2 added lines, -4 removed lines patch added patch discarded remove patch
@@ -38,8 +38,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 }
Please login to merge, or discard this patch.
src/Zanzara/UpdateMode/ReactPHPWebhook.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -39,19 +39,19 @@  discard block
 block discarded – undo
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
 block discarded – undo
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";
Please login to merge, or discard this patch.
src/Zanzara/MessageQueue.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -65,7 +65,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
         };
Please login to merge, or discard this patch.
src/Zanzara/UpdateMode/Polling.php 1 patch
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -21,7 +21,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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) {
Please login to merge, or discard this patch.
src/Zanzara/Telegram/TelegramTrait.php 1 patch
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -1640,7 +1640,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
Please login to merge, or discard this patch.
src/Zanzara/ZanzaraCache.php 1 patch
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -233,14 +233,14 @@  discard block
 block discarded – undo
233 233
      */
234 234
     public function deleteCacheItem(string $cacheKey, $key)
235 235
     {
236
-        return $this->cache->get($cacheKey)->then(function ($arrayData) use ($cacheKey, $key) {
236
+        return $this->cache->get($cacheKey)->then(function($arrayData) use ($cacheKey, $key) {
237 237
             if (!$arrayData) {
238 238
                 return true; //there isn't anything so it's deleted
239 239
             } else {
240 240
                 unset($arrayData[$key]);
241 241
             }
242 242
 
243
-            return $this->cache->set($cacheKey, $arrayData)->then(function ($result) {
243
+            return $this->cache->set($cacheKey, $arrayData)->then(function($result) {
244 244
                 if ($result !== true) {
245 245
                     $this->logger->errorWriteCache();
246 246
                 }
@@ -256,7 +256,7 @@  discard block
 block discarded – undo
256 256
      */
257 257
     public function deleteCache(array $keys)
258 258
     {
259
-        return $this->cache->deleteMultiple($keys)->then(function ($result) {
259
+        return $this->cache->deleteMultiple($keys)->then(function($result) {
260 260
             if ($result !== true) {
261 261
                 $this->logger->errorClearCache();
262 262
             }
@@ -272,7 +272,7 @@  discard block
 block discarded – undo
272 272
      */
273 273
     public function getCacheItem(string $cacheKey, $key)
274 274
     {
275
-        return $this->cache->get($cacheKey)->then(function ($arrayData) use ($key) {
275
+        return $this->cache->get($cacheKey)->then(function($arrayData) use ($key) {
276 276
             if ($arrayData && array_key_exists($key, $arrayData)) {
277 277
                 return $arrayData[$key];
278 278
             } else {
@@ -320,7 +320,7 @@  discard block
 block discarded – undo
320 320
     public function doSet(string $cacheKey, string $key, $data, $ttl = false)
321 321
     {
322 322
         $ttl = $this->checkTtl($ttl);
323
-        return $this->cache->get($cacheKey)->then(function ($arrayData) use ($ttl, $key, $data, $cacheKey) {
323
+        return $this->cache->get($cacheKey)->then(function($arrayData) use ($ttl, $key, $data, $cacheKey) {
324 324
             if (!$arrayData) {
325 325
                 $arrayData = array();
326 326
                 $arrayData[$key] = $data;
@@ -328,7 +328,7 @@  discard block
 block discarded – undo
328 328
                 $arrayData[$key] = $data;
329 329
             }
330 330
 
331
-            return $this->cache->set($cacheKey, $arrayData, $ttl)->then(function ($result) {
331
+            return $this->cache->set($cacheKey, $arrayData, $ttl)->then(function($result) {
332 332
                 if ($result !== true) {
333 333
                     $this->logger->errorWriteCache();
334 334
                 }
@@ -350,10 +350,10 @@  discard block
 block discarded – undo
350 350
     {
351 351
 
352 352
         $ttl = $this->checkTtl($ttl);
353
-        return $this->cache->get($cacheKey)->then(function ($arrayData) use ($ttl, $key, $data, $cacheKey) {
353
+        return $this->cache->get($cacheKey)->then(function($arrayData) use ($ttl, $key, $data, $cacheKey) {
354 354
             $arrayData[$key][] = $data;
355 355
 
356
-            return $this->cache->set($cacheKey, $arrayData, $ttl)->then(function ($result) {
356
+            return $this->cache->set($cacheKey, $arrayData, $ttl)->then(function($result) {
357 357
                 if ($result !== true) {
358 358
                     $this->logger->errorWriteCache();
359 359
                 }
@@ -371,7 +371,7 @@  discard block
 block discarded – undo
371 371
      */
372 372
     public function callHandlerByChatId(int $chatId, $update, $container)
373 373
     {
374
-        return $this->cache->get($this->getConversationKey($chatId))->then(function ($conversation) use ($update, $container) {
374
+        return $this->cache->get($this->getConversationKey($chatId))->then(function($conversation) use ($update, $container) {
375 375
             if (!empty($conversation["state"])) {
376 376
                 $handler = $conversation["state"];
377 377
                 $handler = unserialize($handler);
@@ -380,9 +380,9 @@  discard block
 block discarded – undo
380 380
                 }
381 381
                 call_user_func($handler, new Context($update, $container));
382 382
             }
383
-        }, function ($err) use ($update) {
383
+        }, function($err) use ($update) {
384 384
             $this->logger->errorUpdate($update, $err);
385
-        })->/** @scrutinizer ignore-call */ otherwise(function ($err) use ($update, $chatId) {
385
+        })->/** @scrutinizer ignore-call */ otherwise(function($err) use ($update, $chatId) {
386 386
             $this->logger->errorUpdate($err, $update);
387 387
             $this->deleteConversationCache($chatId);
388 388
         });
Please login to merge, or discard this patch.
src/Zanzara/Listener/ListenerCollector.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -201,7 +201,7 @@  discard block
 block discarded – undo
201 201
     {
202 202
         // merge values with "|" (eg. "accept|refuse|later"), then ListenerResolver will check the callback data
203 203
         // against that regex.
204
-        $id = '/'.implode('|', $data).'/';
204
+        $id = '/' . implode('|', $data) . '/';
205 205
         $listener = new Listener($callback, $this->container, $id);
206 206
         $this->listeners['cb_query_data'][$id] = $listener;
207 207
         return $listener;
@@ -457,7 +457,7 @@  discard block
 block discarded – undo
457 457
      */
458 458
     protected function feedMiddlewareStack()
459 459
     {
460
-        array_walk_recursive($this->listeners, function ($value) {
460
+        array_walk_recursive($this->listeners, function($value) {
461 461
             if ($value instanceof Listener) {
462 462
                 foreach ($this->middleware as $m) {
463 463
                     $value->middleware($m);
Please login to merge, or discard this patch.