New PHP 7.1 type hints for Telegram services.

This commit is contained in:
Alexey Skobkin 2017-01-13 02:25:46 +03:00
parent 5271fd5f59
commit 4babc046e6
5 changed files with 30 additions and 26 deletions

View File

@ -36,7 +36,7 @@ class IncomingUpdateDispatcher
*
* @param Update $update
*/
public function process(Update $update)
public function process(Update $update): void
{
if ($update->message && $update->message instanceof Message) {
$chatType = $update->message->chat->type;

View File

@ -27,7 +27,7 @@ class InlineQueryProcessor
$this->client = $client;
}
public function process(Query $inlineQuery)
public function process(Query $inlineQuery): void
{
if (mb_strlen($inlineQuery->query) < 2) {
return;

View File

@ -53,7 +53,8 @@ class MessageSender
bool $disableWebPreview = true,
bool $disableNotifications = false,
string $parseMode = self::PARSE_MARKDOWN
) {
): void
{
$text = $this->twig->render($template, $templateData);
foreach ($accounts as $account) {
@ -69,7 +70,8 @@ class MessageSender
bool $disableWebPreview = true,
bool $disableNotifications = false,
string $parseMode = self::PARSE_MARKDOWN
): bool {
): bool
{
$text = $this->twig->render($template, $templateData);
return $this->sendMessage($account, $text, $parseMode, $keyboardMarkup, $disableWebPreview, $disableNotifications);
@ -82,7 +84,8 @@ class MessageSender
KeyboardMethods $keyboardMarkup = null,
bool $disableWebPreview = false,
bool $disableNotifications = false
): bool {
): bool
{
return $this->sendMessageToChat($account->getChatId(), $text, $parseMode, $keyboardMarkup, $disableWebPreview, $disableNotifications);
}
@ -93,7 +96,8 @@ class MessageSender
KeyboardMethods $keyboardMarkup = null,
bool $disableWebPreview = false,
bool $disableNotifications = false
): bool {
): bool
{
$sendMessage = new SendMessage();
$sendMessage->chat_id = (string)$chatId;
$sendMessage->text = $text;

View File

@ -32,7 +32,7 @@ class Notifier
/**
* @param UserRenameEvent[] $userRenameEvents
*/
public function sendUsersRenamedNotification(array $userRenameEvents)
public function sendUsersRenamedNotification(array $userRenameEvents): void
{
$accounts = $this->accountsRepo->findBy(['renameNotification' => true]);
@ -46,7 +46,7 @@ class Notifier
* @param User[] $subscribed
* @param User[] $unsubscribed
*/
public function sendUserSubscribersUpdatedNotification(User $user, array $subscribed, array $unsubscribed)
public function sendUserSubscribersUpdatedNotification(User $user, array $subscribed, array $unsubscribed): bool
{
/** @var Account $account */
$account = $this->accountsRepo->findOneBy(
@ -57,10 +57,10 @@ class Notifier
);
if (null === $account) {
return;
return false;
}
$this->messenger->sendTemplatedMessage(
return $this->messenger->sendTemplatedMessage(
$account,
'@SkobkinPointTools/Telegram/user_subscribers_updated_notification.md.twig',
[

View File

@ -89,7 +89,7 @@ class PrivateMessageProcessor
$this->pointUserId = $pointUserId;
}
public function process(Message $message)
public function process(Message $message): void
{
if (!IncomingUpdateDispatcher::CHAT_TYPE_PRIVATE === $message->chat->type) {
throw new \LogicException('This service can process only private chat messages');
@ -183,7 +183,7 @@ class PrivateMessageProcessor
return false;
}
private function processLink(Account $account, array $words)
private function processLink(Account $account, array $words): void
{
if (array_key_exists(2, $words)) {
if ($this->linkAccount($account, $words[1], $words[2])) {
@ -198,7 +198,7 @@ class PrivateMessageProcessor
}
}
private function processMe(Account $account)
private function processMe(Account $account): void
{
if ($user = $account->getUser()) {
$this->sendUserEvents($account, $user);
@ -207,7 +207,7 @@ class PrivateMessageProcessor
}
}
private function processLast(Account $account, array $words)
private function processLast(Account $account, array $words): void
{
if (array_key_exists(1, $words)) {
if (null !== $user = $this->userRepo->findUserByLogin($words[1])) {
@ -220,7 +220,7 @@ class PrivateMessageProcessor
}
}
private function processSub(Account $account, array $words)
private function processSub(Account $account, array $words): void
{
if (array_key_exists(1, $words)) {
if (null !== $user = $this->userRepo->findUserByLogin($words[1])) {
@ -237,12 +237,12 @@ class PrivateMessageProcessor
}
}
private function processStats(Account $account)
private function processStats(Account $account): void
{
$this->sendStats($account);
}
private function processSet(Account $account, array $words)
private function processSet(Account $account, array $words): void
{
$keyboard = new ReplyKeyboardMarkup();
@ -288,24 +288,24 @@ class PrivateMessageProcessor
/**
* Processes exit from keyboard menus and removes the keyboard
*/
private function processExit(Account $account)
private function processExit(Account $account): void
{
$keyboardRemove = new ReplyKeyboardRemove();
$this->messenger->sendMessage($account, 'Done', MessageSender::PARSE_PLAIN, $keyboardRemove);
}
private function processHelp(Account $account)
private function processHelp(Account $account): void
{
$this->sendHelp($account);
}
private function sendAccountLinked(Account $account)
private function sendAccountLinked(Account $account): void
{
$this->messenger->sendMessage($account, 'Account linked. Try using /me now.');
}
private function sendUserSubscribers(Account $account, User $user)
private function sendUserSubscribers(Account $account, User $user): void
{
$subscribers = [];
foreach ($user->getSubscribers() as $subscription) {
@ -322,7 +322,7 @@ class PrivateMessageProcessor
);
}
private function sendUserEvents(Account $account, User $user)
private function sendUserEvents(Account $account, User $user): void
{
$events = $this->subscriptionEventRepo->getUserLastSubscribersEvents($user, 10);
@ -336,14 +336,14 @@ class PrivateMessageProcessor
);
}
private function sendGlobalEvents(Account $account)
private function sendGlobalEvents(Account $account): void
{
$events = $this->subscriptionEventRepo->getLastSubscriptionEvents(10);
$this->messenger->sendTemplatedMessage($account, '@SkobkinPointTools/Telegram/last_global_subscriptions.md.twig', ['events' => $events]);
}
private function sendStats(Account $account)
private function sendStats(Account $account): void
{
$this->messenger->sendTemplatedMessage(
$account,
@ -358,12 +358,12 @@ class PrivateMessageProcessor
);
}
private function sendHelp(Account $account)
private function sendHelp(Account $account): void
{
$this->messenger->sendTemplatedMessage($account, '@SkobkinPointTools/Telegram/help.md.twig');
}
private function sendError(Account $account, string $title, string $text = '')
private function sendError(Account $account, string $title, string $text = ''): void
{
$this->messenger->sendTemplatedMessage(
$account,