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 * @param Update $update
*/ */
public function process(Update $update) public function process(Update $update): void
{ {
if ($update->message && $update->message instanceof Message) { if ($update->message && $update->message instanceof Message) {
$chatType = $update->message->chat->type; $chatType = $update->message->chat->type;

View file

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

View file

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

View file

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

View file

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