diff --git a/.editorconfig b/.editorconfig index f6da06d69..d84f8aa61 100644 --- a/.editorconfig +++ b/.editorconfig @@ -7,3 +7,6 @@ charset = utf-8 indent_style = space indent_size = 4 trim_trailing_whitespace = true + +[*.{yml, yaml}] +indent_size = 2 diff --git a/.scrutinizer.yml b/.scrutinizer.yml index aadb5cb60..e270f48b1 100644 --- a/.scrutinizer.yml +++ b/.scrutinizer.yml @@ -1,22 +1,41 @@ +build: + nodes: + analysis: + tests: + override: + - php-scrutinizer-run + filter: - paths: [src/*] + paths: + - src/ + dependency_paths: + - lib/ checks: - php: - remove_extra_empty_lines: true - remove_php_closing_tag: true - remove_trailing_whitespace: true - fix_use_statements: - remove_unused: true - preserve_multiple: false - preserve_blanklines: true - order_alphabetically: true - fix_php_opening_tag: true - fix_linefeed: true - fix_line_ending: true - fix_identation_4spaces: true - fix_doc_comments: true + php: + check_method_contracts: + verify_interface_like_constraints: true + verify_documented_constraints: true + verify_parent_constraints: true + fix_doc_comments: true + fix_identation_4spaces: true + fix_line_ending: true + fix_linefeed: true + fix_php_opening_tag: true + fix_use_statements: + remove_unused: true + preserve_multiple: false + preserve_blanklines: true + order_alphabetically: true + more_specific_types_in_doc_comments: true + no_goto: true + param_doc_comment_if_not_inferrable: true + parameter_doc_comments: true + remove_extra_empty_lines: true + return_doc_comment_if_not_inferrable: true + return_doc_comments: true + simplify_boolean_return: true tools: - external_code_coverage: - timeout: 120 + external_code_coverage: + timeout: 120 diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 4a39ab878..a2c1819c1 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,27 +1,27 @@ + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/4.8/phpunit.xsd" + bootstrap="./tests/bootstrap.php" + backupGlobals="false" + backupStaticAttributes="false" + colors="true" + convertErrorsToExceptions="true" + convertNoticesToExceptions="true" + convertWarningsToExceptions="true" + processIsolation="false" + stopOnError="false" + stopOnFailure="false" + stopOnIncomplete="false" + stopOnSkipped="false" + syntaxCheck="true" + timeoutForLargeTests="60" + timeoutForMediumTests="10" + timeoutForSmallTests="1" + verbose="false" +> - + diff --git a/src/Commands/AdminCommands/ChatsCommand.php b/src/Commands/AdminCommands/ChatsCommand.php index b5c02d1c7..50ab8479e 100644 --- a/src/Commands/AdminCommands/ChatsCommand.php +++ b/src/Commands/AdminCommands/ChatsCommand.php @@ -13,6 +13,8 @@ use Longman\TelegramBot\Commands\AdminCommand; use Longman\TelegramBot\DB; use Longman\TelegramBot\Entities\Chat; +use Longman\TelegramBot\Entities\ServerResponse; +use Longman\TelegramBot\Exception\TelegramException; use Longman\TelegramBot\Request; class ChatsCommand extends AdminCommand @@ -45,8 +47,8 @@ class ChatsCommand extends AdminCommand /** * Command execute method * - * @return \Longman\TelegramBot\Entities\ServerResponse - * @throws \Longman\TelegramBot\Exception\TelegramException + * @return ServerResponse + * @throws TelegramException */ public function execute() { diff --git a/src/Commands/AdminCommands/CleanupCommand.php b/src/Commands/AdminCommands/CleanupCommand.php index 96b1b3106..7c3b51f4c 100644 --- a/src/Commands/AdminCommands/CleanupCommand.php +++ b/src/Commands/AdminCommands/CleanupCommand.php @@ -12,6 +12,7 @@ use Longman\TelegramBot\Commands\AdminCommand; use Longman\TelegramBot\DB; +use Longman\TelegramBot\Entities\ServerResponse; use Longman\TelegramBot\Exception\TelegramException; use Longman\TelegramBot\Request; use Longman\TelegramBot\TelegramLog; @@ -338,7 +339,8 @@ private function getQueries($settings) /** * Execution if MySQL is required but not available * - * @return \Longman\TelegramBot\Entities\ServerResponse + * @return ServerResponse + * @throws TelegramException */ public function executeNoDb() { @@ -357,8 +359,8 @@ public function executeNoDb() /** * Command execute method * - * @return \Longman\TelegramBot\Entities\ServerResponse - * @throws \Longman\TelegramBot\Exception\TelegramException + * @return ServerResponse + * @throws TelegramException */ public function execute() { diff --git a/src/Commands/AdminCommands/DebugCommand.php b/src/Commands/AdminCommands/DebugCommand.php index ec9b0d831..d023d2a15 100644 --- a/src/Commands/AdminCommands/DebugCommand.php +++ b/src/Commands/AdminCommands/DebugCommand.php @@ -12,6 +12,7 @@ use Longman\TelegramBot\Commands\AdminCommand; use Longman\TelegramBot\DB; +use Longman\TelegramBot\Exception\TelegramException; use Longman\TelegramBot\Request; /** @@ -43,14 +44,14 @@ class DebugCommand extends AdminCommand * Command execute method * * @return mixed - * @throws \Longman\TelegramBot\Exception\TelegramException + * @throws TelegramException */ public function execute() { - $pdo = DB::getPdo(); + $pdo = DB::getPdo(); $message = $this->getMessage(); - $chat = $message->getChat(); - $text = strtolower($message->getText(true)); + $chat = $message->getChat(); + $text = strtolower($message->getText(true)); $data = ['chat_id' => $chat->getId()]; @@ -80,7 +81,7 @@ public function execute() $debug_info[] = sprintf('*Maximum PHP script execution time:* `%d seconds`', ini_get('max_execution_time')); $mysql_version = $pdo ? $pdo->query('SELECT VERSION() AS version')->fetchColumn() : null; - $debug_info[] = sprintf('*MySQL version:* `%s`', $mysql_version ?: 'disabled'); + $debug_info[] = sprintf('*MySQL version:* `%s`', $mysql_version ?: 'disabled'); $debug_info[] = sprintf('*Operating System:* `%s`', php_uname()); @@ -88,7 +89,7 @@ public function execute() $debug_info[] = sprintf('*Web Server:* `%s`', $_SERVER['SERVER_SOFTWARE']); } if (function_exists('curl_init')) { - $curlversion = curl_version(); + $curlversion = curl_version(); $debug_info[] = sprintf('*curl version:* `%1$s; %2$s`', $curlversion['version'], $curlversion['ssl_version']); } @@ -105,8 +106,8 @@ public function execute() } $webhook_info_result_str = json_encode($webhook_info_result, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES); - $debug_info[] = $webhook_info_title; - $debug_info[] = sprintf( + $debug_info[] = $webhook_info_title; + $debug_info[] = sprintf( '```' . PHP_EOL . '%s```', $webhook_info_result_str ); @@ -116,7 +117,7 @@ public function execute() } $data['parse_mode'] = 'Markdown'; - $data['text'] = implode(PHP_EOL, $debug_info); + $data['text'] = implode(PHP_EOL, $debug_info); return Request::sendMessage($data); } diff --git a/src/Commands/AdminCommands/SendtoallCommand.php b/src/Commands/AdminCommands/SendtoallCommand.php index a05a56658..da48e35de 100644 --- a/src/Commands/AdminCommands/SendtoallCommand.php +++ b/src/Commands/AdminCommands/SendtoallCommand.php @@ -13,6 +13,7 @@ use Longman\TelegramBot\Commands\AdminCommand; use Longman\TelegramBot\Entities\Message; use Longman\TelegramBot\Entities\ServerResponse; +use Longman\TelegramBot\Exception\TelegramException; use Longman\TelegramBot\Request; /** @@ -48,8 +49,8 @@ class SendtoallCommand extends AdminCommand /** * Execute command * - * @return \Longman\TelegramBot\Entities\ServerResponse - * @throws \Longman\TelegramBot\Exception\TelegramException + * @return ServerResponse + * @throws TelegramException */ public function execute() { diff --git a/src/Commands/AdminCommands/SendtochannelCommand.php b/src/Commands/AdminCommands/SendtochannelCommand.php index d8d3de78e..d1afd6f25 100644 --- a/src/Commands/AdminCommands/SendtochannelCommand.php +++ b/src/Commands/AdminCommands/SendtochannelCommand.php @@ -15,6 +15,8 @@ use Longman\TelegramBot\Entities\Chat; use Longman\TelegramBot\Entities\Keyboard; use Longman\TelegramBot\Entities\Message; +use Longman\TelegramBot\Entities\ServerResponse; +use Longman\TelegramBot\Exception\TelegramException; use Longman\TelegramBot\Request; class SendtochannelCommand extends AdminCommand @@ -47,15 +49,15 @@ class SendtochannelCommand extends AdminCommand /** * Conversation Object * - * @var \Longman\TelegramBot\Conversation + * @var Conversation */ protected $conversation; /** * Command execute method * - * @return \Longman\TelegramBot\Entities\ServerResponse|mixed - * @throws \Longman\TelegramBot\Exception\TelegramException + * @return ServerResponse|mixed + * @throws TelegramException */ public function execute() { @@ -272,11 +274,11 @@ public function execute() * @todo This method will be moved to a higher level maybe in AdminCommand or Command * @todo Looking for a more significant name * - * @param \Longman\TelegramBot\Entities\Message $message - * @param array $data + * @param Message $message + * @param array $data * - * @return \Longman\TelegramBot\Entities\ServerResponse - * @throws \Longman\TelegramBot\Exception\TelegramException + * @return ServerResponse + * @throws TelegramException */ protected function sendBack(Message $message, array $data) { @@ -311,12 +313,12 @@ protected function sendBack(Message $message, array $data) /** * Publish a message to a channel and return success or failure message in markdown format * - * @param \Longman\TelegramBot\Entities\Message $message - * @param string|int $channel_id - * @param string|null $caption + * @param Message $message + * @param string|int $channel_id + * @param string|null $caption * * @return string - * @throws \Longman\TelegramBot\Exception\TelegramException + * @throws TelegramException */ protected function publish(Message $message, $channel_id, $caption = null) { @@ -351,7 +353,7 @@ protected function publish(Message $message, $channel_id, $caption = null) * @todo Why send just to the first found channel? * * @return mixed - * @throws \Longman\TelegramBot\Exception\TelegramException + * @throws TelegramException */ public function executeNoDb() { diff --git a/src/Commands/AdminCommands/WhoisCommand.php b/src/Commands/AdminCommands/WhoisCommand.php index ad5e26155..d1ed33ec3 100644 --- a/src/Commands/AdminCommands/WhoisCommand.php +++ b/src/Commands/AdminCommands/WhoisCommand.php @@ -16,7 +16,9 @@ use Longman\TelegramBot\DB; use Longman\TelegramBot\Entities\Chat; use Longman\TelegramBot\Entities\PhotoSize; +use Longman\TelegramBot\Entities\ServerResponse; use Longman\TelegramBot\Entities\UserProfilePhotos; +use Longman\TelegramBot\Exception\TelegramException; use Longman\TelegramBot\Request; /** @@ -52,8 +54,8 @@ class WhoisCommand extends AdminCommand /** * Command execute method * - * @return \Longman\TelegramBot\Entities\ServerResponse - * @throws \Longman\TelegramBot\Exception\TelegramException + * @return ServerResponse + * @throws TelegramException */ public function execute() { diff --git a/src/Commands/Command.php b/src/Commands/Command.php index c1523cb8e..20643cd32 100644 --- a/src/Commands/Command.php +++ b/src/Commands/Command.php @@ -18,7 +18,9 @@ use Longman\TelegramBot\Entities\Payments\PreCheckoutQuery; use Longman\TelegramBot\Entities\Payments\ShippingQuery; use Longman\TelegramBot\Entities\Poll; +use Longman\TelegramBot\Entities\ServerResponse; use Longman\TelegramBot\Entities\Update; +use Longman\TelegramBot\Exception\TelegramException; use Longman\TelegramBot\Request; use Longman\TelegramBot\Telegram; @@ -43,14 +45,14 @@ abstract class Command /** * Telegram object * - * @var \Longman\TelegramBot\Telegram + * @var Telegram */ protected $telegram; /** * Update object * - * @var \Longman\TelegramBot\Entities\Update + * @var Update */ protected $update; @@ -120,8 +122,8 @@ abstract class Command /** * Constructor * - * @param \Longman\TelegramBot\Telegram $telegram - * @param \Longman\TelegramBot\Entities\Update $update + * @param Telegram $telegram + * @param Update $update */ public function __construct(Telegram $telegram, Update $update = null) { @@ -133,9 +135,9 @@ public function __construct(Telegram $telegram, Update $update = null) /** * Set update object * - * @param \Longman\TelegramBot\Entities\Update $update + * @param Update $update * - * @return \Longman\TelegramBot\Commands\Command + * @return Command */ public function setUpdate(Update $update = null) { @@ -149,8 +151,8 @@ public function setUpdate(Update $update = null) /** * Pre-execute command * - * @return \Longman\TelegramBot\Entities\ServerResponse - * @throws \Longman\TelegramBot\Exception\TelegramException + * @return ServerResponse + * @throws TelegramException */ public function preExecute() { @@ -182,16 +184,16 @@ public function preExecute() /** * Execute command * - * @return \Longman\TelegramBot\Entities\ServerResponse - * @throws \Longman\TelegramBot\Exception\TelegramException + * @return ServerResponse + * @throws TelegramException */ abstract public function execute(); /** * Execution if MySQL is required but not available * - * @return \Longman\TelegramBot\Entities\ServerResponse - * @throws \Longman\TelegramBot\Exception\TelegramException + * @return ServerResponse + * @throws TelegramException */ public function executeNoDb() { @@ -210,7 +212,7 @@ public function executeNoDb() /** * Get update object * - * @return \Longman\TelegramBot\Entities\Update + * @return Update */ public function getUpdate() { @@ -260,7 +262,7 @@ public function getConfig($name = null) /** * Get telegram object * - * @return \Longman\TelegramBot\Telegram + * @return Telegram */ public function getTelegram() { @@ -399,7 +401,8 @@ protected function removeNonPrivateMessage() * @param string $text * @param array $data * - * @return \Longman\TelegramBot\Entities\ServerResponse + * @return ServerResponse + * @throws TelegramException */ public function replyToChat($text, array $data = []) { @@ -419,7 +422,8 @@ public function replyToChat($text, array $data = []) * @param string $text * @param array $data * - * @return \Longman\TelegramBot\Entities\ServerResponse + * @return ServerResponse + * @throws TelegramException */ public function replyToUser($text, array $data = []) { diff --git a/src/Commands/SystemCommand.php b/src/Commands/SystemCommand.php index e604ba473..054a97221 100644 --- a/src/Commands/SystemCommand.php +++ b/src/Commands/SystemCommand.php @@ -10,6 +10,7 @@ namespace Longman\TelegramBot\Commands; +use Longman\TelegramBot\Entities\ServerResponse; use Longman\TelegramBot\Request; abstract class SystemCommand extends Command @@ -20,7 +21,7 @@ abstract class SystemCommand extends Command * Although system commands should just work and return a successful ServerResponse, * each system command can override this method to add custom functionality. * - * @return \Longman\TelegramBot\Entities\ServerResponse + * @return ServerResponse */ public function execute() { diff --git a/src/Commands/SystemCommands/CallbackqueryCommand.php b/src/Commands/SystemCommands/CallbackqueryCommand.php index c92894755..cedc1f659 100644 --- a/src/Commands/SystemCommands/CallbackqueryCommand.php +++ b/src/Commands/SystemCommands/CallbackqueryCommand.php @@ -42,7 +42,6 @@ class CallbackqueryCommand extends SystemCommand * Command execute method * * @return mixed - * @throws \Longman\TelegramBot\Exception\TelegramException */ public function execute() { diff --git a/src/Commands/SystemCommands/ChannelchatcreatedCommand.php b/src/Commands/SystemCommands/ChannelchatcreatedCommand.php index c815f12de..170dca930 100644 --- a/src/Commands/SystemCommands/ChannelchatcreatedCommand.php +++ b/src/Commands/SystemCommands/ChannelchatcreatedCommand.php @@ -38,7 +38,6 @@ class ChannelchatcreatedCommand extends SystemCommand * Command execute method * * @return mixed - * @throws \Longman\TelegramBot\Exception\TelegramException */ public function execute() { diff --git a/src/Commands/SystemCommands/ChannelpostCommand.php b/src/Commands/SystemCommands/ChannelpostCommand.php index 502df1c31..57ff83d05 100644 --- a/src/Commands/SystemCommands/ChannelpostCommand.php +++ b/src/Commands/SystemCommands/ChannelpostCommand.php @@ -38,7 +38,6 @@ class ChannelpostCommand extends SystemCommand * Execute command * * @return mixed - * @throws \Longman\TelegramBot\Exception\TelegramException */ public function execute() { diff --git a/src/Commands/SystemCommands/ChoseninlineresultCommand.php b/src/Commands/SystemCommands/ChoseninlineresultCommand.php index 0334720e5..b4400cf9e 100644 --- a/src/Commands/SystemCommands/ChoseninlineresultCommand.php +++ b/src/Commands/SystemCommands/ChoseninlineresultCommand.php @@ -38,7 +38,6 @@ class ChoseninlineresultCommand extends SystemCommand * Command execute method * * @return mixed - * @throws \Longman\TelegramBot\Exception\TelegramException */ public function execute() { diff --git a/src/Commands/SystemCommands/DeletechatphotoCommand.php b/src/Commands/SystemCommands/DeletechatphotoCommand.php index 79b9a9d3f..3c2bd1f9d 100644 --- a/src/Commands/SystemCommands/DeletechatphotoCommand.php +++ b/src/Commands/SystemCommands/DeletechatphotoCommand.php @@ -38,7 +38,6 @@ class DeletechatphotoCommand extends SystemCommand * Command execute method * * @return mixed - * @throws \Longman\TelegramBot\Exception\TelegramException */ public function execute() { diff --git a/src/Commands/SystemCommands/EditedchannelpostCommand.php b/src/Commands/SystemCommands/EditedchannelpostCommand.php index 1ac718634..85d018279 100644 --- a/src/Commands/SystemCommands/EditedchannelpostCommand.php +++ b/src/Commands/SystemCommands/EditedchannelpostCommand.php @@ -38,7 +38,6 @@ class EditedchannelpostCommand extends SystemCommand * Execute command * * @return mixed - * @throws \Longman\TelegramBot\Exception\TelegramException */ public function execute() { diff --git a/src/Commands/SystemCommands/EditedmessageCommand.php b/src/Commands/SystemCommands/EditedmessageCommand.php index 06cee9205..b92f3c006 100644 --- a/src/Commands/SystemCommands/EditedmessageCommand.php +++ b/src/Commands/SystemCommands/EditedmessageCommand.php @@ -38,7 +38,6 @@ class EditedmessageCommand extends SystemCommand * Command execute method * * @return mixed - * @throws \Longman\TelegramBot\Exception\TelegramException */ public function execute() { diff --git a/src/Commands/SystemCommands/GenericCommand.php b/src/Commands/SystemCommands/GenericCommand.php index ff11fd3de..4cda448d8 100644 --- a/src/Commands/SystemCommands/GenericCommand.php +++ b/src/Commands/SystemCommands/GenericCommand.php @@ -11,7 +11,7 @@ namespace Longman\TelegramBot\Commands\SystemCommands; use Longman\TelegramBot\Commands\SystemCommand; -use Longman\TelegramBot\Request; +use Longman\TelegramBot\Entities\ServerResponse; /** * Generic command @@ -36,8 +36,7 @@ class GenericCommand extends SystemCommand /** * Command execute method * - * @return mixed - * @throws \Longman\TelegramBot\Exception\TelegramException + * @return ServerResponse */ public function execute() { diff --git a/src/Commands/SystemCommands/GenericmessageCommand.php b/src/Commands/SystemCommands/GenericmessageCommand.php index 8d362fb42..e69a48305 100644 --- a/src/Commands/SystemCommands/GenericmessageCommand.php +++ b/src/Commands/SystemCommands/GenericmessageCommand.php @@ -10,9 +10,11 @@ namespace Longman\TelegramBot\Commands\SystemCommands; +use Longman\TelegramBot\Commands\SystemCommand; use Longman\TelegramBot\Conversation; +use Longman\TelegramBot\Entities\ServerResponse; +use Longman\TelegramBot\Exception\TelegramException; use Longman\TelegramBot\Request; -use Longman\TelegramBot\Commands\SystemCommand; /** * Generic message command @@ -42,7 +44,7 @@ class GenericmessageCommand extends SystemCommand /** * Execution if MySQL is required but not available * - * @return \Longman\TelegramBot\Entities\ServerResponse + * @return ServerResponse */ public function executeNoDb() { @@ -53,8 +55,8 @@ public function executeNoDb() /** * Execute command * - * @return \Longman\TelegramBot\Entities\ServerResponse - * @throws \Longman\TelegramBot\Exception\TelegramException + * @return ServerResponse + * @throws TelegramException */ public function execute() { diff --git a/src/Commands/SystemCommands/GroupchatcreatedCommand.php b/src/Commands/SystemCommands/GroupchatcreatedCommand.php index 8871f2468..10013dccf 100644 --- a/src/Commands/SystemCommands/GroupchatcreatedCommand.php +++ b/src/Commands/SystemCommands/GroupchatcreatedCommand.php @@ -38,7 +38,6 @@ class GroupchatcreatedCommand extends SystemCommand * Command execute method * * @return mixed - * @throws \Longman\TelegramBot\Exception\TelegramException */ public function execute() { diff --git a/src/Commands/SystemCommands/InlinequeryCommand.php b/src/Commands/SystemCommands/InlinequeryCommand.php index 8b6714f18..d73278988 100644 --- a/src/Commands/SystemCommands/InlinequeryCommand.php +++ b/src/Commands/SystemCommands/InlinequeryCommand.php @@ -11,8 +11,6 @@ namespace Longman\TelegramBot\Commands\SystemCommands; use Longman\TelegramBot\Commands\SystemCommand; -use Longman\TelegramBot\Entities\InlineQuery\InlineQueryResultArticle; -use Longman\TelegramBot\Entities\InputMessageContent\InputTextMessageContent; use Longman\TelegramBot\Request; /** @@ -39,7 +37,6 @@ class InlinequeryCommand extends SystemCommand * Command execute method * * @return mixed - * @throws \Longman\TelegramBot\Exception\TelegramException */ public function execute() { diff --git a/src/Commands/SystemCommands/LeftchatmemberCommand.php b/src/Commands/SystemCommands/LeftchatmemberCommand.php index 5326e0186..dc81f17f9 100644 --- a/src/Commands/SystemCommands/LeftchatmemberCommand.php +++ b/src/Commands/SystemCommands/LeftchatmemberCommand.php @@ -38,7 +38,6 @@ class LeftchatmemberCommand extends SystemCommand * Command execute method * * @return mixed - * @throws \Longman\TelegramBot\Exception\TelegramException */ public function execute() { diff --git a/src/Commands/SystemCommands/MigratefromchatidCommand.php b/src/Commands/SystemCommands/MigratefromchatidCommand.php index 754b397cc..0d26f70d1 100644 --- a/src/Commands/SystemCommands/MigratefromchatidCommand.php +++ b/src/Commands/SystemCommands/MigratefromchatidCommand.php @@ -38,7 +38,6 @@ class MigratefromchatidCommand extends SystemCommand * Command execute method * * @return mixed - * @throws \Longman\TelegramBot\Exception\TelegramException */ public function execute() { diff --git a/src/Commands/SystemCommands/MigratetochatidCommand.php b/src/Commands/SystemCommands/MigratetochatidCommand.php index 220a260c7..324a52ef8 100644 --- a/src/Commands/SystemCommands/MigratetochatidCommand.php +++ b/src/Commands/SystemCommands/MigratetochatidCommand.php @@ -38,7 +38,6 @@ class MigratetochatidCommand extends SystemCommand * Command execute method * * @return mixed - * @throws \Longman\TelegramBot\Exception\TelegramException */ public function execute() { diff --git a/src/Commands/SystemCommands/NewchatmembersCommand.php b/src/Commands/SystemCommands/NewchatmembersCommand.php index b618f499b..658dbb909 100644 --- a/src/Commands/SystemCommands/NewchatmembersCommand.php +++ b/src/Commands/SystemCommands/NewchatmembersCommand.php @@ -38,7 +38,6 @@ class NewchatmembersCommand extends SystemCommand * Command execute method * * @return mixed - * @throws \Longman\TelegramBot\Exception\TelegramException */ public function execute() { diff --git a/src/Commands/SystemCommands/NewchatphotoCommand.php b/src/Commands/SystemCommands/NewchatphotoCommand.php index d5b0e2a6f..98f08d376 100644 --- a/src/Commands/SystemCommands/NewchatphotoCommand.php +++ b/src/Commands/SystemCommands/NewchatphotoCommand.php @@ -38,7 +38,6 @@ class NewchatphotoCommand extends SystemCommand * Command execute method * * @return mixed - * @throws \Longman\TelegramBot\Exception\TelegramException */ public function execute() { diff --git a/src/Commands/SystemCommands/NewchattitleCommand.php b/src/Commands/SystemCommands/NewchattitleCommand.php index abc2d5ff6..518fe76e5 100644 --- a/src/Commands/SystemCommands/NewchattitleCommand.php +++ b/src/Commands/SystemCommands/NewchattitleCommand.php @@ -38,7 +38,6 @@ class NewchattitleCommand extends SystemCommand * Command execute method * * @return mixed - * @throws \Longman\TelegramBot\Exception\TelegramException */ public function execute() { diff --git a/src/Commands/SystemCommands/PinnedmessageCommand.php b/src/Commands/SystemCommands/PinnedmessageCommand.php index dbf53e620..5a751f306 100644 --- a/src/Commands/SystemCommands/PinnedmessageCommand.php +++ b/src/Commands/SystemCommands/PinnedmessageCommand.php @@ -38,7 +38,6 @@ class PinnedmessageCommand extends SystemCommand * Execute command * * @return mixed - * @throws \Longman\TelegramBot\Exception\TelegramException */ public function execute() { diff --git a/src/Commands/SystemCommands/StartCommand.php b/src/Commands/SystemCommands/StartCommand.php index 6c0ae60e6..12709033b 100644 --- a/src/Commands/SystemCommands/StartCommand.php +++ b/src/Commands/SystemCommands/StartCommand.php @@ -11,7 +11,6 @@ namespace Longman\TelegramBot\Commands\SystemCommands; use Longman\TelegramBot\Commands\SystemCommand; -use Longman\TelegramBot\Request; /** * Start command @@ -44,7 +43,6 @@ class StartCommand extends SystemCommand * Command execute method * * @return mixed - * @throws \Longman\TelegramBot\Exception\TelegramException */ public function execute() { diff --git a/src/Commands/SystemCommands/SupergroupchatcreatedCommand.php b/src/Commands/SystemCommands/SupergroupchatcreatedCommand.php index e19194807..9c2508b2a 100644 --- a/src/Commands/SystemCommands/SupergroupchatcreatedCommand.php +++ b/src/Commands/SystemCommands/SupergroupchatcreatedCommand.php @@ -38,7 +38,6 @@ class SupergroupchatcreatedCommand extends SystemCommand * Command execute method * * @return mixed - * @throws \Longman\TelegramBot\Exception\TelegramException */ public function execute() { diff --git a/src/Conversation.php b/src/Conversation.php index 36c5f4986..146ecc9e8 100644 --- a/src/Conversation.php +++ b/src/Conversation.php @@ -10,6 +10,8 @@ namespace Longman\TelegramBot; +use Longman\TelegramBot\Exception\TelegramException; + /** * Class Conversation * @@ -67,7 +69,7 @@ class Conversation * @param int $chat_id * @param string $command * - * @throws \Longman\TelegramBot\Exception\TelegramException + * @throws TelegramException */ public function __construct($user_id, $chat_id, $command = null) { @@ -100,7 +102,7 @@ protected function clear() * Load the conversation from the database * * @return bool - * @throws \Longman\TelegramBot\Exception\TelegramException + * @throws TelegramException */ protected function load() { @@ -140,7 +142,7 @@ public function exists() * Start a new conversation if the current command doesn't have one yet * * @return bool - * @throws \Longman\TelegramBot\Exception\TelegramException + * @throws TelegramException */ protected function start() { @@ -164,6 +166,7 @@ protected function start() * Currently the Conversation is not deleted but just set to 'stopped' * * @return bool + * @throws TelegramException */ public function stop() { @@ -174,6 +177,7 @@ public function stop() * Cancel the current conversation * * @return bool + * @throws TelegramException */ public function cancel() { @@ -186,6 +190,7 @@ public function cancel() * @param string $status * * @return bool + * @throws TelegramException */ protected function updateStatus($status) { @@ -209,6 +214,7 @@ protected function updateStatus($status) * Store the array/variable in the database with json_encode() function * * @return bool + * @throws TelegramException */ public function update() { diff --git a/src/DB.php b/src/DB.php index e4108d21b..32f97a53b 100644 --- a/src/DB.php +++ b/src/DB.php @@ -1186,13 +1186,13 @@ public static function selectChats($select_chats_params) * @param integer $chat_id * @param string $inline_message_id * - * @return array|bool Array containing TOTAL and CURRENT fields or false on invalid arguments + * @return array Array containing TOTAL and CURRENT fields or false on invalid arguments * @throws TelegramException */ public static function getTelegramRequestCount($chat_id = null, $inline_message_id = null) { if (!self::isDbConnected()) { - return false; + return []; } try { diff --git a/src/Entities/Entity.php b/src/Entities/Entity.php index 77665442a..12c1155cf 100644 --- a/src/Entities/Entity.php +++ b/src/Entities/Entity.php @@ -33,8 +33,6 @@ abstract class Entity * * @param array $data * @param string $bot_username - * - * @throws \Longman\TelegramBot\Exception\TelegramException */ public function __construct($data, $bot_username = '') { @@ -96,8 +94,6 @@ protected function subEntities() /** * Perform any special entity validation - * - * @throws \Longman\TelegramBot\Exception\TelegramException */ protected function validate() { diff --git a/src/Entities/Games/Game.php b/src/Entities/Games/Game.php index e6e4b5179..98dd59822 100644 --- a/src/Entities/Games/Game.php +++ b/src/Entities/Games/Game.php @@ -47,7 +47,7 @@ protected function subEntities() * This method overrides the default getPhoto method * and returns a nice array of PhotoSize objects. * - * @return null|\Longman\TelegramBot\Entities\PhotoSize[] + * @return null|PhotoSize[] */ public function getPhoto() { @@ -62,7 +62,7 @@ public function getPhoto() * This method overrides the default getTextEntities method * and returns a nice array of MessageEntity objects. * - * @return null|\Longman\TelegramBot\Entities\MessageEntity[] + * @return null|MessageEntity[] */ public function getTextEntities() { diff --git a/src/Entities/InlineQuery/InlineQueryResultArticle.php b/src/Entities/InlineQuery/InlineQueryResultArticle.php index 8aff72173..58a9d31c1 100644 --- a/src/Entities/InlineQuery/InlineQueryResultArticle.php +++ b/src/Entities/InlineQuery/InlineQueryResultArticle.php @@ -62,8 +62,6 @@ class InlineQueryResultArticle extends InlineEntity implements InlineQueryResult * InlineQueryResultArticle constructor * * @param array $data - * - * @throws \Longman\TelegramBot\Exception\TelegramException */ public function __construct(array $data = []) { diff --git a/src/Entities/InlineQuery/InlineQueryResultAudio.php b/src/Entities/InlineQuery/InlineQueryResultAudio.php index 940bd1730..8e5ef6f73 100644 --- a/src/Entities/InlineQuery/InlineQueryResultAudio.php +++ b/src/Entities/InlineQuery/InlineQueryResultAudio.php @@ -56,8 +56,6 @@ class InlineQueryResultAudio extends InlineEntity implements InlineQueryResult * InlineQueryResultAudio constructor * * @param array $data - * - * @throws \Longman\TelegramBot\Exception\TelegramException */ public function __construct(array $data = []) { diff --git a/src/Entities/InlineQuery/InlineQueryResultCachedAudio.php b/src/Entities/InlineQuery/InlineQueryResultCachedAudio.php index 780cef637..263f70c0d 100644 --- a/src/Entities/InlineQuery/InlineQueryResultCachedAudio.php +++ b/src/Entities/InlineQuery/InlineQueryResultCachedAudio.php @@ -47,8 +47,6 @@ class InlineQueryResultCachedAudio extends InlineEntity implements InlineQueryRe * InlineQueryResultCachedAudio constructor * * @param array $data - * - * @throws \Longman\TelegramBot\Exception\TelegramException */ public function __construct(array $data = []) { diff --git a/src/Entities/InlineQuery/InlineQueryResultCachedDocument.php b/src/Entities/InlineQuery/InlineQueryResultCachedDocument.php index c229551df..c496ad119 100644 --- a/src/Entities/InlineQuery/InlineQueryResultCachedDocument.php +++ b/src/Entities/InlineQuery/InlineQueryResultCachedDocument.php @@ -53,8 +53,6 @@ class InlineQueryResultCachedDocument extends InlineEntity implements InlineQuer * InlineQueryResultCachedDocument constructor * * @param array $data - * - * @throws \Longman\TelegramBot\Exception\TelegramException */ public function __construct(array $data = []) { diff --git a/src/Entities/InlineQuery/InlineQueryResultCachedGif.php b/src/Entities/InlineQuery/InlineQueryResultCachedGif.php index 491a49848..230bd3f87 100644 --- a/src/Entities/InlineQuery/InlineQueryResultCachedGif.php +++ b/src/Entities/InlineQuery/InlineQueryResultCachedGif.php @@ -50,8 +50,6 @@ class InlineQueryResultCachedGif extends InlineEntity implements InlineQueryResu * InlineQueryResultCachedGif constructor * * @param array $data - * - * @throws \Longman\TelegramBot\Exception\TelegramException */ public function __construct(array $data = []) { diff --git a/src/Entities/InlineQuery/InlineQueryResultCachedMpeg4Gif.php b/src/Entities/InlineQuery/InlineQueryResultCachedMpeg4Gif.php index c2a5fd9c1..9770276d5 100644 --- a/src/Entities/InlineQuery/InlineQueryResultCachedMpeg4Gif.php +++ b/src/Entities/InlineQuery/InlineQueryResultCachedMpeg4Gif.php @@ -50,8 +50,6 @@ class InlineQueryResultCachedMpeg4Gif extends InlineEntity implements InlineQuer * InlineQueryResultCachedMpeg4Gif constructor * * @param array $data - * - * @throws \Longman\TelegramBot\Exception\TelegramException */ public function __construct(array $data = []) { diff --git a/src/Entities/InlineQuery/InlineQueryResultCachedPhoto.php b/src/Entities/InlineQuery/InlineQueryResultCachedPhoto.php index 97caf5f82..df57579c4 100644 --- a/src/Entities/InlineQuery/InlineQueryResultCachedPhoto.php +++ b/src/Entities/InlineQuery/InlineQueryResultCachedPhoto.php @@ -53,8 +53,6 @@ class InlineQueryResultCachedPhoto extends InlineEntity implements InlineQueryRe * InlineQueryResultCachedPhoto constructor * * @param array $data - * - * @throws \Longman\TelegramBot\Exception\TelegramException */ public function __construct(array $data = []) { diff --git a/src/Entities/InlineQuery/InlineQueryResultCachedSticker.php b/src/Entities/InlineQuery/InlineQueryResultCachedSticker.php index 3a6677a44..8dd5d7e06 100644 --- a/src/Entities/InlineQuery/InlineQueryResultCachedSticker.php +++ b/src/Entities/InlineQuery/InlineQueryResultCachedSticker.php @@ -44,8 +44,6 @@ class InlineQueryResultCachedSticker extends InlineEntity implements InlineQuery * InlineQueryResultCachedSticker constructor * * @param array $data - * - * @throws \Longman\TelegramBot\Exception\TelegramException */ public function __construct(array $data = []) { diff --git a/src/Entities/InlineQuery/InlineQueryResultCachedVideo.php b/src/Entities/InlineQuery/InlineQueryResultCachedVideo.php index 9cc61e2b6..956d34057 100644 --- a/src/Entities/InlineQuery/InlineQueryResultCachedVideo.php +++ b/src/Entities/InlineQuery/InlineQueryResultCachedVideo.php @@ -53,8 +53,6 @@ class InlineQueryResultCachedVideo extends InlineEntity implements InlineQueryRe * InlineQueryResultCachedVideo constructor * * @param array $data - * - * @throws \Longman\TelegramBot\Exception\TelegramException */ public function __construct(array $data = []) { diff --git a/src/Entities/InlineQuery/InlineQueryResultCachedVoice.php b/src/Entities/InlineQuery/InlineQueryResultCachedVoice.php index bd87ecfad..df14d34eb 100644 --- a/src/Entities/InlineQuery/InlineQueryResultCachedVoice.php +++ b/src/Entities/InlineQuery/InlineQueryResultCachedVoice.php @@ -50,8 +50,6 @@ class InlineQueryResultCachedVoice extends InlineEntity implements InlineQueryRe * InlineQueryResultCachedVoice constructor * * @param array $data - * - * @throws \Longman\TelegramBot\Exception\TelegramException */ public function __construct(array $data = []) { diff --git a/src/Entities/InlineQuery/InlineQueryResultContact.php b/src/Entities/InlineQuery/InlineQueryResultContact.php index 23c8d58f3..a29ef0d3b 100644 --- a/src/Entities/InlineQuery/InlineQueryResultContact.php +++ b/src/Entities/InlineQuery/InlineQueryResultContact.php @@ -61,8 +61,6 @@ class InlineQueryResultContact extends InlineEntity implements InlineQueryResult * InlineQueryResultContact constructor * * @param array $data - * - * @throws \Longman\TelegramBot\Exception\TelegramException */ public function __construct(array $data = []) { diff --git a/src/Entities/InlineQuery/InlineQueryResultDocument.php b/src/Entities/InlineQuery/InlineQueryResultDocument.php index ae5b27550..b2d10eaaf 100644 --- a/src/Entities/InlineQuery/InlineQueryResultDocument.php +++ b/src/Entities/InlineQuery/InlineQueryResultDocument.php @@ -65,8 +65,6 @@ class InlineQueryResultDocument extends InlineEntity implements InlineQueryResul * InlineQueryResultDocument constructor * * @param array $data - * - * @throws \Longman\TelegramBot\Exception\TelegramException */ public function __construct(array $data = []) { diff --git a/src/Entities/InlineQuery/InlineQueryResultGame.php b/src/Entities/InlineQuery/InlineQueryResultGame.php index 72889a0c0..39a9feaa4 100644 --- a/src/Entities/InlineQuery/InlineQueryResultGame.php +++ b/src/Entities/InlineQuery/InlineQueryResultGame.php @@ -40,8 +40,6 @@ class InlineQueryResultGame extends InlineEntity implements InlineQueryResult * InlineQueryResultGame constructor * * @param array $data - * - * @throws \Longman\TelegramBot\Exception\TelegramException */ public function __construct(array $data = []) { diff --git a/src/Entities/InlineQuery/InlineQueryResultGif.php b/src/Entities/InlineQuery/InlineQueryResultGif.php index e552f63e7..3ffc46967 100644 --- a/src/Entities/InlineQuery/InlineQueryResultGif.php +++ b/src/Entities/InlineQuery/InlineQueryResultGif.php @@ -61,8 +61,6 @@ class InlineQueryResultGif extends InlineEntity implements InlineQueryResult * InlineQueryResultGif constructor * * @param array $data - * - * @throws \Longman\TelegramBot\Exception\TelegramException */ public function __construct(array $data = []) { diff --git a/src/Entities/InlineQuery/InlineQueryResultLocation.php b/src/Entities/InlineQuery/InlineQueryResultLocation.php index f365ae43a..1a3180431 100644 --- a/src/Entities/InlineQuery/InlineQueryResultLocation.php +++ b/src/Entities/InlineQuery/InlineQueryResultLocation.php @@ -62,8 +62,6 @@ class InlineQueryResultLocation extends InlineEntity implements InlineQueryResul * InlineQueryResultLocation constructor * * @param array $data - * - * @throws \Longman\TelegramBot\Exception\TelegramException */ public function __construct(array $data = []) { diff --git a/src/Entities/InlineQuery/InlineQueryResultMpeg4Gif.php b/src/Entities/InlineQuery/InlineQueryResultMpeg4Gif.php index d182cb15a..b01f1d48d 100644 --- a/src/Entities/InlineQuery/InlineQueryResultMpeg4Gif.php +++ b/src/Entities/InlineQuery/InlineQueryResultMpeg4Gif.php @@ -61,8 +61,6 @@ class InlineQueryResultMpeg4Gif extends InlineEntity implements InlineQueryResul * InlineQueryResultMpeg4Gif constructor * * @param array $data - * - * @throws \Longman\TelegramBot\Exception\TelegramException */ public function __construct(array $data = []) { diff --git a/src/Entities/InlineQuery/InlineQueryResultPhoto.php b/src/Entities/InlineQuery/InlineQueryResultPhoto.php index 1dca095b6..cc8a1401b 100644 --- a/src/Entities/InlineQuery/InlineQueryResultPhoto.php +++ b/src/Entities/InlineQuery/InlineQueryResultPhoto.php @@ -62,8 +62,6 @@ class InlineQueryResultPhoto extends InlineEntity implements InlineQueryResult * InlineQueryResultPhoto constructor * * @param array $data - * - * @throws \Longman\TelegramBot\Exception\TelegramException */ public function __construct(array $data = []) { diff --git a/src/Entities/InlineQuery/InlineQueryResultVenue.php b/src/Entities/InlineQuery/InlineQueryResultVenue.php index 6f615ad92..5add3baf6 100644 --- a/src/Entities/InlineQuery/InlineQueryResultVenue.php +++ b/src/Entities/InlineQuery/InlineQueryResultVenue.php @@ -67,8 +67,6 @@ class InlineQueryResultVenue extends InlineEntity implements InlineQueryResult * InlineQueryResultVenue constructor * * @param array $data - * - * @throws \Longman\TelegramBot\Exception\TelegramException */ public function __construct(array $data = []) { diff --git a/src/Entities/InlineQuery/InlineQueryResultVideo.php b/src/Entities/InlineQuery/InlineQueryResultVideo.php index 8cca4d691..042f8cc66 100644 --- a/src/Entities/InlineQuery/InlineQueryResultVideo.php +++ b/src/Entities/InlineQuery/InlineQueryResultVideo.php @@ -68,8 +68,6 @@ class InlineQueryResultVideo extends InlineEntity implements InlineQueryResult * InlineQueryResultVideo constructor * * @param array $data - * - * @throws \Longman\TelegramBot\Exception\TelegramException */ public function __construct(array $data = []) { diff --git a/src/Entities/InlineQuery/InlineQueryResultVoice.php b/src/Entities/InlineQuery/InlineQueryResultVoice.php index 6dc8d13fa..f9ac372db 100644 --- a/src/Entities/InlineQuery/InlineQueryResultVoice.php +++ b/src/Entities/InlineQuery/InlineQueryResultVoice.php @@ -53,8 +53,6 @@ class InlineQueryResultVoice extends InlineEntity implements InlineQueryResult * InlineQueryResultVoice constructor * * @param array $data - * - * @throws \Longman\TelegramBot\Exception\TelegramException */ public function __construct(array $data = []) { diff --git a/src/Entities/InputMedia/InputMedia.php b/src/Entities/InputMedia/InputMedia.php index b9bd973d1..831393dfa 100644 --- a/src/Entities/InputMedia/InputMedia.php +++ b/src/Entities/InputMedia/InputMedia.php @@ -4,5 +4,20 @@ interface InputMedia { + /** + * @return string Type of the result. + */ + public function getType(); + /** + * @return string File to send. + */ + public function getMedia(); + + /** + * @param string $media File to send. + * + * @return string + */ + public function setMedia($media); } diff --git a/src/Entities/InputMedia/InputMediaAnimation.php b/src/Entities/InputMedia/InputMediaAnimation.php index 6eb779bfd..61c1a78e2 100644 --- a/src/Entities/InputMedia/InputMediaAnimation.php +++ b/src/Entities/InputMedia/InputMediaAnimation.php @@ -52,8 +52,6 @@ class InputMediaAnimation extends Entity implements InputMedia * InputMediaAnimation constructor * * @param array $data - * - * @throws \Longman\TelegramBot\Exception\TelegramException */ public function __construct(array $data = []) { diff --git a/src/Entities/InputMedia/InputMediaAudio.php b/src/Entities/InputMedia/InputMediaAudio.php index 8d01b3485..b8972b3a5 100644 --- a/src/Entities/InputMedia/InputMediaAudio.php +++ b/src/Entities/InputMedia/InputMediaAudio.php @@ -52,8 +52,6 @@ class InputMediaAudio extends Entity implements InputMedia * InputMediaAudio constructor * * @param array $data - * - * @throws \Longman\TelegramBot\Exception\TelegramException */ public function __construct(array $data = []) { diff --git a/src/Entities/InputMedia/InputMediaDocument.php b/src/Entities/InputMedia/InputMediaDocument.php index 2fbab492f..c5a5d2416 100644 --- a/src/Entities/InputMedia/InputMediaDocument.php +++ b/src/Entities/InputMedia/InputMediaDocument.php @@ -43,8 +43,6 @@ class InputMediaDocument extends Entity implements InputMedia * InputMediaDocument constructor * * @param array $data - * - * @throws \Longman\TelegramBot\Exception\TelegramException */ public function __construct(array $data = []) { diff --git a/src/Entities/InputMedia/InputMediaPhoto.php b/src/Entities/InputMedia/InputMediaPhoto.php index af3ab784d..7a45637c9 100644 --- a/src/Entities/InputMedia/InputMediaPhoto.php +++ b/src/Entities/InputMedia/InputMediaPhoto.php @@ -40,8 +40,6 @@ class InputMediaPhoto extends Entity implements InputMedia * InputMediaPhoto constructor * * @param array $data - * - * @throws \Longman\TelegramBot\Exception\TelegramException */ public function __construct(array $data = []) { diff --git a/src/Entities/InputMedia/InputMediaVideo.php b/src/Entities/InputMedia/InputMediaVideo.php index fa394dfcd..58762d45c 100644 --- a/src/Entities/InputMedia/InputMediaVideo.php +++ b/src/Entities/InputMedia/InputMediaVideo.php @@ -55,8 +55,6 @@ class InputMediaVideo extends Entity implements InputMedia * InputMediaVideo constructor * * @param array $data - * - * @throws \Longman\TelegramBot\Exception\TelegramException */ public function __construct(array $data = []) { diff --git a/src/Entities/Keyboard.php b/src/Entities/Keyboard.php index 237d7944d..3105417c5 100644 --- a/src/Entities/Keyboard.php +++ b/src/Entities/Keyboard.php @@ -54,7 +54,7 @@ public function isInlineKeyboard() /** * Get the proper keyboard button class for this keyboard. * - * @return KeyboardButton|InlineKeyboardButton + * @return string */ public function getKeyboardButtonClass() { @@ -154,9 +154,9 @@ protected function parseRow($row) /** * Parse a given button to the correct KeyboardButton object type. * - * @param array|string|\Longman\TelegramBot\Entities\KeyboardButton $button + * @param array|string|KeyboardButton $button * - * @return \Longman\TelegramBot\Entities\KeyboardButton|null + * @return KeyboardButton|null */ protected function parseButton($button) { @@ -166,7 +166,7 @@ protected function parseButton($button) return $button; } - if (!$this->isInlineKeyboard() || $button_class::couldBe($button)) { + if (!$this->isInlineKeyboard() || call_user_func([$button_class, 'couldBe'], $button)) { return new $button_class($button); } @@ -179,7 +179,7 @@ protected function parseButton($button) protected function validate() { $keyboard_type = $this->getKeyboardType(); - $keyboard = $this->getProperty($keyboard_type); + $keyboard = $this->getProperty($keyboard_type); if ($keyboard !== null) { if (!is_array($keyboard)) { @@ -201,8 +201,7 @@ protected function validate() * * @param array $data * - * @return \Longman\TelegramBot\Entities\Keyboard - * @throws \Longman\TelegramBot\Exception\TelegramException + * @return Keyboard */ public static function remove(array $data = []) { @@ -216,8 +215,7 @@ public static function remove(array $data = []) * * @param array $data * - * @return \Longman\TelegramBot\Entities\Keyboard - * @throws \Longman\TelegramBot\Exception\TelegramException + * @return Keyboard */ public static function forceReply(array $data = []) { diff --git a/src/Entities/Message.php b/src/Entities/Message.php index 674e74ac0..db366cc18 100644 --- a/src/Entities/Message.php +++ b/src/Entities/Message.php @@ -104,8 +104,6 @@ protected function subEntities() * * @param array $data * @param string $bot_username - * - * @throws \Longman\TelegramBot\Exception\TelegramException */ public function __construct(array $data, $bot_username = '') { @@ -264,7 +262,6 @@ public function getText($without_cmd = false) * Bot added in chat * * @return bool - * @throws \Longman\TelegramBot\Exception\TelegramException */ public function botAddedInChat() { diff --git a/src/Entities/Payments/PreCheckoutQuery.php b/src/Entities/Payments/PreCheckoutQuery.php index b86e7647a..715f046c6 100644 --- a/src/Entities/Payments/PreCheckoutQuery.php +++ b/src/Entities/Payments/PreCheckoutQuery.php @@ -11,6 +11,7 @@ namespace Longman\TelegramBot\Entities\Payments; use Longman\TelegramBot\Entities\Entity; +use Longman\TelegramBot\Entities\ServerResponse; use Longman\TelegramBot\Entities\User; use Longman\TelegramBot\Request; @@ -48,7 +49,7 @@ public function subEntities() * @param bool $ok * @param array $data * - * @return \Longman\TelegramBot\Entities\ServerResponse + * @return ServerResponse */ public function answer($ok, array $data = []) { diff --git a/src/Entities/Payments/ShippingQuery.php b/src/Entities/Payments/ShippingQuery.php index 0425254d9..0131db6fc 100644 --- a/src/Entities/Payments/ShippingQuery.php +++ b/src/Entities/Payments/ShippingQuery.php @@ -11,6 +11,7 @@ namespace Longman\TelegramBot\Entities\Payments; use Longman\TelegramBot\Entities\Entity; +use Longman\TelegramBot\Entities\ServerResponse; use Longman\TelegramBot\Entities\User; use Longman\TelegramBot\Request; @@ -45,7 +46,7 @@ public function subEntities() * @param bool $ok * @param array $data * - * @return \Longman\TelegramBot\Entities\ServerResponse + * @return ServerResponse */ public function answer($ok, array $data = []) { diff --git a/src/Entities/ReplyToMessage.php b/src/Entities/ReplyToMessage.php index d35f63fd3..19e520989 100644 --- a/src/Entities/ReplyToMessage.php +++ b/src/Entities/ReplyToMessage.php @@ -22,8 +22,6 @@ class ReplyToMessage extends Message * * @param array $data * @param string $bot_username - * - * @throws \Longman\TelegramBot\Exception\TelegramException */ public function __construct(array $data, $bot_username = '') { diff --git a/src/Entities/ServerResponse.php b/src/Entities/ServerResponse.php index 8115b3e79..9976f9dd4 100644 --- a/src/Entities/ServerResponse.php +++ b/src/Entities/ServerResponse.php @@ -30,8 +30,6 @@ class ServerResponse extends Entity * * @param array $data * @param string $bot_username - * - * @throws \Longman\TelegramBot\Exception\TelegramException */ public function __construct(array $data, $bot_username) { @@ -105,7 +103,7 @@ public function printError($return = false) * @param array $result * @param string $bot_username * - * @return \Longman\TelegramBot\Entities\Chat|\Longman\TelegramBot\Entities\ChatMember|\Longman\TelegramBot\Entities\File|\Longman\TelegramBot\Entities\Message|\Longman\TelegramBot\Entities\User|\Longman\TelegramBot\Entities\UserProfilePhotos|\Longman\TelegramBot\Entities\WebhookInfo + * @return Chat|ChatMember|File|Message|User|UserProfilePhotos|WebhookInfo */ private function createResultObject(array $result, $bot_username) { @@ -135,7 +133,7 @@ private function createResultObject(array $result, $bot_username) * @param array $result * @param string $bot_username * - * @return \Longman\TelegramBot\Entities\ChatMember[]|\Longman\TelegramBot\Entities\Games\GameHighScore[]|\Longman\TelegramBot\Entities\Message[]|\Longman\TelegramBot\Entities\Update[] + * @return ChatMember[]|GameHighScore[]|Message[]|Update[] */ private function createResultObjects(array $result, $bot_username) { diff --git a/src/Entities/TelegramPassport/PassportElementError/PassportElementErrorDataField.php b/src/Entities/TelegramPassport/PassportElementError/PassportElementErrorDataField.php index 113cbb630..5e0a076dc 100644 --- a/src/Entities/TelegramPassport/PassportElementError/PassportElementErrorDataField.php +++ b/src/Entities/TelegramPassport/PassportElementError/PassportElementErrorDataField.php @@ -31,8 +31,6 @@ class PassportElementErrorDataField extends Entity implements PassportElementErr * PassportElementErrorDataField constructor * * @param array $data - * - * @throws \Longman\TelegramBot\Exception\TelegramException */ public function __construct(array $data = []) { diff --git a/src/Entities/TelegramPassport/PassportElementError/PassportElementErrorFile.php b/src/Entities/TelegramPassport/PassportElementError/PassportElementErrorFile.php index cfc3a0c03..1ae013f9f 100644 --- a/src/Entities/TelegramPassport/PassportElementError/PassportElementErrorFile.php +++ b/src/Entities/TelegramPassport/PassportElementError/PassportElementErrorFile.php @@ -30,8 +30,6 @@ class PassportElementErrorFile extends Entity implements PassportElementError * PassportElementErrorFile constructor * * @param array $data - * - * @throws \Longman\TelegramBot\Exception\TelegramException */ public function __construct(array $data = []) { diff --git a/src/Entities/TelegramPassport/PassportElementError/PassportElementErrorFiles.php b/src/Entities/TelegramPassport/PassportElementError/PassportElementErrorFiles.php index 450762454..8efc6eb1f 100644 --- a/src/Entities/TelegramPassport/PassportElementError/PassportElementErrorFiles.php +++ b/src/Entities/TelegramPassport/PassportElementError/PassportElementErrorFiles.php @@ -30,8 +30,6 @@ class PassportElementErrorFiles extends Entity implements PassportElementError * PassportElementErrorFiles constructor * * @param array $data - * - * @throws \Longman\TelegramBot\Exception\TelegramException */ public function __construct(array $data = []) { diff --git a/src/Entities/TelegramPassport/PassportElementError/PassportElementErrorFrontSide.php b/src/Entities/TelegramPassport/PassportElementError/PassportElementErrorFrontSide.php index 4dcac607c..4c3000317 100644 --- a/src/Entities/TelegramPassport/PassportElementError/PassportElementErrorFrontSide.php +++ b/src/Entities/TelegramPassport/PassportElementError/PassportElementErrorFrontSide.php @@ -30,8 +30,6 @@ class PassportElementErrorFrontSide extends Entity implements PassportElementErr * PassportElementErrorFrontSide constructor * * @param array $data - * - * @throws \Longman\TelegramBot\Exception\TelegramException */ public function __construct(array $data = []) { diff --git a/src/Entities/TelegramPassport/PassportElementError/PassportElementErrorReverseSide.php b/src/Entities/TelegramPassport/PassportElementError/PassportElementErrorReverseSide.php index 468dcfb41..1c6d4d43c 100644 --- a/src/Entities/TelegramPassport/PassportElementError/PassportElementErrorReverseSide.php +++ b/src/Entities/TelegramPassport/PassportElementError/PassportElementErrorReverseSide.php @@ -30,8 +30,6 @@ class PassportElementErrorReverseSide extends Entity implements PassportElementE * PassportElementErrorReverseSide constructor * * @param array $data - * - * @throws \Longman\TelegramBot\Exception\TelegramException */ public function __construct(array $data = []) { diff --git a/src/Entities/TelegramPassport/PassportElementError/PassportElementErrorSelfie.php b/src/Entities/TelegramPassport/PassportElementError/PassportElementErrorSelfie.php index fa8dbde34..1444d6640 100644 --- a/src/Entities/TelegramPassport/PassportElementError/PassportElementErrorSelfie.php +++ b/src/Entities/TelegramPassport/PassportElementError/PassportElementErrorSelfie.php @@ -30,8 +30,6 @@ class PassportElementErrorSelfie extends Entity implements PassportElementError * PassportElementErrorSelfie constructor * * @param array $data - * - * @throws \Longman\TelegramBot\Exception\TelegramException */ public function __construct(array $data = []) { diff --git a/src/Entities/TelegramPassport/PassportElementError/PassportElementErrorTranslationFile.php b/src/Entities/TelegramPassport/PassportElementError/PassportElementErrorTranslationFile.php index fba8c76cd..ba8b1e9c6 100644 --- a/src/Entities/TelegramPassport/PassportElementError/PassportElementErrorTranslationFile.php +++ b/src/Entities/TelegramPassport/PassportElementError/PassportElementErrorTranslationFile.php @@ -30,8 +30,6 @@ class PassportElementErrorTranslationFile extends Entity implements PassportElem * PassportElementErrorTranslationFile constructor * * @param array $data - * - * @throws \Longman\TelegramBot\Exception\TelegramException */ public function __construct(array $data = []) { diff --git a/src/Entities/TelegramPassport/PassportElementError/PassportElementErrorTranslationFiles.php b/src/Entities/TelegramPassport/PassportElementError/PassportElementErrorTranslationFiles.php index 8e0654794..73e2bcdd0 100644 --- a/src/Entities/TelegramPassport/PassportElementError/PassportElementErrorTranslationFiles.php +++ b/src/Entities/TelegramPassport/PassportElementError/PassportElementErrorTranslationFiles.php @@ -30,8 +30,6 @@ class PassportElementErrorTranslationFiles extends Entity implements PassportEle * PassportElementErrorTranslationFiles constructor * * @param array $data - * - * @throws \Longman\TelegramBot\Exception\TelegramException */ public function __construct(array $data = []) { diff --git a/src/Entities/TelegramPassport/PassportElementError/PassportElementErrorUnspecified.php b/src/Entities/TelegramPassport/PassportElementError/PassportElementErrorUnspecified.php index d8e0679c7..8b0767af5 100644 --- a/src/Entities/TelegramPassport/PassportElementError/PassportElementErrorUnspecified.php +++ b/src/Entities/TelegramPassport/PassportElementError/PassportElementErrorUnspecified.php @@ -30,8 +30,6 @@ class PassportElementErrorUnspecified extends Entity implements PassportElementE * PassportElementErrorUnspecified constructor * * @param array $data - * - * @throws \Longman\TelegramBot\Exception\TelegramException */ public function __construct(array $data = []) { diff --git a/src/Entities/Update.php b/src/Entities/Update.php index 605137cba..e2c520cd1 100644 --- a/src/Entities/Update.php +++ b/src/Entities/Update.php @@ -82,10 +82,7 @@ public function getUpdateType() /** * Get update content * - * @return \Longman\TelegramBot\Entities\CallbackQuery - * |\Longman\TelegramBot\Entities\ChosenInlineResult - * |\Longman\TelegramBot\Entities\InlineQuery - * |\Longman\TelegramBot\Entities\Message + * @return CallbackQuery|ChosenInlineResult|InlineQuery|Message */ public function getUpdateContent() { diff --git a/src/Entities/UserProfilePhotos.php b/src/Entities/UserProfilePhotos.php index 29c3d4d4a..a58ae84bb 100644 --- a/src/Entities/UserProfilePhotos.php +++ b/src/Entities/UserProfilePhotos.php @@ -34,7 +34,7 @@ protected function subEntities() * * This method overrides the default getPhotos method and returns a nice array * - * @return PhotoSize[] + * @return PhotoSize[][] */ public function getPhotos() { @@ -42,11 +42,9 @@ public function getPhotos() if ($these_photos = $this->getProperty('photos')) { foreach ($these_photos as $photos) { - $new_photos = []; - foreach ($photos as $photo) { - $new_photos[] = new PhotoSize($photo); - } - $all_photos[] = $new_photos; + $all_photos[] = array_map(function ($photo) { + return new PhotoSize($photo); + }, $photos); } } diff --git a/src/Request.php b/src/Request.php index 8dbdd71c5..bfc49c5cf 100644 --- a/src/Request.php +++ b/src/Request.php @@ -91,7 +91,7 @@ class Request /** * Telegram object * - * @var \Longman\TelegramBot\Telegram + * @var Telegram */ private static $telegram; @@ -105,7 +105,7 @@ class Request /** * Guzzle Client object * - * @var \GuzzleHttp\Client + * @var Client */ private static $client; @@ -253,7 +253,7 @@ class Request /** * Initialize * - * @param \Longman\TelegramBot\Telegram $telegram + * @param Telegram $telegram * * @throws TelegramException */ @@ -287,7 +287,7 @@ public static function setClient(Client $client) * Set input from custom input or stdin and return it * * @return string - * @throws \Longman\TelegramBot\Exception\TelegramException + * @throws TelegramException */ public static function getInput() { @@ -377,7 +377,7 @@ private static function setUpRequestParams(array $data) } // Reformat data array in multipart way if it contains a resource - $has_resource |= (is_resource($item) || $item instanceof Stream); + $has_resource = $has_resource || is_resource($item) || $item instanceof Stream; $multipart[] = ['name' => $key, 'contents' => $item]; } @@ -421,6 +421,7 @@ private static function setUpRequestParams(array $data) * @param array $multipart * * @return mixed + * @throws TelegramException */ private static function mediaInputHelper($item, &$has_resource, array &$multipart) { @@ -472,7 +473,7 @@ public static function getCurrentAction() * @param array $data Data to attach to the execution * * @return string Result of the HTTP Request - * @throws \Longman\TelegramBot\Exception\TelegramException + * @throws TelegramException */ public static function execute($action, array $data = []) { @@ -509,10 +510,10 @@ public static function execute($action, array $data = []) /** * Download file * - * @param \Longman\TelegramBot\Entities\File $file + * @param File $file * * @return boolean - * @throws \Longman\TelegramBot\Exception\TelegramException + * @throws TelegramException */ public static function downloadFile(File $file) { @@ -540,7 +541,7 @@ public static function downloadFile(File $file) return filesize($file_path) > 0; } catch (RequestException $e) { - return ($e->getResponse()) ? (string) $e->getResponse()->getBody() : ''; + return false; } finally { //Logging verbose debug output TelegramLog::endDebugLogTempStream('Verbose HTTP File Download Request output:' . PHP_EOL . '%s' . PHP_EOL); @@ -553,7 +554,7 @@ public static function downloadFile(File $file) * @param string $file * * @return resource - * @throws \Longman\TelegramBot\Exception\TelegramException + * @throws TelegramException */ public static function encodeFile($file) { @@ -574,8 +575,8 @@ public static function encodeFile($file) * @param string $action * @param array $data * - * @return \Longman\TelegramBot\Entities\ServerResponse - * @throws \Longman\TelegramBot\Exception\TelegramException + * @return ServerResponse + * @throws TelegramException */ public static function send($action, array $data = []) { @@ -643,7 +644,7 @@ protected static function addDummyParamIfNecessary($action, array &$data) * * @param array $data * - * @throws \Longman\TelegramBot\Exception\TelegramException + * @throws TelegramException */ private static function ensureNonEmptyData(array $data) { @@ -657,7 +658,7 @@ private static function ensureNonEmptyData(array $data) * * @param string $action * - * @throws \Longman\TelegramBot\Exception\TelegramException + * @throws TelegramException */ private static function ensureValidAction($action) { @@ -673,8 +674,8 @@ private static function ensureValidAction($action) * * @param array $data * - * @return \Longman\TelegramBot\Entities\ServerResponse - * @throws \Longman\TelegramBot\Exception\TelegramException + * @return ServerResponse + * @throws TelegramException */ public static function sendMessage(array $data) { @@ -698,8 +699,7 @@ public static function sendMessage(array $data) * @param string $action * @param array $data * - * @return \Longman\TelegramBot\Entities\ServerResponse - * @throws \Longman\TelegramBot\Exception\TelegramException + * @return ServerResponse */ public static function __callStatic($action, array $data) { @@ -716,8 +716,7 @@ public static function __callStatic($action, array $data) * No request to telegram are sent, this function is used in commands that * don't need to fire a message after execution * - * @return \Longman\TelegramBot\Entities\ServerResponse - * @throws \Longman\TelegramBot\Exception\TelegramException + * @return ServerResponse */ public static function emptyResponse() { @@ -760,7 +759,7 @@ public static function sendToActiveChats( * @param boolean $enable * @param array $options * - * @throws \Longman\TelegramBot\Exception\TelegramException + * @throws TelegramException */ public static function setLimiter($enable = true, array $options = []) { @@ -789,7 +788,7 @@ public static function setLimiter($enable = true, array $options = []) * @param string $action * @param array $data * - * @throws \Longman\TelegramBot\Exception\TelegramException + * @throws TelegramException */ private static function limitTelegramRequests($action, array $data = []) { @@ -830,7 +829,7 @@ private static function limitTelegramRequests($action, array $data = []) $chat_id = isset($data['chat_id']) ? $data['chat_id'] : null; $inline_message_id = isset($data['inline_message_id']) ? $data['inline_message_id'] : null; - if (($chat_id || $inline_message_id) && in_array($action, $limited_methods)) { + if (($chat_id || $inline_message_id) && in_array($action, $limited_methods, true)) { $timeout = 60; while (true) { @@ -838,18 +837,23 @@ private static function limitTelegramRequests($action, array $data = []) throw new TelegramException('Timed out while waiting for a request spot!'); } - $requests = DB::getTelegramRequestCount($chat_id, $inline_message_id); + if (!($requests = DB::getTelegramRequestCount($chat_id, $inline_message_id))) { + break; + } + + // Make sure we're handling integers here. + $requests = array_map('intval', $requests); - $chat_per_second = ($requests['LIMIT_PER_SEC'] == 0); // No more than one message per second inside a particular chat - $global_per_second = ($requests['LIMIT_PER_SEC_ALL'] < 30); // No more than 30 messages per second to different chats - $groups_per_minute = (((is_numeric($chat_id) && $chat_id > 0) || !is_null($inline_message_id)) || ((!is_numeric($chat_id) || $chat_id < 0) && $requests['LIMIT_PER_MINUTE'] < 20)); // No more than 20 messages per minute in groups and channels + $chat_per_second = ($requests['LIMIT_PER_SEC'] === 0); // No more than one message per second inside a particular chat + $global_per_second = ($requests['LIMIT_PER_SEC_ALL'] < 30); // No more than 30 messages per second to different chats + $groups_per_minute = (((is_numeric($chat_id) && $chat_id > 0) || $inline_message_id !== null) || ((!is_numeric($chat_id) || $chat_id < 0) && $requests['LIMIT_PER_MINUTE'] < 20)); // No more than 20 messages per minute in groups and channels if ($chat_per_second && $global_per_second && $groups_per_minute) { break; } $timeout--; - usleep(self::$limiter_interval * 1000000); + usleep((int) (self::$limiter_interval * 1000000)); } DB::insertTelegramRequest($action, $data); diff --git a/src/Telegram.php b/src/Telegram.php index 73e8cd644..a869fee10 100644 --- a/src/Telegram.php +++ b/src/Telegram.php @@ -70,7 +70,7 @@ class Telegram /** * Current Update object * - * @var \Longman\TelegramBot\Entities\Update + * @var Update */ protected $update; @@ -98,7 +98,7 @@ class Telegram /** * PDO object * - * @var \PDO + * @var PDO */ protected $pdo; @@ -119,7 +119,7 @@ class Telegram /** * ServerResponse of the last Command execution * - * @var \Longman\TelegramBot\Entities\ServerResponse + * @var ServerResponse */ protected $last_command_response; @@ -151,7 +151,7 @@ class Telegram * @param string $api_key * @param string $bot_username * - * @throws \Longman\TelegramBot\Exception\TelegramException + * @throws TelegramException */ public function __construct($api_key, $bot_username = '') { @@ -182,8 +182,8 @@ public function __construct($api_key, $bot_username = '') * @param string $table_prefix * @param string $encoding * - * @return \Longman\TelegramBot\Telegram - * @throws \Longman\TelegramBot\Exception\TelegramException + * @return Telegram + * @throws TelegramException */ public function enableMySql(array $credential, $table_prefix = null, $encoding = 'utf8mb4') { @@ -200,8 +200,8 @@ public function enableMySql(array $credential, $table_prefix = null, $encoding = * @param PDO $external_pdo_connection PDO database object * @param string $table_prefix * - * @return \Longman\TelegramBot\Telegram - * @throws \Longman\TelegramBot\Exception\TelegramException + * @return Telegram + * @throws TelegramException */ public function enableExternalMySql($external_pdo_connection, $table_prefix = null) { @@ -216,7 +216,7 @@ public function enableExternalMySql($external_pdo_connection, $table_prefix = nu * Get commands list * * @return array $commands - * @throws \Longman\TelegramBot\Exception\TelegramException + * @throws TelegramException */ public function getCommandsList() { @@ -261,7 +261,7 @@ public function getCommandsList() * * @param string $command * - * @return \Longman\TelegramBot\Commands\Command|null + * @return Command|null */ public function getCommandObject($command) { @@ -284,7 +284,7 @@ public function getCommandObject($command) * * @param string $input (json format) * - * @return \Longman\TelegramBot\Telegram + * @return Telegram */ public function setCustomInput($input) { @@ -306,7 +306,7 @@ public function getCustomInput() /** * Get the ServerResponse of the last Command execution * - * @return \Longman\TelegramBot\Entities\ServerResponse + * @return ServerResponse */ public function getLastCommandResponse() { @@ -319,8 +319,8 @@ public function getLastCommandResponse() * @param int|null $limit * @param int|null $timeout * - * @return \Longman\TelegramBot\Entities\ServerResponse - * @throws \Longman\TelegramBot\Exception\TelegramException + * @return ServerResponse + * @throws TelegramException */ public function handleGetUpdates($limit = null, $timeout = null) { @@ -344,9 +344,8 @@ public function handleGetUpdates($limit = null, $timeout = null) if ($custom_input = $this->getCustomInput()) { $response = new ServerResponse(json_decode($custom_input, true), $this->bot_username); } else { - if (DB::isDbConnected()) { + if (DB::isDbConnected() && $last_update = DB::selectTelegramUpdate(1)) { //Get last update id from the database - $last_update = DB::selectTelegramUpdate(1); $last_update = reset($last_update); $this->last_update_id = isset($last_update['id']) ? $last_update['id'] : null; @@ -394,7 +393,7 @@ public function handleGetUpdates($limit = null, $timeout = null) * * @return bool * - * @throws \Longman\TelegramBot\Exception\TelegramException + * @throws TelegramException */ public function handle() { @@ -435,14 +434,14 @@ protected function getCommandFromType($type) /** * Process bot Update request * - * @param \Longman\TelegramBot\Entities\Update $update + * @param Update $update * - * @return \Longman\TelegramBot\Entities\ServerResponse - * @throws \Longman\TelegramBot\Exception\TelegramException + * @return ServerResponse + * @throws TelegramException */ public function processUpdate(Update $update) { - $this->update = $update; + $this->update = $update; $this->last_update_id = $update->getUpdateId(); //Load admin commands @@ -493,7 +492,7 @@ public function processUpdate(Update $update) * @param string $command * * @return mixed - * @throws \Longman\TelegramBot\Exception\TelegramException + * @throws TelegramException */ public function executeCommand($command) { @@ -534,7 +533,7 @@ protected function sanitizeCommand($command) * * @param integer $admin_id Single admin id * - * @return \Longman\TelegramBot\Telegram + * @return Telegram */ public function enableAdmin($admin_id) { @@ -552,7 +551,7 @@ public function enableAdmin($admin_id) * * @param array $admin_ids List of admin ids * - * @return \Longman\TelegramBot\Telegram + * @return Telegram */ public function enableAdmins(array $admin_ids) { @@ -627,7 +626,7 @@ public function isDbEnabled() * @param string $path Custom commands path to add * @param bool $before If the path should be prepended or appended to the list * - * @return \Longman\TelegramBot\Telegram + * @return Telegram */ public function addCommandsPath($path, $before = true) { @@ -650,7 +649,7 @@ public function addCommandsPath($path, $before = true) * @param array $paths Custom commands paths to add * @param bool $before If the paths should be prepended or appended to the list * - * @return \Longman\TelegramBot\Telegram + * @return Telegram */ public function addCommandsPaths(array $paths, $before = true) { @@ -676,7 +675,7 @@ public function getCommandsPaths() * * @param string $path Custom upload path * - * @return \Longman\TelegramBot\Telegram + * @return Telegram */ public function setUploadPath($path) { @@ -700,7 +699,7 @@ public function getUploadPath() * * @param string $path Custom download path * - * @return \Longman\TelegramBot\Telegram + * @return Telegram */ public function setDownloadPath($path) { @@ -729,7 +728,7 @@ public function getDownloadPath() * @param string $command * @param array $config * - * @return \Longman\TelegramBot\Telegram + * @return Telegram */ public function setCommandConfig($command, array $config) { @@ -796,8 +795,8 @@ public function getVersion() * @param string $url * @param array $data Optional parameters. * - * @return \Longman\TelegramBot\Entities\ServerResponse - * @throws \Longman\TelegramBot\Exception\TelegramException + * @return ServerResponse + * @throws TelegramException */ public function setWebhook($url, array $data = []) { @@ -832,7 +831,7 @@ public function setWebhook($url, array $data = []) * Delete any assigned webhook * * @return mixed - * @throws \Longman\TelegramBot\Exception\TelegramException + * @throws TelegramException */ public function deleteWebhook() { @@ -877,9 +876,10 @@ protected function ucfirstUnicode($str, $encoding = 'UTF-8') /** * Enable requests limiter * - * @param array $options + * @param array $options * - * @return \Longman\TelegramBot\Telegram + * @return Telegram + * @throws TelegramException */ public function enableLimiter(array $options = []) { @@ -901,7 +901,7 @@ public function runCommands($commands) throw new TelegramException('No command(s) provided!'); } - $this->run_commands = true; + $this->run_commands = true; $result = Request::getMe(); diff --git a/src/TelegramLog.php b/src/TelegramLog.php index 19f3d7b85..3f746f1d7 100644 --- a/src/TelegramLog.php +++ b/src/TelegramLog.php @@ -20,14 +20,14 @@ class TelegramLog /** * Monolog instance * - * @var \Monolog\Logger + * @var Logger */ protected static $monolog; /** * Monolog instance for update * - * @var \Monolog\Logger + * @var Logger */ protected static $monolog_update; @@ -62,9 +62,9 @@ class TelegramLog /** * Initialize Monolog Logger instance, optionally passing an existing one * - * @param \Monolog\Logger + * @param Logger * - * @return \Monolog\Logger + * @return Logger */ public static function initialize(Logger $external_monolog = null) { @@ -93,8 +93,8 @@ public static function initialize(Logger $external_monolog = null) * * @param string $path * - * @return \Monolog\Logger - * @throws \Longman\TelegramBot\Exception\TelegramLogException + * @return Logger + * @throws TelegramLogException * @throws \InvalidArgumentException * @throws \Exception */ @@ -117,8 +117,8 @@ public static function initErrorLog($path) * * @param string $path * - * @return \Monolog\Logger - * @throws \Longman\TelegramBot\Exception\TelegramLogException + * @return Logger + * @throws TelegramLogException * @throws \InvalidArgumentException * @throws \Exception */ @@ -147,7 +147,9 @@ public static function getDebugLogTempStream() if (!self::isDebugLogActive()) { return false; } - self::$debug_log_temp_stream_handle = fopen('php://temp', 'w+b'); + if ($temp_stream_handle = fopen('php://temp', 'wb+')) { + self::$debug_log_temp_stream_handle = $temp_stream_handle; + } } return self::$debug_log_temp_stream_handle; @@ -173,8 +175,8 @@ public static function endDebugLogTempStream($message = '%s') * * @param string $path * - * @return \Monolog\Logger - * @throws \Longman\TelegramBot\Exception\TelegramLogException + * @return Logger + * @throws TelegramLogException * @throws \InvalidArgumentException * @throws \Exception */ diff --git a/tests/unit/Commands/CommandTest.php b/tests/unit/Commands/CommandTest.php index 746f57d5b..cf0f66b41 100644 --- a/tests/unit/Commands/CommandTest.php +++ b/tests/unit/Commands/CommandTest.php @@ -10,6 +10,7 @@ namespace Longman\TelegramBot\Tests\Unit\Commands; +use Longman\TelegramBot\Commands\Command; use Longman\TelegramBot\Telegram; use Longman\TelegramBot\Tests\Unit\TestCase; use Longman\TelegramBot\Tests\Unit\TestHelpers; @@ -26,25 +27,25 @@ class CommandTest extends TestCase /** * @var string */ - private $command_namespace = 'Longman\TelegramBot\Commands\Command'; + private $command_namespace = Command::class; /** - * @var \Longman\TelegramBot\Telegram + * @var Telegram */ private $telegram; /** - * @var \Longman\TelegramBot\Commands\Command + * @var Command */ private $command_stub; /** - * @var \Longman\TelegramBot\Telegram + * @var Telegram */ private $telegram_with_config; /** - * @var \Longman\TelegramBot\Commands\Command + * @var Command */ private $command_stub_with_config; diff --git a/tests/unit/Commands/CommandTestCase.php b/tests/unit/Commands/CommandTestCase.php index 043e3677b..57551c5eb 100644 --- a/tests/unit/Commands/CommandTestCase.php +++ b/tests/unit/Commands/CommandTestCase.php @@ -10,6 +10,7 @@ namespace Longman\TelegramBot\Tests\Unit\Commands; +use Longman\TelegramBot\Commands\Command; use Longman\TelegramBot\Telegram; use Longman\TelegramBot\Tests\Unit\TestCase; @@ -23,12 +24,12 @@ class CommandTestCase extends TestCase { /** - * @var \Longman\TelegramBot\Telegram + * @var Telegram */ protected $telegram; /** - * @var \Longman\TelegramBot\Commands\Command + * @var Command */ protected $command; diff --git a/tests/unit/Commands/CustomTestCommands/HiddenCommand.php b/tests/unit/Commands/CustomTestCommands/HiddenCommand.php index acc82a13b..c60674e33 100644 --- a/tests/unit/Commands/CustomTestCommands/HiddenCommand.php +++ b/tests/unit/Commands/CustomTestCommands/HiddenCommand.php @@ -47,7 +47,6 @@ class HiddenCommand extends UserCommand * Command execute method * * @return mixed - * @throws \Longman\TelegramBot\Exception\TelegramException */ public function execute() { diff --git a/tests/unit/Commands/CustomTestCommands/VisibleCommand.php b/tests/unit/Commands/CustomTestCommands/VisibleCommand.php index 6d800e896..03c919b22 100644 --- a/tests/unit/Commands/CustomTestCommands/VisibleCommand.php +++ b/tests/unit/Commands/CustomTestCommands/VisibleCommand.php @@ -47,7 +47,6 @@ class VisibleCommand extends UserCommand * Command execute method * * @return mixed - * @throws \Longman\TelegramBot\Exception\TelegramException */ public function execute() { diff --git a/tests/unit/ConversationTest.php b/tests/unit/ConversationTest.php index 0bd8b9ed7..81068b08e 100644 --- a/tests/unit/ConversationTest.php +++ b/tests/unit/ConversationTest.php @@ -23,7 +23,7 @@ class ConversationTest extends TestCase { /** - * @var \Longman\TelegramBot\Telegram + * @var Telegram */ private $telegram; @@ -53,7 +53,7 @@ public function testConversationThatDoesntExistPropertiesSetCorrectly() public function testConversationThatExistsPropertiesSetCorrectly() { - $info = TestHelpers::startFakeConversation(); + $info = TestHelpers::startFakeConversation(); $conversation = new Conversation($info['user_id'], $info['chat_id'], 'command'); $this->assertAttributeEquals($info['user_id'], 'user_id', $conversation); $this->assertAttributeEquals($info['chat_id'], 'chat_id', $conversation); @@ -85,7 +85,7 @@ public function testNewConversationThatWontExistWithoutCommand() public function testNewConversationThatWillExistWithCommand() { - $info = TestHelpers::startFakeConversation(); + $info = TestHelpers::startFakeConversation(); $conversation = new Conversation($info['user_id'], $info['chat_id'], 'command'); $this->assertTrue($conversation->exists()); $this->assertEquals('command', $conversation->getCommand()); @@ -93,7 +93,7 @@ public function testNewConversationThatWillExistWithCommand() public function testStopConversation() { - $info = TestHelpers::startFakeConversation(); + $info = TestHelpers::startFakeConversation(); $conversation = new Conversation($info['user_id'], $info['chat_id'], 'command'); $this->assertTrue($conversation->exists()); $conversation->stop(); @@ -104,7 +104,7 @@ public function testStopConversation() public function testCancelConversation() { - $info = TestHelpers::startFakeConversation(); + $info = TestHelpers::startFakeConversation(); $conversation = new Conversation($info['user_id'], $info['chat_id'], 'command'); $this->assertTrue($conversation->exists()); $conversation->cancel(); @@ -115,8 +115,8 @@ public function testCancelConversation() public function testUpdateConversationNotes() { - $info = TestHelpers::startFakeConversation(); - $conversation = new Conversation($info['user_id'], $info['chat_id'], 'command'); + $info = TestHelpers::startFakeConversation(); + $conversation = new Conversation($info['user_id'], $info['chat_id'], 'command'); $conversation->notes = 'newnote'; $conversation->update(); diff --git a/tests/unit/Entities/AudioTest.php b/tests/unit/Entities/AudioTest.php index 261d9c017..3f704565b 100644 --- a/tests/unit/Entities/AudioTest.php +++ b/tests/unit/Entities/AudioTest.php @@ -34,7 +34,7 @@ public function setUp() public function testInstance() { $audio = new Audio($this->record); - self::assertInstanceOf('Longman\TelegramBot\Entities\Audio', $audio); + self::assertInstanceOf(Audio::class, $audio); } public function testGetProperties() diff --git a/tests/unit/Entities/FileTest.php b/tests/unit/Entities/FileTest.php index 91323ecb7..6eac4fe3d 100644 --- a/tests/unit/Entities/FileTest.php +++ b/tests/unit/Entities/FileTest.php @@ -38,7 +38,7 @@ public function setUp() public function testBaseStageLocation() { $file = new File($this->data); - $this->assertInstanceOf('Longman\TelegramBot\Entities\File', $file); + $this->assertInstanceOf(File::class, $file); } public function testGetFileId() diff --git a/tests/unit/Entities/LocationTest.php b/tests/unit/Entities/LocationTest.php index e594ba00d..d5309c1fb 100644 --- a/tests/unit/Entities/LocationTest.php +++ b/tests/unit/Entities/LocationTest.php @@ -34,7 +34,7 @@ public function setUp() public function testBaseStageLocation() { $location = new Location($this->coordinates); - $this->assertInstanceOf('Longman\TelegramBot\Entities\Location', $location); + $this->assertInstanceOf(Location::class, $location); } public function testGetLongitude() diff --git a/tests/unit/Entities/ServerResponseTest.php b/tests/unit/Entities/ServerResponseTest.php index ffe0ab119..ed2f06037 100644 --- a/tests/unit/Entities/ServerResponseTest.php +++ b/tests/unit/Entities/ServerResponseTest.php @@ -12,8 +12,14 @@ namespace Longman\TelegramBot\Tests\Unit; +use Longman\TelegramBot\Entities\File; use Longman\TelegramBot\Entities\Message; +use Longman\TelegramBot\Entities\PhotoSize; use Longman\TelegramBot\Entities\ServerResponse; +use Longman\TelegramBot\Entities\Sticker; +use Longman\TelegramBot\Entities\StickerSet; +use Longman\TelegramBot\Entities\Update; +use Longman\TelegramBot\Entities\UserProfilePhotos; use Longman\TelegramBot\Request; /** @@ -54,7 +60,7 @@ public function testSendMessageOk() self::assertTrue($server->isOk()); self::assertNull($server->getErrorCode()); self::assertNull($server->getDescription()); - self::assertInstanceOf('\Longman\TelegramBot\Entities\Message', $server_result); + self::assertInstanceOf(Message::class, $server_result); //Message self::assertEquals('1234', $server_result->getMessageId()); @@ -181,7 +187,7 @@ public function testGetUpdatesArray() $server = new ServerResponse(json_decode($result, true), 'testbot'); self::assertCount(4, $server->getResult()); - self::assertInstanceOf('\Longman\TelegramBot\Entities\Update', $server->getResult()[0]); + self::assertInstanceOf(Update::class, $server->getResult()[0]); } public function getUpdatesEmpty() @@ -239,8 +245,8 @@ public function testGetUserProfilePhotos() //Photo size count self::assertCount(3, $photos[0]); - self::assertInstanceOf('\Longman\TelegramBot\Entities\UserProfilePhotos', $server_result); - self::assertInstanceOf('\Longman\TelegramBot\Entities\PhotoSize', $photos[0][0]); + self::assertInstanceOf(UserProfilePhotos::class, $server_result); + self::assertInstanceOf(PhotoSize::class, $photos[0][0]); } public function getFile() @@ -261,7 +267,7 @@ public function testGetFile() $result = $this->getFile(); $server = new ServerResponse(json_decode($result, true), 'testbot'); - self::assertInstanceOf('\Longman\TelegramBot\Entities\File', $server->getResult()); + self::assertInstanceOf(File::class, $server->getResult()); } public function testSetGeneralTestFakeResponse() @@ -287,7 +293,7 @@ public function testSetGeneralTestFakeResponse() self::assertTrue($server->isOk()); self::assertNull($server->getErrorCode()); self::assertNull($server->getDescription()); - self::assertInstanceOf('\Longman\TelegramBot\Entities\Message', $server_result); + self::assertInstanceOf(Message::class, $server_result); //Message self::assertEquals('1234', $server_result->getMessageId()); @@ -306,7 +312,7 @@ public function testSetGeneralTestFakeResponse() //... they are not finished... } - + public function getStickerSet() { TestHelpers::setStaticProperty(Request::class, 'current_action', 'getStickerSet'); @@ -357,21 +363,21 @@ public function getStickerSet() } }'; } - + public function testGetStickerSet() { $result = $this->getStickerSet(); $server = new ServerResponse(json_decode($result, true), 'testbot'); $server_result = $server->getResult(); - - self::assertInstanceOf('\Longman\TelegramBot\Entities\StickerSet', $server_result); + + self::assertInstanceOf(StickerSet::class, $server_result); self::assertEquals('stickerset_name', $server_result->getName()); self::assertEquals('Some name', $server_result->getTitle()); self::assertFalse($server_result->getContainsMasks()); - + $stickers = $server_result->getStickers(); self::assertCount(4, $stickers); - self::assertInstanceOf('\Longman\TelegramBot\Entities\Sticker', $stickers[0]); + self::assertInstanceOf(Sticker::class, $stickers[0]); } } diff --git a/tests/unit/Entities/UserTest.php b/tests/unit/Entities/UserTest.php index b0edc0d2e..6c79cc665 100644 --- a/tests/unit/Entities/UserTest.php +++ b/tests/unit/Entities/UserTest.php @@ -24,7 +24,7 @@ class UserTest extends TestCase public function testInstance() { $user = new User(['id' => 1]); - self::assertInstanceOf('Longman\TelegramBot\Entities\User', $user); + self::assertInstanceOf(User::class, $user); } public function testGetId() diff --git a/tests/unit/Entities/WebhookInfoTest.php b/tests/unit/Entities/WebhookInfoTest.php index 1d18b64ad..e63162d80 100644 --- a/tests/unit/Entities/WebhookInfoTest.php +++ b/tests/unit/Entities/WebhookInfoTest.php @@ -42,7 +42,7 @@ public function setUp() public function testBaseStageWebhookInfo() { $webhook = new WebhookInfo($this->data); - $this->assertInstanceOf('Longman\TelegramBot\Entities\WebhookInfo', $webhook); + $this->assertInstanceOf(WebhookInfo::class, $webhook); } public function testGetUrl() diff --git a/tests/unit/TelegramLogTest.php b/tests/unit/TelegramLogTest.php index 069e9dabd..40561bfa5 100644 --- a/tests/unit/TelegramLogTest.php +++ b/tests/unit/TelegramLogTest.php @@ -36,7 +36,7 @@ class TelegramLogTest extends TestCase protected function setUp() { // Make sure no monolog instance is set before each test. - TestHelpers::setStaticProperty('Longman\TelegramBot\TelegramLog', 'monolog', null); + TestHelpers::setStaticProperty(TelegramLog::class, 'monolog', null); } protected function tearDown() diff --git a/tests/unit/TelegramTest.php b/tests/unit/TelegramTest.php index e219c7512..559d517c3 100644 --- a/tests/unit/TelegramTest.php +++ b/tests/unit/TelegramTest.php @@ -22,7 +22,7 @@ class TelegramTest extends TestCase { /** - * @var \Longman\TelegramBot\Telegram + * @var Telegram */ private $telegram; diff --git a/tests/unit/TestHelpers.php b/tests/unit/TestHelpers.php index fe818a912..0fd7d579c 100644 --- a/tests/unit/TestHelpers.php +++ b/tests/unit/TestHelpers.php @@ -85,7 +85,7 @@ public static function setStaticProperty($class, $property, $value) * * @param array $data Pass custom data array if needed * - * @return \Longman\TelegramBot\Entities\Update + * @return Update */ public static function getFakeUpdateObject($data = null) { @@ -107,7 +107,7 @@ public static function getFakeUpdateObject($data = null) * * @param string $command_text * - * @return \Longman\TelegramBot\Entities\Update + * @return Update */ public static function getFakeUpdateCommandObject($command_text) { @@ -129,7 +129,7 @@ public static function getFakeUpdateCommandObject($command_text) * * @param array $data Pass custom data array if needed * - * @return \Longman\TelegramBot\Entities\User + * @return User */ public static function getFakeUserObject(array $data = []) { @@ -143,7 +143,7 @@ public static function getFakeUserObject(array $data = []) * * @param array $data Pass custom data array if needed * - * @return \Longman\TelegramBot\Entities\Chat + * @return Chat */ public static function getFakeChatObject(array $data = []) { @@ -179,7 +179,7 @@ public static function getFakeRecordedAudio() * @param array $user_data Pass custom user data array if needed * @param array $chat_data Pass custom chat data array if needed * - * @return \Longman\TelegramBot\Entities\Message + * @return Message */ public static function getFakeMessageObject(array $message_data = [], array $user_data = [], array $chat_data = []) { @@ -223,7 +223,7 @@ public static function startFakeConversation() /** * Empty all tables for the passed database * - * @param array $credentials + * @param array $credentials */ public static function emptyDb(array $credentials) { diff --git a/utils/importFromLog.php b/utils/importFromLog.php index b7083c145..80289f807 100644 --- a/utils/importFromLog.php +++ b/utils/importFromLog.php @@ -1,13 +1,13 @@ 'localhost', 'user'=>'', 'password'=>'', 'database'=>''); +$CREDENTIALS = ['host' => 'localhost', 'user' => '', 'password' => '', 'database' => '']; $update = null; try {