Skip to content

Commit 639508a

Browse files
cleancode ingnore ElseExpression warming.
fix BooleanArgumentFlag The - [x] method getText has a boolean flag argument $without_cmd, which is a certain sign of a Single Responsibility Principle violation. - [x] The method printError has a boolean flag argument $return, which is a certain sign of a Single Responsibility Principle violation. - [x] The method printError has a boolean flag argument $return, which is a certain sign of a Single Responsibility Principle violation.
1 parent 50ef48f commit 639508a

File tree

10 files changed

+20
-18
lines changed

10 files changed

+20
-18
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -210,14 +210,14 @@ use TelegramBot\Entities\WebAppData;
210210
class MainPlugin extends \TelegramBot\Plugin {
211211

212212
public function onMessage(int $update_id, Message $message): \Generator {
213-
if ($message->getText() === '/start') {
213+
if ($message->getText(false) === '/start') {
214214
yield \TelegramBot\Request::sendMessage([
215215
'chat_id' => $message->getChat()->getId(),
216216
'text' => 'Hello, ' . $message->getFrom()->getFirstName(),
217217
]);
218218
}
219219

220-
if ($message->getText() === '/ping') {
220+
if ($message->getText(false) === '/ping') {
221221
yield \TelegramBot\Request::sendMessage([
222222
'chat_id' => $message->getChat()->getId(),
223223
'text' => 'pong',
@@ -249,7 +249,7 @@ $commands = new class() extends \TelegramBot\Plugin {
249249
$admin = new class() extends \TelegramBot\Plugin {
250250

251251
// TODO: Write your code here
252-
252+
253253
};
254254

255255
(new \TelegramBot\UpdateHandler())->addPlugins([$commands, $admin])->resolve();
@@ -319,4 +319,4 @@ or just email [opensource@litehex.com](mailto:opensource@litehex.com).
319319
## License
320320

321321
The Telegram-Bot-PHP library is open-sourced under
322-
the [MIT license](https://github.com/telegram-bot-php/core/blob/master/LICENSE).
322+
the [MIT license](https://github.com/telegram-bot-php/core/blob/master/LICENSE).

phpmd.xml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,7 @@
2727

2828
<rule ref="rulesets/design.xml" />
2929

30-
<rule ref="rulesets/cleancode.xml" />
30+
<rule ref="rulesets/cleancode.xml" >
31+
<exclude name="ElseExpression"></exclude>
32+
</rule>
3133
</ruleset>

src/Entities/Keyboard.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public function setKeyboard(array $rows): array
7272
$this->addRow($row);
7373
}
7474

75-
return $this->getRawData();
75+
return $this->getRawData(true);
7676
}
7777

7878
/**
@@ -91,7 +91,7 @@ public function addRow(array $row): Keyboard
9191

9292
$new_row = [];
9393
foreach ($row as $button) {
94-
$new_row[] = $button->getRawData();
94+
$new_row[] = $button->getRawData(true);
9595
}
9696

9797
$this->raw_data[$keyboard_type][] = $new_row;

src/Entities/Message.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ class Message extends Entity
8585
*
8686
* @return string|null
8787
*/
88-
public function getText(bool $without_cmd = false): ?string
88+
public function getText(bool $without_cmd): ?string
8989
{
9090
$text = $this->getProperty('text');
9191
$command = $this->getFullCommand();

src/Entities/Response.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public function isOk(): bool
7474
* @param bool $return
7575
* @return bool|string
7676
*/
77-
public function printError(bool $return = false): bool|string
77+
public function printError(bool $return): bool|string
7878
{
7979
$error = sprintf('Error N: %s, Description: %s', $this->getErrorCode(), $this->getDescription());
8080

src/Entity.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public static function escapeMarkdownV2(string $string): string {
9292
* @param bool $associated
9393
* @return array|string
9494
*/
95-
public function getRawData(bool $associated = true): array|string {
95+
public function getRawData(bool $associated): array|string {
9696
return $associated ? $this->raw_data : json_encode($this->raw_data);
9797
}
9898

src/Request.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ private static function getClient(): Client {
371371
*/
372372
private static function getItemEncode($item): string {
373373
if ($item instanceof Entity) {
374-
$item = $item->getRawData();
374+
$item = $item->getRawData(true);
375375
}
376376

377377
if (is_array($item)) {

tests/CrashTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public function __process(Update $update): void {
2525
CrashPad::sendCrash(
2626
Telegram::getAdminId(),
2727
new \Exception('test'),
28-
json_encode($update->getRawData(), JSON_PRETTY_PRINT)
28+
json_encode($update->getRawData(true), JSON_PRETTY_PRINT)
2929
);
3030
CrashPad::clearCrashLogs();
3131
}

tests/Examples/EchoBot/Plugins/MainPlugin.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
class MainPlugin extends \TelegramBot\Plugin {
99

1010
public function onMessage(int $updateId, Message $message): \Generator {
11-
echo "UpdateId: " . $updateId . ", Text: " . $message->getText();
11+
echo "UpdateId: " . $updateId . ", Text: " . $message->getText(false);
1212
yield;
1313
}
1414

15-
}
15+
}

tests/WebhookTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public function __construct(TestCase $testCase) {
2121

2222
public function onMessage(int $update_id, Message $message): \Generator {
2323
$this->testCase->assertEquals(1, $update_id);
24-
$this->testCase->assertEquals('Hello World!', $message->getText());
24+
$this->testCase->assertEquals('Hello World!', $message->getText(false));
2525
yield;
2626
}
2727

@@ -32,7 +32,7 @@ public function onMessage(int $update_id, Message $message): \Generator {
3232

3333
(new UpdateHandler())->addPlugins($plugin)->resolve(new Update([
3434
'update_id' => 1,
35-
'message' => $message->getRawData(),
35+
'message' => $message->getRawData(true),
3636
]));
3737
}
3838

@@ -57,10 +57,10 @@ public function __process(Update $update): void {
5757

5858
$handler->resolve(new Update([
5959
'update_id' => 1,
60-
'message' => DummyUpdate::message()->getRawData(),
60+
'message' => DummyUpdate::message()->getRawData(true),
6161
]));
6262

6363
$this->assertTrue(true);
6464
}
6565

66-
}
66+
}

0 commit comments

Comments
 (0)