Skip to content

Commit 321c2f3

Browse files
committed
Fixed the code style according to PSR12.
1 parent 7eccb0e commit 321c2f3

File tree

1 file changed

+111
-101
lines changed

1 file changed

+111
-101
lines changed

Telegram.php

Lines changed: 111 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class Telegram
5454
/**
5555
* Constant for type sticker.
5656
*/
57-
const STICKER = 'sticker';
57+
const STICKER = 'sticker';
5858
/**
5959
* Constant for type Document.
6060
*/
@@ -106,7 +106,7 @@ public function __construct($bot_token, $log_errors = true, array $proxy = [])
106106
*/
107107
public function endpoint($api, array $content, $post = true)
108108
{
109-
$url = 'https://api.telegram.org/bot'.$this->bot_token.'/'.$api;
109+
$url = 'https://api.telegram.org/bot' . $this->bot_token . '/' . $api;
110110
if ($post) {
111111
$reply = $this->sendAPIRequest($url, $content);
112112
} else {
@@ -420,87 +420,87 @@ public function sendDocument(array $content)
420420
{
421421
return $this->endpoint('sendDocument', $content);
422422
}
423-
423+
424424
/// Send an animation
425425

426426
/**
427427
* Use this method to send animation files (GIF or H.264/MPEG-4 AVC video without sound). On success, the sent Message is returned. Bots can currently send animation files of up to 50 MB in size, this limit may be changed in the future.<br/>Values inside $content:<br/>
428-
* </table>
429-
* <tr>
430-
* <th>Parameter</th>
431-
* <th>Type</th>
432-
* <th>Required</th>
433-
* <th>Description</th>
434-
* </tr>
435-
* </thead>
436-
* <tbody>
437-
* <tr>
438-
* <td>chat_id</td>
439-
* <td>Integer or String</td>
440-
* <td>Yes</td>
441-
* <td>Unique identifier for the target chat or username of the target channel (in the format <code>@channelusername</code>)</td>
442-
* </tr>
443-
* <tr>
444-
* <td>animation</td>
445-
* <td><a href="#inputfile">InputFile</a> or String</td>
446-
* <td>Yes</td>
447-
* <td>Animation to send. Pass a file_id as String to send an animation that exists on the Telegram servers (recommended), pass an HTTP URL as a String for Telegram to get an animation from the Internet, or upload a new animation using multipart/form-data. <a href="#sending-files">More info on Sending Files »</a></td>
448-
* </tr>
449-
* <tr>
450-
* <td>duration</td>
451-
* <td>Integer</td>
452-
* <td>Optional</td>
453-
* <td>Duration of sent animation in seconds</td>
454-
* </tr>
455-
* <tr>
456-
* <td>width</td>
457-
* <td>Integer</td>
458-
* <td>Optional</td>
459-
* <td>Animation width</td>
460-
* </tr>
461-
* <tr>
462-
* <td>height</td>
463-
* <td>Integer</td>
464-
* <td>Optional</td>
465-
* <td>Animation height</td>
466-
* </tr>
467-
* <tr>
468-
* <td>thumb</td>
469-
* <td><a href="#inputfile">InputFile</a> or String</td>
470-
* <td>Optional</td>
471-
* <td>Thumbnail of the file sent; can be ignored if thumbnail generation for the file is supported server-side. The thumbnail should be in JPEG format and less than 200 kB in size. A thumbnail‘s width and height should not exceed 90. Ignored if the file is not uploaded using multipart/form-data. Thumbnails can’t be reused and can be only uploaded as a new file, so you can pass “attach://&lt;file_attach_name&gt;” if the thumbnail was uploaded using multipart/form-data under &lt;file_attach_name&gt;. <a href="#sending-files">More info on Sending Files »</a></td>
472-
* </tr>
473-
* <tr>
474-
* <td>caption</td>
475-
* <td>String</td>
476-
* <td>Optional</td>
477-
* <td>Animation caption (may also be used when resending animation by <em>file_id</em>), 0-1024 characters</td>
478-
* </tr>
479-
* <tr>
480-
* <td>parse_mode</td>
481-
* <td>String</td>
482-
* <td>Optional</td>
483-
* <td>Send <a href="#markdown-style"><em>Markdown</em></a> or <a href="#html-style"><em>HTML</em></a>, if you want Telegram apps to show <a href="#formatting-* options">bold, italic, fixed-width text or inline URLs</a> in the media caption.</td>
484-
* </tr>
485-
* <tr>
486-
* <td>disable_notification</td>
487-
* <td>Boolean</td>
488-
* <td>Optional</td>
489-
* <td>Sends the message <a href="https://telegram.org/blog/channels-2-0#silent-messages">silently</a>. Users will receive a notification with no sound.</td>
490-
* </tr>
491-
* <tr>
492-
* <td>reply_to_message_id</td>
493-
* <td>Integer</td>
494-
* <td>Optional</td>
495-
* <td>If the message is a reply, ID of the original message</td>
496-
* </tr>
497-
* <tr>
498-
* <td>reply_markup</td>
499-
* <td><a href="#inlinekeyboardmarkup">InlineKeyboardMarkup</a> or <a href="#replykeyboardmarkup">ReplyKeyboardMarkup</a> or <a href="#replykeyboardremove">ReplyKeyboardRemove</a> or <a href="#forcereply">ForceReply</a></td>
500-
* <td>Optional</td>
501-
* <td>Additional interface options. A JSON-serialized object for an <a href="https://core.telegram.org/bots#inline-keyboards-and-on-the-fly-updating">inline keyboard</a>, <a href="https://core.telegram.org/bots#keyboards">custom reply keyboard</a>, instructions to remove reply keyboard or to force a reply from the user.</td>
502-
* </tr>
503-
* </table>
428+
* </table>
429+
* <tr>
430+
* <th>Parameter</th>
431+
* <th>Type</th>
432+
* <th>Required</th>
433+
* <th>Description</th>
434+
* </tr>
435+
* </thead>
436+
* <tbody>
437+
* <tr>
438+
* <td>chat_id</td>
439+
* <td>Integer or String</td>
440+
* <td>Yes</td>
441+
* <td>Unique identifier for the target chat or username of the target channel (in the format <code>@channelusername</code>)</td>
442+
* </tr>
443+
* <tr>
444+
* <td>animation</td>
445+
* <td><a href="#inputfile">InputFile</a> or String</td>
446+
* <td>Yes</td>
447+
* <td>Animation to send. Pass a file_id as String to send an animation that exists on the Telegram servers (recommended), pass an HTTP URL as a String for Telegram to get an animation from the Internet, or upload a new animation using multipart/form-data. <a href="#sending-files">More info on Sending Files »</a></td>
448+
* </tr>
449+
* <tr>
450+
* <td>duration</td>
451+
* <td>Integer</td>
452+
* <td>Optional</td>
453+
* <td>Duration of sent animation in seconds</td>
454+
* </tr>
455+
* <tr>
456+
* <td>width</td>
457+
* <td>Integer</td>
458+
* <td>Optional</td>
459+
* <td>Animation width</td>
460+
* </tr>
461+
* <tr>
462+
* <td>height</td>
463+
* <td>Integer</td>
464+
* <td>Optional</td>
465+
* <td>Animation height</td>
466+
* </tr>
467+
* <tr>
468+
* <td>thumb</td>
469+
* <td><a href="#inputfile">InputFile</a> or String</td>
470+
* <td>Optional</td>
471+
* <td>Thumbnail of the file sent; can be ignored if thumbnail generation for the file is supported server-side. The thumbnail should be in JPEG format and less than 200 kB in size. A thumbnail‘s width and height should not exceed 90. Ignored if the file is not uploaded using multipart/form-data. Thumbnails can’t be reused and can be only uploaded as a new file, so you can pass “attach://&lt;file_attach_name&gt;” if the thumbnail was uploaded using multipart/form-data under &lt;file_attach_name&gt;. <a href="#sending-files">More info on Sending Files »</a></td>
472+
* </tr>
473+
* <tr>
474+
* <td>caption</td>
475+
* <td>String</td>
476+
* <td>Optional</td>
477+
* <td>Animation caption (may also be used when resending animation by <em>file_id</em>), 0-1024 characters</td>
478+
* </tr>
479+
* <tr>
480+
* <td>parse_mode</td>
481+
* <td>String</td>
482+
* <td>Optional</td>
483+
* <td>Send <a href="#markdown-style"><em>Markdown</em></a> or <a href="#html-style"><em>HTML</em></a>, if you want Telegram apps to show <a href="#formatting-* options">bold, italic, fixed-width text or inline URLs</a> in the media caption.</td>
484+
* </tr>
485+
* <tr>
486+
* <td>disable_notification</td>
487+
* <td>Boolean</td>
488+
* <td>Optional</td>
489+
* <td>Sends the message <a href="https://telegram.org/blog/channels-2-0#silent-messages">silently</a>. Users will receive a notification with no sound.</td>
490+
* </tr>
491+
* <tr>
492+
* <td>reply_to_message_id</td>
493+
* <td>Integer</td>
494+
* <td>Optional</td>
495+
* <td>If the message is a reply, ID of the original message</td>
496+
* </tr>
497+
* <tr>
498+
* <td>reply_markup</td>
499+
* <td><a href="#inlinekeyboardmarkup">InlineKeyboardMarkup</a> or <a href="#replykeyboardmarkup">ReplyKeyboardMarkup</a> or <a href="#replykeyboardremove">ReplyKeyboardRemove</a> or <a href="#forcereply">ForceReply</a></td>
500+
* <td>Optional</td>
501+
* <td>Additional interface options. A JSON-serialized object for an <a href="https://core.telegram.org/bots#inline-keyboards-and-on-the-fly-updating">inline keyboard</a>, <a href="https://core.telegram.org/bots#keyboards">custom reply keyboard</a>, instructions to remove reply keyboard or to force a reply from the user.</td>
502+
* </tr>
503+
* </table>
504504
* \param $content the request parameters as array
505505
* \return the JSON Telegram's reply.
506506
*/
@@ -1022,6 +1022,7 @@ public function sendVenue(array $content)
10221022
}
10231023

10241024
//Send contact
1025+
10251026
/**Use this method to send phone contacts. On success, the sent <a href="https://core.telegram.org/bots/api#message">Message</a> is returned.</p> <br/>Values inside $content:<br/>
10261027
* <table>
10271028
* <tr>
@@ -1683,7 +1684,7 @@ public function editMessageReplyMarkup(array $content)
16831684
*/
16841685
public function downloadFile($telegram_file_path, $local_file_path)
16851686
{
1686-
$file_url = 'https://api.telegram.org/file/bot'.$this->bot_token.'/'.$telegram_file_path;
1687+
$file_url = 'https://api.telegram.org/file/bot' . $this->bot_token . '/' . $telegram_file_path;
16871688
$in = fopen($file_url, 'rb');
16881689
$out = fopen($local_file_path, 'wb');
16891690

@@ -1771,11 +1772,11 @@ public function Text()
17711772

17721773
public function Caption()
17731774
{
1774-
$type = $this->getUpdateType();
1775-
if ($type == self::CHANNEL_POST) {
1776-
return @$this->data['channel_post']['caption'];
1777-
}
1778-
return @$this->data['message']['caption'];
1775+
$type = $this->getUpdateType();
1776+
if ($type == self::CHANNEL_POST) {
1777+
return @$this->data['channel_post']['caption'];
1778+
}
1779+
return @$this->data['message']['caption'];
17791780
}
17801781

17811782
/// Get the chat_id of the current message
@@ -2051,10 +2052,10 @@ public function messageFromGroupTitle()
20512052
public function buildKeyBoard(array $options, $onetime = false, $resize = false, $selective = true)
20522053
{
20532054
$replyMarkup = [
2054-
'keyboard' => $options,
2055+
'keyboard' => $options,
20552056
'one_time_keyboard' => $onetime,
2056-
'resize_keyboard' => $resize,
2057-
'selective' => $selective,
2057+
'resize_keyboard' => $resize,
2058+
'selective' => $selective,
20582059
];
20592060
$encodedMarkup = json_encode($replyMarkup, true);
20602061

@@ -2089,8 +2090,15 @@ public function buildInlineKeyBoard(array $options)
20892090
* \param $pay Boolean Optional. Specify True, to send a <a href="https://core.telegram.org/bots/api#payments">Pay button</a>.
20902091
* \return the requested button as Array.
20912092
*/
2092-
public function buildInlineKeyboardButton($text, $url = '', $callback_data = '', $switch_inline_query = null, $switch_inline_query_current_chat = null, $callback_game = '', $pay = '')
2093-
{
2093+
public function buildInlineKeyboardButton(
2094+
$text,
2095+
$url = '',
2096+
$callback_data = '',
2097+
$switch_inline_query = null,
2098+
$switch_inline_query_current_chat = null,
2099+
$callback_game = '',
2100+
$pay = ''
2101+
) {
20942102
$replyMarkup = [
20952103
'text' => $text,
20962104
];
@@ -2122,8 +2130,8 @@ public function buildInlineKeyboardButton($text, $url = '', $callback_data = '',
21222130
public function buildKeyboardButton($text, $request_contact = false, $request_location = false)
21232131
{
21242132
$replyMarkup = [
2125-
'text' => $text,
2126-
'request_contact' => $request_contact,
2133+
'text' => $text,
2134+
'request_contact' => $request_contact,
21272135
'request_location' => $request_location,
21282136
];
21292137

@@ -2140,7 +2148,7 @@ public function buildKeyBoardHide($selective = true)
21402148
{
21412149
$replyMarkup = [
21422150
'remove_keyboard' => true,
2143-
'selective' => $selective,
2151+
'selective' => $selective,
21442152
];
21452153
$encodedMarkup = json_encode($replyMarkup, true);
21462154

@@ -2156,7 +2164,7 @@ public function buildForceReply($selective = true)
21562164
{
21572165
$replyMarkup = [
21582166
'force_reply' => true,
2159-
'selective' => $selective,
2167+
'selective' => $selective,
21602168
];
21612169
$encodedMarkup = json_encode($replyMarkup, true);
21622170

@@ -3075,7 +3083,7 @@ public function getUpdates($offset = 0, $limit = 100, $timeout = 0, $update = tr
30753083
$content = ['offset' => $offset, 'limit' => $limit, 'timeout' => $timeout];
30763084
$this->updates = $this->endpoint('getUpdates', $content);
30773085
if ($update) {
3078-
if (array_key_exists('result', $this->updates) && is_array($this->updates['result']) && count($this->updates['result']) >= 1) { //for CLI working.
3086+
if (is_array($this->updates['result']) && count($this->updates['result']) >= 1) { //for CLI working.
30793087
$last_element_id = $this->updates['result'][count($this->updates['result']) - 1]['update_id'] + 1;
30803088
$content = ['offset' => $last_element_id, 'limit' => '1', 'timeout' => $timeout];
30813089
$this->endpoint('getUpdates', $content);
@@ -3141,9 +3149,9 @@ public function getUpdateType()
31413149
if (isset($update['message']['animation'])) {
31423150
return self::ANIMATION;
31433151
}
3144-
if (isset($update['message']['sticker'])) {
3152+
if (isset($update['message']['sticker'])) {
31453153
return self::STICKER;
3146-
}
3154+
}
31473155
if (isset($update['message']['document'])) {
31483156
return self::DOCUMENT;
31493157
}
@@ -3157,7 +3165,7 @@ public function getUpdateType()
31573165
private function sendAPIRequest($url, array $content, $post = true)
31583166
{
31593167
if (isset($content['chat_id'])) {
3160-
$url = $url.'?chat_id='.$content['chat_id'];
3168+
$url = $url . '?chat_id=' . $content['chat_id'];
31613169
unset($content['chat_id']);
31623170
}
31633171
$ch = curl_init();
@@ -3192,7 +3200,9 @@ private function sendAPIRequest($url, array $content, $post = true)
31923200
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
31933201
$result = curl_exec($ch);
31943202
if ($result === false) {
3195-
$result = json_encode(['ok'=>false, 'curl_error_code' => curl_errno($ch), 'curl_error' => curl_error($ch)]);
3203+
$result = json_encode(
3204+
['ok' => false, 'curl_error_code' => curl_errno($ch), 'curl_error' => curl_error($ch)]
3205+
);
31963206
}
31973207
curl_close($ch);
31983208
if ($this->log_errors) {
@@ -3211,7 +3221,7 @@ private function sendAPIRequest($url, array $content, $post = true)
32113221
function curl_file_create($filename, $mimetype = '', $postname = '')
32123222
{
32133223
return "@$filename;filename="
3214-
.($postname ?: basename($filename))
3215-
.($mimetype ? ";type=$mimetype" : '');
3224+
. ($postname ?: basename($filename))
3225+
. ($mimetype ? ";type=$mimetype" : '');
32163226
}
32173227
}

0 commit comments

Comments
 (0)