Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
danog committed Nov 11, 2023
1 parent 77ce9de commit 151a809
Show file tree
Hide file tree
Showing 93 changed files with 468 additions and 465 deletions.
6 changes: 6 additions & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ public function getRules(): array
'array_indentation' => true,
'ternary_to_null_coalescing' => true,
'assign_null_coalescing_to_coalesce_equal' => true,
'@PHP82Migration' => true,
'@PHP81Migration' => true,
'@PHP80Migration' => true,
'@PHP80Migration:risky' => true,
'static_lambda' => true,
'strict_param' => true,
"native_function_invocation" => ['include' => ['@compiler_optimized'], 'scope' => 'namespaced'],
]);
}
Expand Down
2 changes: 1 addition & 1 deletion docs
Submodule docs updated 64 files
+30 −0 docs/PHP/danog/MadelineProto/EventHandler/AbstractMessage.md
+30 −0 docs/PHP/danog/MadelineProto/EventHandler/AbstractPrivateMessage.md
+23 −0 docs/PHP/danog/MadelineProto/EventHandler/BotCommands.md
+23 −0 docs/PHP/danog/MadelineProto/EventHandler/Channel/MessageForwards.md
+23 −0 docs/PHP/danog/MadelineProto/EventHandler/Channel/MessageViewsChanged.md
+21 −0 docs/PHP/danog/MadelineProto/EventHandler/Channel/UpdateChannel.md
+35 −0 docs/PHP/danog/MadelineProto/EventHandler/ChatInvite.md
+48 −0 docs/PHP/danog/MadelineProto/EventHandler/ChatInvite/ChatInviteExported.md
+35 −0 docs/PHP/danog/MadelineProto/EventHandler/ChatInvite/ChatInvitePublicJoin.md
+21 −0 docs/PHP/danog/MadelineProto/EventHandler/ChatInviteRequester.md
+25 −0 docs/PHP/danog/MadelineProto/EventHandler/ChatInviteRequester/BotChatInviteRequest.md
+23 −0 docs/PHP/danog/MadelineProto/EventHandler/ChatInviteRequester/PendingJoinRequests.md
+22 −0 docs/PHP/danog/MadelineProto/EventHandler/Command.md
+21 −0 docs/PHP/danog/MadelineProto/EventHandler/Delete.md
+22 −0 docs/PHP/danog/MadelineProto/EventHandler/Delete/DeleteChannelMessages.md
+21 −0 docs/PHP/danog/MadelineProto/EventHandler/Delete/DeleteMessages.md
+22 −0 docs/PHP/danog/MadelineProto/EventHandler/Delete/DeleteScheduledMessages.md
+30 −0 docs/PHP/danog/MadelineProto/EventHandler/Message.md
+30 −0 docs/PHP/danog/MadelineProto/EventHandler/Message/ChannelMessage.md
+30 −0 docs/PHP/danog/MadelineProto/EventHandler/Message/GroupMessage.md
+30 −0 docs/PHP/danog/MadelineProto/EventHandler/Message/PrivateMessage.md
+30 −0 docs/PHP/danog/MadelineProto/EventHandler/Message/SecretMessage.md
+30 −0 docs/PHP/danog/MadelineProto/EventHandler/Message/Service/DialogBotAllowed.md
+30 −0 docs/PHP/danog/MadelineProto/EventHandler/Message/Service/DialogChannelCreated.md
+30 −0 docs/PHP/danog/MadelineProto/EventHandler/Message/Service/DialogChannelMigrateFrom.md
+30 −0 docs/PHP/danog/MadelineProto/EventHandler/Message/Service/DialogChatJoinedByLink.md
+30 −0 docs/PHP/danog/MadelineProto/EventHandler/Message/Service/DialogChatMigrateTo.md
+30 −0 docs/PHP/danog/MadelineProto/EventHandler/Message/Service/DialogContactSignUp.md
+30 −0 docs/PHP/danog/MadelineProto/EventHandler/Message/Service/DialogCreated.md
+30 −0 docs/PHP/danog/MadelineProto/EventHandler/Message/Service/DialogDeleteMessages.md
+30 −0 docs/PHP/danog/MadelineProto/EventHandler/Message/Service/DialogGameScore.md
+30 −0 docs/PHP/danog/MadelineProto/EventHandler/Message/Service/DialogGeoProximityReached.md
+30 −0 docs/PHP/danog/MadelineProto/EventHandler/Message/Service/DialogGiftPremium.md
+30 −0 docs/PHP/danog/MadelineProto/EventHandler/Message/Service/DialogGroupCall.md
+30 −0 docs/PHP/danog/MadelineProto/EventHandler/Message/Service/DialogGroupCall/GroupCall.md
+30 −0 docs/PHP/danog/MadelineProto/EventHandler/Message/Service/DialogGroupCall/GroupCallInvited.md
+30 −0 docs/PHP/danog/MadelineProto/EventHandler/Message/Service/DialogGroupCall/GroupCallScheduled.md
+30 −0 docs/PHP/danog/MadelineProto/EventHandler/Message/Service/DialogHistoryCleared.md
+30 −0 docs/PHP/danog/MadelineProto/EventHandler/Message/Service/DialogMemberJoinedByRequest.md
+30 −0 docs/PHP/danog/MadelineProto/EventHandler/Message/Service/DialogMemberLeft.md
+30 −0 docs/PHP/danog/MadelineProto/EventHandler/Message/Service/DialogMembersJoined.md
+30 −0 docs/PHP/danog/MadelineProto/EventHandler/Message/Service/DialogMessagePinned.md
+30 −0 docs/PHP/danog/MadelineProto/EventHandler/Message/Service/DialogPeerRequested.md
+30 −0 docs/PHP/danog/MadelineProto/EventHandler/Message/Service/DialogPhoneCall.md
+30 −0 docs/PHP/danog/MadelineProto/EventHandler/Message/Service/DialogPhotoChanged.md
+30 −0 docs/PHP/danog/MadelineProto/EventHandler/Message/Service/DialogReadMessages.md
+30 −0 docs/PHP/danog/MadelineProto/EventHandler/Message/Service/DialogScreenshotTaken.md
+30 −0 docs/PHP/danog/MadelineProto/EventHandler/Message/Service/DialogSetChatTheme.md
+30 −0 docs/PHP/danog/MadelineProto/EventHandler/Message/Service/DialogSetChatWallPaper.md
+30 −0 docs/PHP/danog/MadelineProto/EventHandler/Message/Service/DialogSetTTL.md
+30 −0 docs/PHP/danog/MadelineProto/EventHandler/Message/Service/DialogSuggestProfilePhoto.md
+30 −0 docs/PHP/danog/MadelineProto/EventHandler/Message/Service/DialogTitleChanged.md
+30 −0 docs/PHP/danog/MadelineProto/EventHandler/Message/Service/DialogTopicCreated.md
+30 −0 docs/PHP/danog/MadelineProto/EventHandler/Message/Service/DialogTopicEdited.md
+30 −0 docs/PHP/danog/MadelineProto/EventHandler/Message/Service/DialogWebView.md
+30 −0 docs/PHP/danog/MadelineProto/EventHandler/Message/ServiceMessage.md
+23 −0 docs/PHP/danog/MadelineProto/EventHandler/Pinned.md
+23 −0 docs/PHP/danog/MadelineProto/EventHandler/Pinned/PinnedChannelMessages.md
+23 −0 docs/PHP/danog/MadelineProto/EventHandler/Pinned/PinnedGroupMessages.md
+23 −0 docs/PHP/danog/MadelineProto/EventHandler/Pinned/PinnedPrivateMessages.md
+19 −0 docs/PHP/index.md
+45 −0 docs/docs/FILTERS.md
+45 −0 docs/docs/UPDATES.md
+5 −0 docs/index.md
8 changes: 4 additions & 4 deletions examples/bot.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class MyEventHandler extends SimpleEventHandler
/**
* @var int|string Username or ID of bot admin
*/
const ADMIN = "@me"; // !!! Change this to your username !!!
public const ADMIN = "@me"; // !!! Change this to your username !!!

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

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

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

