Skip to content

Commit 151a809

Browse files
committed
Fixes
1 parent 77ce9de commit 151a809

File tree

93 files changed

+468
-465
lines changed

Some content is hidden

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

93 files changed

+468
-465
lines changed

‎.php-cs-fixer.dist.php

+6
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ public function getRules(): array
88
'array_indentation' => true,
99
'ternary_to_null_coalescing' => true,
1010
'assign_null_coalescing_to_coalesce_equal' => true,
11+
'@PHP82Migration' => true,
12+
'@PHP81Migration' => true,
13+
'@PHP80Migration' => true,
14+
'@PHP80Migration:risky' => true,
15+
'static_lambda' => true,
16+
'strict_param' => true,
1117
"native_function_invocation" => ['include' => ['@compiler_optimized'], 'scope' => 'namespaced'],
1218
]);
1319
}

‎docs

Submodule docs updated 64 files

‎examples/bot.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ class MyEventHandler extends SimpleEventHandler
6969
/**
7070
* @var int|string Username or ID of bot admin
7171
*/
72-
const ADMIN = "@me"; // !!! Change this to your username !!!
72+
public const ADMIN = "@me"; // !!! Change this to your username !!!
7373

7474
/**
7575
* @var array<int, bool>
@@ -112,7 +112,7 @@ public static function getPlugins(): array
112112
return [
113113
// Offers a /restart command to admins that can be used to restart the bot, applying changes.
114114
// Make sure to run in a bash while loop when running via CLI to allow self-restarts.
115-
RestartPlugin::class
115+
RestartPlugin::class,
116116
];
117117
}
118118

@@ -185,9 +185,9 @@ public function dlStoriesCommand(Message $message): void
185185

186186
$stories = $this->stories->getUserStories(user_id: $message->commandArgs[0])['stories']['stories'];
187187
// Skip deleted stories
188-
$stories = array_filter($stories, fn (array $s): bool => $s['_'] === 'storyItem');
188+
$stories = array_filter($stories, static fn (array $s): bool => $s['_'] === 'storyItem');
189189
// Sort by date
190-
usort($stories, fn ($a, $b) => $a['date'] <=> $b['date']);
190+
usort($stories, static fn ($a, $b) => $a['date'] <=> $b['date']);
191191

192192
$result = "Total stories: ".count($stories)."\n\n";
193193
foreach ($stories as $story) {

‎examples/combinedBot.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class MyEventHandler extends EventHandler
4141
/**
4242
* @var int|string Username or ID of bot admin
4343
*/
44-
const ADMIN = "danogentili"; // Change this
44+
public const ADMIN = "danogentili"; // Change this
4545
/**
4646
* Get peer(s) where to report errors.
4747
*

‎examples/downloadRenameBot.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
*/
4444
class MyEventHandler extends EventHandler
4545
{
46-
const START = "Send me a file URL and I will download it and send it to you!\n\n".
46+
public const START = "Send me a file URL and I will download it and send it to you!\n\n".
4747
"Usage: `https://example.com`\n".
4848
"Usage: `https://example.com file name.ext`\n\n".
4949
"I can also rename Telegram files, just send me any file and I will rename it!\n\n".
@@ -52,7 +52,7 @@ class MyEventHandler extends EventHandler
5252
/**
5353
* @var int|string Username or ID of bot admin
5454
*/
55-
const ADMIN = 'danogentili'; // Change this
55+
public const ADMIN = 'danogentili'; // Change this
5656

5757
/**
5858
* Get peer(s) where to report errors.
@@ -149,7 +149,7 @@ function ($progress, $speed, $time) use ($peerId, $id): void {
149149

150150
$msg->delete();
151151
} catch (Throwable $e) {
152-
if (strpos($e->getMessage(), 'Could not connect to URI') === false && !($e instanceof UriException) && strpos($e->getMessage(), 'URI') === false) {
152+
if (!str_contains($e->getMessage(), 'Could not connect to URI') && !($e instanceof UriException) && !str_contains($e->getMessage(), 'URI')) {
153153
$this->report((string) $e);
154154
$this->logger((string) $e, Logger::FATAL_ERROR);
155155
}

‎examples/secret_bot.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class SecretHandler extends SimpleEventHandler
4646
/**
4747
* @var int|string Username or ID of bot admin
4848
*/
49-
const ADMIN = "danogentili"; // Change this
49+
public const ADMIN = "danogentili"; // Change this
5050
/**
5151
* Get peer(s) where to report errors.
5252
*

‎examples/simpleBot.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
class MyEventHandler extends SimpleEventHandler
2828
{
2929
// !!! Change this to your username !!!
30-
const ADMIN = "@me";
30+
public const ADMIN = "@me";
3131

3232
/**
3333
* Get peer(s) where to report errors.
@@ -47,7 +47,7 @@ public static function getPlugins(): array
4747
return [
4848
// Offers a /restart command to admins that can be used to restart the bot, applying changes.
4949
// Make sure to run in a bash while loop when running via CLI to allow self-restarts.
50-
RestartPlugin::class
50+
RestartPlugin::class,
5151
];
5252
}
5353

‎examples/tgstories_dl_bot.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -124,11 +124,11 @@ public function dlStoriesCommand(Message $message): void
124124

125125
$stories = $this->userInstance->stories->getUserStories(user_id: $message->commandArgs[0])['stories']['stories'];
126126
// Skip deleted stories
127-
$stories = array_filter($stories, fn (array $s): bool => $s['_'] === 'storyItem');
127+
$stories = array_filter($stories, static fn (array $s): bool => $s['_'] === 'storyItem');
128128
// Skip protected stories
129-
$stories = array_filter($stories, fn (array $s): bool => !$s['noforwards']);
129+
$stories = array_filter($stories, static fn (array $s): bool => !$s['noforwards']);
130130
// Sort by date
131-
usort($stories, fn ($a, $b) => $a['date'] <=> $b['date']);
131+
usort($stories, static fn ($a, $b) => $a['date'] <=> $b['date']);
132132

133133
$result = "Total stories: ".count($stories)."\n\n";
134134
foreach ($stories as $story) {

‎src/API.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ public static function startAndLoopMulti(array $instances, array|string $eventHa
415415

416416
$prev = EventLoop::getErrorHandler();
417417
EventLoop::setErrorHandler(
418-
$cb = function (Throwable $e) use ($instanceOne, &$errors, &$started, $eventHandler): void {
418+
$cb = static function (Throwable $e) use ($instanceOne, &$errors, &$started, $eventHandler): void {
419419
if ($e instanceof UnhandledFutureError) {
420420
$e = $e->getPrevious();
421421
}
@@ -442,7 +442,7 @@ public static function startAndLoopMulti(array $instances, array|string $eventHa
442442
$promises = [];
443443
foreach ($instances as $k => $instance) {
444444
$instance->start();
445-
$promises []= async(function () use ($k, $instance, $eventHandler, &$started): void {
445+
$promises []= async(static function () use ($k, $instance, $eventHandler, &$started): void {
446446
$instance->startAndLoopLogic($eventHandler[$k], $started[$k]);
447447
});
448448
}

‎src/AnnotationsBuilder.php

+10-10
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ private function filterParams(array $params, string $type, ?string $method = nul
322322
}
323323
$newParams[$param['name']] = $param;
324324
}
325-
uasort($newParams, fn (array $arr1, array $arr2) => isset($arr1['pow']) <=> isset($arr2['pow']));
325+
uasort($newParams, static fn (array $arr1, array $arr2) => isset($arr1['pow']) <=> isset($arr2['pow']));
326326
return $newParams;
327327
}
328328
private function prepareTLParams(array $data): array
@@ -418,14 +418,14 @@ private function createInternalClasses(): void
418418
foreach ($methods as $key => $method) {
419419
$name = $method->getName();
420420
if ($name == 'methodCallAsyncRead') {
421-
unset($methods[array_search('methodCall', $methods)]);
422-
} elseif (strpos($name, '__') === 0) {
421+
unset($methods[array_search('methodCall', $methods, true)]);
422+
} elseif (str_starts_with($name, '__')) {
423423
unset($methods[$key]);
424424
} elseif (stripos($name, 'async') !== false) {
425-
if (strpos($name, '_async') !== false) {
426-
unset($methods[array_search(str_ireplace('_async', '', $name), $methods)]);
425+
if (str_contains($name, '_async')) {
426+
unset($methods[array_search(str_ireplace('_async', '', $name), $methods, true)]);
427427
} else {
428-
unset($methods[array_search(str_ireplace('async', '', $name), $methods)]);
428+
unset($methods[array_search(str_ireplace('async', '', $name), $methods, true)]);
429429
}
430430
}
431431
}
@@ -439,21 +439,21 @@ private function createInternalClasses(): void
439439

440440
foreach ($methods as $method) {
441441
$name = $method->getName();
442-
if (strpos($method->getDocComment() ?: '', '@internal') !== false) {
442+
if (str_contains($method->getDocComment() ?: '', '@internal')) {
443443
continue;
444444
}
445445
$static = $method->isStatic();
446446
if (!$static) {
447447
$code = file_get_contents($method->getFileName());
448448
$code = implode("\n", \array_slice(explode("\n", $code), $method->getStartLine(), $method->getEndLine() - $method->getStartLine()));
449-
if (strpos($code, '$this') === false) {
449+
if (!str_contains($code, '$this')) {
450450
Logger::log("{$name} should be STATIC!", Logger::FATAL_ERROR);
451451
}
452452
}
453453
if ($name == 'methodCallAsyncRead') {
454454
$name = 'methodCall';
455455
} elseif (stripos($name, 'async') !== false) {
456-
if (strpos($name, '_async') !== false) {
456+
if (str_contains($name, '_async')) {
457457
$name = str_ireplace('_async', '', $name);
458458
} else {
459459
$name = str_ireplace('async', '', $name);
@@ -629,7 +629,7 @@ protected function exportNamespaces(): void
629629
fwrite($handle, "/** @internal An internal interface used to avoid type errors when using simple filters. */\n");
630630
fwrite($handle, "interface SimpleFilters extends ");
631631
/** @psalm-suppress UndefinedClass */
632-
fwrite($handle, implode(", ", array_map(fn ($s) => "\\$s", ClassFinder::getClassesInNamespace(\danog\MadelineProto\EventHandler\SimpleFilter::class, ClassFinder::RECURSIVE_MODE|ClassFinder::ALLOW_INTERFACES))));
632+
fwrite($handle, implode(", ", array_map(static fn ($s) => "\\$s", ClassFinder::getClassesInNamespace(\danog\MadelineProto\EventHandler\SimpleFilter::class, ClassFinder::RECURSIVE_MODE|ClassFinder::ALLOW_INTERFACES))));
633633
fwrite($handle, "{}\n");
634634
}
635635

