From 7d6ea3c3673b551aa5b4312472a152253a137be0 Mon Sep 17 00:00:00 2001 From: Ilya Gusev Date: Sun, 20 Sep 2015 02:05:44 +0300 Subject: [PATCH] Refactoring2 --- src/BaseType.php | 6 ++-- src/BotApi.php | 60 +++++++++++++++---------------- src/Botan.php | 4 +-- src/Client.php | 4 +-- src/Types/ArrayOfPhotoSize.php | 2 +- src/Types/ArrayOfUpdates.php | 2 +- src/Types/Audio.php | 6 ++-- src/Types/Contact.php | 6 ++-- src/Types/Document.php | 6 ++-- src/Types/ForceReply.php | 6 ++-- src/Types/GroupChat.php | 6 ++-- src/Types/Location.php | 8 ++--- src/Types/Message.php | 6 ++-- src/Types/PhotoSize.php | 6 ++-- src/Types/ReplyKeyboardHide.php | 6 ++-- src/Types/ReplyKeyboardMarkup.php | 6 ++-- src/Types/Sticker.php | 6 ++-- src/Types/Update.php | 6 ++-- src/Types/User.php | 6 ++-- src/Types/UserProfilePhotos.php | 6 ++-- src/Types/Video.php | 6 ++-- src/Types/Voice.php | 8 ++--- 22 files changed, 89 insertions(+), 89 deletions(-) diff --git a/src/BaseType.php b/src/BaseType.php index f90f7001..7ed47587 100644 --- a/src/BaseType.php +++ b/src/BaseType.php @@ -15,14 +15,14 @@ abstract class BaseType * * @var array */ - protected static $requiredParams = array(); + protected static $requiredParams = []; /** * Map of input data * * @var array */ - protected static $map = array(); + protected static $map = []; /** * Validate input data @@ -59,7 +59,7 @@ protected static function toCamelCase($str) public function toJson($inner = false) { - $output = array(); + $output = []; foreach (static::$map as $key => $item) { $property = lcfirst(self::toCamelCase($key)); diff --git a/src/BotApi.php b/src/BotApi.php index 8f273d4b..8d92a425 100644 --- a/src/BotApi.php +++ b/src/BotApi.php @@ -20,7 +20,7 @@ class BotApi * * @var array */ - public static $codes = array( + public static $codes = [ // Informational 1xx 100 => 'Continue', 101 => 'Switching Protocols', @@ -68,7 +68,7 @@ class BotApi 504 => 'Gateway Timeout', 505 => 'HTTP Version Not Supported', 509 => 'Bandwidth Limit Exceeded' - ); + ]; /** @@ -112,7 +112,7 @@ class BotApi * * @var array */ - protected $trackedEvents = array(); + protected $trackedEvents = []; /** * Check whether return associative array @@ -166,12 +166,12 @@ public function setModeObject($mode = true) */ public function call($method, array $data = null) { - $options = array( + $options = [ CURLOPT_URL => $this->getUrl() . '/' . $method, CURLOPT_RETURNTRANSFER => true, CURLOPT_POST => null, CURLOPT_POSTFIELDS => null - ); + ]; if ($data) { $options[CURLOPT_POST] = true; @@ -270,14 +270,14 @@ public function sendMessage( $replyToMessageId = null, $replyMarkup = null ) { - return Message::fromResponse($this->call('sendMessage', array( + return Message::fromResponse($this->call('sendMessage', [ 'chat_id' => (int) $chatId, 'text' => $text, 'parse_mode' => $parseMode, 'disable_web_page_preview' => $disablePreview, 'reply_to_message_id' => (int) $replyToMessageId, 'reply_markup' => is_null($replyMarkup) ? $replyMarkup : $replyMarkup->toJson() - ))); + ])); } /** @@ -300,10 +300,10 @@ public function sendMessage( */ public function sendChatAction($chatId, $action) { - return $this->call('sendChatAction', array( + return $this->call('sendChatAction', [ 'chat_id' => (int) $chatId, 'action' => $action - )); + ]); } /** @@ -318,11 +318,11 @@ public function sendChatAction($chatId, $action) */ public function getUserProfilePhotos($userId, $offset = 0, $limit = 100) { - return UserProfilePhotos::fromResponse($this->call('getUserProfilePhotos', array( + return UserProfilePhotos::fromResponse($this->call('getUserProfilePhotos', [ 'user_id' => (int) $userId, 'offset' => (int) $offset, 'limit' => (int) $limit, - ))); + ])); } /** @@ -339,7 +339,7 @@ public function getUserProfilePhotos($userId, $offset = 0, $limit = 100) */ public function setWebhook($url = '', $certificate = null) { - return $this->call('setWebhook', array('url' => $url, 'certificate' => $certificate)); + return $this->call('setWebhook', ['url' => $url, 'certificate' => $certificate]); } /** @@ -373,11 +373,11 @@ public function getMe() */ public function getUpdates($offset = 0, $limit = 100, $timeout = 0) { - $updates = ArrayOfUpdates::fromResponse($this->call('getUpdates', array( + $updates = ArrayOfUpdates::fromResponse($this->call('getUpdates', [ 'offset' => $offset, 'limit' => $limit, 'timeout' => $timeout - ))); + ])); if ($this->tracker instanceof Botan) { foreach ($updates as $update) { @@ -402,13 +402,13 @@ public function getUpdates($offset = 0, $limit = 100, $timeout = 0) */ public function sendLocation($chatId, $latitude, $longitude, $replyToMessageId = null, $replyMarkup = null) { - return Message::fromResponse($this->call('sendLocation', array( + return Message::fromResponse($this->call('sendLocation', [ 'chat_id' => (int) $chatId, 'latitude' => $latitude, 'longitude' => $longitude, 'reply_to_message_id' => $replyToMessageId, 'reply_markup' => is_null($replyMarkup) ? $replyMarkup : $replyMarkup->toJson() - ))); + ])); } /** @@ -425,12 +425,12 @@ public function sendLocation($chatId, $latitude, $longitude, $replyToMessageId = */ public function sendSticker($chatId, $sticker, $replyToMessageId = null, $replyMarkup = null) { - return Message::fromResponse($this->call('sendSticker', array( + return Message::fromResponse($this->call('sendSticker', [ 'chat_id' => (int) $chatId, 'sticker' => $sticker, 'reply_to_message_id' => $replyToMessageId, 'reply_markup' => is_null($replyMarkup) ? $replyMarkup : $replyMarkup->toJson() - ))); + ])); } /** @@ -457,14 +457,14 @@ public function sendVideo( $replyToMessageId = null, $replyMarkup = null ) { - return Message::fromResponse($this->call('sendVideo', array( + return Message::fromResponse($this->call('sendVideo', [ 'chat_id' => (int) $chatId, 'video' => $video, 'duration' => $duration, 'caption' => $caption, 'reply_to_message_id' => $replyToMessageId, 'reply_markup' => is_null($replyMarkup) ? $replyMarkup : $replyMarkup->toJson() - ))); + ])); } /** @@ -487,13 +487,13 @@ public function sendVideo( */ public function sendVoice($chatId, $voice, $duration = null, $replyToMessageId = null, $replyMarkup = null) { - return Message::fromResponse($this->call('sendVoice', array( + return Message::fromResponse($this->call('sendVoice', [ 'chat_id' => (int) $chatId, 'voice' => $voice, 'duration' => $duration, 'reply_to_message_id' => $replyToMessageId, 'reply_markup' => is_null($replyMarkup) ? $replyMarkup : $replyMarkup->toJson() - ))); + ])); } @@ -510,11 +510,11 @@ public function sendVoice($chatId, $voice, $duration = null, $replyToMessageId = */ public function forwardMessage($chatId, $fromChatId, $messageId) { - return Message::fromResponse($this->call('forwardMessage', array( + return Message::fromResponse($this->call('forwardMessage', [ 'chat_id' => (int) $chatId, 'from_chat_id' => (int) $fromChatId, 'message_id' => (int) $messageId, - ))); + ])); } /** @@ -550,7 +550,7 @@ public function sendAudio( $replyToMessageId = null, $replyMarkup = null ) { - return Message::fromResponse($this->call('sendAudio', array( + return Message::fromResponse($this->call('sendAudio', [ 'chat_id' => (int) $chatId, 'audio' => $audio, 'duration' => $duration, @@ -558,7 +558,7 @@ public function sendAudio( 'title' => $title, 'reply_to_message_id' => $replyToMessageId, 'reply_markup' => is_null($replyMarkup) ? $replyMarkup : $replyMarkup->toJson() - ))); + ])); } /** @@ -576,13 +576,13 @@ public function sendAudio( */ public function sendPhoto($chatId, $photo, $caption = null, $replyToMessageId = null, $replyMarkup = null) { - return Message::fromResponse($this->call('sendPhoto', array( + return Message::fromResponse($this->call('sendPhoto', [ 'chat_id' => (int) $chatId, 'photo' => $photo, 'caption' => $caption, 'reply_to_message_id' => $replyToMessageId, 'reply_markup' => is_null($replyMarkup) ? $replyMarkup : $replyMarkup->toJson() - ))); + ])); } /** @@ -600,12 +600,12 @@ public function sendPhoto($chatId, $photo, $caption = null, $replyToMessageId = */ public function sendDocument($chatId, $document, $replyToMessageId = null, $replyMarkup = null) { - return Message::fromResponse($this->call('sendDocument', array( + return Message::fromResponse($this->call('sendDocument', [ 'chat_id' => (int) $chatId, 'document' => $document, 'reply_to_message_id' => $replyToMessageId, 'reply_markup' => is_null($replyMarkup) ? $replyMarkup : $replyMarkup->toJson() - ))); + ])); } /** diff --git a/src/Botan.php b/src/Botan.php index 275a0c3c..1abb17fa 100644 --- a/src/Botan.php +++ b/src/Botan.php @@ -61,7 +61,7 @@ public function track(Message $message, $eventName = 'Message') { $uid = $message->getFrom()->getId(); - $options = array( + $options = [ CURLOPT_URL => self::BASE_URL . "?token={$this->token}&uid={$uid}&name={$eventName}", CURLOPT_RETURNTRANSFER => true, CURLOPT_POST => true, @@ -69,7 +69,7 @@ public function track(Message $message, $eventName = 'Message') 'Content-Type: application/json' ], CURLOPT_POSTFIELDS => $message->toJson() - ); + ]; curl_setopt_array($this->curl, $options); $result = BotApi::jsonValidate(curl_exec($this->curl), true); diff --git a/src/Client.php b/src/Client.php index 4b72404b..c9004534 100644 --- a/src/Client.php +++ b/src/Client.php @@ -150,9 +150,9 @@ protected static function getChecker($name) public function __call($name, array $arguments) { if (method_exists($this, $name)) { - return call_user_func_array(array($this, $name), $arguments); + return call_user_func_array([$this, $name], $arguments); } elseif (method_exists($this->api, $name)) { - return call_user_func_array(array($this->api, $name), $arguments); + return call_user_func_array([$this->api, $name], $arguments); } throw new BadMethodCallException("Method {$name} not exists"); } diff --git a/src/Types/ArrayOfPhotoSize.php b/src/Types/ArrayOfPhotoSize.php index 99a4b48a..e35ff840 100644 --- a/src/Types/ArrayOfPhotoSize.php +++ b/src/Types/ArrayOfPhotoSize.php @@ -6,7 +6,7 @@ abstract class ArrayOfPhotoSize { public static function fromResponse($data) { - $arrayOfPhotoSize = array(); + $arrayOfPhotoSize = []; foreach ($data as $photoSizeItem) { $arrayOfPhotoSize[] = PhotoSize::fromResponse($photoSizeItem); } diff --git a/src/Types/ArrayOfUpdates.php b/src/Types/ArrayOfUpdates.php index f7293792..6c062b46 100644 --- a/src/Types/ArrayOfUpdates.php +++ b/src/Types/ArrayOfUpdates.php @@ -6,7 +6,7 @@ abstract class ArrayOfUpdates { public static function fromResponse($data) { - $arrayOfUpdates = array(); + $arrayOfUpdates = []; foreach ($data as $update) { $arrayOfUpdates[] = Update::fromResponse($update); } diff --git a/src/Types/Audio.php b/src/Types/Audio.php index 844346b7..e28d9251 100644 --- a/src/Types/Audio.php +++ b/src/Types/Audio.php @@ -19,21 +19,21 @@ class Audio extends BaseType implements TypeInterface * * @var array */ - static protected $requiredParams = array('file_id', 'duration'); + static protected $requiredParams = ['file_id', 'duration']; /** * {@inheritdoc} * * @var array */ - static protected $map = array( + static protected $map = [ 'file_id' => true, 'duration' => true, 'performer' => true, 'title' => true, 'mime_type' => true, 'file_size' => true - ); + ]; /** * Unique identifier for this file diff --git a/src/Types/Contact.php b/src/Types/Contact.php index 0b780f99..bbf6360f 100644 --- a/src/Types/Contact.php +++ b/src/Types/Contact.php @@ -19,19 +19,19 @@ class Contact extends BaseType implements TypeInterface * * @var array */ - static protected $requiredParams = array('phone_number', 'first_name'); + static protected $requiredParams = ['phone_number', 'first_name']; /** * {@inheritdoc} * * @var array */ - static protected $map = array( + static protected $map = [ 'phone_number' => true, 'first_name' => true, 'last_name' => true, 'user_id' => true - ); + ]; /** * Contact's phone number diff --git a/src/Types/Document.php b/src/Types/Document.php index 4c2e2876..4df82954 100644 --- a/src/Types/Document.php +++ b/src/Types/Document.php @@ -20,20 +20,20 @@ class Document extends BaseType implements TypeInterface * * @var array */ - static protected $map = array( + static protected $map = [ 'file_id' => true, 'thumb' => \TelegramBot\Api\Types\PhotoSize::class, 'file_name' => true, 'mime_type' => true, 'file_size' => true - ); + ]; /** * {@inheritdoc} * * @var array */ - static protected $requiredParams = array('file_id'); + static protected $requiredParams = ['file_id']; /** * Unique identifier for this file diff --git a/src/Types/ForceReply.php b/src/Types/ForceReply.php index 02d6972b..6dbd2d79 100644 --- a/src/Types/ForceReply.php +++ b/src/Types/ForceReply.php @@ -19,17 +19,17 @@ class ForceReply extends BaseType * * @var array */ - static protected $requiredParams = array('force_reply'); + static protected $requiredParams = ['force_reply']; /** * {@inheritdoc} * * @var array */ - static protected $map = array( + static protected $map = [ 'force_reply' => true, 'selective' => true - ); + ]; /** * Shows reply interface to the user, as if they manually selected the bot‘s message and tapped ’Reply' diff --git a/src/Types/GroupChat.php b/src/Types/GroupChat.php index a66bb51a..f56f5c27 100644 --- a/src/Types/GroupChat.php +++ b/src/Types/GroupChat.php @@ -19,17 +19,17 @@ class GroupChat extends BaseType implements TypeInterface * * @var array */ - static protected $requiredParams = array('id', 'title'); + static protected $requiredParams = ['id', 'title']; /** * {@inheritdoc} * * @var array */ - static protected $map = array( + static protected $map = [ 'id' => true, 'title' => true - ); + ]; /** * Unique identifier for this group chat diff --git a/src/Types/Location.php b/src/Types/Location.php index cbfae154..b38ac48f 100644 --- a/src/Types/Location.php +++ b/src/Types/Location.php @@ -19,17 +19,17 @@ class Location extends BaseType implements TypeInterface * * @var array */ - static protected $requiredParams = array('latitude', 'longitude'); + static protected $requiredParams = ['latitude', 'longitude']; /** * {@inheritdoc} * * @var array */ - static protected $map = array( + static protected $map = [ 'latitude' => true, - 'longitude' => true, - ); + 'longitude' => true + ]; /** * Longitude as defined by sender diff --git a/src/Types/Message.php b/src/Types/Message.php index 258b7be4..27987513 100644 --- a/src/Types/Message.php +++ b/src/Types/Message.php @@ -12,14 +12,14 @@ class Message extends BaseType implements TypeInterface * * @var array */ - static protected $requiredParams = array('message_id', 'from', 'date', 'chat'); + static protected $requiredParams = ['message_id', 'from', 'date', 'chat']; /** * {@inheritdoc} * * @var array */ - static protected $map = array( + static protected $map = [ 'message_id' => true, 'from' => \TelegramBot\Api\Types\User::class, 'date' => true, @@ -43,7 +43,7 @@ class Message extends BaseType implements TypeInterface 'new_chat_photo' => \TelegramBot\Api\Types\ArrayOfPhotoSize::class, 'delete_chat_photo' => true, 'group_chat_created' => true - ); + ]; /** * Unique message identifier diff --git a/src/Types/PhotoSize.php b/src/Types/PhotoSize.php index 11995131..e96324a5 100644 --- a/src/Types/PhotoSize.php +++ b/src/Types/PhotoSize.php @@ -19,19 +19,19 @@ class PhotoSize extends BaseType implements TypeInterface * * @var array */ - static protected $requiredParams = array('file_id', 'width', 'height'); + static protected $requiredParams = ['file_id', 'width', 'height']; /** * {@inheritdoc} * * @var array */ - static protected $map = array( + static protected $map = [ 'file_id' => true, 'width' => true, 'height' => true, 'file_size' => true, - ); + ]; /** * Unique identifier for this file diff --git a/src/Types/ReplyKeyboardHide.php b/src/Types/ReplyKeyboardHide.php index e0f85643..d7c27e51 100644 --- a/src/Types/ReplyKeyboardHide.php +++ b/src/Types/ReplyKeyboardHide.php @@ -20,17 +20,17 @@ class ReplyKeyboardHide extends BaseType * * @var array */ - static protected $requiredParams = array('hide_keyboard'); + static protected $requiredParams = ['hide_keyboard']; /** * {@inheritdoc} * * @var array */ - static protected $map = array( + static protected $map = [ 'hide_keyboard' => true, 'selective' => true - ); + ]; /** * Requests clients to hide the custom keyboard diff --git a/src/Types/ReplyKeyboardMarkup.php b/src/Types/ReplyKeyboardMarkup.php index be246786..5c9cce9e 100644 --- a/src/Types/ReplyKeyboardMarkup.php +++ b/src/Types/ReplyKeyboardMarkup.php @@ -17,19 +17,19 @@ class ReplyKeyboardMarkup extends BaseType * * @var array */ - static protected $requiredParams = array('keyboard'); + static protected $requiredParams = ['keyboard']; /** * {@inheritdoc} * * @var array */ - static protected $map = array( + static protected $map = [ 'keyboard' => true, 'one_time_keyboard' => true, 'resize_keyboard' => true, 'selective' => true - ); + ]; /** * Array of button rows, each represented by an Array of Strings diff --git a/src/Types/Sticker.php b/src/Types/Sticker.php index 31aa19ac..079801f4 100644 --- a/src/Types/Sticker.php +++ b/src/Types/Sticker.php @@ -19,20 +19,20 @@ class Sticker extends BaseType implements TypeInterface * * @var array */ - static protected $requiredParams = array('file_id', 'width', 'height'); + static protected $requiredParams = ['file_id', 'width', 'height']; /** * {@inheritdoc} * * @var array */ - static protected $map = array( + static protected $map = [ 'file_id' => true, 'width' => true, 'height' => true, 'thumb' => \TelegramBot\Api\Types\PhotoSize::class, 'file_size' => true, - ); + ]; /** * Unique identifier for this file diff --git a/src/Types/Update.php b/src/Types/Update.php index 7cb9a2d0..90a732d9 100644 --- a/src/Types/Update.php +++ b/src/Types/Update.php @@ -12,17 +12,17 @@ class Update extends BaseType implements TypeInterface * * @var array */ - static protected $requiredParams = array('update_id'); + static protected $requiredParams = ['update_id']; /** * {@inheritdoc} * * @var array */ - static protected $map = array( + static protected $map = [ 'update_id' => true, 'message' => \TelegramBot\Api\Types\Message::class, - ); + ]; /** * The update‘s unique identifier. diff --git a/src/Types/User.php b/src/Types/User.php index de7ba848..0d59708e 100644 --- a/src/Types/User.php +++ b/src/Types/User.php @@ -19,19 +19,19 @@ class User extends BaseType implements TypeInterface * * @var array */ - static protected $requiredParams = array('id', 'first_name'); + static protected $requiredParams = ['id', 'first_name']; /** * {@inheritdoc} * * @var array */ - static protected $map = array( + static protected $map = [ 'id' => true, 'first_name' => true, 'last_name' => true, 'username' => true, - ); + ]; /** * Unique identifier for this user or bot diff --git a/src/Types/UserProfilePhotos.php b/src/Types/UserProfilePhotos.php index eb7cd48d..68b43614 100644 --- a/src/Types/UserProfilePhotos.php +++ b/src/Types/UserProfilePhotos.php @@ -19,17 +19,17 @@ class UserProfilePhotos extends BaseType implements TypeInterface * * @var array */ - static protected $requiredParams = array('total_count', 'photos'); + static protected $requiredParams = ['total_count', 'photos']; /** * {@inheritdoc} * * @var array */ - static protected $map = array( + static protected $map = [ 'total_count' => true, 'photos' => \TelegramBot\Api\Types\ArrayOfArrayOfPhotoSize::class, - ); + ]; /** * Total number of profile pictures the target user has diff --git a/src/Types/Video.php b/src/Types/Video.php index 140d5417..a49fc06e 100644 --- a/src/Types/Video.php +++ b/src/Types/Video.php @@ -19,14 +19,14 @@ class Video extends BaseType implements TypeInterface * * @var array */ - static protected $requiredParams = array('file_id', 'width', 'height', 'duration'); + static protected $requiredParams = ['file_id', 'width', 'height', 'duration']; /** * {@inheritdoc} * * @var array */ - static protected $map = array( + static protected $map = [ 'file_id' => true, 'width' => true, 'height' => true, @@ -34,7 +34,7 @@ class Video extends BaseType implements TypeInterface 'thumb' => \TelegramBot\Api\Types\PhotoSize::class, 'mime_type' => true, 'file_size' => true - ); + ]; /** * Unique identifier for this file diff --git a/src/Types/Voice.php b/src/Types/Voice.php index 4c22309a..f9841600 100644 --- a/src/Types/Voice.php +++ b/src/Types/Voice.php @@ -19,19 +19,19 @@ class Voice extends BaseType implements TypeInterface * * @var array */ - static protected $requiredParams = array('file_id', 'duration'); + static protected $requiredParams = ['file_id', 'duration']; /** * {@inheritdoc} * * @var array */ - static protected $map = array( + static protected $map = [ 'file_id' => true, 'duration' => true, 'mime_type' => true, - 'file_size' => true, - ); + 'file_size' => true + ]; /** * Unique identifier for this file