$result = "Total stories: ".count($stories)."\n\n";
foreach ($stories as $story) {
Expand Down
2 changes: 1 addition & 1 deletion examples/combinedBot.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class MyEventHandler extends EventHandler
/**
* @var int|string Username or ID of bot admin
*/
const ADMIN = "danogentili"; // Change this
public const ADMIN = "danogentili"; // Change this
/**
* Get peer(s) where to report errors.
*
Expand Down
6 changes: 3 additions & 3 deletions examples/downloadRenameBot.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
*/
class MyEventHandler extends EventHandler
{
const START = "Send me a file URL and I will download it and send it to you!\n\n".
public const START = "Send me a file URL and I will download it and send it to you!\n\n".
"Usage: `https://example.com`\n".
"Usage: `https://example.com file name.ext`\n\n".
"I can also rename Telegram files, just send me any file and I will rename it!\n\n".
Expand All @@ -52,7 +52,7 @@ class MyEventHandler extends EventHandler
/**
* @var int|string Username or ID of bot admin
*/
const ADMIN = 'danogentili'; // Change this
public const ADMIN = 'danogentili'; // Change this

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

$msg->delete();
} catch (Throwable $e) {
if (strpos($e->getMessage(), 'Could not connect to URI') === false && !($e instanceof UriException) && strpos($e->getMessage(), 'URI') === false) {
if (!str_contains($e->getMessage(), 'Could not connect to URI') && !($e instanceof UriException) && !str_contains($e->getMessage(), 'URI')) {
$this->report((string) $e);
$this->logger((string) $e, Logger::FATAL_ERROR);
}
Expand Down
2 changes: 1 addition & 1 deletion examples/secret_bot.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class SecretHandler extends SimpleEventHandler
/**
* @var int|string Username or ID of bot admin
*/
const ADMIN = "danogentili"; // Change this
public const ADMIN = "danogentili"; // Change this
/**
* Get peer(s) where to report errors.
*
Expand Down
4 changes: 2 additions & 2 deletions examples/simpleBot.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
class MyEventHandler extends SimpleEventHandler
{
// !!! Change this to your username !!!
const ADMIN = "@me";
public const ADMIN = "@me";

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

Expand Down
6 changes: 3 additions & 3 deletions examples/tgstories_dl_bot.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,11 @@ public function dlStoriesCommand(Message $message): void

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

$result = "Total stories: ".count($stories)."\n\n";
foreach ($stories as $story) {
Expand Down
4 changes: 2 additions & 2 deletions src/API.php
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ public static function startAndLoopMulti(array $instances, array|string $eventHa

$prev = EventLoop::getErrorHandler();
EventLoop::setErrorHandler(
$cb = function (Throwable $e) use ($instanceOne, &$errors, &$started, $eventHandler): void {
$cb = static function (Throwable $e) use ($instanceOne, &$errors, &$started, $eventHandler): void {
if ($e instanceof UnhandledFutureError) {
$e = $e->getPrevious();
}
Expand All @@ -442,7 +442,7 @@ public static function startAndLoopMulti(array $instances, array|string $eventHa
$promises = [];
foreach ($instances as $k => $instance) {
$instance->start();
$promises []= async(function () use ($k, $instance, $eventHandler, &$started): void {
$promises []= async(static function () use ($k, $instance, $eventHandler, &$started): void {
$instance->startAndLoopLogic($eventHandler[$k], $started[$k]);
});
}
Expand Down
20 changes: 10 additions & 10 deletions src/AnnotationsBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ private function filterParams(array $params, string $type, ?string $method = nul
}
$newParams[$param['name']] = $param;
}
uasort($newParams, fn (array $arr1, array $arr2) => isset($arr1['pow']) <=> isset($arr2['pow']));
uasort($newParams, static fn (array $arr1, array $arr2) => isset($arr1['pow']) <=> isset($arr2['pow']));
return $newParams;
}
private function prepareTLParams(array $data): array
Expand Down Expand Up @@ -418,14 +418,14 @@ private function createInternalClasses(): void
foreach ($methods as $key => $method) {
$name = $method->getName();
if ($name == 'methodCallAsyncRead') {
unset($methods[array_search('methodCall', $methods)]);
} elseif (strpos($name, '__') === 0) {
unset($methods[array_search('methodCall', $methods, true)]);
} elseif (str_starts_with($name, '__')) {
unset($methods[$key]);
} elseif (stripos($name, 'async') !== false) {
if (strpos($name, '_async') !== false) {
unset($methods[array_search(str_ireplace('_async', '', $name), $methods)]);
if (str_contains($name, '_async')) {
unset($methods[array_search(str_ireplace('_async', '', $name), $methods, true)]);
} else {
unset($methods[array_search(str_ireplace('async', '', $name), $methods)]);
unset($methods[array_search(str_ireplace('async', '', $name), $methods, true)]);
}
}
}
Expand All @@ -439,21 +439,21 @@ private function createInternalClasses(): void

foreach ($methods as $method) {
$name = $method->getName();
if (strpos($method->getDocComment() ?: '', '@internal') !== false) {
if (str_contains($method->getDocComment() ?: '', '@internal')) {
continue;
}
$static = $method->isStatic();
if (!$static) {
$code = file_get_contents($method->getFileName());
$code = implode("\n", \array_slice(explode("\n", $code), $method->getStartLine(), $method->getEndLine() - $method->getStartLine()));
if (strpos($code, '$this') === false) {
if (!str_contains($code, '$this')) {
Logger::log("{$name} should be STATIC!", Logger::FATAL_ERROR);
}
}
if ($name == 'methodCallAsyncRead') {
$name = 'methodCall';
} elseif (stripos($name, 'async') !== false) {
if (strpos($name, '_async') !== false) {
if (str_contains($name, '_async')) {
$name = str_ireplace('_async', '', $name);
} else {
$name = str_ireplace('async', '', $name);
Expand Down Expand Up @@ -629,7 +629,7 @@ protected function exportNamespaces(): void
fwrite($handle, "/** @internal An internal interface used to avoid type errors when using simple filters. */\n");
fwrite($handle, "interface SimpleFilters extends ");
/** @psalm-suppress UndefinedClass */
fwrite($handle, implode(", ", array_map(fn ($s) => "\\$s", ClassFinder::getClassesInNamespace(\danog\MadelineProto\EventHandler\SimpleFilter::class, ClassFinder::RECURSIVE_MODE|ClassFinder::ALLOW_INTERFACES))));
fwrite($handle, implode(", ", array_map(static fn ($s) => "\\$s", ClassFinder::getClassesInNamespace(\danog\MadelineProto\EventHandler\SimpleFilter::class, ClassFinder::RECURSIVE_MODE|ClassFinder::ALLOW_INTERFACES))));
fwrite($handle, "{}\n");
}

Expand Down
4 changes: 2 additions & 2 deletions src/AsyncTools.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ abstract class AsyncTools extends StrTools
*/
public static function rethrow(Throwable $e): void
{
EventLoop::queue(fn () => throw $e);
EventLoop::queue(static fn () => throw $e);
}
/**
* Fork a new green thread and execute the passed function in the background.
Expand Down Expand Up @@ -133,7 +133,7 @@ public static function getTimeoutCancellation(float $timeout, string $message =
{
$e = new TimeoutException($message);
$deferred = new DeferredCancellation;
EventLoop::delay($timeout, fn () => $deferred->cancel($e));
EventLoop::delay($timeout, static fn () => $deferred->cancel($e));
return $deferred->getCancellation();
}

Expand Down
2 changes: 1 addition & 1 deletion src/Broadcast/Action/ActionForward.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public function act(int $broadcastId, int $peer, Cancellation $cancellation): vo
'unpin' => false,
'pm_oneside' => false,
'floodWaitLimit' => 2*86400,
'cancellation' => $cancellation
'cancellation' => $cancellation,
],
);
} catch (RPCErrorException) {
Expand Down
4 changes: 2 additions & 2 deletions src/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ private function connect(): self
foreach ($this->new_outgoing as $message_id => $message) {
if ($message->unencrypted) {
if (!($message->getState() & MTProtoOutgoingMessage::STATE_REPLIED)) {
$message->reply(fn () => new Exception('Restart because we were reconnected'));
$message->reply(static fn () => new Exception('Restart because we were reconnected'));
}
unset($this->new_outgoing[$message_id], $this->outgoing_messages[$message_id]);
}
Expand Down Expand Up @@ -527,7 +527,7 @@ private function methodAbstractions(string &$method, array &$arguments): void
$arguments['reply_to'] = [
'_' => 'inputReplyToMessage',
'reply_to_msg_id' => $arguments['reply_to_msg_id'],
'top_msg_id' => $arguments['top_msg_id'] ?? null
'top_msg_id' => $arguments['top_msg_id'] ?? null,
];
unset($arguments['reply_to_msg_id'], $arguments['top_msg_id']);
}
Expand Down
Loading

0 comments on commit 151a809

Please sign in to comment.