Skip to content

Commit

Permalink
Refactoring2
Browse files Browse the repository at this point in the history
  • Loading branch information
iGusev committed Sep 19, 2015
1 parent 53e8e61 commit 7d6ea3c
Show file tree
Hide file tree
Showing 22 changed files with 89 additions and 89 deletions.
6 changes: 3 additions & 3 deletions src/BaseType.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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));
Expand Down
60 changes: 30 additions & 30 deletions src/BotApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class BotApi
*
* @var array
*/
public static $codes = array(
public static $codes = [
// Informational 1xx
100 => 'Continue',
101 => 'Switching Protocols',
Expand Down Expand Up @@ -68,7 +68,7 @@ class BotApi
504 => 'Gateway Timeout',
505 => 'HTTP Version Not Supported',
509 => 'Bandwidth Limit Exceeded'
);
];


/**
Expand Down Expand Up @@ -112,7 +112,7 @@ class BotApi
*
* @var array
*/
protected $trackedEvents = array();
protected $trackedEvents = [];

/**
* Check whether return associative array
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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()
)));
]));
}

/**
Expand All @@ -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
));
]);
}

/**
Expand All @@ -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,
)));
]));
}

/**
Expand All @@ -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]);
}

/**
Expand Down Expand Up @@ -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) {
Expand All @@ -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()
)));
]));
}

/**
Expand All @@ -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()
)));
]));
}

/**
Expand All @@ -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()
)));
]));
}

/**
Expand All @@ -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()
)));
]));
}


Expand All @@ -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,
)));
]));
}

/**
Expand Down Expand Up @@ -550,15 +550,15 @@ 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,
'performer' => $performer,
'title' => $title,
'reply_to_message_id' => $replyToMessageId,
'reply_markup' => is_null($replyMarkup) ? $replyMarkup : $replyMarkup->toJson()
)));
]));
}

/**
Expand All @@ -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()
)));
]));
}

/**
Expand All @@ -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()
)));
]));
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Botan.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,15 @@ 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,
CURLOPT_HTTPHEADER => [
'Content-Type: application/json'
],
CURLOPT_POSTFIELDS => $message->toJson()
);
];

curl_setopt_array($this->curl, $options);
$result = BotApi::jsonValidate(curl_exec($this->curl), true);
Expand Down
4 changes: 2 additions & 2 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand Down
2 changes: 1 addition & 1 deletion src/Types/ArrayOfPhotoSize.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ abstract class ArrayOfPhotoSize
{
public static function fromResponse($data)
{
$arrayOfPhotoSize = array();
$arrayOfPhotoSize = [];
foreach ($data as $photoSizeItem) {
$arrayOfPhotoSize[] = PhotoSize::fromResponse($photoSizeItem);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Types/ArrayOfUpdates.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ abstract class ArrayOfUpdates
{
public static function fromResponse($data)
{
$arrayOfUpdates = array();
$arrayOfUpdates = [];
foreach ($data as $update) {
$arrayOfUpdates[] = Update::fromResponse($update);
}
Expand Down
6 changes: 3 additions & 3 deletions src/Types/Audio.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/Types/Contact.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/Types/Document.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading

0 comments on commit 7d6ea3c

Please sign in to comment.