Skip to content

Commit 50ef48f

Browse files
cleancode fix IfStatementAssignment warning message "Avoid assigning values to variables in if clauses and the like ..."
1 parent c3f2f27 commit 50ef48f

File tree

5 files changed

+20
-8
lines changed

5 files changed

+20
-8
lines changed

src/CrashPad.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,9 @@ public static function sendCrash(int $chat_id, Exception|Throwable $exception, s
8383
Telegram::tryAutoloadEnv();
8484
}
8585

86-
if (($token = self::loadToken()) === null) {
86+
$token = self::loadToken();
87+
88+
if ($token === null) {
8789
throw new RuntimeException(
8890
'The token is not set. Please set the token using `Telegram::setToken()` method.'
8991
);
@@ -180,7 +182,9 @@ public static function clearCrashLogs(): void
180182
*/
181183
protected static function loadToken(): string|null
182184
{
183-
if (($token = Telegram::getApiToken()) !== false) {
185+
$token = Telegram::getApiToken();
186+
187+
if ($token !== false) {
184188
return $token;
185189
}
186190

src/Entities/Message.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,9 @@ class Message extends Entity
8888
public function getText(bool $without_cmd = false): ?string
8989
{
9090
$text = $this->getProperty('text');
91+
$command = $this->getFullCommand();
9192

92-
if ($without_cmd && $command = $this->getFullCommand()) {
93+
if ($without_cmd && $command) {
9394
if (strlen($command) + 1 < strlen($text)) {
9495
return substr($text, strlen($command) + 1);
9596
}
@@ -201,7 +202,9 @@ public function getType(): string
201202
*/
202203
public function getCommand(): ?string
203204
{
204-
if ($command = $this->getProperty('command')) {
205+
$command = $this->getProperty('command');
206+
207+
if ($command) {
205208
return $command;
206209
}
207210

src/Entities/UserProfilePhotos.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,9 @@ class UserProfilePhotos extends Entity
2525
public function getPhotos(): array
2626
{
2727
$all_photos = [];
28+
$these_photos = $this->getProperty('photos');
2829

29-
if ($these_photos = $this->getProperty('photos')) {
30+
if ($these_photos) {
3031
foreach ($these_photos as $photos) {
3132
$all_photos[] = array_map(function ($photo) {
3233
return new PhotoSize($photo);

src/TelegramLog.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,9 @@ public static function initialize(LoggerInterface $logger = null, LoggerInterfac
7979
*/
8080
public static function getDebugLogTempStream()
8181
{
82-
if ((self::$debug_log_temp_stream_handle === null) && $temp_stream_handle = fopen('php://temp', 'wb+')) {
82+
$temp_stream_handle = fopen('php://temp', 'wb+');
83+
84+
if ((self::$debug_log_temp_stream_handle === null) && $temp_stream_handle) {
8385
self::$debug_log_temp_stream_handle = $temp_stream_handle;
8486
}
8587

src/Traits/PluginTrait.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,9 @@ public function __execute(UpdateHandler $receiver, Update $update): void {
5353
}
5454

5555
$type = $this->__identify($update);
56-
if (method_exists($this, ($method = 'on' . $type)) && $type !== null) {
56+
$method = 'on' . $type;
57+
58+
if (method_exists($this, $method) && $type !== null) {
5759
$this->__checkExit($this->__callEvent($method, $update));
5860
}
5961
}
@@ -110,4 +112,4 @@ private function __callEvent(string $method, Update $update): \Generator {
110112
};
111113
}
112114

113-
}
115+
}

0 commit comments

Comments
 (0)