Skip to content

Commit

Permalink
code reformat
Browse files Browse the repository at this point in the history
  • Loading branch information
cheeghi committed Apr 16, 2023
1 parent 85e15b7 commit 402ac35
Show file tree
Hide file tree
Showing 15 changed files with 55 additions and 55 deletions.
2 changes: 1 addition & 1 deletion src/Zanzara/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -622,7 +622,7 @@ public function getPollingRetry(): float
}

/**
* @param float $pollingRetry
* @param float $pollingRetry
*/
public function setPollingRetry(float $pollingRetry): void
{
Expand Down
4 changes: 2 additions & 2 deletions src/Zanzara/Context.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,9 @@ public function getUpdate(): ?Update
*
* This callable must be take on parameter of type Context
* @param $handler
* @param bool $skipListeners if true the conversation handler has precedence over the listeners, so the listener
* @param bool $skipListeners if true the conversation handler has precedence over the listeners, so the listener
* callbacks are not executed.
* @param bool $skipMiddlewares if true, the next conversation handler will be called without apply middlewares
* @param bool $skipMiddlewares if true, the next conversation handler will be called without apply middlewares
* @return PromiseInterface
* @throws \DI\DependencyException
* @throws \DI\NotFoundException
Expand Down
21 changes: 10 additions & 11 deletions src/Zanzara/Listener/ListenerCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ abstract class ListenerCollector
* You can also parameterized the command, eg:
* Eg. $bot->onCommand('start {myParam}', function(Context $ctx, $myParam) {});
*
* @param string $command
* @param string $command
* @param $callback
* @param array $filters eg. ['chat_type' => 'group']
* @return MiddlewareCollector
Expand All @@ -100,7 +100,7 @@ abstract class ListenerCollector
public function onCommand(string $command, $callback, array $filters = []): MiddlewareCollector
{
$pattern = str_replace('/', '\/', "/{$command}");
$command = '/^'.preg_replace(self::PARAMETER_REGEX, '(?<$1>.*)', $pattern).' ?$/miu';
$command = '/^' . preg_replace(self::PARAMETER_REGEX, '(?<$1>.*)', $pattern) . ' ?$/miu';

$listener = new Listener($callback, $this->container, $command, $filters);
$this->listeners['messages'][$command] = $listener;
Expand All @@ -117,7 +117,7 @@ public function onCommand(string $command, $callback, array $filters = []): Midd
* You can also parameterized the text, eg:
* Eg. $bot->onText('Hello {name}', function(Context $ctx, $name) {});
*
* @param string $text
* @param string $text
* @param $callback
* @param array $filters eg. ['chat_type' => 'group']
* @return MiddlewareCollector
Expand All @@ -126,7 +126,7 @@ public function onCommand(string $command, $callback, array $filters = []): Midd
*/
public function onText(string $text, $callback, array $filters = []): MiddlewareCollector
{
$text = '/^'.preg_replace(self::PARAMETER_REGEX, '(?<$1>.*)', $text).' ?$/miu';
$text = '/^' . preg_replace(self::PARAMETER_REGEX, '(?<$1>.*)', $text) . ' ?$/miu';
$listener = new Listener($callback, $this->container, $text, $filters);
$this->listeners['messages'][$text] = $listener;
return $listener;
Expand Down Expand Up @@ -203,7 +203,7 @@ public function onEditedMessage($callback, array $filters = []): MiddlewareColle
* You can also parameterized the text, eg:
* Eg. $bot->onCbQueryText('Hello {name}', function(Context $ctx, $name) {});
*
* @param string $text
* @param string $text
* @param $callback
* @param array $filters for ex. ['chat_type' => 'group'], in this case the listener will be executed only if the
* message is sent in a group chat.
Expand All @@ -213,7 +213,7 @@ public function onEditedMessage($callback, array $filters = []): MiddlewareColle
*/
public function onCbQueryText(string $text, $callback, array $filters = []): MiddlewareCollector
{
$text = '/^'.preg_replace(self::PARAMETER_REGEX, '(?<$1>.*)', $text).' ?$/miu';
$text = '/^' . preg_replace(self::PARAMETER_REGEX, '(?<$1>.*)', $text) . ' ?$/miu';
$listener = new Listener($callback, $this->container, $text, $filters);
$this->listeners['cb_query_texts'][$text] = $listener;
return $listener;
Expand All @@ -227,7 +227,7 @@ public function onCbQueryText(string $text, $callback, array $filters = []): Mid
* Data values are a regex, so you could also do something like:
* $bot->onCbQueryData(['acc.'], function(Context $ctx) {});
*
* @param array $data
* @param array $data
* @param $callback
* @param array $filters for ex. ['chat_type' => 'group'], in this case the listener will be executed only if the
* message is sent in a group chat.
Expand All @@ -239,7 +239,7 @@ public function onCbQueryData(array $data, $callback, array $filters = []): Midd
{
// merge values with "|" (eg. "accept|refuse|later"), then ListenerResolver will check the callback data
// against that regex.
$id = '/'.implode('|', $data).'/';
$id = '/' . implode('|', $data) . '/';
$listener = new Listener($callback, $this->container, $id, $filters);
$this->listeners['cb_query_data'][$id] = $listener;
return $listener;
Expand Down Expand Up @@ -582,7 +582,6 @@ public function onUpdate($callback, array $filters = []): MiddlewareCollector
return $listener;
}


/**
* If the processing of the current update gives an error, this listener will be called.
*
Expand Down Expand Up @@ -626,7 +625,7 @@ public function fallback($callback): MiddlewareCollector
*
* In this case GenericMiddleware will be executed before SpecificMiddleware.
*
* @param MiddlewareInterface|callable $middleware
* @param MiddlewareInterface|callable $middleware
* @return self
*/
public function middleware($middleware): self
Expand All @@ -650,7 +649,7 @@ protected function feedMiddlewareStack()

/**
* Add cross-request middlewares to a listener.
* @param Listener $listener
* @param Listener $listener
* @return Listener
* @throws DependencyException
* @throws NotFoundException
Expand Down
20 changes: 10 additions & 10 deletions src/Zanzara/Listener/ListenerResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ abstract class ListenerResolver extends ListenerCollector
protected $conversationManager;

/**
* @param Update $update
* @param Update $update
* @return PromiseInterface
*/
public function resolveListeners(Update $update): PromiseInterface
Expand Down Expand Up @@ -95,7 +95,7 @@ public function resolveListeners(Update $update): PromiseInterface
$deferred->reject($e);
});
} else {
if (is_string($updateType)){
if (is_string($updateType)) {
$this->mergeListenersByType($update, $listeners, $updateType);
}
$this->mergeListenersByType($update, $listeners, Update::class);
Expand All @@ -106,18 +106,18 @@ public function resolveListeners(Update $update): PromiseInterface
}

/**
* @param Update $update
* @param Listener[] $listeners
* @param string $listenerType
* @param string|null $listenerId
* @param Update $update
* @param Listener[] $listeners
* @param string $listenerType
* @param string|null $listenerId
* @return Listener|null
*/
private function findListenerAndPush(Update $update, array &$listeners, string $listenerType, ?string $listenerId = null): ?Listener
{
if ($listenerId !== null) {
$typedListeners = $this->listeners[$listenerType] ?? [];
foreach ($typedListeners as $regex => $listener) {
$regexMatched = (bool) preg_match($regex, $listenerId, $matches, PREG_UNMATCHED_AS_NULL);
$regexMatched = (bool)preg_match($regex, $listenerId, $matches, PREG_UNMATCHED_AS_NULL);
$filterPassed = $this->filterListener($update, $listener->getFilters());
if ($regexMatched && $filterPassed) {
$parameters = array_unique(array_values(array_slice($matches, 1)));
Expand All @@ -131,9 +131,9 @@ private function findListenerAndPush(Update $update, array &$listeners, string $
}

/**
* @param Update $update
* @param Listener[] $listeners
* @param string $listenerType
* @param Update $update
* @param Listener[] $listeners
* @param string $listenerType
*/
private function mergeListenersByType(Update $update, array &$listeners, string $listenerType)
{
Expand Down
4 changes: 2 additions & 2 deletions src/Zanzara/Middleware/MiddlewareCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ abstract class MiddlewareCollector

/**
* MiddlewareCollector constructor.
* @param ContainerInterface $container
* @param ContainerInterface $container
*/
public function __construct(ContainerInterface $container)
{
Expand All @@ -39,7 +39,7 @@ public function __construct(ContainerInterface $container)
/**
* Last in, first out.
*
* @param MiddlewareInterface|callable $middleware
* @param MiddlewareInterface|callable $middleware
* @return MiddlewareCollector
* @throws \DI\DependencyException
* @throws \DI\NotFoundException
Expand Down
5 changes: 2 additions & 3 deletions src/Zanzara/Telegram/TelegramTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -1012,7 +1012,6 @@ public function getChatMembersCount($chat_id, array $opt = []): PromiseInterface
return $this->callApi("getChatMembersCount", $params); //integer
}


/**
* Use this method to get the number of members in a chat. Returns Int on success.
*
Expand Down Expand Up @@ -1711,7 +1710,7 @@ public function getCustomEmojiStickers(array $custom_emoji_ids, array $opt = [])
*
* @param $user_id
* @param string|InputFile $sticker
* @param string $sticker_format,
* @param string $sticker_format ,
* @param array $opt
* @return PromiseInterface
*/
Expand Down Expand Up @@ -1957,7 +1956,7 @@ public function answerInlineQuery($results, array $opt = []): PromiseInterface
*/
public function answerWebAppQuery(string $web_app_query_id, array $result, array $opt = []): PromiseInterface
{
$required = compact("web_app_query_id","result");
$required = compact("web_app_query_id", "result");
$params = array_merge($required, $opt);
return $this->callApi("answerWebAppQuery", $params, SentWebAppMessage::class);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,5 @@ public function setType(string $type): void
{
$this->type = $type;
}

}
2 changes: 1 addition & 1 deletion src/Zanzara/Telegram/Type/File/Sticker.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class Sticker
* Type of the sticker, currently one of “regular”, “mask”, “custom_emoji”.
* The type of the sticker is independent from its format, which
* is determined by the fields is_animated and is_video.
*
*
* @var string
*/
private $type;
Expand Down
1 change: 1 addition & 0 deletions src/Zanzara/Telegram/Type/Input/InputMediaAnimation.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
declare(strict_types=1);

namespace Zanzara\Telegram\Type\Input;

use Zanzara\Telegram\Type\MessageEntity;

/**
Expand Down
1 change: 1 addition & 0 deletions src/Zanzara/Telegram/Type/Input/InputMediaVideo.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
declare(strict_types=1);

namespace Zanzara\Telegram\Type\Input;

use Zanzara\Telegram\Type\MessageEntity;

/**
Expand Down
38 changes: 19 additions & 19 deletions src/Zanzara/Telegram/Type/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -1701,25 +1701,25 @@ public function isServiceMessage(): bool
{
return (
$this->delete_chat_photo !== null ||
$this->group_chat_created!== null ||
$this->supergroup_chat_created!== null ||
$this->channel_chat_created!== null ||
$this->message_auto_delete_timer_changed!== null ||
$this->successful_payment!== null ||
$this->user_shared!== null ||
$this->chat_shared!== null ||
$this->write_access_allowed!== null ||
$this->proximity_alert_triggered!== null ||
$this->forum_topic_created!== null ||
$this->forum_topic_edited!== null ||
$this->forum_topic_closed!== null ||
$this->forum_topic_reopened!== null ||
$this->general_forum_topic_hidden!== null ||
$this->general_forum_topic_unhidden!== null ||
$this->video_chat_scheduled!== null ||
$this->video_chat_started!== null ||
$this->video_chat_ended!== null ||
$this->video_chat_participants_invited!== null ||
$this->group_chat_created !== null ||
$this->supergroup_chat_created !== null ||
$this->channel_chat_created !== null ||
$this->message_auto_delete_timer_changed !== null ||
$this->successful_payment !== null ||
$this->user_shared !== null ||
$this->chat_shared !== null ||
$this->write_access_allowed !== null ||
$this->proximity_alert_triggered !== null ||
$this->forum_topic_created !== null ||
$this->forum_topic_edited !== null ||
$this->forum_topic_closed !== null ||
$this->forum_topic_reopened !== null ||
$this->general_forum_topic_hidden !== null ||
$this->general_forum_topic_unhidden !== null ||
$this->video_chat_scheduled !== null ||
$this->video_chat_started !== null ||
$this->video_chat_ended !== null ||
$this->video_chat_participants_invited !== null ||
$this->web_app_data !== null
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Zanzara/UpdateMode/Polling.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ function (WebhookInfo $webhookInfo) {
$this->logger->logIsListening();
return;
}
$message = "Your bot has a webhook set, please delete it before running Zanzara in polling mode. ".
$message = "Your bot has a webhook set, please delete it before running Zanzara in polling mode. " .
"See https://core.telegram.org/bots/api#deletewebhook";
$this->logger->error($message);
echo "Type 'yes' if you want to delete the webhook: ";
Expand Down
2 changes: 1 addition & 1 deletion src/Zanzara/UpdateMode/ReactPHPWebhook.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class ReactPHPWebhook extends BaseWebhook
private $server;

public function __construct(ContainerInterface $container, Zanzara $zanzara, Telegram $telegram, Config $config,
ZanzaraLogger $logger, LoopInterface $loop, ZanzaraMapper $zanzaraMapper)
ZanzaraLogger $logger, LoopInterface $loop, ZanzaraMapper $zanzaraMapper)
{
parent::__construct($container, $zanzara, $telegram, $config, $logger, $loop, $zanzaraMapper);
$this->init();
Expand Down
4 changes: 2 additions & 2 deletions src/Zanzara/UpdateMode/UpdateMode.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ abstract class UpdateMode implements UpdateModeInterface
* @param ZanzaraMapper $zanzaraMapper
*/
public function __construct(ContainerInterface $container, Zanzara $zanzara, Telegram $telegram, Config $config,
ZanzaraLogger $logger, LoopInterface $loop, ZanzaraMapper $zanzaraMapper)
ZanzaraLogger $logger, LoopInterface $loop, ZanzaraMapper $zanzaraMapper)
{
$this->container = $container;
$this->zanzara = $zanzara;
Expand All @@ -93,7 +93,7 @@ protected function processUpdate(Update $update)
$middlewareTip($context);
}
})->otherwise(function ($e) use ($context, $update) {
if (!$this->zanzara->callOnException($context, $e)){
if (!$this->zanzara->callOnException($context, $e)) {
$this->logger->error("Unable to resolve listeners for update $update, reason: $e");
}
});
Expand Down
2 changes: 1 addition & 1 deletion src/Zanzara/Zanzara.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public function __construct(string $botToken, ?Config $config = null)
$this->container->set(
Browser::class,
$this->config->getBrowser() ?? (new Browser($this->config->getConnector(), $this->loop))
->withBase("{$this->config->getApiTelegramUrl()}/bot{$botToken}/")
->withBase("{$this->config->getApiTelegramUrl()}/bot{$botToken}/")
);
$this->telegram = $this->container->get(Telegram::class);
$this->container->set(CacheInterface::class, $this->config->getCache() ?? new ArrayCache());
Expand Down

0 comments on commit 402ac35

Please sign in to comment.