Skip to content

Commit ba25843

Browse files
authored
Merge pull request #973 from noplanman/smaller_code_and_docblock_fixes
Smaller code and docblock fixes
2 parents 6aa29b4 + f88a7bd commit ba25843

File tree

96 files changed

+307
-341
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

96 files changed

+307
-341
lines changed

.editorconfig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,6 @@ charset = utf-8
77
indent_style = space
88
indent_size = 4
99
trim_trailing_whitespace = true
10+
11+
[*.{yml, yaml}]
12+
indent_size = 2

.scrutinizer.yml

Lines changed: 36 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,41 @@
1+
build:
2+
nodes:
3+
analysis:
4+
tests:
5+
override:
6+
- php-scrutinizer-run
7+
18
filter:
2-
paths: [src/*]
9+
paths:
10+
- src/
11+
dependency_paths:
12+
- lib/
313

414
checks:
5-
php:
6-
remove_extra_empty_lines: true
7-
remove_php_closing_tag: true
8-
remove_trailing_whitespace: true
9-
fix_use_statements:
10-
remove_unused: true
11-
preserve_multiple: false
12-
preserve_blanklines: true
13-
order_alphabetically: true
14-
fix_php_opening_tag: true
15-
fix_linefeed: true
16-
fix_line_ending: true
17-
fix_identation_4spaces: true
18-
fix_doc_comments: true
15+
php:
16+
check_method_contracts:
17+
verify_interface_like_constraints: true
18+
verify_documented_constraints: true
19+
verify_parent_constraints: true
20+
fix_doc_comments: true
21+
fix_identation_4spaces: true
22+
fix_line_ending: true
23+
fix_linefeed: true
24+
fix_php_opening_tag: true
25+
fix_use_statements:
26+
remove_unused: true
27+
preserve_multiple: false
28+
preserve_blanklines: true
29+
order_alphabetically: true
30+
more_specific_types_in_doc_comments: true
31+
no_goto: true
32+
param_doc_comment_if_not_inferrable: true
33+
parameter_doc_comments: true
34+
remove_extra_empty_lines: true
35+
return_doc_comment_if_not_inferrable: true
36+
return_doc_comments: true
37+
simplify_boolean_return: true
1938

2039
tools:
21-
external_code_coverage:
22-
timeout: 120
40+
external_code_coverage:
41+
timeout: 120

phpunit.xml.dist

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<phpunit
3-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4-
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/4.8/phpunit.xsd"
5-
bootstrap="./tests/bootstrap.php"
6-
backupGlobals="false"
7-
backupStaticAttributes="false"
8-
colors="true"
9-
convertErrorsToExceptions="true"
10-
convertNoticesToExceptions="true"
11-
convertWarningsToExceptions="true"
12-
processIsolation="false"
13-
stopOnError="false"
14-
stopOnFailure="false"
15-
stopOnIncomplete="false"
16-
stopOnSkipped="false"
17-
syntaxCheck="true"
18-
timeoutForLargeTests="60"
19-
timeoutForMediumTests="10"
20-
timeoutForSmallTests="1"
21-
verbose="false"
22-
>
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/4.8/phpunit.xsd"
5+
bootstrap="./tests/bootstrap.php"
6+
backupGlobals="false"
7+
backupStaticAttributes="false"
8+
colors="true"
9+
convertErrorsToExceptions="true"
10+
convertNoticesToExceptions="true"
11+
convertWarningsToExceptions="true"
12+
processIsolation="false"
13+
stopOnError="false"
14+
stopOnFailure="false"
15+
stopOnIncomplete="false"
16+
stopOnSkipped="false"
17+
syntaxCheck="true"
18+
timeoutForLargeTests="60"
19+
timeoutForMediumTests="10"
20+
timeoutForSmallTests="1"
21+
verbose="false"
22+
>
2323
<php>
24-
<ini name="error_reporting" value="-1" />
24+
<ini name="error_reporting" value="-1"/>
2525
<const name="PHPUNIT_TESTSUITE" value="true"/>
2626
<const name="PHPUNIT_DB_HOST" value="127.0.0.1"/>
2727
<const name="PHPUNIT_DB_NAME" value="telegrambot"/>

src/Commands/AdminCommands/ChatsCommand.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
use Longman\TelegramBot\Commands\AdminCommand;
1414
use Longman\TelegramBot\DB;
1515
use Longman\TelegramBot\Entities\Chat;
16+
use Longman\TelegramBot\Entities\ServerResponse;
17+
use Longman\TelegramBot\Exception\TelegramException;
1618
use Longman\TelegramBot\Request;
1719

1820
class ChatsCommand extends AdminCommand
@@ -45,8 +47,8 @@ class ChatsCommand extends AdminCommand
4547
/**
4648
* Command execute method
4749
*
48-
* @return \Longman\TelegramBot\Entities\ServerResponse
49-
* @throws \Longman\TelegramBot\Exception\TelegramException
50+
* @return ServerResponse
51+
* @throws TelegramException
5052
*/
5153
public function execute()
5254
{

src/Commands/AdminCommands/CleanupCommand.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
use Longman\TelegramBot\Commands\AdminCommand;
1414
use Longman\TelegramBot\DB;
15+
use Longman\TelegramBot\Entities\ServerResponse;
1516
use Longman\TelegramBot\Exception\TelegramException;
1617
use Longman\TelegramBot\Request;
1718
use Longman\TelegramBot\TelegramLog;
@@ -338,7 +339,8 @@ private function getQueries($settings)
338339
/**
339340
* Execution if MySQL is required but not available
340341
*
341-
* @return \Longman\TelegramBot\Entities\ServerResponse
342+
* @return ServerResponse
343+
* @throws TelegramException
342344
*/
343345
public function executeNoDb()
344346
{
@@ -357,8 +359,8 @@ public function executeNoDb()
357359
/**
358360
* Command execute method
359361
*
360-
* @return \Longman\TelegramBot\Entities\ServerResponse
361-
* @throws \Longman\TelegramBot\Exception\TelegramException
362+
* @return ServerResponse
363+
* @throws TelegramException
362364
*/
363365
public function execute()
364366
{

src/Commands/AdminCommands/DebugCommand.php

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
use Longman\TelegramBot\Commands\AdminCommand;
1414
use Longman\TelegramBot\DB;
15+
use Longman\TelegramBot\Exception\TelegramException;
1516
use Longman\TelegramBot\Request;
1617

1718
/**
@@ -43,14 +44,14 @@ class DebugCommand extends AdminCommand
4344
* Command execute method
4445
*
4546
* @return mixed
46-
* @throws \Longman\TelegramBot\Exception\TelegramException
47+
* @throws TelegramException
4748
*/
4849
public function execute()
4950
{
50-
$pdo = DB::getPdo();
51+
$pdo = DB::getPdo();
5152
$message = $this->getMessage();
52-
$chat = $message->getChat();
53-
$text = strtolower($message->getText(true));
53+
$chat = $message->getChat();
54+
$text = strtolower($message->getText(true));
5455

5556
$data = ['chat_id' => $chat->getId()];
5657

@@ -80,15 +81,15 @@ public function execute()
8081
$debug_info[] = sprintf('*Maximum PHP script execution time:* `%d seconds`', ini_get('max_execution_time'));
8182

8283
$mysql_version = $pdo ? $pdo->query('SELECT VERSION() AS version')->fetchColumn() : null;
83-
$debug_info[] = sprintf('*MySQL version:* `%s`', $mysql_version ?: 'disabled');
84+
$debug_info[] = sprintf('*MySQL version:* `%s`', $mysql_version ?: 'disabled');
8485

8586
$debug_info[] = sprintf('*Operating System:* `%s`', php_uname());
8687

8788
if (isset($_SERVER['SERVER_SOFTWARE'])) {
8889
$debug_info[] = sprintf('*Web Server:* `%s`', $_SERVER['SERVER_SOFTWARE']);
8990
}
9091
if (function_exists('curl_init')) {
91-
$curlversion = curl_version();
92+
$curlversion = curl_version();
9293
$debug_info[] = sprintf('*curl version:* `%1$s; %2$s`', $curlversion['version'], $curlversion['ssl_version']);
9394
}
9495

@@ -105,8 +106,8 @@ public function execute()
105106
}
106107

107108
$webhook_info_result_str = json_encode($webhook_info_result, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
108-
$debug_info[] = $webhook_info_title;
109-
$debug_info[] = sprintf(
109+
$debug_info[] = $webhook_info_title;
110+
$debug_info[] = sprintf(
110111
'```' . PHP_EOL . '%s```',
111112
$webhook_info_result_str
112113
);
@@ -116,7 +117,7 @@ public function execute()
116117
}
117118

118119
$data['parse_mode'] = 'Markdown';
119-
$data['text'] = implode(PHP_EOL, $debug_info);
120+
$data['text'] = implode(PHP_EOL, $debug_info);
120121

121122
return Request::sendMessage($data);
122123
}

src/Commands/AdminCommands/SendtoallCommand.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use Longman\TelegramBot\Commands\AdminCommand;
1414
use Longman\TelegramBot\Entities\Message;
1515
use Longman\TelegramBot\Entities\ServerResponse;
16+
use Longman\TelegramBot\Exception\TelegramException;
1617
use Longman\TelegramBot\Request;
1718

1819
/**
@@ -48,8 +49,8 @@ class SendtoallCommand extends AdminCommand
4849
/**
4950
* Execute command
5051
*
51-
* @return \Longman\TelegramBot\Entities\ServerResponse
52-
* @throws \Longman\TelegramBot\Exception\TelegramException
52+
* @return ServerResponse
53+
* @throws TelegramException
5354
*/
5455
public function execute()
5556
{

src/Commands/AdminCommands/SendtochannelCommand.php

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
use Longman\TelegramBot\Entities\Chat;
1616
use Longman\TelegramBot\Entities\Keyboard;
1717
use Longman\TelegramBot\Entities\Message;
18+
use Longman\TelegramBot\Entities\ServerResponse;
19+
use Longman\TelegramBot\Exception\TelegramException;
1820
use Longman\TelegramBot\Request;
1921

2022
class SendtochannelCommand extends AdminCommand
@@ -47,15 +49,15 @@ class SendtochannelCommand extends AdminCommand
4749
/**
4850
* Conversation Object
4951
*
50-
* @var \Longman\TelegramBot\Conversation
52+
* @var Conversation
5153
*/
5254
protected $conversation;
5355

5456
/**
5557
* Command execute method
5658
*
57-
* @return \Longman\TelegramBot\Entities\ServerResponse|mixed
58-
* @throws \Longman\TelegramBot\Exception\TelegramException
59+
* @return ServerResponse|mixed
60+
* @throws TelegramException
5961
*/
6062
public function execute()
6163
{
@@ -272,11 +274,11 @@ public function execute()
272274
* @todo This method will be moved to a higher level maybe in AdminCommand or Command
273275
* @todo Looking for a more significant name
274276
*
275-
* @param \Longman\TelegramBot\Entities\Message $message
276-
* @param array $data
277+
* @param Message $message
278+
* @param array $data
277279
*
278-
* @return \Longman\TelegramBot\Entities\ServerResponse
279-
* @throws \Longman\TelegramBot\Exception\TelegramException
280+
* @return ServerResponse
281+
* @throws TelegramException
280282
*/
281283
protected function sendBack(Message $message, array $data)
282284
{
@@ -311,12 +313,12 @@ protected function sendBack(Message $message, array $data)
311313
/**
312314
* Publish a message to a channel and return success or failure message in markdown format
313315
*
314-
* @param \Longman\TelegramBot\Entities\Message $message
315-
* @param string|int $channel_id
316-
* @param string|null $caption
316+
* @param Message $message
317+
* @param string|int $channel_id
318+
* @param string|null $caption
317319
*
318320
* @return string
319-
* @throws \Longman\TelegramBot\Exception\TelegramException
321+
* @throws TelegramException
320322
*/
321323
protected function publish(Message $message, $channel_id, $caption = null)
322324
{
@@ -351,7 +353,7 @@ protected function publish(Message $message, $channel_id, $caption = null)
351353
* @todo Why send just to the first found channel?
352354
*
353355
* @return mixed
354-
* @throws \Longman\TelegramBot\Exception\TelegramException
356+
* @throws TelegramException
355357
*/
356358
public function executeNoDb()
357359
{

src/Commands/AdminCommands/WhoisCommand.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@
1616
use Longman\TelegramBot\DB;
1717
use Longman\TelegramBot\Entities\Chat;
1818
use Longman\TelegramBot\Entities\PhotoSize;
19+
use Longman\TelegramBot\Entities\ServerResponse;
1920
use Longman\TelegramBot\Entities\UserProfilePhotos;
21+
use Longman\TelegramBot\Exception\TelegramException;
2022
use Longman\TelegramBot\Request;
2123

2224
/**
@@ -52,8 +54,8 @@ class WhoisCommand extends AdminCommand
5254
/**
5355
* Command execute method
5456
*
55-
* @return \Longman\TelegramBot\Entities\ServerResponse
56-
* @throws \Longman\TelegramBot\Exception\TelegramException
57+
* @return ServerResponse
58+
* @throws TelegramException
5759
*/
5860
public function execute()
5961
{

0 commit comments

Comments
 (0)