Skip to content

Smaller code and docblock fixes #973

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@ charset = utf-8
indent_style = space
indent_size = 4
trim_trailing_whitespace = true

[*.{yml, yaml}]
indent_size = 2
53 changes: 36 additions & 17 deletions .scrutinizer.yml
Original file line number Diff line number Diff line change
@@ -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
42 changes: 21 additions & 21 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
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"
>
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"
>
<php>
<ini name="error_reporting" value="-1" />
<ini name="error_reporting" value="-1"/>
<const name="PHPUNIT_TESTSUITE" value="true"/>
<const name="PHPUNIT_DB_HOST" value="127.0.0.1"/>
<const name="PHPUNIT_DB_NAME" value="telegrambot"/>
Expand Down
6 changes: 4 additions & 2 deletions src/Commands/AdminCommands/ChatsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
{
Expand Down
8 changes: 5 additions & 3 deletions src/Commands/AdminCommands/CleanupCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()
{
Expand All @@ -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()
{
Expand Down
19 changes: 10 additions & 9 deletions src/Commands/AdminCommands/DebugCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

use Longman\TelegramBot\Commands\AdminCommand;
use Longman\TelegramBot\DB;
use Longman\TelegramBot\Exception\TelegramException;
use Longman\TelegramBot\Request;

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

Expand Down Expand Up @@ -80,15 +81,15 @@ 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());

if (isset($_SERVER['SERVER_SOFTWARE'])) {
$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']);
}

Expand All @@ -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
);
Expand All @@ -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);
}
Expand Down
5 changes: 3 additions & 2 deletions src/Commands/AdminCommands/SendtoallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -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()
{
Expand Down
26 changes: 14 additions & 12 deletions src/Commands/AdminCommands/SendtochannelCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
{
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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()
{
Expand Down
6 changes: 4 additions & 2 deletions src/Commands/AdminCommands/WhoisCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -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()
{
Expand Down
Loading