Passed
Push — develop ( 651ae1...1d5e32 )
by Michele
04:13
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/Listener/ListenerCollector.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -368,7 +368,7 @@
 block discarded – undo
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);
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/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 ($method) {
1643
+                    return $this->prepareMultipartDataAsync($params)->then(function($result) use ($method) {
1644 1644
                         $headers = array("Content-Length" => $result->getSize(), "Content-Type" => "multipart/form-data; boundary={$result->getBoundary()}");
1645 1645
                         return $this->browser->post($method, $headers, $result);
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/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/ZanzaraCache.php 1 patch
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -228,14 +228,14 @@  discard block
 block discarded – undo
228 228
      */
229 229
     public function deleteCacheItem(string $cacheKey, $key)
230 230
     {
231
-        return $this->cache->get($cacheKey)->then(function ($arrayData) use ($cacheKey, $key) {
231
+        return $this->cache->get($cacheKey)->then(function($arrayData) use ($cacheKey, $key) {
232 232
             if (!$arrayData) {
233 233
                 return true; //there isn't anything so it's deleted
234 234
             } else {
235 235
                 unset($arrayData[$key]);
236 236
             }
237 237
 
238
-            return $this->cache->set($cacheKey, $arrayData)->then(function ($result) {
238
+            return $this->cache->set($cacheKey, $arrayData)->then(function($result) {
239 239
                 if ($result !== true) {
240 240
                     $this->logger->errorWriteCache($result);
241 241
                 }
@@ -251,7 +251,7 @@  discard block
 block discarded – undo
251 251
      */
252 252
     public function deleteCache(array $keys)
253 253
     {
254
-        return $this->cache->deleteMultiple($keys)->then(function ($result) {
254
+        return $this->cache->deleteMultiple($keys)->then(function($result) {
255 255
             if ($result !== true) {
256 256
                 $this->logger->errorClearCache($result);
257 257
             }
@@ -267,7 +267,7 @@  discard block
 block discarded – undo
267 267
      */
268 268
     public function getCacheItem(string $cacheKey, $key)
269 269
     {
270
-        return $this->cache->get($cacheKey)->then(function ($arrayData) use ($key) {
270
+        return $this->cache->get($cacheKey)->then(function($arrayData) use ($key) {
271 271
             if ($arrayData && array_key_exists($key, $arrayData)) {
272 272
                 return $arrayData[$key];
273 273
             } else {
@@ -315,7 +315,7 @@  discard block
 block discarded – undo
315 315
     public function doSet(string $cacheKey, string $key, $data, $ttl = false)
316 316
     {
317 317
         $ttl = $this->checkTtl($ttl);
318
-        return $this->cache->get($cacheKey)->then(function ($arrayData) use ($ttl, $key, $data, $cacheKey) {
318
+        return $this->cache->get($cacheKey)->then(function($arrayData) use ($ttl, $key, $data, $cacheKey) {
319 319
             if (!$arrayData) {
320 320
                 $arrayData = array();
321 321
                 $arrayData[$key] = $data;
@@ -323,7 +323,7 @@  discard block
 block discarded – undo
323 323
                 $arrayData[$key] = $data;
324 324
             }
325 325
 
326
-            return $this->cache->set($cacheKey, $arrayData, $ttl)->then(function ($result) {
326
+            return $this->cache->set($cacheKey, $arrayData, $ttl)->then(function($result) {
327 327
                 if ($result !== true) {
328 328
                     $this->logger->errorWriteCache($result);
329 329
                 }
@@ -345,10 +345,10 @@  discard block
 block discarded – undo
345 345
     {
346 346
 
347 347
         $ttl = $this->checkTtl($ttl);
348
-        return $this->cache->get($cacheKey)->then(function ($arrayData) use ($ttl, $key, $data, $cacheKey) {
348
+        return $this->cache->get($cacheKey)->then(function($arrayData) use ($ttl, $key, $data, $cacheKey) {
349 349
             $arrayData[$key][] = $data;
350 350
 
351
-            return $this->cache->set($cacheKey, $arrayData, $ttl)->then(function ($result) {
351
+            return $this->cache->set($cacheKey, $arrayData, $ttl)->then(function($result) {
352 352
                 if ($result !== true) {
353 353
                     $this->logger->errorWriteCache($result);
354 354
                 }
@@ -366,14 +366,14 @@  discard block
 block discarded – undo
366 366
      */
367 367
     public function callHandlerByChatId(int $chatId, $update, $container)
368 368
     {
369
-        return $this->cache->get($this->getConversationKey($chatId))->then(function ($conversation) use ($update, $container) {
369
+        return $this->cache->get($this->getConversationKey($chatId))->then(function($conversation) use ($update, $container) {
370 370
             if (!empty($conversation["state"])) {
371 371
                 $handler = $conversation["state"];
372 372
                 $handler(new Context($update, $container));
373 373
             }
374
-        }, function ($err) use ($update) {
374
+        }, function($err) use ($update) {
375 375
             $this->logger->errorUpdate($update, $err);
376
-        })->/** @scrutinizer ignore-call */ otherwise(function ($err) use ($update, $chatId) {
376
+        })->/** @scrutinizer ignore-call */ otherwise(function($err) use ($update, $chatId) {
377 377
             $this->logger->errorUpdate($err, $update);
378 378
             $this->deleteConversationCache($chatId);
379 379
         });
Please login to merge, or discard this patch.