‎src/AsyncTools.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ abstract class AsyncTools extends StrTools
4848
*/
4949
public static function rethrow(Throwable $e): void
5050
{
51-
EventLoop::queue(fn () => throw $e);
51+
EventLoop::queue(static fn () => throw $e);
5252
}
5353
/**
5454
* Fork a new green thread and execute the passed function in the background.
@@ -133,7 +133,7 @@ public static function getTimeoutCancellation(float $timeout, string $message =
133133
{
134134
$e = new TimeoutException($message);
135135
$deferred = new DeferredCancellation;
136-
EventLoop::delay($timeout, fn () => $deferred->cancel($e));
136+
EventLoop::delay($timeout, static fn () => $deferred->cancel($e));
137137
return $deferred->getCancellation();
138138
}
139139

‎src/Broadcast/Action/ActionForward.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public function act(int $broadcastId, int $peer, Cancellation $cancellation): vo
6363
'unpin' => false,
6464
'pm_oneside' => false,
6565
'floodWaitLimit' => 2*86400,
66-
'cancellation' => $cancellation
66+
'cancellation' => $cancellation,
6767
],
6868
);
6969
} catch (RPCErrorException) {

‎src/Connection.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ private function connect(): self
304304
foreach ($this->new_outgoing as $message_id => $message) {
305305
if ($message->unencrypted) {
306306
if (!($message->getState() & MTProtoOutgoingMessage::STATE_REPLIED)) {
307-
$message->reply(fn () => new Exception('Restart because we were reconnected'));
307+
$message->reply(static fn () => new Exception('Restart because we were reconnected'));
308308
}
309309
unset($this->new_outgoing[$message_id], $this->outgoing_messages[$message_id]);
310310
}
@@ -527,7 +527,7 @@ private function methodAbstractions(string &$method, array &$arguments): void
527527
$arguments['reply_to'] = [
528528
'_' => 'inputReplyToMessage',
529529
'reply_to_msg_id' => $arguments['reply_to_msg_id'],
530-
'top_msg_id' => $arguments['top_msg_id'] ?? null
530+
'top_msg_id' => $arguments['top_msg_id'] ?? null,
531531
];
532532
unset($arguments['reply_to_msg_id'], $arguments['top_msg_id']);
533533
}

0 commit comments

Comments
 (0)