Skip to content

Commit c7f3fed

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 b0594df commit c7f3fed

File tree

10 files changed

+17
-13
lines changed

10 files changed

+17
-13
lines changed

README.md

Lines changed: 2 additions & 2 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',

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: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@ public function onMessage(int $update_id, Message $message): \Generator {
1515
}
1616

1717
}
18+

tests/WebhookTest.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public function testAnonymousPlugins() {
1515

1616
public function onMessage(int $update_id, Message $message): \Generator {
1717
Assert::assertEquals(1, $update_id);
18-
Assert::assertEquals('Hello World!', $message->getText());
18+
Assert::assertEquals('Hello World!', $message->getText(false));
1919
yield;
2020
}
2121

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

2727
(new UpdateHandler())->addPlugins($plugin)->resolve(new Update([
2828
'update_id' => 1,
29-
'message' => $message->getRawData(),
29+
'message' => $message->getRawData(true),
3030
]));
3131
}
3232

@@ -46,10 +46,11 @@ public function __process(Update $update): void {
4646

4747
$handler->resolve(new Update([
4848
'update_id' => 1,
49-
'message' => DummyUpdate::message()->getRawData(),
49+
'message' => DummyUpdate::message()->getRawData(true),
5050
]));
5151

5252
$this->assertTrue(true);
5353
}
5454

5555
}
56+

0 commit comments

Comments
 (0)