From 151a809c6e4c9f82303b5f55d97b4e194e021211 Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Sat, 11 Nov 2023 16:55:29 +0100 Subject: [PATCH] Fixes --- .php-cs-fixer.dist.php | 6 + docs | 2 +- examples/bot.php | 8 +- examples/combinedBot.php | 2 +- examples/downloadRenameBot.php | 6 +- examples/secret_bot.php | 2 +- examples/simpleBot.php | 4 +- examples/tgstories_dl_bot.php | 6 +- src/API.php | 4 +- src/AnnotationsBuilder.php | 20 +-- src/AsyncTools.php | 4 +- src/Broadcast/Action/ActionForward.php | 2 +- src/Connection.php | 4 +- src/Conversion.php | 150 +++++++++--------- src/DataCenter.php | 2 +- src/DataCenterConnection.php | 8 +- src/Db/Driver/Mysql.php | 2 +- src/Db/DriverArray.php | 6 +- src/Db/PostgresArray.php | 16 +- src/Db/PostgresArrayBytea.php | 12 +- src/DoHConnector.php | 8 +- src/DoHWrapper.php | 2 +- src/DocsBuilder.php | 2 +- src/DocsBuilder/Constructors.php | 4 +- src/EventHandler.php | 8 +- src/EventHandler/AbstractMessage.php | 8 +- src/EventHandler/Action/EmojiTap.php | 4 +- src/EventHandler/BotCommands.php | 2 +- .../Filter/Combinator/FiltersAnd.php | 2 +- src/EventHandler/Media/Gif.php | 4 +- src/EventHandler/Media/MediaStory.php | 4 +- src/EventHandler/Message.php | 20 +-- src/EventHandler/Message/ChannelMessage.php | 2 +- src/EventHandler/Message/GroupMessage.php | 10 +- src/EventHandler/Message/SecretMessage.php | 4 +- src/EventHandler/Story/Story.php | 2 +- src/EventHandler/Typing/SecretUserTyping.php | 2 +- src/EventHandler/User/Username.php | 2 +- src/Exception.php | 14 +- src/GarbageCollector.php | 4 +- src/Ipc/Runner/ProcessRunner.php | 4 +- src/Ipc/Runner/WebRunner.php | 4 +- src/Ipc/Runner/entry.php | 2 +- src/Ipc/Server.php | 6 +- src/Logger.php | 48 +++--- src/Loop/Connection/WriteLoop.php | 10 +- src/Loop/Generic/PeriodicLoopInternal.php | 2 +- src/Loop/Update/FeedLoop.php | 2 +- src/Loop/Update/UpdateLoop.php | 2 +- src/Loop/VoIP/DjLoop.php | 6 +- src/MTProto.php | 22 ++- src/MTProto/AuthKey.php | 4 +- src/MTProto/MTProtoIncomingMessage.php | 6 +- src/MTProto/MTProtoOutgoingMessage.php | 10 +- src/MTProtoSession/AckHandler.php | 2 +- src/MTProtoSession/CallHandler.php | 4 +- src/MTProtoSession/ResponseHandler.php | 20 +-- src/MTProtoTools/Files.php | 14 +- src/MTProtoTools/FilesAbstraction.php | 4 +- src/MTProtoTools/FilesLogic.php | 2 +- src/MTProtoTools/MinDatabase.php | 6 +- src/MTProtoTools/PeerDatabase.php | 6 +- src/MTProtoTools/PeerHandler.php | 4 +- src/MTProtoTools/ReferenceDatabase.php | 34 ++-- src/MTProtoTools/UpdateHandler.php | 2 +- src/Magic.php | 16 +- src/MyTelegramOrgWrapper.php | 3 +- src/Ogg.php | 26 +-- src/RPCErrorException.php | 2 +- src/SecretChats/SecretChatController.php | 4 +- src/Serialization.php | 6 +- src/Settings/Connection.php | 2 +- src/Shutdown.php | 2 +- src/Snitch.php | 2 +- src/TL/Conversion/BotAPI.php | 2 +- src/TL/Conversion/MarkdownEntities.php | 2 +- src/TL/TL.php | 24 +-- src/TL/TLConstructors.php | 2 +- src/TL/TLMethods.php | 2 +- src/TL/TLParams.php | 2 +- src/Tools.php | 12 +- src/VoIP/AuthKeyHandler.php | 4 +- src/VoIP/Endpoint.php | 2 +- src/VoIPController.php | 112 ++++++------- src/Wrappers/DialogHandler.php | 2 +- src/Wrappers/Loop.php | 2 +- src/Wrappers/Start.php | 2 +- tests/danog/MadelineProto/EntitiesTest.php | 34 ++-- tests/testing.php | 12 +- tools/build_docs.php | 10 +- tools/phar.php | 12 +- tools/phpdoc.php | 4 +- tools/std.php | 6 +- 93 files changed, 457 insertions(+), 454 deletions(-) diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php index ce6abea6e..e9af59df5 100644 --- a/.php-cs-fixer.dist.php +++ b/.php-cs-fixer.dist.php @@ -8,6 +8,12 @@ $config = new class extends Amp\CodeStyle\Config { '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'], ]); } diff --git a/docs b/docs index 6033bfa2a..8d71029d3 160000 --- a/docs +++ b/docs @@ -1 +1 @@ -Subproject commit 6033bfa2a31f6661681a06f4240d5bf18090df45 +Subproject commit 8d71029d3b3211f9298f58693d94d9572af3dae1 diff --git a/examples/bot.php b/examples/bot.php index 1195b8a63..d66aaebc0 100755 --- a/examples/bot.php +++ b/examples/bot.php @@ -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 @@ -112,7 +112,7 @@ class MyEventHandler extends SimpleEventHandler 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, ]; } @@ -185,9 +185,9 @@ class MyEventHandler extends SimpleEventHandler $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) { diff --git a/examples/combinedBot.php b/examples/combinedBot.php index 6c076099d..23617ad48 100755 --- a/examples/combinedBot.php +++ b/examples/combinedBot.php @@ -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. * diff --git a/examples/downloadRenameBot.php b/examples/downloadRenameBot.php index 3e9eace03..9a8948287 100755 --- a/examples/downloadRenameBot.php +++ b/examples/downloadRenameBot.php @@ -43,7 +43,7 @@ if (file_exists('vendor/autoload.php')) { */ 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". @@ -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. @@ -149,7 +149,7 @@ class MyEventHandler extends EventHandler $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); } diff --git a/examples/secret_bot.php b/examples/secret_bot.php index 96d66be36..35af0d3ff 100755 --- a/examples/secret_bot.php +++ b/examples/secret_bot.php @@ -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. * diff --git a/examples/simpleBot.php b/examples/simpleBot.php index bf169dfe5..d3b769d13 100644 --- a/examples/simpleBot.php +++ b/examples/simpleBot.php @@ -27,7 +27,7 @@ if (file_exists('vendor/autoload.php')) { class MyEventHandler extends SimpleEventHandler { // !!! Change this to your username !!! - const ADMIN = "@me"; + public const ADMIN = "@me"; /** * Get peer(s) where to report errors. @@ -47,7 +47,7 @@ class MyEventHandler extends SimpleEventHandler 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, ]; } diff --git a/examples/tgstories_dl_bot.php b/examples/tgstories_dl_bot.php index 2e565e831..e59bab670 100644 --- a/examples/tgstories_dl_bot.php +++ b/examples/tgstories_dl_bot.php @@ -124,11 +124,11 @@ final class StoriesEventHandler extends SimpleEventHandler $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) { diff --git a/src/API.php b/src/API.php index 5708a2430..de23c3527 100644 --- a/src/API.php +++ b/src/API.php @@ -415,7 +415,7 @@ final class API extends AbstractAPI $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(); } @@ -442,7 +442,7 @@ final class API extends AbstractAPI $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]); }); } diff --git a/src/AnnotationsBuilder.php b/src/AnnotationsBuilder.php index 07dd55497..3eaedc547 100644 --- a/src/AnnotationsBuilder.php +++ b/src/AnnotationsBuilder.php @@ -322,7 +322,7 @@ final class Blacklist { } $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 @@ -418,14 +418,14 @@ final class Blacklist { 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)]); } } } @@ -439,21 +439,21 @@ final class Blacklist { 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); @@ -629,7 +629,7 @@ final class Blacklist { 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"); } diff --git a/src/AsyncTools.php b/src/AsyncTools.php index 7a5e0c5f7..cf6ebb429 100644 --- a/src/AsyncTools.php +++ b/src/AsyncTools.php @@ -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. @@ -133,7 +133,7 @@ abstract class AsyncTools extends StrTools { $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(); } diff --git a/src/Broadcast/Action/ActionForward.php b/src/Broadcast/Action/ActionForward.php index c2df7119b..fdbac889a 100644 --- a/src/Broadcast/Action/ActionForward.php +++ b/src/Broadcast/Action/ActionForward.php @@ -63,7 +63,7 @@ final class ActionForward implements Action 'unpin' => false, 'pm_oneside' => false, 'floodWaitLimit' => 2*86400, - 'cancellation' => $cancellation + 'cancellation' => $cancellation, ], ); } catch (RPCErrorException) { diff --git a/src/Connection.php b/src/Connection.php index 1f8b87335..69eff3cc3 100644 --- a/src/Connection.php +++ b/src/Connection.php @@ -304,7 +304,7 @@ final class Connection 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]); } @@ -527,7 +527,7 @@ final class Connection $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']); } diff --git a/src/Conversion.php b/src/Conversion.php index 91360a7e9..e86ae941a 100644 --- a/src/Conversion.php +++ b/src/Conversion.php @@ -136,8 +136,8 @@ final class Conversion return strtoupper($result); } - const FILEOPTION_SAFE = 1; - const FILEOPTION_USER = 2; + private const FILEOPTION_SAFE = 1; + private const FILEOPTION_USER = 2; public static $tdesktop_base_path; public static $tdesktop_user_base_path; public static $tdesktop_key; @@ -227,85 +227,85 @@ final class Conversion return $res; } - const dbiKey = 0x00; - const dbiUser = 0x01; - const dbiDcOptionOldOld = 0x02; - const dbiChatSizeMax = 0x03; - const dbiMutePeer = 0x04; - const dbiSendKey = 0x05; - const dbiAutoStart = 0x06; - const dbiStartMinimized = 0x07; - const dbiSoundNotify = 0x08; - const dbiWorkMode = 0x09; - const dbiSeenTrayTooltip = 0x0a; - const dbiDesktopNotify = 0x0b; - const dbiAutoUpdate = 0x0c; - const dbiLastUpdateCheck = 0x0d; - const dbiWindowPosition = 0x0e; - const dbiConnectionTypeOld = 0x0f; + private const dbiKey = 0x00; + private const dbiUser = 0x01; + private const dbiDcOptionOldOld = 0x02; + private const dbiChatSizeMax = 0x03; + private const dbiMutePeer = 0x04; + private const dbiSendKey = 0x05; + private const dbiAutoStart = 0x06; + private const dbiStartMinimized = 0x07; + private const dbiSoundNotify = 0x08; + private const dbiWorkMode = 0x09; + private const dbiSeenTrayTooltip = 0x0a; + private const dbiDesktopNotify = 0x0b; + private const dbiAutoUpdate = 0x0c; + private const dbiLastUpdateCheck = 0x0d; + private const dbiWindowPosition = 0x0e; + private const dbiConnectionTypeOld = 0x0f; // 0x10 reserved - const dbiDefaultAttach = 0x11; - const dbiCatsAndDogs = 0x12; - const dbiReplaceEmojis = 0x13; - const dbiAskDownloadPath = 0x14; - const dbiDownloadPathOld = 0x15; - const dbiScale = 0x16; - const dbiEmojiTabOld = 0x17; - const dbiRecentEmojiOldOld = 0x18; - const dbiLoggedPhoneNumber = 0x19; - const dbiMutedPeers = 0x1a; + private const dbiDefaultAttach = 0x11; + private const dbiCatsAndDogs = 0x12; + private const dbiReplaceEmojis = 0x13; + private const dbiAskDownloadPath = 0x14; + private const dbiDownloadPathOld = 0x15; + private const dbiScale = 0x16; + private const dbiEmojiTabOld = 0x17; + private const dbiRecentEmojiOldOld = 0x18; + private const dbiLoggedPhoneNumber = 0x19; + private const dbiMutedPeers = 0x1a; // 0x1b reserved - const dbiNotifyView = 0x1c; - const dbiSendToMenu = 0x1d; - const dbiCompressPastedImage = 0x1e; - const dbiLangOld = 0x1f; - const dbiLangFileOld = 0x20; - const dbiTileBackground = 0x21; - const dbiAutoLock = 0x22; - const dbiDialogLastPath = 0x23; - const dbiRecentEmojiOld = 0x24; - const dbiEmojiVariantsOld = 0x25; - const dbiRecentStickers = 0x26; - const dbiDcOptionOld = 0x27; - const dbiTryIPv6 = 0x28; - const dbiSongVolume = 0x29; - const dbiWindowsNotificationsOld = 0x30; - const dbiIncludeMuted = 0x31; - const dbiMegagroupSizeMax = 0x32; - const dbiDownloadPath = 0x33; - const dbiAutoDownload = 0x34; - const dbiSavedGifsLimit = 0x35; - const dbiShowingSavedGifsOld = 0x36; - const dbiAutoPlay = 0x37; - const dbiAdaptiveForWide = 0x38; - const dbiHiddenPinnedMessages = 0x39; - const dbiRecentEmoji = 0x3a; - const dbiEmojiVariants = 0x3b; - const dbiDialogsMode = 0x40; - const dbiModerateMode = 0x41; - const dbiVideoVolume = 0x42; - const dbiStickersRecentLimit = 0x43; - const dbiNativeNotifications = 0x44; - const dbiNotificationsCount = 0x45; - const dbiNotificationsCorner = 0x46; - const dbiThemeKey = 0x47; - const dbiDialogsWidthRatioOld = 0x48; - const dbiUseExternalVideoPlayer = 0x49; - const dbiDcOptions = 0x4a; - const dbiMtpAuthorization = 0x4b; - const dbiLastSeenWarningSeenOld = 0x4c; - const dbiAuthSessionSettings = 0x4d; - const dbiLangPackKey = 0x4e; - const dbiConnectionType = 0x4f; - const dbiStickersFavedLimit = 0x50; - const dbiSuggestStickersByEmoji = 0x51; + private const dbiNotifyView = 0x1c; + private const dbiSendToMenu = 0x1d; + private const dbiCompressPastedImage = 0x1e; + private const dbiLangOld = 0x1f; + private const dbiLangFileOld = 0x20; + private const dbiTileBackground = 0x21; + private const dbiAutoLock = 0x22; + private const dbiDialogLastPath = 0x23; + private const dbiRecentEmojiOld = 0x24; + private const dbiEmojiVariantsOld = 0x25; + private const dbiRecentStickers = 0x26; + private const dbiDcOptionOld = 0x27; + private const dbiTryIPv6 = 0x28; + private const dbiSongVolume = 0x29; + private const dbiWindowsNotificationsOld = 0x30; + private const dbiIncludeMuted = 0x31; + private const dbiMegagroupSizeMax = 0x32; + private const dbiDownloadPath = 0x33; + private const dbiAutoDownload = 0x34; + private const dbiSavedGifsLimit = 0x35; + private const dbiShowingSavedGifsOld = 0x36; + private const dbiAutoPlay = 0x37; + private const dbiAdaptiveForWide = 0x38; + private const dbiHiddenPinnedMessages = 0x39; + private const dbiRecentEmoji = 0x3a; + private const dbiEmojiVariants = 0x3b; + private const dbiDialogsMode = 0x40; + private const dbiModerateMode = 0x41; + private const dbiVideoVolume = 0x42; + private const dbiStickersRecentLimit = 0x43; + private const dbiNativeNotifications = 0x44; + private const dbiNotificationsCount = 0x45; + private const dbiNotificationsCorner = 0x46; + private const dbiThemeKey = 0x47; + private const dbiDialogsWidthRatioOld = 0x48; + private const dbiUseExternalVideoPlayer = 0x49; + private const dbiDcOptions = 0x4a; + private const dbiMtpAuthorization = 0x4b; + private const dbiLastSeenWarningSeenOld = 0x4c; + private const dbiAuthSessionSettings = 0x4d; + private const dbiLangPackKey = 0x4e; + private const dbiConnectionType = 0x4f; + private const dbiStickersFavedLimit = 0x50; + private const dbiSuggestStickersByEmoji = 0x51; - const dbiEncryptedWithSalt = 333; - const dbiEncrypted = 444; + private const dbiEncryptedWithSalt = 333; + private const dbiEncrypted = 444; // 500-600 reserved - const dbiVersion = 666; + private const dbiVersion = 666; private static function tdesktop(string $session, string $new_session, $settings = []) { diff --git a/src/DataCenter.php b/src/DataCenter.php index a4432348b..646551c9d 100644 --- a/src/DataCenter.php +++ b/src/DataCenter.php @@ -293,7 +293,7 @@ final class DataCenter foreach ([true, false] as $useDoH) { $ipv6Combos = [ $this->getSettings()->getIpv6() ? 'ipv6' : 'ipv4', - $this->getSettings()->getIpv6() ? 'ipv4' : 'ipv6' + $this->getSettings()->getIpv6() ? 'ipv4' : 'ipv6', ]; foreach ($ipv6Combos as $ipv6) { if ($onlyIPv6 !== null && $onlyIPv6 !== $ipv6) { diff --git a/src/DataCenterConnection.php b/src/DataCenterConnection.php index cfd4bf840..294d8eaf0 100644 --- a/src/DataCenterConnection.php +++ b/src/DataCenterConnection.php @@ -41,9 +41,9 @@ use function count; */ final class DataCenterConnection implements JsonSerializable { - const READ_WEIGHT = 1; - const READ_WEIGHT_MEDIA = 5; - const WRITE_WEIGHT = 10; + public const READ_WEIGHT = 1; + public const READ_WEIGHT_MEDIA = 5; + public const WRITE_WEIGHT = 10; /** * Promise for connection. * @@ -604,7 +604,7 @@ final class DataCenterConnection implements JsonSerializable return $this->connections[0]; } $max = max($this->availableConnections); - $key = array_search($max, $this->availableConnections); + $key = array_search($max, $this->availableConnections, true); // Decrease to implement round robin $this->availableConnections[$key]--; return $this->connections[$key]; diff --git a/src/Db/Driver/Mysql.php b/src/Db/Driver/Mysql.php index 6175e3afe..b9368a6f0 100644 --- a/src/Db/Driver/Mysql.php +++ b/src/Db/Driver/Mysql.php @@ -76,7 +76,7 @@ final class Mysql self::$connections[$dbKey] = [ new MysqlConnectionPool($config, $settings->getMaxConnections(), $settings->getIdleTimeout()), - $pdo + $pdo, ]; } } finally { diff --git a/src/Db/DriverArray.php b/src/Db/DriverArray.php index 581f3a895..b569a52be 100644 --- a/src/Db/DriverArray.php +++ b/src/Db/DriverArray.php @@ -140,14 +140,14 @@ abstract class DriverArray implements DbArray, IteratorAggregate $this->serializer = match ($serializer) { SerializerType::SERIALIZE => \serialize(...), SerializerType::IGBINARY => \igbinary_serialize(...), - SerializerType::JSON => fn ($value) => json_encode($value, JSON_THROW_ON_ERROR|JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES), + SerializerType::JSON => static fn ($value) => json_encode($value, JSON_THROW_ON_ERROR|JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES), SerializerType::STRING => strval(...), }; $this->deserializer = match ($serializer) { SerializerType::SERIALIZE => \unserialize(...), SerializerType::IGBINARY => \igbinary_unserialize(...), - SerializerType::JSON => fn ($value) => json_decode($value, true, 256, JSON_THROW_ON_ERROR), - SerializerType::STRING => fn ($v) => $v, + SerializerType::JSON => static fn ($value) => json_decode($value, true, 256, JSON_THROW_ON_ERROR), + SerializerType::STRING => static fn ($v) => $v, }; } private static function migrateDataToDb(self $new, DbType|null $old): void diff --git a/src/Db/PostgresArray.php b/src/Db/PostgresArray.php index 77ede094c..131d7610d 100644 --- a/src/Db/PostgresArray.php +++ b/src/Db/PostgresArray.php @@ -72,16 +72,16 @@ final class PostgresArray extends PostgresArrayBytea protected function setSerializer(SerializerType $serializer): void { $this->serializer = match ($serializer) { - SerializerType::SERIALIZE => fn ($v) => bin2hex(serialize($v)), - SerializerType::IGBINARY => fn ($v) => bin2hex(igbinary_serialize($v)), - SerializerType::JSON => fn ($v) => bin2hex(json_encode($v, JSON_THROW_ON_ERROR|JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES)), - SerializerType::STRING => fn ($v) => bin2hex(\strval($v)), + SerializerType::SERIALIZE => static fn ($v) => bin2hex(serialize($v)), + SerializerType::IGBINARY => static fn ($v) => bin2hex(igbinary_serialize($v)), + SerializerType::JSON => static fn ($v) => bin2hex(json_encode($v, JSON_THROW_ON_ERROR|JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES)), + SerializerType::STRING => static fn ($v) => bin2hex(\strval($v)), }; $this->deserializer = match ($serializer) { - SerializerType::SERIALIZE => fn ($v) => unserialize(hex2bin($v)), - SerializerType::IGBINARY => fn ($v) => igbinary_unserialize(hex2bin($v)), - SerializerType::JSON => fn ($value) => json_decode(hex2bin($value), true, 256, JSON_THROW_ON_ERROR), - SerializerType::STRING => fn ($v) => hex2bin($v), + SerializerType::SERIALIZE => static fn ($v) => unserialize(hex2bin($v)), + SerializerType::IGBINARY => static fn ($v) => igbinary_unserialize(hex2bin($v)), + SerializerType::JSON => static fn ($value) => json_decode(hex2bin($value), true, 256, JSON_THROW_ON_ERROR), + SerializerType::STRING => static fn ($v) => hex2bin($v), }; } /** diff --git a/src/Db/PostgresArrayBytea.php b/src/Db/PostgresArrayBytea.php index dd95d6fad..b74982425 100644 --- a/src/Db/PostgresArrayBytea.php +++ b/src/Db/PostgresArrayBytea.php @@ -90,16 +90,16 @@ class PostgresArrayBytea extends SqlArray protected function setSerializer(SerializerType $serializer): void { $this->serializer = match ($serializer) { - SerializerType::SERIALIZE => fn ($v) => new ByteA(serialize($v)), - SerializerType::IGBINARY => fn ($v) => new ByteA(igbinary_serialize($v)), - SerializerType::JSON => fn ($v) => new ByteA(json_encode($v, JSON_THROW_ON_ERROR|JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES)), - SerializerType::STRING => fn ($v) => new ByteA(\strval($v)), + SerializerType::SERIALIZE => static fn ($v) => new ByteA(serialize($v)), + SerializerType::IGBINARY => static fn ($v) => new ByteA(igbinary_serialize($v)), + SerializerType::JSON => static fn ($v) => new ByteA(json_encode($v, JSON_THROW_ON_ERROR|JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES)), + SerializerType::STRING => static fn ($v) => new ByteA(\strval($v)), }; $this->deserializer = match ($serializer) { SerializerType::SERIALIZE => \unserialize(...), SerializerType::IGBINARY => \igbinary_unserialize(...), - SerializerType::JSON => fn ($value) => json_decode($value, true, 256, JSON_THROW_ON_ERROR), - SerializerType::STRING => fn ($v) => $v, + SerializerType::JSON => static fn ($value) => json_decode($value, true, 256, JSON_THROW_ON_ERROR), + SerializerType::STRING => static fn ($v) => $v, }; } /** diff --git a/src/DoHConnector.php b/src/DoHConnector.php index ee420b8a9..ca2daf5d9 100644 --- a/src/DoHConnector.php +++ b/src/DoHConnector.php @@ -91,7 +91,7 @@ final class DoHConnector implements SocketConnector } else { $records = $this->dataCenter->DoHClient->resolve($host, $socketContext->getDnsTypeRestriction()); } - usort($records, fn (DnsRecord $a, DnsRecord $b) => $a->getType() - $b->getType()); + usort($records, static fn (DnsRecord $a, DnsRecord $b) => $a->getType() - $b->getType()); if ($this->ctx->getIpv6()) { $records = array_reverse($records); } @@ -111,7 +111,7 @@ final class DoHConnector implements SocketConnector $streamContext = stream_context_create($socketContext->withoutTlsContext()->toStreamContextArray()); /** @psalm-suppress NullArgument */ if (!($socket = @stream_socket_client($builtUri, $errno, $errstr, null, $flags, $streamContext))) { - throw new ConnectException(sprintf('Connection to %s failed: [Error #%d] %s%s', (string) $uri, $errno, $errstr, $failures ? '; previous attempts: '.implode($failures) : ''), $errno); + throw new ConnectException(sprintf('Connection to %s failed: [Error #%d] %s%s', (string) $uri, $errno, $errstr, $failures ? '; previous attempts: '.implode('', $failures) : ''), $errno); } stream_set_blocking($socket, false); $deferred = new DeferredFuture(); @@ -125,7 +125,7 @@ final class DoHConnector implements SocketConnector throw $e; } - throw new ConnectException(sprintf('Connecting to %s failed: timeout exceeded (%d ms)%s', (string) $uri, $timeout, $failures ? '; previous attempts: '.implode($failures) : ''), 110); + throw new ConnectException(sprintf('Connecting to %s failed: timeout exceeded (%d ms)%s', (string) $uri, $timeout, $failures ? '; previous attempts: '.implode('', $failures) : ''), 110); // See ETIMEDOUT in http://www.virtsync.com/c-error-codes-include-errno } finally { EventLoop::cancel($watcher); @@ -134,7 +134,7 @@ final class DoHConnector implements SocketConnector // The following hack looks like the only way to detect connection refused errors with PHP's stream sockets. if (stream_socket_get_name($socket, true) === false) { fclose($socket); - throw new ConnectException(sprintf('Connection to %s refused%s', (string) $uri, $failures ? '; previous attempts: '.implode($failures) : ''), 111); + throw new ConnectException(sprintf('Connection to %s refused%s', (string) $uri, $failures ? '; previous attempts: '.implode('', $failures) : ''), 111); // See ECONNREFUSED in http://www.virtsync.com/c-error-codes-include-errno } } catch (ConnectException $e) { diff --git a/src/DoHWrapper.php b/src/DoHWrapper.php index a13a60553..8eb199068 100644 --- a/src/DoHWrapper.php +++ b/src/DoHWrapper.php @@ -133,7 +133,7 @@ final class DoHWrapper { $ctxs = []; $combos = [ - [[DefaultStream::class, []], [BufferedRawStream::class, []]] + [[DefaultStream::class, []], [BufferedRawStream::class, []]], ]; if ($this->API->getSettings()->getConnection()->getRetry()) { $proxyCombos = []; diff --git a/src/DocsBuilder.php b/src/DocsBuilder.php index 478602f5a..a762272fb 100644 --- a/src/DocsBuilder.php +++ b/src/DocsBuilder.php @@ -27,7 +27,7 @@ use danog\MadelineProto\TL\TL; // This code was written a few years ago: it is garbage, and has to be rewritten final class DocsBuilder { - const DEFAULT_TEMPLATES = [ + public const DEFAULT_TEMPLATES = [ 'User' => ['User', 'InputUser', 'Chat', 'InputChannel', 'Peer', 'InputDialogPeer', 'DialogPeer', 'InputPeer', 'NotifyPeer', 'InputNotifyPeer'], 'ReplyMarkup' => ['ReplyMarkup'], 'InputFile' => ['InputFile', 'InputEncryptedFile'], diff --git a/src/DocsBuilder/Constructors.php b/src/DocsBuilder/Constructors.php index f783c9afd..73a96fb56 100644 --- a/src/DocsBuilder/Constructors.php +++ b/src/DocsBuilder/Constructors.php @@ -143,10 +143,10 @@ trait Constructors $ptype = 'Bool'; } $human_ptype = $ptype; - if (strpos($type, 'Input') === 0 && \in_array($ptype, ['User', 'InputUser', 'Chat', 'InputChannel', 'Peer', 'InputDialogPeer', 'DialogPeer', 'NotifyPeer', 'InputNotifyPeer', 'InputPeer'], true) && !isset($this->settings['td'])) { + if (str_starts_with($type, 'Input') && \in_array($ptype, ['User', 'InputUser', 'Chat', 'InputChannel', 'Peer', 'InputDialogPeer', 'DialogPeer', 'NotifyPeer', 'InputNotifyPeer', 'InputPeer'], true) && !isset($this->settings['td'])) { $human_ptype = 'Username, chat ID, Update, Message or '.$ptype; } - if (strpos($type, 'Input') === 0 && \in_array($ptype, ['InputMedia', 'InputDocument', 'InputPhoto'], true) && !isset($this->settings['td'])) { + if (str_starts_with($type, 'Input') && \in_array($ptype, ['InputMedia', 'InputDocument', 'InputPhoto'], true) && !isset($this->settings['td'])) { $human_ptype = 'MessageMedia, Message, Update or '.$ptype; } if (\in_array($ptype, ['InputMessage'], true) && !isset($this->settings['td'])) { diff --git a/src/EventHandler.php b/src/EventHandler.php index e6b431f9f..e12201e4d 100644 --- a/src/EventHandler.php +++ b/src/EventHandler.php @@ -180,12 +180,12 @@ abstract class EventHandler extends AbstractAPI $methods[$method_name] = [ static function (array $update) use ($basic_handler, $closure): void { EventLoop::queue($basic_handler, $update, $closure); - } + }, ]; continue; } - array_map(fn (ReflectionAttribute $attribute) => $attribute->newInstance(), $methodRefl->getAttributes()); + array_map(static fn (ReflectionAttribute $attribute) => $attribute->newInstance(), $methodRefl->getAttributes()); if ($periodic = $methodRefl->getAttributes(Cron::class)) { if (!$this instanceof SimpleEventHandler) { @@ -193,9 +193,7 @@ abstract class EventHandler extends AbstractAPI } $periodic = $periodic[0]->newInstance(); $this->periodicLoops[$method] = new PeriodicLoop( - static function (PeriodicLoop $loop) use ($closure): bool { - return $closure($loop) ?? false; - }, + static fn (PeriodicLoop $loop): bool => $closure($loop) ?? false, $method, $periodic->period ); diff --git a/src/EventHandler/AbstractMessage.php b/src/EventHandler/AbstractMessage.php index 1fd2bb1a8..162a91840 100644 --- a/src/EventHandler/AbstractMessage.php +++ b/src/EventHandler/AbstractMessage.php @@ -167,7 +167,7 @@ abstract class AbstractMessage extends Update implements SimpleFilters DialogId::isSupergroupOrChannel($this->chatId) ? 'channels.getMessages' : 'messages.getMessages', [ 'channel' => $this->chatId, - 'id' => [['_' => 'inputMessageReplyTo', 'id' => $this->id]] + 'id' => [['_' => 'inputMessageReplyTo', 'id' => $this->id]], ] )['messages']; /** @psalm-suppress InaccessibleProperty */ @@ -342,7 +342,7 @@ abstract class AbstractMessage extends Update implements SimpleFilters 'peer' => $this->senderId, ] )['stories']['stories']; - $result = array_filter($result, fn (array $t): bool => $t['_'] !== 'storyItemDeleted'); + $result = array_filter($result, static fn (array $t): bool => $t['_'] !== 'storyItemDeleted'); // Recall it because storyItemSkipped // TODO: Do this more efficiently $result = $client->methodCallAsyncRead( @@ -375,7 +375,7 @@ abstract class AbstractMessage extends Update implements SimpleFilters [ 'peer' => $this->senderId, 'top_msg_id' => $this->topicId, - 'action' => $action + 'action' => $action, ] ); } @@ -393,7 +393,7 @@ abstract class AbstractMessage extends Update implements SimpleFilters [ 'peer' => $this->chatId, 'channel' => $this->chatId, - 'max_id' => $readAll ? 0 : $this->id + 'max_id' => $readAll ? 0 : $this->id, ] ); } diff --git a/src/EventHandler/Action/EmojiTap.php b/src/EventHandler/Action/EmojiTap.php index 976dcef11..c4cc069b1 100644 --- a/src/EventHandler/Action/EmojiTap.php +++ b/src/EventHandler/Action/EmojiTap.php @@ -45,8 +45,8 @@ final class EmojiTap extends Action 'emoticon' => $this->emoticon, 'interaction' => [ 'v' => 1, - 'a' => $this->animation - ] + 'a' => $this->animation, + ], ]; } } diff --git a/src/EventHandler/BotCommands.php b/src/EventHandler/BotCommands.php index 3d1e3a09e..93b25baec 100644 --- a/src/EventHandler/BotCommands.php +++ b/src/EventHandler/BotCommands.php @@ -39,7 +39,7 @@ final class BotCommands extends Update $this->botId = $rawBotCommands['bot_id']; $this->chatId = $API->getIdInternal($rawBotCommands['peer']); $this->commands = array_map( - fn (array $command): Command => new Command($command), + static fn (array $command): Command => new Command($command), $rawBotCommands['commands'] ); } diff --git a/src/EventHandler/Filter/Combinator/FiltersAnd.php b/src/EventHandler/Filter/Combinator/FiltersAnd.php index 4697f1e50..b8a8c8c30 100644 --- a/src/EventHandler/Filter/Combinator/FiltersAnd.php +++ b/src/EventHandler/Filter/Combinator/FiltersAnd.php @@ -49,7 +49,7 @@ final class FiltersAnd extends Filter } $final = array_filter( $final, - fn (Filter $f): bool => !$f instanceof FilterAllowAll, + static fn (Filter $f): bool => !$f instanceof FilterAllowAll, ); $final = array_values($final); return match (\count($final)) { diff --git a/src/EventHandler/Media/Gif.php b/src/EventHandler/Media/Gif.php index 3ddc7177e..040434160 100644 --- a/src/EventHandler/Media/Gif.php +++ b/src/EventHandler/Media/Gif.php @@ -54,7 +54,7 @@ final class Gif extends AbstractVideo 'messages.saveGif', [ 'id' => $this->botApiFileId, - 'unsave' => false + 'unsave' => false, ] ); } @@ -69,7 +69,7 @@ final class Gif extends AbstractVideo 'messages.saveGif', [ 'id' => $this->botApiFileId, - 'unsave' => true + 'unsave' => true, ] ); } diff --git a/src/EventHandler/Media/MediaStory.php b/src/EventHandler/Media/MediaStory.php index f7d294ed5..15d3795c3 100644 --- a/src/EventHandler/Media/MediaStory.php +++ b/src/EventHandler/Media/MediaStory.php @@ -50,11 +50,11 @@ abstract class MediaStory extends IpcCapable implements JsonSerializable // for $this->story = match ($rawMedia['story']['_'] ?? null) { 'storyItem' => new Story($API, [ 'peer' => $this->senderId, - 'story' => $rawMedia['story'] + 'story' => $rawMedia['story'], ]), 'storyItemDeleted' => new StoryDeleted($API, [ 'peer' => $this->senderId, - 'story' => $rawMedia['story'] + 'story' => $rawMedia['story'], ]), 'storyItemSkipped' => null, // Will it happen? default => null diff --git a/src/EventHandler/Message.php b/src/EventHandler/Message.php index 030bebb93..84a8ce44c 100644 --- a/src/EventHandler/Message.php +++ b/src/EventHandler/Message.php @@ -202,7 +202,7 @@ abstract class Message extends AbstractMessage 'id' => $this->id, 'pm_oneside' => $pmOneside, 'silent' => $silent, - 'unpin' => false + 'unpin' => false, ] ); } @@ -222,7 +222,7 @@ abstract class Message extends AbstractMessage 'id' => $this->id, 'pm_oneside' => $pmOneside, 'silent' => $silent, - 'unpin' => true + 'unpin' => true, ] ); return $this->getClient()->wrapUpdate($result); @@ -252,7 +252,7 @@ abstract class Message extends AbstractMessage 'reason' => ['_' => $reason->value], 'message' => $message, 'id' => [$this->id], - 'peer' => $this->chatId + 'peer' => $this->chatId, ] ); } @@ -278,7 +278,7 @@ abstract class Message extends AbstractMessage 'last_name' => $lastName, 'phone_number' => $phoneNumber, 'add_phone_privacy_exception' => $addPhonePrivacyException, - 'id' => $this->senderId + 'id' => $this->senderId, ] ); } @@ -291,7 +291,7 @@ abstract class Message extends AbstractMessage $this->getClient()->methodCallAsyncRead( 'contacts.deleteContacts', [ - 'id' => [$this->senderId] + 'id' => [$this->senderId], ] ); } @@ -307,7 +307,7 @@ abstract class Message extends AbstractMessage 'channels.inviteToChannel', [ 'channel' => $channel, - 'users' => [$this->senderId] + 'users' => [$this->senderId], ] ); } @@ -335,7 +335,7 @@ abstract class Message extends AbstractMessage ? [['_' => 'reactionCustomEmoji', 'document_id' => $reaction]] : [['_' => 'reactionEmoji', 'emoticon' => $reaction]], 'big' => $big, - 'add_to_recent' => $addToRecent + 'add_to_recent' => $addToRecent, ] ); $this->reactions[] = $reaction; @@ -357,7 +357,7 @@ abstract class Message extends AbstractMessage } unset($this->reactions[$key]); $this->reactions = array_values($this->reactions); - $r = array_map(fn (string|int $r): array => \is_int($r) ? ['_' => 'reactionCustomEmoji', 'document_id' => $r] : ['_' => 'reactionEmoji', 'emoticon' => $r], $this->reactions); + $r = array_map(static fn (string|int $r): array => \is_int($r) ? ['_' => 'reactionCustomEmoji', 'document_id' => $r] : ['_' => 'reactionEmoji', 'emoticon' => $r], $this->reactions); $r[]= ['_' => 'reactionEmpty']; $this->getClient()->methodCallAsyncRead( 'messages.sendReaction', @@ -387,7 +387,7 @@ abstract class Message extends AbstractMessage [ 'peer' => $this->chatId, 'id' => [$this->id], - 'to_lang' => $toLang + 'to_lang' => $toLang, ] ); return $result['result'][0]['text']; @@ -419,7 +419,7 @@ abstract class Message extends AbstractMessage 'reply_markup' => $replyMarkup, 'parse_mode' => $parseMode, 'schedule_date' => $scheduleDate, - 'no_webpage' => $noWebpage + 'no_webpage' => $noWebpage, ] ); return $this->getClient()->wrapMessage($this->getClient()->extractMessage($result)); diff --git a/src/EventHandler/Message/ChannelMessage.php b/src/EventHandler/Message/ChannelMessage.php index b46061f4d..4897b2205 100644 --- a/src/EventHandler/Message/ChannelMessage.php +++ b/src/EventHandler/Message/ChannelMessage.php @@ -110,7 +110,7 @@ final class ChannelMessage extends Message [ 'peer' => $this->chatId, 'id' => [$this->id], - 'increment' => true + 'increment' => true, ] ); } diff --git a/src/EventHandler/Message/GroupMessage.php b/src/EventHandler/Message/GroupMessage.php index 736ff92b2..de1893f6c 100644 --- a/src/EventHandler/Message/GroupMessage.php +++ b/src/EventHandler/Message/GroupMessage.php @@ -165,14 +165,14 @@ final class GroupMessage extends Message 'send_voices' => false, 'send_docs' => false, 'send_plain' => false, - 'until_date' => $untilDate + 'until_date' => $untilDate, ]; $this->getClient()->methodCallAsyncRead( 'channels.editBanned', [ 'channel' => $this->chatId, 'participant' => $this->senderId, - 'banned_rights' => $chatBannedRights + 'banned_rights' => $chatBannedRights, ] ); } @@ -206,14 +206,14 @@ final class GroupMessage extends Message 'send_voices' => true, 'send_docs' => true, 'send_plain' => true, - 'until_date' => $untilDate + 'until_date' => $untilDate, ]; $this->getClient()->methodCallAsyncRead( 'channels.editBanned', [ 'channel' => $this->chatId, 'participant' => $this->senderId, - 'banned_rights' => $chatBannedRights + 'banned_rights' => $chatBannedRights, ] ); } @@ -237,7 +237,7 @@ final class GroupMessage extends Message [ 'channel' => $this->chatId, 'for_everyone' => $forEveryone, - 'max_id' => $maxId + 'max_id' => $maxId, ] ); } diff --git a/src/EventHandler/Message/SecretMessage.php b/src/EventHandler/Message/SecretMessage.php index 3444828a5..d961d1c24 100644 --- a/src/EventHandler/Message/SecretMessage.php +++ b/src/EventHandler/Message/SecretMessage.php @@ -63,8 +63,8 @@ class SecretMessage extends AbstractPrivateMessage 'peer' => $this->chatId, 'message' => [ '_' => 'decryptedMessageService', - 'action' => ['_' => 'decryptedMessageActionScreenshotMessages', 'random_ids' => [$this->id]] - ] + 'action' => ['_' => 'decryptedMessageActionScreenshotMessages', 'random_ids' => [$this->id]], + ], ] ); return $this->getClient()->wrapMessage($this->getClient()->extractMessage($result)); diff --git a/src/EventHandler/Story/Story.php b/src/EventHandler/Story/Story.php index a095e8ca0..410d1ddf4 100644 --- a/src/EventHandler/Story/Story.php +++ b/src/EventHandler/Story/Story.php @@ -170,7 +170,7 @@ final class Story extends AbstractStory 'background' => $background, 'clear_draft' => $clearDraft, 'no_webpage' => $noWebpage, - 'update_stickersets_order' => $updateStickersetsOrder + 'update_stickersets_order' => $updateStickersetsOrder, ] ); if (isset($result['_'])) { diff --git a/src/EventHandler/Typing/SecretUserTyping.php b/src/EventHandler/Typing/SecretUserTyping.php index e6e4f1be3..1687e49f2 100644 --- a/src/EventHandler/Typing/SecretUserTyping.php +++ b/src/EventHandler/Typing/SecretUserTyping.php @@ -33,7 +33,7 @@ final class SecretUserTyping extends Typing $this->chatId = $rawMessage['chat_id']; parent::__construct($API, [ 'user_id' => $info['user_id'], - 'action' => $rawMessage['decrypted_message']['action'] + 'action' => $rawMessage['decrypted_message']['action'], ]); } } diff --git a/src/EventHandler/User/Username.php b/src/EventHandler/User/Username.php index e9e06492c..6deaf3e0b 100644 --- a/src/EventHandler/User/Username.php +++ b/src/EventHandler/User/Username.php @@ -44,7 +44,7 @@ final class Username extends Update $this->firstName = $rawUserName['first_name']; $this->lastName = $rawUserName['last_name']; $this->usernames = array_map( - fn (array $username) => new UsernameInfo($username), + static fn (array $username) => new UsernameInfo($username), $rawUserName['usernames'] ); } diff --git a/src/Exception.php b/src/Exception.php index b924d17b3..47d92546d 100644 --- a/src/Exception.php +++ b/src/Exception.php @@ -46,7 +46,7 @@ class Exception extends \Exception $this->line = $line; } parent::__construct($message, $code, $previous); - if (strpos($message, 'socket_accept') === false + if (!str_contains($message, 'socket_accept') && !\in_array(basename($this->file), ['PKCS8.php', 'PSS.php'], true) ) { Logger::log($message.' in '.basename($this->file).':'.$this->line, Logger::FATAL_ERROR); @@ -85,13 +85,13 @@ class Exception extends \Exception // If error is suppressed with @, don't throw an exception if (error_reporting() === 0 || strpos($errstr, 'headers already sent') - || strpos($errstr, 'Creation of dynamic property') !== false - || strpos($errstr, 'Legacy nullable type detected') !== false + || str_contains($errstr, 'Creation of dynamic property') + || str_contains($errstr, 'Legacy nullable type detected') || str_contains($errstr, '$tdMethods is deprecated') || $errfileReplaced && ( - strpos($errfileReplaced, DIRECTORY_SEPARATOR.'amphp'.DIRECTORY_SEPARATOR) !== false - || strpos($errfileReplaced, DIRECTORY_SEPARATOR.'league'.DIRECTORY_SEPARATOR) !== false - || strpos($errfileReplaced, DIRECTORY_SEPARATOR.'phpseclib'.DIRECTORY_SEPARATOR) !== false + str_contains($errfileReplaced, DIRECTORY_SEPARATOR.'amphp'.DIRECTORY_SEPARATOR) + || str_contains($errfileReplaced, DIRECTORY_SEPARATOR.'league'.DIRECTORY_SEPARATOR) + || str_contains($errfileReplaced, DIRECTORY_SEPARATOR.'phpseclib'.DIRECTORY_SEPARATOR) ) ) { return false; @@ -105,7 +105,7 @@ class Exception extends \Exception */ public static function exceptionHandler(\Throwable $exception): void { - $print = function (string $s): void { + $print = static function (string $s): void { Logger::log($s, Logger::FATAL_ERROR); if (headers_sent()) { return; diff --git a/src/GarbageCollector.php b/src/GarbageCollector.php index f7eeaab3c..e0b974a04 100644 --- a/src/GarbageCollector.php +++ b/src/GarbageCollector.php @@ -81,7 +81,7 @@ final class GarbageCollector $client = HttpClientBuilder::buildDefault(); $id = null; - $cb = function () use ($client, &$id): void { + $cb = static function () use ($client, &$id): void { try { $request = new Request(MADELINE_RELEASE_URL); $latest = $client->request($request); @@ -91,7 +91,7 @@ final class GarbageCollector $new = Magic::$latest_release; Logger::log("!!!!!!!!!!!!! An update of MadelineProto is required (old=$old, new=$new)! !!!!!!!!!!!!!", Logger::FATAL_ERROR); - $contents = $client->request(new Request("https://phar.madelineproto.xyz/phar.php?v=new".rand(0, PHP_INT_MAX))) + $contents = $client->request(new Request("https://phar.madelineproto.xyz/phar.php?v=new".random_int(0, PHP_INT_MAX))) ->getBody() ->buffer(); diff --git a/src/Ipc/Runner/ProcessRunner.php b/src/Ipc/Runner/ProcessRunner.php index e862b84dc..2c796631b 100644 --- a/src/Ipc/Runner/ProcessRunner.php +++ b/src/Ipc/Runner/ProcessRunner.php @@ -112,11 +112,11 @@ final class ProcessRunner extends RunnerAbstract } } $envVars = array_merge( - array_filter($_SERVER, fn ($v, $k): bool => \is_string($v) && !\in_array($k, self::CGI_VARS, true), ARRAY_FILTER_USE_BOTH), + array_filter($_SERVER, static fn ($v, $k): bool => \is_string($v) && !\in_array($k, self::CGI_VARS, true), ARRAY_FILTER_USE_BOTH), [ 'QUERY_STRING' => http_build_query($params), 'absoluteRootDir' => $root, - 'serverName' => $_SERVER['SERVER_NAME'] ?? '' + 'serverName' => $_SERVER['SERVER_NAME'] ?? '', ], ); diff --git a/src/Ipc/Runner/WebRunner.php b/src/Ipc/Runner/WebRunner.php index e935ac1c5..16b1bffb7 100644 --- a/src/Ipc/Runner/WebRunner.php +++ b/src/Ipc/Runner/WebRunner.php @@ -68,7 +68,7 @@ final class WebRunner extends RunnerAbstract $params = [ 'argv' => ['madeline-ipc', $session, $startupId], 'cwd' => Magic::getcwd(), - 'MadelineSelfRestart' => 1 + 'MadelineSelfRestart' => 1, ]; if (\function_exists('memprof_enabled') && memprof_enabled()) { $params['MEMPROF_PROFILE'] = '1'; @@ -80,7 +80,7 @@ final class WebRunner extends RunnerAbstract } private static ?string $absoluteRootDir = null; - final public static function getAbsoluteRootDir(): string + public static function getAbsoluteRootDir(): string { if (self::$absoluteRootDir) { return self::$absoluteRootDir; diff --git a/src/Ipc/Runner/entry.php b/src/Ipc/Runner/entry.php index b86d67b0e..c7523ab48 100644 --- a/src/Ipc/Runner/entry.php +++ b/src/Ipc/Runner/entry.php @@ -59,7 +59,7 @@ use Webmozart\Assert\Assert; if (\defined('SIGHUP')) { try { - pcntl_signal(SIGHUP, fn () => null); + pcntl_signal(SIGHUP, static fn () => null); } catch (\Throwable $e) { } } diff --git a/src/Ipc/Server.php b/src/Ipc/Server.php index 894ba9c66..29b694c51 100644 --- a/src/Ipc/Server.php +++ b/src/Ipc/Server.php @@ -52,11 +52,11 @@ class Server extends Loop /** * Server version. */ - const VERSION = 1; + public const VERSION = 1; /** * Shutdown server. */ - const SHUTDOWN = 0; + public const SHUTDOWN = 0; /** * Boolean to shut down worker, if started. */ @@ -246,7 +246,7 @@ class Server extends Loop $result = new ExitFailure($e); } finally { if (isset($wrapper)) { - EventLoop::queue(function () use ($wrapper): void { + EventLoop::queue(static function () use ($wrapper): void { try { $wrapper->disconnect(); } catch (Throwable $e) { diff --git a/src/Logger.php b/src/Logger.php index 0e2658cc2..ddeb6e534 100644 --- a/src/Logger.php +++ b/src/Logger.php @@ -54,19 +54,19 @@ final class Logger /** * @internal ANSI foreground color escapes */ - const FOREGROUND = ['default' => 39, 'black' => 30, 'red' => 31, 'green' => 32, 'yellow' => 33, 'blue' => 34, 'magenta' => 35, 'cyan' => 36, 'light_gray' => 37, 'dark_gray' => 90, 'light_red' => 91, 'light_green' => 92, 'light_yellow' => 93, 'light_blue' => 94, 'light_magenta' => 95, 'light_cyan' => 96, 'white' => 97]; + public const FOREGROUND = ['default' => 39, 'black' => 30, 'red' => 31, 'green' => 32, 'yellow' => 33, 'blue' => 34, 'magenta' => 35, 'cyan' => 36, 'light_gray' => 37, 'dark_gray' => 90, 'light_red' => 91, 'light_green' => 92, 'light_yellow' => 93, 'light_blue' => 94, 'light_magenta' => 95, 'light_cyan' => 96, 'white' => 97]; /** * @internal ANSI background color escapes */ - const BACKGROUND = ['default' => 49, 'black' => 40, 'red' => 41, 'magenta' => 45, 'yellow' => 43, 'green' => 42, 'blue' => 44, 'cyan' => 46, 'light_gray' => 47, 'dark_gray' => 100, 'light_red' => 101, 'light_green' => 102, 'light_yellow' => 103, 'light_blue' => 104, 'light_magenta' => 105, 'light_cyan' => 106, 'white' => 107]; + public const BACKGROUND = ['default' => 49, 'black' => 40, 'red' => 41, 'magenta' => 45, 'yellow' => 43, 'green' => 42, 'blue' => 44, 'cyan' => 46, 'light_gray' => 47, 'dark_gray' => 100, 'light_red' => 101, 'light_green' => 102, 'light_yellow' => 103, 'light_blue' => 104, 'light_magenta' => 105, 'light_cyan' => 106, 'white' => 107]; /** * @internal ANSI modifier escapes */ - const SET = ['bold' => 1, 'dim' => 2, 'underlined' => 3, 'blink' => 4, 'reverse' => 5, 'hidden' => 6]; + public const SET = ['bold' => 1, 'dim' => 2, 'underlined' => 3, 'blink' => 4, 'reverse' => 5, 'hidden' => 6]; /** * @internal ANSI reset modifier escapes */ - const RESET = ['all' => 0, 'bold' => 21, 'dim' => 22, 'underlined' => 24, 'blink' => 25, 'reverse' => 26, 'hidden' => 28]; + public const RESET = ['all' => 0, 'bold' => 21, 'dim' => 22, 'underlined' => 24, 'blink' => 25, 'reverse' => 26, 'hidden' => 28]; /** * Logging mode. * @@ -134,104 +134,104 @@ final class Logger * * @internal */ - const ULTRA_VERBOSE = 5; + public const ULTRA_VERBOSE = 5; /** * Verbose logging. * * @internal */ - const VERBOSE = 4; + public const VERBOSE = 4; /** * Notice logging. * * @internal */ - const NOTICE = 3; + public const NOTICE = 3; /** * Warning logging. * * @internal */ - const WARNING = 2; + public const WARNING = 2; /** * Error logging. * * @internal */ - const ERROR = 1; + public const ERROR = 1; /** * Log only fatal errors. * * @internal */ - const FATAL_ERROR = 0; + public const FATAL_ERROR = 0; /** * Default logger (syslog). * * @internal */ - const DEFAULT_LOGGER = 1; + public const DEFAULT_LOGGER = 1; /** * File logger. * * @internal */ - const FILE_LOGGER = 2; + public const FILE_LOGGER = 2; /** * Echo logger. * * @internal */ - const ECHO_LOGGER = 3; + public const ECHO_LOGGER = 3; /** * Callable logger. * * @internal */ - const CALLABLE_LOGGER = 4; + public const CALLABLE_LOGGER = 4; /** * Ultra verbose level. */ - const LEVEL_ULTRA_VERBOSE = self::ULTRA_VERBOSE; + public const LEVEL_ULTRA_VERBOSE = self::ULTRA_VERBOSE; /** * Verbose level. */ - const LEVEL_VERBOSE = self::VERBOSE; + public const LEVEL_VERBOSE = self::VERBOSE; /** * Notice level. */ - const LEVEL_NOTICE = self::NOTICE; + public const LEVEL_NOTICE = self::NOTICE; /** * Warning level. */ - const LEVEL_WARNING = self::WARNING; + public const LEVEL_WARNING = self::WARNING; /** * Error level. */ - const LEVEL_ERROR = self::ERROR; + public const LEVEL_ERROR = self::ERROR; /** * Fatal error level. */ - const LEVEL_FATAL = self::FATAL_ERROR; + public const LEVEL_FATAL = self::FATAL_ERROR; /** * Default logger (syslog). */ - const LOGGER_DEFAULT = self::DEFAULT_LOGGER; + public const LOGGER_DEFAULT = self::DEFAULT_LOGGER; /** * Echo logger. */ - const LOGGER_ECHO = self::ECHO_LOGGER; + public const LOGGER_ECHO = self::ECHO_LOGGER; /** * File logger. */ - const LOGGER_FILE = self::FILE_LOGGER; + public const LOGGER_FILE = self::FILE_LOGGER; /** * Callable logger. */ - const LOGGER_CALLABLE = self::CALLABLE_LOGGER; + public const LOGGER_CALLABLE = self::CALLABLE_LOGGER; /** * Construct global static logger from MadelineProto settings. diff --git a/src/Loop/Connection/WriteLoop.php b/src/Loop/Connection/WriteLoop.php index 09e3bf79e..c9d55f2af 100644 --- a/src/Loop/Connection/WriteLoop.php +++ b/src/Loop/Connection/WriteLoop.php @@ -40,9 +40,9 @@ use function strlen; */ final class WriteLoop extends Loop { - const MAX_COUNT = 1020; + public const MAX_COUNT = 1020; private const MAX_SIZE = 1 << 15; - const MAX_IDS = 8192; + public const MAX_IDS = 8192; use Common; /** @@ -226,9 +226,9 @@ final class WriteLoop extends Loop 'lang_code' => $this->API->settings->getAppInfo()->getLangCode(), 'lang_pack' => $this->API->settings->getAppInfo()->getLangPack(), 'proxy' => $this->connection->getInputClientProxy(), - 'query' => $MTmessage['body'] + 'query' => $MTmessage['body'], ] - ) + ), ])); } else { $this->API->logger("Skipping $message due to uninited connection in DC $this->datacenter"); @@ -257,7 +257,7 @@ final class WriteLoop extends Loop 'invokeAfterMsg', [ 'msg_id' => $prevId, - 'query' => $MTmessage['body'] + 'query' => $MTmessage['body'], ] ); } diff --git a/src/Loop/Generic/PeriodicLoopInternal.php b/src/Loop/Generic/PeriodicLoopInternal.php index af4a67f0c..2836a9326 100644 --- a/src/Loop/Generic/PeriodicLoopInternal.php +++ b/src/Loop/Generic/PeriodicLoopInternal.php @@ -45,6 +45,6 @@ final class PeriodicLoopInternal extends PeriodicLoop public function __construct(MTProto $API, callable $callable, string $name, ?int $interval) { $this->init($API); - parent::__construct(fn () => $callable(), $name, $interval); + parent::__construct(static fn () => $callable(), $name, $interval); } } diff --git a/src/Loop/Update/FeedLoop.php b/src/Loop/Update/FeedLoop.php index 3a0aaec1c..78bce9637 100644 --- a/src/Loop/Update/FeedLoop.php +++ b/src/Loop/Update/FeedLoop.php @@ -43,7 +43,7 @@ final class FeedLoop extends Loop /** * Main loop ID. */ - const GENERIC = 0; + public const GENERIC = 0; /** * Incoming updates array. */ diff --git a/src/Loop/Update/UpdateLoop.php b/src/Loop/Update/UpdateLoop.php index 94923a48e..d4f745fc7 100644 --- a/src/Loop/Update/UpdateLoop.php +++ b/src/Loop/Update/UpdateLoop.php @@ -47,7 +47,7 @@ final class UpdateLoop extends Loop /** * Main loop ID. */ - const GENERIC = 0; + public const GENERIC = 0; private const DEFAULT_TIMEOUT = 10.0; diff --git a/src/Loop/VoIP/DjLoop.php b/src/Loop/VoIP/DjLoop.php index 8d974e55b..923448dbd 100644 --- a/src/Loop/VoIP/DjLoop.php +++ b/src/Loop/VoIP/DjLoop.php @@ -90,11 +90,11 @@ final class DjLoop extends VoIPLoop 'instance' => $this->instance, 'holdFiles' => array_filter( $this->holdFiles, - fn ($v) => !$v instanceof ReadableStream + static fn ($v) => !$v instanceof ReadableStream ), 'inputFiles' => array_filter( $this->inputFiles, - fn ($v) => !$v instanceof ReadableStream + static fn ($v) => !$v instanceof ReadableStream ), 'packetQueuePrimary' => $this->packetQueuePrimary, 'packetQueueSecondary' => $this->packetQueueSecondary, @@ -206,7 +206,7 @@ final class DjLoop extends VoIPLoop } $this->instance->log("Starting conversion fiber..."); $pipe = new Pipe(4096); - EventLoop::queue(function () use ($f, $pipe, $cancellation): void { + EventLoop::queue(static function () use ($f, $pipe, $cancellation): void { try { Ogg::convert($f, $pipe->getSink(), $cancellation); } catch (CancelledException) { diff --git a/src/MTProto.php b/src/MTProto.php index 1dac3e463..89a4a50e5 100644 --- a/src/MTProto.php +++ b/src/MTProto.php @@ -122,37 +122,37 @@ final class MTProto implements TLCallback, LoggerGetter, SettingsGetter * @internal * @var int */ - const V = 176; + public const V = 176; /** * Bad message error codes. * * @internal * @var array */ - const BAD_MSG_ERROR_CODES = [16 => 'msg_id too low (most likely, client time is wrong; it would be worthwhile to synchronize it using msg_id notifications and re-send the original message with the correct msg_id or wrap it in a container with a new msg_id if the original message had waited too long on the client to be transmitted)', 17 => 'msg_id too high (similar to the previous case, the client time has to be synchronized, and the message re-sent with the correct msg_id)', 18 => 'incorrect two lower order msg_id bits (the server expects client message msg_id to be divisible by 4)', 19 => 'container msg_id is the same as msg_id of a previously received message (this must never happen)', 20 => 'message too old, and it cannot be verified whether the server has received a message with this msg_id or not', 32 => 'msg_seqno too low (the server has already received a message with a lower msg_id but with either a higher or an equal and odd seqno)', 33 => 'msg_seqno too high (similarly, there is a message with a higher msg_id but with either a lower or an equal and odd seqno)', 34 => 'an even msg_seqno expected (irrelevant message), but odd received', 35 => 'odd msg_seqno expected (relevant message), but even received', 48 => 'incorrect server salt (in this case, the bad_server_salt response is received with the correct salt, and the message is to be re-sent with it)', 64 => 'invalid container']; + public const BAD_MSG_ERROR_CODES = [16 => 'msg_id too low (most likely, client time is wrong; it would be worthwhile to synchronize it using msg_id notifications and re-send the original message with the correct msg_id or wrap it in a container with a new msg_id if the original message had waited too long on the client to be transmitted)', 17 => 'msg_id too high (similar to the previous case, the client time has to be synchronized, and the message re-sent with the correct msg_id)', 18 => 'incorrect two lower order msg_id bits (the server expects client message msg_id to be divisible by 4)', 19 => 'container msg_id is the same as msg_id of a previously received message (this must never happen)', 20 => 'message too old, and it cannot be verified whether the server has received a message with this msg_id or not', 32 => 'msg_seqno too low (the server has already received a message with a lower msg_id but with either a higher or an equal and odd seqno)', 33 => 'msg_seqno too high (similarly, there is a message with a higher msg_id but with either a lower or an equal and odd seqno)', 34 => 'an even msg_seqno expected (irrelevant message), but odd received', 35 => 'odd msg_seqno expected (relevant message), but even received', 48 => 'incorrect server salt (in this case, the bad_server_salt response is received with the correct salt, and the message is to be re-sent with it)', 64 => 'invalid container']; /** * Localized message info flags. * * @internal * @var array */ - const MSGS_INFO_FLAGS = [1 => 'nothing is known about the message (msg_id too low, the other party may have forgotten it)', 2 => 'message not received (msg_id falls within the range of stored identifiers; however, the other party has certainly not received a message like that)', 3 => 'message not received (msg_id too high; however, the other party has certainly not received it yet)', 4 => 'message received (note that this response is also at the same time a receipt acknowledgment)', 8 => ' and message already acknowledged', 16 => ' and message not requiring acknowledgment', 32 => ' and RPC query contained in message being processed or processing already complete', 64 => ' and content-related response to message already generated', 128 => ' and other party knows for a fact that message is already received']; + public const MSGS_INFO_FLAGS = [1 => 'nothing is known about the message (msg_id too low, the other party may have forgotten it)', 2 => 'message not received (msg_id falls within the range of stored identifiers; however, the other party has certainly not received a message like that)', 3 => 'message not received (msg_id too high; however, the other party has certainly not received it yet)', 4 => 'message received (note that this response is also at the same time a receipt acknowledgment)', 8 => ' and message already acknowledged', 16 => ' and message not requiring acknowledgment', 32 => ' and RPC query contained in message being processed or processing already complete', 64 => ' and content-related response to message already generated', 128 => ' and other party knows for a fact that message is already received']; /** * @internal */ - const TD_PARAMS_CONVERSION = ['updateNewMessage' => ['_' => 'updateNewMessage', 'disable_notification' => ['message', 'silent'], 'message' => ['message']], 'message' => ['_' => 'message', 'id' => ['id'], 'sender_user_id' => ['from_id'], 'chat_id' => ['peer_id', 'choose_chat_id_from_botapi'], 'send_state' => ['choose_incoming_or_sent'], 'can_be_edited' => ['choose_can_edit'], 'can_be_deleted' => ['choose_can_delete'], 'is_post' => ['post'], 'date' => ['date'], 'edit_date' => ['edit_date'], 'forward_info' => ['fwd_info', 'choose_forward_info'], 'reply_to_message_id' => ['reply_to_msg_id'], 'ttl' => ['choose_ttl'], 'ttl_expires_in' => ['choose_ttl_expires_in'], 'via_bot_user_id' => ['via_bot_id'], 'views' => ['views'], 'content' => ['choose_message_content'], 'reply_markup' => ['reply_markup']], 'messages.sendMessage' => ['chat_id' => ['peer'], 'reply_to_message_id' => ['reply_to_msg_id'], 'disable_notification' => ['silent'], 'from_background' => ['background'], 'input_message_content' => ['choose_message_content'], 'reply_markup' => ['reply_markup']]]; + public const TD_PARAMS_CONVERSION = ['updateNewMessage' => ['_' => 'updateNewMessage', 'disable_notification' => ['message', 'silent'], 'message' => ['message']], 'message' => ['_' => 'message', 'id' => ['id'], 'sender_user_id' => ['from_id'], 'chat_id' => ['peer_id', 'choose_chat_id_from_botapi'], 'send_state' => ['choose_incoming_or_sent'], 'can_be_edited' => ['choose_can_edit'], 'can_be_deleted' => ['choose_can_delete'], 'is_post' => ['post'], 'date' => ['date'], 'edit_date' => ['edit_date'], 'forward_info' => ['fwd_info', 'choose_forward_info'], 'reply_to_message_id' => ['reply_to_msg_id'], 'ttl' => ['choose_ttl'], 'ttl_expires_in' => ['choose_ttl_expires_in'], 'via_bot_user_id' => ['via_bot_id'], 'views' => ['views'], 'content' => ['choose_message_content'], 'reply_markup' => ['reply_markup']], 'messages.sendMessage' => ['chat_id' => ['peer'], 'reply_to_message_id' => ['reply_to_msg_id'], 'disable_notification' => ['silent'], 'from_background' => ['background'], 'input_message_content' => ['choose_message_content'], 'reply_markup' => ['reply_markup']]]; /** * @internal */ - const TD_REVERSE = ['sendMessage' => 'messages.sendMessage']; + public const TD_REVERSE = ['sendMessage' => 'messages.sendMessage']; /** * @internal */ - const TD_IGNORE = ['updateMessageID']; + public const TD_IGNORE = ['updateMessageID']; /** * @internal */ - const BOTAPI_PARAMS_CONVERSION = ['disable_web_page_preview' => 'no_webpage', 'disable_notification' => 'silent', 'reply_to_message_id' => 'reply_to_msg_id', 'chat_id' => 'peer', 'text' => 'message']; + public const BOTAPI_PARAMS_CONVERSION = ['disable_web_page_preview' => 'no_webpage', 'disable_notification' => 'silent', 'reply_to_message_id' => 'reply_to_msg_id', 'chat_id' => 'peer', 'text' => 'message']; /** * Array of references to all instances of MTProto. * @@ -1572,7 +1572,7 @@ final class MTProto implements TLCallback, LoggerGetter, SettingsGetter public function setReportPeers(int|string|array $userOrId): void { $this->reportDest = $this->sanitizeReportPeers($userOrId); - $this->admins = array_values(array_filter($this->reportDest, fn (int $v) => $v > 0)); + $this->admins = array_values(array_filter($this->reportDest, static fn (int $v) => $v > 0)); } /** * Flush all postponed messages. @@ -1762,7 +1762,7 @@ final class MTProto implements TLCallback, LoggerGetter, SettingsGetter }], 'config' => [function (array $config): void { $this->config = $config; - }] + }], ]; } /** @@ -1813,9 +1813,7 @@ final class MTProto implements TLCallback, LoggerGetter, SettingsGetter [ 'InputFileLocation' => $this->getDownloadInfo(...), 'InputPeer' => $this->getInputPeer(...), - 'InputCheckPasswordSRP' => function (string $password): array { - return (new PasswordCalculator($this->methodCallAsyncRead('account.getPassword', [])))->getCheckPassword($password); - }, + 'InputCheckPasswordSRP' => fn (string $password): array => (new PasswordCalculator($this->methodCallAsyncRead('account.getPassword', [])))->getCheckPassword($password), ], ); } diff --git a/src/MTProto/AuthKey.php b/src/MTProto/AuthKey.php index c98dd74a7..a36353195 100644 --- a/src/MTProto/AuthKey.php +++ b/src/MTProto/AuthKey.php @@ -53,8 +53,8 @@ abstract class AuthKey implements JsonSerializable public function __construct(array $old = []) { if (isset($old['auth_key'])) { - if (\strlen($old['auth_key']) !== 2048 / 8 && strpos($old['auth_key'], 'pony') === 0) { - $old['auth_key'] = base64_decode(substr($old['auth_key'], 4)); + if (\strlen($old['auth_key']) !== 2048 / 8 && str_starts_with($old['auth_key'], 'pony')) { + $old['auth_key'] = base64_decode(substr($old['auth_key'], 4), true); } $this->setAuthKey($old['auth_key']); } diff --git a/src/MTProto/MTProtoIncomingMessage.php b/src/MTProto/MTProtoIncomingMessage.php index 734b132f9..f9a993663 100644 --- a/src/MTProto/MTProtoIncomingMessage.php +++ b/src/MTProto/MTProtoIncomingMessage.php @@ -30,15 +30,15 @@ final class MTProtoIncomingMessage extends MTProtoMessage /** * We have received this message. */ - const STATE_RECEIVED = 4; + public const STATE_RECEIVED = 4; /** * We have acknowledged this message. */ - const STATE_ACKED = 8; + public const STATE_ACKED = 8; /** * We have read the contents of this message. */ - const STATE_READ = 128; + public const STATE_READ = 128; /** * Response field map. diff --git a/src/MTProto/MTProtoOutgoingMessage.php b/src/MTProto/MTProtoOutgoingMessage.php index 54ca5a5a5..e2c98bdc5 100644 --- a/src/MTProto/MTProtoOutgoingMessage.php +++ b/src/MTProto/MTProtoOutgoingMessage.php @@ -40,19 +40,19 @@ class MTProtoOutgoingMessage extends MTProtoMessage /** * The message was created. */ - const STATE_PENDING = 0; + public const STATE_PENDING = 0; /** * The message was sent. */ - const STATE_SENT = 1; + public const STATE_SENT = 1; /** * The message was acked. */ - const STATE_ACKED = 2; + public const STATE_ACKED = 2; /** * We got a reply to the message. */ - const STATE_REPLIED = self::STATE_ACKED | 4; + public const STATE_REPLIED = self::STATE_ACKED | 4; /** * State of message. @@ -127,7 +127,7 @@ class MTProtoOutgoingMessage extends MTProtoMessage $this->userRelated = $constructor === 'users.getUsers' && $body === ['id' => [['_' => 'inputUserSelf']]] || $constructor === 'auth.exportAuthorization' || $constructor === 'updates.getDifference'; parent::__construct(!isset(MTProtoMessage::NOT_CONTENT_RELATED[$constructor])); - $cancellation?->subscribe(fn (CancelledException $e) => $this->reply(fn () => throw $e)); + $cancellation?->subscribe(fn (CancelledException $e) => $this->reply(static fn () => throw $e)); } /** diff --git a/src/MTProtoSession/AckHandler.php b/src/MTProtoSession/AckHandler.php index 3afc8b66f..09ef86fdc 100644 --- a/src/MTProtoSession/AckHandler.php +++ b/src/MTProtoSession/AckHandler.php @@ -122,7 +122,7 @@ trait AckHandler continue; } if ($message->getSent() + $dropTimeout < time()) { - $this->handleReject($message, fn () => new Exception('Request timeout')); + $this->handleReject($message, static fn () => new Exception('Request timeout')); continue; } if ($message->getState() & MTProtoOutgoingMessage::STATE_REPLIED) { diff --git a/src/MTProtoSession/CallHandler.php b/src/MTProtoSession/CallHandler.php index df659c84e..58cd4021f 100644 --- a/src/MTProtoSession/CallHandler.php +++ b/src/MTProtoSession/CallHandler.php @@ -137,8 +137,8 @@ trait CallHandler if (!$postpone) { $this->flush(); } - return new WrappedFuture(async(fn () => array_map( - fn (WrappedFuture $f) => $f->await(), + return new WrappedFuture(async(static fn () => array_map( + static fn (WrappedFuture $f) => $f->await(), await($promises) ))); } diff --git a/src/MTProtoSession/ResponseHandler.php b/src/MTProtoSession/ResponseHandler.php index 11a3dc548..373e3598e 100644 --- a/src/MTProtoSession/ResponseHandler.php +++ b/src/MTProtoSession/ResponseHandler.php @@ -200,7 +200,7 @@ trait ResponseHandler try { $exception = $this->handleRpcError($request, $response); } catch (Throwable $e) { - $exception = fn () => $e; + $exception = static fn () => $e; } if ($exception) { $this->handleReject($request, $exception); @@ -229,7 +229,7 @@ trait ResponseHandler EventLoop::queue($this->methodRecall(...), $requestId); return; } - $this->handleReject($request, fn () => new RPCErrorException('Received bad_msg_notification: ' . MTProto::BAD_MSG_ERROR_CODES[$response['error_code']], $response['error_code'], $request->getConstructor())); + $this->handleReject($request, static fn () => new RPCErrorException('Received bad_msg_notification: ' . MTProto::BAD_MSG_ERROR_CODES[$response['error_code']], $response['error_code'], $request->getConstructor())); return; } @@ -284,7 +284,7 @@ trait ResponseHandler $this->shared->getTempAuthKey()->init(true); } if (\in_array($response['error_message'], ['PERSISTENT_TIMESTAMP_EMPTY', 'PERSISTENT_TIMESTAMP_INVALID'], true)) { - return fn () => new PTSException($response['error_message']); + return static fn () => new PTSException($response['error_message']); } if ($response['error_message'] === 'PERSISTENT_TIMESTAMP_OUTDATED') { $response['error_code'] = 500; @@ -335,7 +335,7 @@ trait ResponseHandler EventLoop::delay(1.0, fn () => $this->methodRecall($msgId)); return null; } - return fn () => new RPCErrorException($response['error_message'], $response['error_code'], $request->getConstructor()); + return static fn () => new RPCErrorException($response['error_message'], $response['error_code'], $request->getConstructor()); case 303: $datacenter = (int) preg_replace('/[^0-9]+/', '', $response['error_message']); if ($this->API->isTestMode()) { @@ -379,7 +379,7 @@ trait ResponseHandler } return null; } - return fn () => new RPCErrorException($response['error_message'], $response['error_code'], $request->getConstructor()); + return static fn () => new RPCErrorException($response['error_message'], $response['error_code'], $request->getConstructor()); case 401: switch ($response['error_message']) { case 'USER_DEACTIVATED': @@ -400,7 +400,7 @@ trait ResponseHandler EventLoop::queue( $this->handleReject(...), $request, - fn () => new RPCErrorException($response['error_message'], $response['error_code'], $request->getConstructor()) + static fn () => new RPCErrorException($response['error_message'], $response['error_code'], $request->getConstructor()) ); return null; } @@ -427,7 +427,7 @@ trait ResponseHandler EventLoop::queue($this->methodRecall(...), $request->getMsgId()); return null; } - return fn () => new RPCErrorException($response['error_message'], $response['error_code'], $request->getConstructor()); + return static fn () => new RPCErrorException($response['error_message'], $response['error_code'], $request->getConstructor()); case 420: $seconds = preg_replace('/[^0-9]+/', '', $response['error_message']); $limit = $request->floodWaitLimit ?? $this->API->settings->getRPC()->getFloodTimeout(); @@ -440,15 +440,15 @@ trait ResponseHandler $request->setSeqNo(null); \assert($msgId !== null); $id = EventLoop::delay((float) $seconds, fn () => $this->methodRecall($msgId)); - $request->cancellation?->subscribe(fn () => EventLoop::cancel($id)); + $request->cancellation?->subscribe(static fn () => EventLoop::cancel($id)); return null; } if (str_starts_with($response['error_message'], 'FLOOD_WAIT_')) { - return fn () => new FloodWaitError($response['error_message'], $response['error_code'], $request->getConstructor()); + return static fn () => new FloodWaitError($response['error_message'], $response['error_code'], $request->getConstructor()); } // no break default: - return fn () => new RPCErrorException($response['error_message'], $response['error_code'], $request->getConstructor()); + return static fn () => new RPCErrorException($response['error_message'], $response['error_code'], $request->getConstructor()); } } } diff --git a/src/MTProtoTools/Files.php b/src/MTProtoTools/Files.php index 134ba1114..e5a3338d4 100644 --- a/src/MTProtoTools/Files.php +++ b/src/MTProtoTools/Files.php @@ -110,7 +110,7 @@ trait Files '_' => 'messageMediaDocument', 'document' => $media, 'ttl_seconds' => $media['ttl_seconds'], - 'secret' => true + 'secret' => true, ]; } if ($media['_'] !== 'messageMediaDocument') { @@ -234,8 +234,8 @@ trait Files $this->logger->logger('Upload status: '.$percent.'%', Logger::NOTICE); }; } else { - $cb = function (float $percent, float $speed, float $time) use ($cb): void { - EventLoop::queue(function () use ($percent, $speed, $time, $cb): void { + $cb = static function (float $percent, float $speed, float $time) use ($cb): void { + EventLoop::queue(static function () use ($percent, $speed, $time, $cb): void { $cb($percent, $speed, $time); }); }; @@ -272,7 +272,7 @@ trait Files $speed = 0; $time = 0; if ($size) { - $cb = function () use ($cb, $part_total_num, &$speed, &$time): void { + $cb = static function () use ($cb, $part_total_num, &$speed, &$time): void { static $cur = 0; $cur++; $cb($cur * 100 / $part_total_num, $speed, $time); @@ -996,7 +996,7 @@ trait Files $this->logger->logger('Waiting for lock of file to download...'); $unlock = Tools::flock("$file.lock", LOCK_EX); $this->logger->logger('Got lock of file to download'); - async($this->downloadToStream(...), $messageMedia, $stream, $cb, $size, -1, $cancellation)->finally(function () use ($stream, $unlock, $file): void { + async($this->downloadToStream(...), $messageMedia, $stream, $cb, $size, -1, $cancellation)->finally(static function () use ($stream, $unlock, $file): void { $stream->close(); $unlock(); try { @@ -1034,8 +1034,8 @@ trait Files $this->logger->logger('Download status: '.$percent.'%', Logger::NOTICE); }; } else { - $cb = function (float $percent, float $speed, float $time) use ($cb): void { - EventLoop::queue(function () use ($percent, $speed, $time, $cb): void { + $cb = static function (float $percent, float $speed, float $time) use ($cb): void { + EventLoop::queue(static function () use ($percent, $speed, $time, $cb): void { $cb($percent, $speed, $time); }); }; diff --git a/src/MTProtoTools/FilesAbstraction.php b/src/MTProtoTools/FilesAbstraction.php index 2c847efda..566a9a5c8 100644 --- a/src/MTProtoTools/FilesAbstraction.php +++ b/src/MTProtoTools/FilesAbstraction.php @@ -405,7 +405,7 @@ trait FilesAbstraction '_' => 'inputMediaUploadedPhoto', 'spoiler' => $spoiler, 'file' => $file, - 'ttl_seconds' => $ttl + 'ttl_seconds' => $ttl, ], default => [ '_' => 'inputMediaUploadedDocument', @@ -415,7 +415,7 @@ trait FilesAbstraction 'file' => $file, 'thumb' => $thumb, 'mime_type' => $mimeType, - 'attributes' => $attributes + 'attributes' => $attributes, ] }; if ($reuseId) { diff --git a/src/MTProtoTools/FilesLogic.php b/src/MTProtoTools/FilesLogic.php index 75e9c5e10..aaa2999e6 100644 --- a/src/MTProtoTools/FilesLogic.php +++ b/src/MTProtoTools/FilesLogic.php @@ -230,7 +230,7 @@ trait FilesLogic $result = ResponseInfo::parseHeaders( $request->getMethod(), - array_map(fn (array $headers) => $headers[0], $request->getHeaders()), + array_map(static fn (array $headers) => $headers[0], $request->getHeaders()), $messageMedia, ); diff --git a/src/MTProtoTools/MinDatabase.php b/src/MTProtoTools/MinDatabase.php index f63e8a745..d26e61a08 100644 --- a/src/MTProtoTools/MinDatabase.php +++ b/src/MTProtoTools/MinDatabase.php @@ -38,9 +38,9 @@ final class MinDatabase implements TLCallback { use DbPropertiesTrait; - const SWITCH_CONSTRUCTORS = ['inputChannel', 'inputUser', 'inputPeerUser', 'inputPeerChannel']; - const CATCH_PEERS = ['message', 'messageService', 'peerUser', 'peerChannel', 'messageEntityMentionName', 'messageFwdHeader', 'messageActionChatCreate', 'messageActionChatAddUser', 'messageActionChatDeleteUser', 'messageActionChatJoinedByLink']; - const ORIGINS = ['message', 'messageService']; + public const SWITCH_CONSTRUCTORS = ['inputChannel', 'inputUser', 'inputPeerUser', 'inputPeerChannel']; + public const CATCH_PEERS = ['message', 'messageService', 'peerUser', 'peerChannel', 'messageEntityMentionName', 'messageFwdHeader', 'messageActionChatCreate', 'messageActionChatAddUser', 'messageActionChatDeleteUser', 'messageActionChatJoinedByLink']; + public const ORIGINS = ['message', 'messageService']; private const V = 1; /** * References indexed by location. diff --git a/src/MTProtoTools/PeerDatabase.php b/src/MTProtoTools/PeerDatabase.php index 4b00d7998..ec9fe3bf6 100644 --- a/src/MTProtoTools/PeerDatabase.php +++ b/src/MTProtoTools/PeerDatabase.php @@ -85,16 +85,16 @@ final class PeerDatabase implements TLCallback protected static array $dbProperties = [ 'db' => [ 'innerMadelineProto' => true, - 'table' => 'MTProto_chats' + 'table' => 'MTProto_chats', ], 'fullDb' => [ 'innerMadelineProto' => true, - 'table' => 'MTProto_full_chats' + 'table' => 'MTProto_full_chats', ], 'usernames' => [ 'innerMadelineProto' => true, 'innerMadelineProtoSerializer' => SerializerType::STRING, - 'table' => 'MTProto_usernames' + 'table' => 'MTProto_usernames', ], ]; diff --git a/src/MTProtoTools/PeerHandler.php b/src/MTProtoTools/PeerHandler.php index ea6fcb2f8..dafcd3ab2 100644 --- a/src/MTProtoTools/PeerHandler.php +++ b/src/MTProtoTools/PeerHandler.php @@ -167,7 +167,7 @@ trait PeerHandler */ public function getId(mixed $id): int { - if (\is_integer($id)) { + if (\is_int($id)) { return $id; } return $this->getInfo($id, \danog\MadelineProto\API::INFO_TYPE_ID); @@ -306,7 +306,7 @@ trait PeerHandler } } if (\is_string($id)) { - if (strpos($id, '#') !== false) { + if (str_contains($id, '#')) { if (preg_match('/^channel#(\\d*)/', $id, $matches)) { return DialogId::fromSupergroupOrChannel((int) $matches[1]); } diff --git a/src/MTProtoTools/ReferenceDatabase.php b/src/MTProtoTools/ReferenceDatabase.php index 56636e743..792620ca3 100644 --- a/src/MTProtoTools/ReferenceDatabase.php +++ b/src/MTProtoTools/ReferenceDatabase.php @@ -46,34 +46,34 @@ final class ReferenceDatabase implements TLCallback return $this->API->getDbPrefix(); } // Reference from a document - const DOCUMENT_LOCATION = 0; + public const DOCUMENT_LOCATION = 0; // Reference from a photo - const PHOTO_LOCATION = 1; + public const PHOTO_LOCATION = 1; // Reference from a photo location (can only be photo location) - const PHOTO_LOCATION_LOCATION = 2; + public const PHOTO_LOCATION_LOCATION = 2; // Peer + photo ID - const USER_PHOTO_ORIGIN = 0; + public const USER_PHOTO_ORIGIN = 0; // Peer (default photo ID) - const PEER_PHOTO_ORIGIN = 1; + public const PEER_PHOTO_ORIGIN = 1; // set ID - const STICKER_SET_ID_ORIGIN = 2; + public const STICKER_SET_ID_ORIGIN = 2; // Peer + msg ID - const MESSAGE_ORIGIN = 3; - const SAVED_GIFS_ORIGIN = 4; - const STICKER_SET_RECENT_ORIGIN = 5; - const STICKER_SET_FAVED_ORIGIN = 6; + public const MESSAGE_ORIGIN = 3; + public const SAVED_GIFS_ORIGIN = 4; + public const STICKER_SET_RECENT_ORIGIN = 5; + public const STICKER_SET_FAVED_ORIGIN = 6; // emoticon - const STICKER_SET_EMOTICON_ORIGIN = 8; - const WALLPAPER_ORIGIN = 9; - const LOCATION_CONTEXT = [ + public const STICKER_SET_EMOTICON_ORIGIN = 8; + public const WALLPAPER_ORIGIN = 9; + public const LOCATION_CONTEXT = [ //'inputFileLocation' => self::PHOTO_LOCATION_LOCATION, // DEPRECATED 'inputDocumentFileLocation' => self::DOCUMENT_LOCATION, 'inputPhotoFileLocation' => self::PHOTO_LOCATION, 'inputPhoto' => self::PHOTO_LOCATION, 'inputDocument' => self::DOCUMENT_LOCATION, ]; - const METHOD_CONTEXT = ['photos.updateProfilePhoto' => self::USER_PHOTO_ORIGIN, 'photos.getUserPhotos' => self::USER_PHOTO_ORIGIN, 'photos.uploadProfilePhoto' => self::USER_PHOTO_ORIGIN, 'messages.getStickers' => self::STICKER_SET_EMOTICON_ORIGIN]; - const CONSTRUCTOR_CONTEXT = ['message' => self::MESSAGE_ORIGIN, 'messageService' => self::MESSAGE_ORIGIN, 'chatFull' => self::PEER_PHOTO_ORIGIN, 'channelFull' => self::PEER_PHOTO_ORIGIN, 'chat' => self::PEER_PHOTO_ORIGIN, 'channel' => self::PEER_PHOTO_ORIGIN, 'updateUserPhoto' => self::USER_PHOTO_ORIGIN, 'user' => self::USER_PHOTO_ORIGIN, 'userFull' => self::USER_PHOTO_ORIGIN, 'wallPaper' => self::WALLPAPER_ORIGIN, 'messages.savedGifs' => self::SAVED_GIFS_ORIGIN, 'messages.recentStickers' => self::STICKER_SET_RECENT_ORIGIN, 'messages.favedStickers' => self::STICKER_SET_FAVED_ORIGIN, 'messages.stickerSet' => self::STICKER_SET_ID_ORIGIN, 'document' => self::STICKER_SET_ID_ORIGIN]; + public const METHOD_CONTEXT = ['photos.updateProfilePhoto' => self::USER_PHOTO_ORIGIN, 'photos.getUserPhotos' => self::USER_PHOTO_ORIGIN, 'photos.uploadProfilePhoto' => self::USER_PHOTO_ORIGIN, 'messages.getStickers' => self::STICKER_SET_EMOTICON_ORIGIN]; + public const CONSTRUCTOR_CONTEXT = ['message' => self::MESSAGE_ORIGIN, 'messageService' => self::MESSAGE_ORIGIN, 'chatFull' => self::PEER_PHOTO_ORIGIN, 'channelFull' => self::PEER_PHOTO_ORIGIN, 'chat' => self::PEER_PHOTO_ORIGIN, 'channel' => self::PEER_PHOTO_ORIGIN, 'updateUserPhoto' => self::USER_PHOTO_ORIGIN, 'user' => self::USER_PHOTO_ORIGIN, 'userFull' => self::USER_PHOTO_ORIGIN, 'wallPaper' => self::WALLPAPER_ORIGIN, 'messages.savedGifs' => self::SAVED_GIFS_ORIGIN, 'messages.recentStickers' => self::STICKER_SET_RECENT_ORIGIN, 'messages.favedStickers' => self::STICKER_SET_FAVED_ORIGIN, 'messages.stickerSet' => self::STICKER_SET_ID_ORIGIN, 'document' => self::STICKER_SET_ID_ORIGIN]; private const V = 1; /** @@ -97,7 +97,7 @@ final class ReferenceDatabase implements TLCallback * @see DbPropertiesFactory */ protected static array $dbProperties = [ - 'db' => ['innerMadelineProto' => true] + 'db' => ['innerMadelineProto' => true], ]; private LocalKeyedMutex $flushMutex; @@ -428,7 +428,7 @@ final class ReferenceDatabase implements TLCallback $this->pendingDb[$location] = [ $reference, $originType, - $origin + $origin, ]; if ($this->refresh) { diff --git a/src/MTProtoTools/UpdateHandler.php b/src/MTProtoTools/UpdateHandler.php index a41950d5f..cc9b72924 100644 --- a/src/MTProtoTools/UpdateHandler.php +++ b/src/MTProtoTools/UpdateHandler.php @@ -789,7 +789,7 @@ trait UpdateHandler 'clear_draft' => $clearDraft, 'no_webpage' => $noWebpage, 'update_stickersets_order' => $updateStickersetsOrder, - 'cancellation' => $cancellation + 'cancellation' => $cancellation, ] ); if (isset($result['_'])) { diff --git a/src/Magic.php b/src/Magic.php index 63c407131..38ac53f94 100644 --- a/src/Magic.php +++ b/src/Magic.php @@ -46,13 +46,13 @@ use function function_exists; */ final class Magic { - const ZERO_CHANNEL_ID = -1000000000000; - const ZERO_SECRET_CHAT_ID = -2000000000000; - const MIN_INT32 = -2147483648; + public const ZERO_CHANNEL_ID = -1000000000000; + public const ZERO_SECRET_CHAT_ID = -2000000000000; + public const MIN_INT32 = -2147483648; - const MAX_USER_ID = (1 << 40) - 1; - const MAX_CHAT_ID = 999_999_999_999; - const MAX_CHANNEL_ID = 1000000000000 - (1 << 31); + public const MAX_USER_ID = (1 << 40) - 1; + public const MAX_CHAT_ID = 999_999_999_999; + public const MAX_CHANNEL_ID = 1000000000000 - (1 << 31); /** * Static storage. * @@ -207,7 +207,7 @@ final class Magic * * @var string */ - const JSON_EMOJIS = '["\\ud83d\\ude09","\\ud83d\\ude0d","\\ud83d\\ude1b","\\ud83d\\ude2d","\\ud83d\\ude31","\\ud83d\\ude21","\\ud83d\\ude0e","\\ud83d\\ude34","\\ud83d\\ude35","\\ud83d\\ude08","\\ud83d\\ude2c","\\ud83d\\ude07","\\ud83d\\ude0f","\\ud83d\\udc6e","\\ud83d\\udc77","\\ud83d\\udc82","\\ud83d\\udc76","\\ud83d\\udc68","\\ud83d\\udc69","\\ud83d\\udc74","\\ud83d\\udc75","\\ud83d\\ude3b","\\ud83d\\ude3d","\\ud83d\\ude40","\\ud83d\\udc7a","\\ud83d\\ude48","\\ud83d\\ude49","\\ud83d\\ude4a","\\ud83d\\udc80","\\ud83d\\udc7d","\\ud83d\\udca9","\\ud83d\\udd25","\\ud83d\\udca5","\\ud83d\\udca4","\\ud83d\\udc42","\\ud83d\\udc40","\\ud83d\\udc43","\\ud83d\\udc45","\\ud83d\\udc44","\\ud83d\\udc4d","\\ud83d\\udc4e","\\ud83d\\udc4c","\\ud83d\\udc4a","\\u270c","\\u270b","\\ud83d\\udc50","\\ud83d\\udc46","\\ud83d\\udc47","\\ud83d\\udc49","\\ud83d\\udc48","\\ud83d\\ude4f","\\ud83d\\udc4f","\\ud83d\\udcaa","\\ud83d\\udeb6","\\ud83c\\udfc3","\\ud83d\\udc83","\\ud83d\\udc6b","\\ud83d\\udc6a","\\ud83d\\udc6c","\\ud83d\\udc6d","\\ud83d\\udc85","\\ud83c\\udfa9","\\ud83d\\udc51","\\ud83d\\udc52","\\ud83d\\udc5f","\\ud83d\\udc5e","\\ud83d\\udc60","\\ud83d\\udc55","\\ud83d\\udc57","\\ud83d\\udc56","\\ud83d\\udc59","\\ud83d\\udc5c","\\ud83d\\udc53","\\ud83c\\udf80","\\ud83d\\udc84","\\ud83d\\udc9b","\\ud83d\\udc99","\\ud83d\\udc9c","\\ud83d\\udc9a","\\ud83d\\udc8d","\\ud83d\\udc8e","\\ud83d\\udc36","\\ud83d\\udc3a","\\ud83d\\udc31","\\ud83d\\udc2d","\\ud83d\\udc39","\\ud83d\\udc30","\\ud83d\\udc38","\\ud83d\\udc2f","\\ud83d\\udc28","\\ud83d\\udc3b","\\ud83d\\udc37","\\ud83d\\udc2e","\\ud83d\\udc17","\\ud83d\\udc34","\\ud83d\\udc11","\\ud83d\\udc18","\\ud83d\\udc3c","\\ud83d\\udc27","\\ud83d\\udc25","\\ud83d\\udc14","\\ud83d\\udc0d","\\ud83d\\udc22","\\ud83d\\udc1b","\\ud83d\\udc1d","\\ud83d\\udc1c","\\ud83d\\udc1e","\\ud83d\\udc0c","\\ud83d\\udc19","\\ud83d\\udc1a","\\ud83d\\udc1f","\\ud83d\\udc2c","\\ud83d\\udc0b","\\ud83d\\udc10","\\ud83d\\udc0a","\\ud83d\\udc2b","\\ud83c\\udf40","\\ud83c\\udf39","\\ud83c\\udf3b","\\ud83c\\udf41","\\ud83c\\udf3e","\\ud83c\\udf44","\\ud83c\\udf35","\\ud83c\\udf34","\\ud83c\\udf33","\\ud83c\\udf1e","\\ud83c\\udf1a","\\ud83c\\udf19","\\ud83c\\udf0e","\\ud83c\\udf0b","\\u26a1","\\u2614","\\u2744","\\u26c4","\\ud83c\\udf00","\\ud83c\\udf08","\\ud83c\\udf0a","\\ud83c\\udf93","\\ud83c\\udf86","\\ud83c\\udf83","\\ud83d\\udc7b","\\ud83c\\udf85","\\ud83c\\udf84","\\ud83c\\udf81","\\ud83c\\udf88","\\ud83d\\udd2e","\\ud83c\\udfa5","\\ud83d\\udcf7","\\ud83d\\udcbf","\\ud83d\\udcbb","\\u260e","\\ud83d\\udce1","\\ud83d\\udcfa","\\ud83d\\udcfb","\\ud83d\\udd09","\\ud83d\\udd14","\\u23f3","\\u23f0","\\u231a","\\ud83d\\udd12","\\ud83d\\udd11","\\ud83d\\udd0e","\\ud83d\\udca1","\\ud83d\\udd26","\\ud83d\\udd0c","\\ud83d\\udd0b","\\ud83d\\udebf","\\ud83d\\udebd","\\ud83d\\udd27","\\ud83d\\udd28","\\ud83d\\udeaa","\\ud83d\\udeac","\\ud83d\\udca3","\\ud83d\\udd2b","\\ud83d\\udd2a","\\ud83d\\udc8a","\\ud83d\\udc89","\\ud83d\\udcb0","\\ud83d\\udcb5","\\ud83d\\udcb3","\\u2709","\\ud83d\\udceb","\\ud83d\\udce6","\\ud83d\\udcc5","\\ud83d\\udcc1","\\u2702","\\ud83d\\udccc","\\ud83d\\udcce","\\u2712","\\u270f","\\ud83d\\udcd0","\\ud83d\\udcda","\\ud83d\\udd2c","\\ud83d\\udd2d","\\ud83c\\udfa8","\\ud83c\\udfac","\\ud83c\\udfa4","\\ud83c\\udfa7","\\ud83c\\udfb5","\\ud83c\\udfb9","\\ud83c\\udfbb","\\ud83c\\udfba","\\ud83c\\udfb8","\\ud83d\\udc7e","\\ud83c\\udfae","\\ud83c\\udccf","\\ud83c\\udfb2","\\ud83c\\udfaf","\\ud83c\\udfc8","\\ud83c\\udfc0","\\u26bd","\\u26be","\\ud83c\\udfbe","\\ud83c\\udfb1","\\ud83c\\udfc9","\\ud83c\\udfb3","\\ud83c\\udfc1","\\ud83c\\udfc7","\\ud83c\\udfc6","\\ud83c\\udfca","\\ud83c\\udfc4","\\u2615","\\ud83c\\udf7c","\\ud83c\\udf7a","\\ud83c\\udf77","\\ud83c\\udf74","\\ud83c\\udf55","\\ud83c\\udf54","\\ud83c\\udf5f","\\ud83c\\udf57","\\ud83c\\udf71","\\ud83c\\udf5a","\\ud83c\\udf5c","\\ud83c\\udf61","\\ud83c\\udf73","\\ud83c\\udf5e","\\ud83c\\udf69","\\ud83c\\udf66","\\ud83c\\udf82","\\ud83c\\udf70","\\ud83c\\udf6a","\\ud83c\\udf6b","\\ud83c\\udf6d","\\ud83c\\udf6f","\\ud83c\\udf4e","\\ud83c\\udf4f","\\ud83c\\udf4a","\\ud83c\\udf4b","\\ud83c\\udf52","\\ud83c\\udf47","\\ud83c\\udf49","\\ud83c\\udf53","\\ud83c\\udf51","\\ud83c\\udf4c","\\ud83c\\udf50","\\ud83c\\udf4d","\\ud83c\\udf46","\\ud83c\\udf45","\\ud83c\\udf3d","\\ud83c\\udfe1","\\ud83c\\udfe5","\\ud83c\\udfe6","\\u26ea","\\ud83c\\udff0","\\u26fa","\\ud83c\\udfed","\\ud83d\\uddfb","\\ud83d\\uddfd","\\ud83c\\udfa0","\\ud83c\\udfa1","\\u26f2","\\ud83c\\udfa2","\\ud83d\\udea2","\\ud83d\\udea4","\\u2693","\\ud83d\\ude80","\\u2708","\\ud83d\\ude81","\\ud83d\\ude82","\\ud83d\\ude8b","\\ud83d\\ude8e","\\ud83d\\ude8c","\\ud83d\\ude99","\\ud83d\\ude97","\\ud83d\\ude95","\\ud83d\\ude9b","\\ud83d\\udea8","\\ud83d\\ude94","\\ud83d\\ude92","\\ud83d\\ude91","\\ud83d\\udeb2","\\ud83d\\udea0","\\ud83d\\ude9c","\\ud83d\\udea6","\\u26a0","\\ud83d\\udea7","\\u26fd","\\ud83c\\udfb0","\\ud83d\\uddff","\\ud83c\\udfaa","\\ud83c\\udfad","\\ud83c\\uddef\\ud83c\\uddf5","\\ud83c\\uddf0\\ud83c\\uddf7","\\ud83c\\udde9\\ud83c\\uddea","\\ud83c\\udde8\\ud83c\\uddf3","\\ud83c\\uddfa\\ud83c\\uddf8","\\ud83c\\uddeb\\ud83c\\uddf7","\\ud83c\\uddea\\ud83c\\uddf8","\\ud83c\\uddee\\ud83c\\uddf9","\\ud83c\\uddf7\\ud83c\\uddfa","\\ud83c\\uddec\\ud83c\\udde7","1\\u20e3","2\\u20e3","3\\u20e3","4\\u20e3","5\\u20e3","6\\u20e3","7\\u20e3","8\\u20e3","9\\u20e3","0\\u20e3","\\ud83d\\udd1f","\\u2757","\\u2753","\\u2665","\\u2666","\\ud83d\\udcaf","\\ud83d\\udd17","\\ud83d\\udd31","\\ud83d\\udd34","\\ud83d\\udd35","\\ud83d\\udd36","\\ud83d\\udd37"]'; + public const JSON_EMOJIS = '["\\ud83d\\ude09","\\ud83d\\ude0d","\\ud83d\\ude1b","\\ud83d\\ude2d","\\ud83d\\ude31","\\ud83d\\ude21","\\ud83d\\ude0e","\\ud83d\\ude34","\\ud83d\\ude35","\\ud83d\\ude08","\\ud83d\\ude2c","\\ud83d\\ude07","\\ud83d\\ude0f","\\ud83d\\udc6e","\\ud83d\\udc77","\\ud83d\\udc82","\\ud83d\\udc76","\\ud83d\\udc68","\\ud83d\\udc69","\\ud83d\\udc74","\\ud83d\\udc75","\\ud83d\\ude3b","\\ud83d\\ude3d","\\ud83d\\ude40","\\ud83d\\udc7a","\\ud83d\\ude48","\\ud83d\\ude49","\\ud83d\\ude4a","\\ud83d\\udc80","\\ud83d\\udc7d","\\ud83d\\udca9","\\ud83d\\udd25","\\ud83d\\udca5","\\ud83d\\udca4","\\ud83d\\udc42","\\ud83d\\udc40","\\ud83d\\udc43","\\ud83d\\udc45","\\ud83d\\udc44","\\ud83d\\udc4d","\\ud83d\\udc4e","\\ud83d\\udc4c","\\ud83d\\udc4a","\\u270c","\\u270b","\\ud83d\\udc50","\\ud83d\\udc46","\\ud83d\\udc47","\\ud83d\\udc49","\\ud83d\\udc48","\\ud83d\\ude4f","\\ud83d\\udc4f","\\ud83d\\udcaa","\\ud83d\\udeb6","\\ud83c\\udfc3","\\ud83d\\udc83","\\ud83d\\udc6b","\\ud83d\\udc6a","\\ud83d\\udc6c","\\ud83d\\udc6d","\\ud83d\\udc85","\\ud83c\\udfa9","\\ud83d\\udc51","\\ud83d\\udc52","\\ud83d\\udc5f","\\ud83d\\udc5e","\\ud83d\\udc60","\\ud83d\\udc55","\\ud83d\\udc57","\\ud83d\\udc56","\\ud83d\\udc59","\\ud83d\\udc5c","\\ud83d\\udc53","\\ud83c\\udf80","\\ud83d\\udc84","\\ud83d\\udc9b","\\ud83d\\udc99","\\ud83d\\udc9c","\\ud83d\\udc9a","\\ud83d\\udc8d","\\ud83d\\udc8e","\\ud83d\\udc36","\\ud83d\\udc3a","\\ud83d\\udc31","\\ud83d\\udc2d","\\ud83d\\udc39","\\ud83d\\udc30","\\ud83d\\udc38","\\ud83d\\udc2f","\\ud83d\\udc28","\\ud83d\\udc3b","\\ud83d\\udc37","\\ud83d\\udc2e","\\ud83d\\udc17","\\ud83d\\udc34","\\ud83d\\udc11","\\ud83d\\udc18","\\ud83d\\udc3c","\\ud83d\\udc27","\\ud83d\\udc25","\\ud83d\\udc14","\\ud83d\\udc0d","\\ud83d\\udc22","\\ud83d\\udc1b","\\ud83d\\udc1d","\\ud83d\\udc1c","\\ud83d\\udc1e","\\ud83d\\udc0c","\\ud83d\\udc19","\\ud83d\\udc1a","\\ud83d\\udc1f","\\ud83d\\udc2c","\\ud83d\\udc0b","\\ud83d\\udc10","\\ud83d\\udc0a","\\ud83d\\udc2b","\\ud83c\\udf40","\\ud83c\\udf39","\\ud83c\\udf3b","\\ud83c\\udf41","\\ud83c\\udf3e","\\ud83c\\udf44","\\ud83c\\udf35","\\ud83c\\udf34","\\ud83c\\udf33","\\ud83c\\udf1e","\\ud83c\\udf1a","\\ud83c\\udf19","\\ud83c\\udf0e","\\ud83c\\udf0b","\\u26a1","\\u2614","\\u2744","\\u26c4","\\ud83c\\udf00","\\ud83c\\udf08","\\ud83c\\udf0a","\\ud83c\\udf93","\\ud83c\\udf86","\\ud83c\\udf83","\\ud83d\\udc7b","\\ud83c\\udf85","\\ud83c\\udf84","\\ud83c\\udf81","\\ud83c\\udf88","\\ud83d\\udd2e","\\ud83c\\udfa5","\\ud83d\\udcf7","\\ud83d\\udcbf","\\ud83d\\udcbb","\\u260e","\\ud83d\\udce1","\\ud83d\\udcfa","\\ud83d\\udcfb","\\ud83d\\udd09","\\ud83d\\udd14","\\u23f3","\\u23f0","\\u231a","\\ud83d\\udd12","\\ud83d\\udd11","\\ud83d\\udd0e","\\ud83d\\udca1","\\ud83d\\udd26","\\ud83d\\udd0c","\\ud83d\\udd0b","\\ud83d\\udebf","\\ud83d\\udebd","\\ud83d\\udd27","\\ud83d\\udd28","\\ud83d\\udeaa","\\ud83d\\udeac","\\ud83d\\udca3","\\ud83d\\udd2b","\\ud83d\\udd2a","\\ud83d\\udc8a","\\ud83d\\udc89","\\ud83d\\udcb0","\\ud83d\\udcb5","\\ud83d\\udcb3","\\u2709","\\ud83d\\udceb","\\ud83d\\udce6","\\ud83d\\udcc5","\\ud83d\\udcc1","\\u2702","\\ud83d\\udccc","\\ud83d\\udcce","\\u2712","\\u270f","\\ud83d\\udcd0","\\ud83d\\udcda","\\ud83d\\udd2c","\\ud83d\\udd2d","\\ud83c\\udfa8","\\ud83c\\udfac","\\ud83c\\udfa4","\\ud83c\\udfa7","\\ud83c\\udfb5","\\ud83c\\udfb9","\\ud83c\\udfbb","\\ud83c\\udfba","\\ud83c\\udfb8","\\ud83d\\udc7e","\\ud83c\\udfae","\\ud83c\\udccf","\\ud83c\\udfb2","\\ud83c\\udfaf","\\ud83c\\udfc8","\\ud83c\\udfc0","\\u26bd","\\u26be","\\ud83c\\udfbe","\\ud83c\\udfb1","\\ud83c\\udfc9","\\ud83c\\udfb3","\\ud83c\\udfc1","\\ud83c\\udfc7","\\ud83c\\udfc6","\\ud83c\\udfca","\\ud83c\\udfc4","\\u2615","\\ud83c\\udf7c","\\ud83c\\udf7a","\\ud83c\\udf77","\\ud83c\\udf74","\\ud83c\\udf55","\\ud83c\\udf54","\\ud83c\\udf5f","\\ud83c\\udf57","\\ud83c\\udf71","\\ud83c\\udf5a","\\ud83c\\udf5c","\\ud83c\\udf61","\\ud83c\\udf73","\\ud83c\\udf5e","\\ud83c\\udf69","\\ud83c\\udf66","\\ud83c\\udf82","\\ud83c\\udf70","\\ud83c\\udf6a","\\ud83c\\udf6b","\\ud83c\\udf6d","\\ud83c\\udf6f","\\ud83c\\udf4e","\\ud83c\\udf4f","\\ud83c\\udf4a","\\ud83c\\udf4b","\\ud83c\\udf52","\\ud83c\\udf47","\\ud83c\\udf49","\\ud83c\\udf53","\\ud83c\\udf51","\\ud83c\\udf4c","\\ud83c\\udf50","\\ud83c\\udf4d","\\ud83c\\udf46","\\ud83c\\udf45","\\ud83c\\udf3d","\\ud83c\\udfe1","\\ud83c\\udfe5","\\ud83c\\udfe6","\\u26ea","\\ud83c\\udff0","\\u26fa","\\ud83c\\udfed","\\ud83d\\uddfb","\\ud83d\\uddfd","\\ud83c\\udfa0","\\ud83c\\udfa1","\\u26f2","\\ud83c\\udfa2","\\ud83d\\udea2","\\ud83d\\udea4","\\u2693","\\ud83d\\ude80","\\u2708","\\ud83d\\ude81","\\ud83d\\ude82","\\ud83d\\ude8b","\\ud83d\\ude8e","\\ud83d\\ude8c","\\ud83d\\ude99","\\ud83d\\ude97","\\ud83d\\ude95","\\ud83d\\ude9b","\\ud83d\\udea8","\\ud83d\\ude94","\\ud83d\\ude92","\\ud83d\\ude91","\\ud83d\\udeb2","\\ud83d\\udea0","\\ud83d\\ude9c","\\ud83d\\udea6","\\u26a0","\\ud83d\\udea7","\\u26fd","\\ud83c\\udfb0","\\ud83d\\uddff","\\ud83c\\udfaa","\\ud83c\\udfad","\\ud83c\\uddef\\ud83c\\uddf5","\\ud83c\\uddf0\\ud83c\\uddf7","\\ud83c\\udde9\\ud83c\\uddea","\\ud83c\\udde8\\ud83c\\uddf3","\\ud83c\\uddfa\\ud83c\\uddf8","\\ud83c\\uddeb\\ud83c\\uddf7","\\ud83c\\uddea\\ud83c\\uddf8","\\ud83c\\uddee\\ud83c\\uddf9","\\ud83c\\uddf7\\ud83c\\uddfa","\\ud83c\\uddec\\ud83c\\udde7","1\\u20e3","2\\u20e3","3\\u20e3","4\\u20e3","5\\u20e3","6\\u20e3","7\\u20e3","8\\u20e3","9\\u20e3","0\\u20e3","\\ud83d\\udd1f","\\u2757","\\u2753","\\u2665","\\u2666","\\ud83d\\udcaf","\\ud83d\\udd17","\\ud83d\\udd31","\\ud83d\\udd34","\\ud83d\\udd35","\\ud83d\\udd36","\\ud83d\\udd37"]'; /** * Initialize magic constants. * @@ -267,7 +267,7 @@ final class Magic if (\defined('SIGINT')) { //if (function_exists('pcntl_async_signals')) pcntl_async_signals(true); try { - pcntl_signal(SIGINT, fn () => null); + pcntl_signal(SIGINT, static fn () => null); pcntl_signal(SIGINT, SIG_DFL); EventLoop::unreference(EventLoop::onSignal(SIGINT, static function (): void { if (self::$suspendPeriodicLogging) { diff --git a/src/MyTelegramOrgWrapper.php b/src/MyTelegramOrgWrapper.php index c0b2b22c7..8ad1aa763 100644 --- a/src/MyTelegramOrgWrapper.php +++ b/src/MyTelegramOrgWrapper.php @@ -90,7 +90,8 @@ final class MyTelegramOrgWrapper $this->jar = new LocalCookieJar(); } $this->datacenter = new DoHWrapper( - new class($this->settings) implements SettingsGetter, + new class($this->settings) implements + SettingsGetter, LoggerGetter { public function __construct( private readonly Settings $settings diff --git a/src/Ogg.php b/src/Ogg.php index 7b0af2437..32b6b6e43 100644 --- a/src/Ogg.php +++ b/src/Ogg.php @@ -108,7 +108,7 @@ final class Ogg 0x89b8fd09,0x8d79e0be,0x803ac667,0x84fbdbd0, 0x9abc8bd5,0x9e7d9662,0x933eb0bb,0x97ffad0c, 0xafb010b1,0xab710d06,0xa6322bdf,0xa2f33668, - 0xbcb4666d,0xb8757bda,0xb5365d03,0xb1f740b4 + 0xbcb4666d,0xb8757bda,0xb5365d03,0xb1f740b4, ]; private const OPUS_SET_APPLICATION_REQUEST = 4000; private const OPUS_GET_APPLICATION_REQUEST = 4001; @@ -185,14 +185,14 @@ final class Ogg private const OPUS_FRAMESIZE_120_MS = 5009 /**< Use 120 ms frames */; private const CAPTURE_PATTERN = "OggS"; - const CONTINUATION = 1; - const BOS = 2; - const EOS = 4; + public const CONTINUATION = 1; + public const BOS = 2; + public const EOS = 4; - const STATE_READ_HEADER = 0; - const STATE_READ_COMMENT = 1; - const STATE_STREAMING = 3; - const STATE_END = 4; + public const STATE_READ_HEADER = 0; + public const STATE_READ_COMMENT = 1; + public const STATE_STREAMING = 3; + public const STATE_END = 4; private int $currentDuration = 0; /** @@ -243,7 +243,7 @@ final class Ogg $this->packFormat = implode( '/', array_map( - fn (string $v, string $k): string => $v.$k, + static fn (string $v, string $k): string => $v.$k, $pack_format, array_keys($pack_format), ), @@ -608,7 +608,7 @@ final class Ogg } } } - $checkErr = function (int|CData $err) use ($opus): void { + $checkErr = static function (int|CData $err) use ($opus): void { if ($err instanceof CData) { $err = $err->cdata; } @@ -660,11 +660,11 @@ final class Ogg ? openFile($oggOut->file, 'w') : $oggOut; - $writePage = function (int $header_type_flag, int $granule, int $streamId, int &$streamSeqno, string $packet) use ($out): void { + $writePage = static function (int $header_type_flag, int $granule, int $streamId, int &$streamSeqno, string $packet) use ($out): void { Assert::true(\strlen($packet) < 65025); $segments = [ ...array_fill(0, (int) (\strlen($packet) / 255), 255), - \strlen($packet) % 255 + \strlen($packet) % 255, ]; $data = 'OggS'.pack( 'CCPVVVCC*', @@ -713,7 +713,7 @@ final class Ogg ); $tags = 'OpusTags'; - $writeTag = function (string $tag) use (&$tags): void { + $writeTag = static function (string $tag) use (&$tags): void { $tags .= pack('V', \strlen($tag)).$tag; }; $writeTag("MadelineProto ".API::RELEASE.", ".$opus->opus_get_version_string()); diff --git a/src/RPCErrorException.php b/src/RPCErrorException.php index 583ca2b4f..f711f7798 100644 --- a/src/RPCErrorException.php +++ b/src/RPCErrorException.php @@ -77,7 +77,7 @@ class RPCErrorException extends \Exception && !self::isBad($error, $code) && !($error === 'Timeout' && !\in_array(strtolower($method), ['messages.getbotcallbackanswer', 'messages.getinlinebotresults'], true)) ) { - EventLoop::queue(function () use ($method, $code, $error): void { + EventLoop::queue(static function () use ($method, $code, $error): void { try { $res = json_decode( ( diff --git a/src/SecretChats/SecretChatController.php b/src/SecretChats/SecretChatController.php index e608443e0..c63166ea4 100644 --- a/src/SecretChats/SecretChatController.php +++ b/src/SecretChats/SecretChatController.php @@ -120,7 +120,7 @@ final class SecretChatController implements Stringable $this->inputChat = [ '_' => 'inputEncryptedChat', 'chat_id' => $id, - 'access_hash' => $accessHash + 'access_hash' => $accessHash, ]; if ($creator) { $this->in_seq_no_base = 0; @@ -695,7 +695,7 @@ final class SecretChatController implements Stringable $this->gapQuery = ['peer' => $this->id, 'message' => ['_' => 'decryptedMessageService', 'action' => [ '_' => 'decryptedMessageActionResend', 'start_seq_no' => $C_plus_one * 2 + $this->in_seq_no_base, - 'end_seq_no' => $this->gapEnd * 2 + $this->in_seq_no_base + 'end_seq_no' => $this->gapEnd * 2 + $this->in_seq_no_base, ]]]; $this->API->methodCallAsyncRead('messages.sendEncryptedService', $this->gapQuery); return; diff --git a/src/Serialization.php b/src/Serialization.php index 44b35f58d..2b808e3d0 100644 --- a/src/Serialization.php +++ b/src/Serialization.php @@ -125,7 +125,7 @@ abstract class Serialization } else { Logger::log('It seems like the session is busy.'); Logger::log('Telegram does not support starting multiple instances of the same session, make sure no other instance of the session is running.'); - $warningId = EventLoop::repeat(5, fn () => Logger::log('Still waiting for exclusive session lock...')); + $warningId = EventLoop::repeat(5, static fn () => Logger::log('Still waiting for exclusive session lock...')); EventLoop::unreference($warningId); } }); @@ -144,7 +144,7 @@ abstract class Serialization $copy->cancel(); } }; - EventLoop::queue(function () use ($session, $cancelFull, &$canContinue, &$lightState): void { + EventLoop::queue(static function () use ($session, $cancelFull, &$canContinue, &$lightState): void { try { $lightState = $session->getLightState(); if (!$lightState->canStartIpc()) { @@ -181,7 +181,7 @@ abstract class Serialization // Unlock and fork $unlock(); $monitor = Server::startMe($session); - EventLoop::queue(function () use ($cancelIpc, $monitor): void { + EventLoop::queue(static function () use ($cancelIpc, $monitor): void { try { $cancelIpc->complete($monitor->await()); } catch (\Throwable $e) { diff --git a/src/Settings/Connection.php b/src/Settings/Connection.php index 016ea15e8..746b55a67 100644 --- a/src/Settings/Connection.php +++ b/src/Settings/Connection.php @@ -377,7 +377,7 @@ final class Connection extends SettingsAbstract if (!isset($this->proxy[$proxy])) { return $this; } - if (false === $index = array_search($extra, $this->proxy[$proxy])) { + if (false === $index = array_search($extra, $this->proxy[$proxy], true)) { return $this; } unset($this->proxy[$proxy][$index]); diff --git a/src/Shutdown.php b/src/Shutdown.php index 2ae5b9cbb..c70cb62d7 100644 --- a/src/Shutdown.php +++ b/src/Shutdown.php @@ -84,7 +84,7 @@ final class Shutdown public static function init(): void { if (!self::$registered) { - register_shutdown_function(fn () => self::shutdown()); + register_shutdown_function(static fn () => self::shutdown()); self::$registered = true; } } diff --git a/src/Snitch.php b/src/Snitch.php index caffa9f3d..d3a5c7fd6 100644 --- a/src/Snitch.php +++ b/src/Snitch.php @@ -33,7 +33,7 @@ final class Snitch /** * Maximum starts without a phar file. */ - const MAX_NO_PHAR_STARTS = 3; + public const MAX_NO_PHAR_STARTS = 3; /** * Whether madeline.phar was downloaded from scratch. diff --git a/src/TL/Conversion/BotAPI.php b/src/TL/Conversion/BotAPI.php index ae81235b3..f6a82b518 100644 --- a/src/TL/Conversion/BotAPI.php +++ b/src/TL/Conversion/BotAPI.php @@ -409,7 +409,7 @@ trait BotAPI 'file_id' => (string) $fileId, 'file_unique_id' => $fileId->getUniqueBotAPI(), 'file_size' => $data['size'], - 'mime_type' => 'application/octet-stream' + 'mime_type' => 'application/octet-stream', ]; return ['encrypted' => $res]; default: diff --git a/src/TL/Conversion/MarkdownEntities.php b/src/TL/Conversion/MarkdownEntities.php index 38ee87179..bd35a6826 100644 --- a/src/TL/Conversion/MarkdownEntities.php +++ b/src/TL/Conversion/MarkdownEntities.php @@ -147,7 +147,7 @@ final class MarkdownEntities extends Entities '_' => 'messageEntityPre', 'language' => $language, 'offset' => $start, - 'length' => $pieceLen + 'length' => $pieceLen, ]; } diff --git a/src/TL/TL.php b/src/TL/TL.php index 45b881037..8f32fe340 100644 --- a/src/TL/TL.php +++ b/src/TL/TL.php @@ -367,29 +367,29 @@ final class TL implements TLInterface public function updateCallbacks(array $callbacks): void { $this->beforeMethodResponseDeserialization = array_merge_recursive(...array_map( - fn (TLCallback $t) => $t->getMethodBeforeResponseDeserializationCallbacks(), + static fn (TLCallback $t) => $t->getMethodBeforeResponseDeserializationCallbacks(), $callbacks )); $this->afterMethodResponseDeserialization = array_merge_recursive(...array_map( - fn (TLCallback $t) => $t->getMethodAfterResponseDeserializationCallbacks(), + static fn (TLCallback $t) => $t->getMethodAfterResponseDeserializationCallbacks(), $callbacks )); $this->beforeConstructorSerialization = array_merge(...array_map( - fn (TLCallback $t) => $t->getConstructorBeforeSerializationCallbacks(), + static fn (TLCallback $t) => $t->getConstructorBeforeSerializationCallbacks(), $callbacks )); $this->beforeConstructorDeserialization = array_merge_recursive(...array_map( - fn (TLCallback $t) => $t->getConstructorBeforeDeserializationCallbacks(), + static fn (TLCallback $t) => $t->getConstructorBeforeDeserializationCallbacks(), $callbacks )); $this->afterConstructorDeserialization = array_merge_recursive(...array_map( - fn (TLCallback $t) => $t->getConstructorAfterDeserializationCallbacks(), + static fn (TLCallback $t) => $t->getConstructorAfterDeserializationCallbacks(), $callbacks )); $this->typeMismatch = array_merge(...array_map( - fn (TLCallback $t) => $t->getTypeMismatchCallbacks(), + static fn (TLCallback $t) => $t->getTypeMismatchCallbacks(), $callbacks )); } @@ -451,7 +451,7 @@ final class TL implements TLInterface return Tools::packSignedLong((int) $object); case 'int128': if (\strlen($object) !== 16) { - $object = base64_decode($object); + $object = base64_decode($object, true); if (\strlen($object) !== 16) { throw new Exception(Lang::$current_lang['long_not_16']); } @@ -459,7 +459,7 @@ final class TL implements TLInterface return (string) $object; case 'int256': if (\strlen($object) !== 32) { - $object = base64_decode($object); + $object = base64_decode($object, true); if (\strlen($object) !== 32) { throw new Exception(Lang::$current_lang['long_not_32']); } @@ -467,7 +467,7 @@ final class TL implements TLInterface return (string) $object; case 'int512': if (\strlen($object) !== 64) { - $object = base64_decode($object); + $object = base64_decode($object, true); if (\strlen($object) !== 64) { throw new Exception(Lang::$current_lang['long_not_64']); } @@ -497,7 +497,7 @@ final class TL implements TLInterface return $concat; case 'bytes': if (\is_array($object) && isset($object['_']) && $object['_'] === 'bytes') { - $object = base64_decode($object['bytes']); + $object = base64_decode($object['bytes'], true); } if ($object instanceof Bytes || \is_int($object) || \is_float($object)) { $object = (string) $object; @@ -520,7 +520,7 @@ final class TL implements TLInterface return $concat; case 'waveform': if (\is_array($object) && isset($object['_']) && $object['_'] === 'bytes') { - $object = base64_decode($object['bytes']); + $object = base64_decode($object['bytes'], true); } if (\is_array($object)) { $object = self::compressWaveform($object); @@ -742,7 +742,7 @@ final class TL implements TLInterface $value = ['_' => 'dataJSON', 'data' => json_encode($value)]; } if (isset($current_argument['subtype']) && \in_array($current_argument['subtype'], ['DataJSON', '%DataJSON'], true)) { - array_walk($value, function (&$arg): void { + array_walk($value, static function (&$arg): void { $arg = ['_' => 'dataJSON', 'data' => json_encode($arg)]; }); } diff --git a/src/TL/TLConstructors.php b/src/TL/TLConstructors.php index 53ac424c7..5f54a7f1a 100644 --- a/src/TL/TLConstructors.php +++ b/src/TL/TLConstructors.php @@ -44,7 +44,7 @@ final class TLConstructors 'params' => $json_dict['params'], 'flags' => [], 'type' => ($scheme_type === 'mtproto' && $json_dict['type'] === 'Message' ? 'MT' : '').$json_dict['type'], - 'encrypted' => $scheme_type !== 'mtproto' + 'encrypted' => $scheme_type !== 'mtproto', ]; if ($scheme_type === 'secret') { $this->by_id[$json_dict['id']]['layer'] = $json_dict['layer']; diff --git a/src/TL/TLMethods.php b/src/TL/TLMethods.php index 26b7e9c97..57d2c53b8 100644 --- a/src/TL/TLMethods.php +++ b/src/TL/TLMethods.php @@ -40,7 +40,7 @@ final class TLMethods 'type' => $json_dict['type'], 'params' => $json_dict['params'], 'flags' => [], - 'encrypted' => $scheme_type !== 'mtproto' + 'encrypted' => $scheme_type !== 'mtproto', ]; if (preg_match('/^(v|V)ector\\<(.*)\\>$/', $json_dict['type'], $matches)) { $this->by_id[$json_dict['id']]['type'] = $matches[1] === 'v' ? 'vector' : 'Vector t'; diff --git a/src/TL/TLParams.php b/src/TL/TLParams.php index 1083f43c4..f8ef6fab7 100644 --- a/src/TL/TLParams.php +++ b/src/TL/TLParams.php @@ -30,7 +30,7 @@ trait TLParams foreach ($this->by_id[$key]['params'] as $kkey => $param) { if (preg_match('/([^.]+)\\.(\\d+)\\?(.+)/', $param['type'], $matches)) { $param['flag'] = $matches[1]; - $param['pow'] = pow(2, (int) $matches[2]); + $param['pow'] = 2** (int) $matches[2]; $param['type'] = $matches[3]; } if (preg_match('/^(v|V)ector\\<(.*)\\>$/', $param['type'], $matches)) { diff --git a/src/Tools.php b/src/Tools.php index bd3fb9640..79a48515e 100644 --- a/src/Tools.php +++ b/src/Tools.php @@ -84,7 +84,7 @@ abstract class Tools extends AsyncTools $f = []; for ($x = 0; $x < $fiberCount; $x++) { try { - $f []= $cur = new Fiber(function (): void { + $f []= $cur = new Fiber(static function (): void { Fiber::suspend(); }); $cur->start(); @@ -338,7 +338,7 @@ abstract class Tools extends AsyncTools */ public static function base64urlDecode(string $data): string { - return base64_decode(str_pad(strtr($data, '-_', '+/'), \strlen($data) % 4, '=', STR_PAD_RIGHT)); + return base64_decode(str_pad(strtr($data, '-_', '+/'), \strlen($data) % 4, '=', STR_PAD_RIGHT), true); } /** * Base64URL encode. @@ -616,7 +616,7 @@ abstract class Tools extends AsyncTools { if ($stream instanceof LocalFile) { $stream = openFile($stream->file, 'r'); - return fn (int $len): ?string => $stream->read(cancellation: $cancellation, length: $len); + return static fn (int $len): ?string => $stream->read(cancellation: $cancellation, length: $len); } if ($stream instanceof RemoteUrl) { self::$client ??= HttpClientBuilder::buildDefault(); @@ -628,7 +628,7 @@ abstract class Tools extends AsyncTools )->getBody(); } $buffer = ''; - return function (int $len) use (&$buffer, $stream, $cancellation): ?string { + return static function (int $len) use (&$buffer, $stream, $cancellation): ?string { if ($buffer === null) { return null; } @@ -683,7 +683,7 @@ abstract class Tools extends AsyncTools private const NO_YIELD_FUNCTIONS = [ 'onstart', 'onupdatenewmessage', - 'onupdatenewchannelmessage' + 'onupdatenewchannelmessage', ]; /** * Perform static analysis on a certain event handler class, to make sure it satisfies some performance requirements. @@ -712,7 +712,7 @@ abstract class Tools extends AsyncTools if ($plugin) { $class = $finder->findInstanceOf($code, ClassLike::class); - $class = array_filter($class, fn (ClassLike $c): bool => $c->name !== null); + $class = array_filter($class, static fn (ClassLike $c): bool => $c->name !== null); if (\count($class) !== 1 || !$class[0] instanceof Class_) { $issues []= new EventHandlerIssue( message: Lang::$current_lang['plugins_must_have_exactly_one_class'], diff --git a/src/VoIP/AuthKeyHandler.php b/src/VoIP/AuthKeyHandler.php index 07e80fa95..a9940b24c 100644 --- a/src/VoIP/AuthKeyHandler.php +++ b/src/VoIP/AuthKeyHandler.php @@ -82,7 +82,7 @@ trait AuthKeyHandler $res = $this->methodCallAsyncRead('phone.requestCall', [ 'user_id' => $user, 'g_a_hash' => hash('sha256', $g_a->toBytes(), true), - 'protocol' => VoIPController::CALL_PROTOCOL + 'protocol' => VoIPController::CALL_PROTOCOL, ])['phone_call']; $res['a'] = $a; $res['g_a'] = str_pad($g_a->toBytes(), 256, \chr(0), STR_PAD_LEFT); @@ -152,7 +152,7 @@ trait AuthKeyHandler */ public function getAllCalls(): array { - return array_map(fn (VoIPController $v): VoIP => $v->public, $this->callsByPeer); + return array_map(static fn (VoIPController $v): VoIP => $v->public, $this->callsByPeer); } /** diff --git a/src/VoIP/Endpoint.php b/src/VoIP/Endpoint.php index f169540f7..edc6435ba 100644 --- a/src/VoIP/Endpoint.php +++ b/src/VoIP/Endpoint.php @@ -457,7 +457,7 @@ final class Endpoint 'protocol' => VoIPController::PROTOCOL_VERSION, 'min_protocol' => VoIPController::MIN_PROTOCOL_VERSION, 'audio_streams' => [VoIPController::CODEC_OPUS], - 'video_streams' => [] + 'video_streams' => [], ])); } } diff --git a/src/VoIPController.php b/src/VoIPController.php index ed1f100dd..d9b51681d 100644 --- a/src/VoIPController.php +++ b/src/VoIPController.php @@ -60,61 +60,61 @@ final class VoIPController "11.0.0" ]*/ ]; - const NET_TYPE_UNKNOWN = 0; - const NET_TYPE_GPRS = 1; - const NET_TYPE_EDGE = 2; - const NET_TYPE_3G = 3; - const NET_TYPE_HSPA = 4; - const NET_TYPE_LTE = 5; - const NET_TYPE_WIFI = 6; - const NET_TYPE_ETHERNET = 7; - const NET_TYPE_OTHER_HIGH_SPEED = 8; - const NET_TYPE_OTHER_LOW_SPEED = 9; - const NET_TYPE_DIALUP = 10; - const NET_TYPE_OTHER_MOBILE = 11; + public const NET_TYPE_UNKNOWN = 0; + public const NET_TYPE_GPRS = 1; + public const NET_TYPE_EDGE = 2; + public const NET_TYPE_3G = 3; + public const NET_TYPE_HSPA = 4; + public const NET_TYPE_LTE = 5; + public const NET_TYPE_WIFI = 6; + public const NET_TYPE_ETHERNET = 7; + public const NET_TYPE_OTHER_HIGH_SPEED = 8; + public const NET_TYPE_OTHER_LOW_SPEED = 9; + public const NET_TYPE_DIALUP = 10; + public const NET_TYPE_OTHER_MOBILE = 11; - const DATA_SAVING_NEVER = 0; - const DATA_SAVING_MOBILE = 1; - const DATA_SAVING_ALWAYS = 2; + public const DATA_SAVING_NEVER = 0; + public const DATA_SAVING_MOBILE = 1; + public const DATA_SAVING_ALWAYS = 2; - const PROXY_NONE = 0; - const PROXY_SOCKS5 = 1; + public const PROXY_NONE = 0; + public const PROXY_SOCKS5 = 1; - const AUDIO_STATE_NONE = -1; - const AUDIO_STATE_CREATED = 0; - const AUDIO_STATE_CONFIGURED = 1; - const AUDIO_STATE_RUNNING = 2; + public const AUDIO_STATE_NONE = -1; + public const AUDIO_STATE_CREATED = 0; + public const AUDIO_STATE_CONFIGURED = 1; + public const AUDIO_STATE_RUNNING = 2; - const PKT_INIT = 1; - const PKT_INIT_ACK = 2; - const PKT_STREAM_STATE = 3; - const PKT_STREAM_DATA = 4; - const PKT_UPDATE_STREAMS = 5; - const PKT_PING = 6; - const PKT_PONG = 7; - const PKT_STREAM_DATA_X2 = 8; - const PKT_STREAM_DATA_X3 = 9; - const PKT_LAN_ENDPOINT = 10; - const PKT_NETWORK_CHANGED = 11; - const PKT_SWITCH_PREF_RELAY = 12; - const PKT_SWITCH_TO_P2P = 13; - const PKT_NOP = 14; + public const PKT_INIT = 1; + public const PKT_INIT_ACK = 2; + public const PKT_STREAM_STATE = 3; + public const PKT_STREAM_DATA = 4; + public const PKT_UPDATE_STREAMS = 5; + public const PKT_PING = 6; + public const PKT_PONG = 7; + public const PKT_STREAM_DATA_X2 = 8; + public const PKT_STREAM_DATA_X3 = 9; + public const PKT_LAN_ENDPOINT = 10; + public const PKT_NETWORK_CHANGED = 11; + public const PKT_SWITCH_PREF_RELAY = 12; + public const PKT_SWITCH_TO_P2P = 13; + public const PKT_NOP = 14; - const TLID_DECRYPTED_AUDIO_BLOCK = "\xc1\xdb\xf9\x48"; - const TLID_SIMPLE_AUDIO_BLOCK = "\x0d\x0e\x76\xcc"; + public const TLID_DECRYPTED_AUDIO_BLOCK = "\xc1\xdb\xf9\x48"; + public const TLID_SIMPLE_AUDIO_BLOCK = "\x0d\x0e\x76\xcc"; - const TLID_REFLECTOR_SELF_INFO = "\xC7\x72\x15\xc0"; - const TLID_REFLECTOR_PEER_INFO = "\x1C\x37\xD9\x27"; + public const TLID_REFLECTOR_SELF_INFO = "\xC7\x72\x15\xc0"; + public const TLID_REFLECTOR_PEER_INFO = "\x1C\x37\xD9\x27"; - const PROTO_ID = 'GrVP'; + public const PROTO_ID = 'GrVP'; - const PROTOCOL_VERSION = 9; - const MIN_PROTOCOL_VERSION = 9; + public const PROTOCOL_VERSION = 9; + public const MIN_PROTOCOL_VERSION = 9; - const STREAM_TYPE_AUDIO = 1; - const STREAM_TYPE_VIDEO = 2; + public const STREAM_TYPE_AUDIO = 1; + public const STREAM_TYPE_VIDEO = 2; - const CODEC_OPUS = 'SUPO'; + public const CODEC_OPUS = 'SUPO'; private MessageHandler $messageHandler; private VoIPState $voipState = VoIPState::CREATED; @@ -229,7 +229,7 @@ final class VoIPController 'key_fingerprint' => substr(sha1($key, true), -8), 'peer' => ['id' => $params['id'], 'access_hash' => $params['access_hash'], '_' => 'inputPhoneCall'], 'g_a' => $this->call['g_a'], - 'protocol' => self::CALL_PROTOCOL + 'protocol' => self::CALL_PROTOCOL, ]))['phone_call']; } catch (RPCErrorException $e) { if ($e->rpc === 'CALL_ALREADY_ACCEPTED') { @@ -287,10 +287,10 @@ final class VoIPController 'peer' => [ 'id' => $this->call['id'], 'access_hash' => $this->call['access_hash'], - '_' => 'inputPhoneCall' + '_' => 'inputPhoneCall', ], 'g_b' => $g_b->toBytes(), - 'protocol' => self::CALL_PROTOCOL + 'protocol' => self::CALL_PROTOCOL, ]); } catch (RPCErrorException $e) { if ($e->rpc === 'CALL_ALREADY_ACCEPTED') { @@ -469,7 +469,7 @@ final class VoIPController } $formats[]= [ 'name' => $name, - 'parameters' => $parameters + 'parameters' => $parameters, ]; } return [ @@ -596,8 +596,8 @@ final class VoIPController 'protocol' => self::PROTOCOL_VERSION, 'min_protocol' => self::MIN_PROTOCOL_VERSION, 'all_streams' => [ - ['id' => 0, 'type' => self::STREAM_TYPE_AUDIO, 'codec' => self::CODEC_OPUS, 'frame_duration' => 60, 'enabled' => 1] - ] + ['id' => 0, 'type' => self::STREAM_TYPE_AUDIO, 'codec' => self::CODEC_OPUS, 'frame_duration' => 60, 'enabled' => 1], + ], ])); $socket->sendInit(); break; @@ -634,7 +634,7 @@ final class VoIPController $this->bestEndpoint->writeReliably([ '_' => self::PKT_STREAM_STATE, 'id' => 0, - 'enabled' => false + 'enabled' => false, ]); $this->startWriteLoop(); @@ -696,7 +696,7 @@ final class VoIPController if (!$this->bestEndpoint->writeReliably([ '_' => self::PKT_STREAM_STATE, 'id' => 0, - 'enabled' => true + 'enabled' => true, ])) { $this->log("Exiting write loop in $this because we could not write stream state!"); return; @@ -709,7 +709,7 @@ final class VoIPController '_' => self::PKT_STREAM_DATA, 'stream_id' => 0, 'data' => $packet, - 'timestamp' => $this->opusTimestamp + 'timestamp' => $this->opusTimestamp, ]); $this->opusTimestamp += 60; } else { @@ -718,7 +718,7 @@ final class VoIPController if (!$this->bestEndpoint->writeReliably([ '_' => self::PKT_STREAM_STATE, 'id' => 0, - 'enabled' => false + 'enabled' => false, ])) { $this->log("Exiting write loop in $this because we could not write stream state!"); return; @@ -727,7 +727,7 @@ final class VoIPController $delay = 0.2; } $packet = $this->messageHandler->encryptPacket([ - '_' => self::PKT_NOP + '_' => self::PKT_NOP, ]); } //$this->log("Writing {$this->opusTimestamp} in $this!"); diff --git a/src/Wrappers/DialogHandler.php b/src/Wrappers/DialogHandler.php index 6fbfede1b..149cd4fe5 100644 --- a/src/Wrappers/DialogHandler.php +++ b/src/Wrappers/DialogHandler.php @@ -70,7 +70,7 @@ trait DialogHandler [ ...$this->botDialogsUpdatesState, 'pts_total_limit' => 2147483647, - 'floodWaitLimit' => 86400 + 'floodWaitLimit' => 86400, ], ); switch ($result['_']) { diff --git a/src/Wrappers/Loop.php b/src/Wrappers/Loop.php index 325f13a4e..4ef785bea 100644 --- a/src/Wrappers/Loop.php +++ b/src/Wrappers/Loop.php @@ -125,7 +125,7 @@ trait Loop { if (!$this->hasEventHandler()) { if (Magic::$isIpcWorker) { - EventLoop::queue(fn () => throw new SignalException('Restarting IPC daemon!')); + EventLoop::queue(static fn () => throw new SignalException('Restarting IPC daemon!')); } return; } diff --git a/src/Wrappers/Start.php b/src/Wrappers/Start.php index 3957928c3..8ffde8832 100644 --- a/src/Wrappers/Start.php +++ b/src/Wrappers/Start.php @@ -226,7 +226,7 @@ trait Start if ($qr) { $result = [ 'logged_in' => false, - 'svg' => $qr->getQRSvg(400, 2) + 'svg' => $qr->getQRSvg(400, 2), ]; } else { $result = [ diff --git a/tests/danog/MadelineProto/EntitiesTest.php b/tests/danog/MadelineProto/EntitiesTest.php index 85c1094c9..47cb71671 100644 --- a/tests/danog/MadelineProto/EntitiesTest.php +++ b/tests/danog/MadelineProto/EntitiesTest.php @@ -68,7 +68,7 @@ class EntitiesTest extends MadelineTestCase private function assertNoRelevantEntities(array $entities): void { - $entities = array_filter($entities, fn (array $e) => !\in_array( + $entities = array_filter($entities, static fn (array $e) => !\in_array( $e['type'], ['url', 'email', 'phone_number', 'mention', 'bot_command'], true @@ -244,7 +244,7 @@ class EntitiesTest extends MadelineTestCase 'type' => 'spoiler', ], ], - 'test
test test
test
test strikethrough underline blockquote https://google.com daniil@daniil.it +39398172758722 @daniilgentili spoiler <b>not_bold</b>' + 'test
test test
test
test strikethrough underline blockquote https://google.com daniil@daniil.it +39398172758722 @daniilgentili spoiler <b>not_bold</b>', ], [ 'markdown', @@ -290,8 +290,8 @@ class EntitiesTest extends MadelineTestCase 'offset' => 2, 'length' => 17, 'type' => 'pre', - 'language' => 'php' - ] + 'language' => 'php', + ], ], ], [ @@ -305,7 +305,7 @@ class EntitiesTest extends MadelineTestCase 'type' => 'bold', ], ], - ''"' + ''"', ], [ 'html', @@ -353,8 +353,8 @@ class EntitiesTest extends MadelineTestCase 'offset' => 0, 'length' => 5, 'type' => 'pre', - 'language' => '' - ] + 'language' => '', + ], ], ], [ @@ -366,7 +366,7 @@ class EntitiesTest extends MadelineTestCase 'offset' => 0, 'length' => 4, 'type' => 'text_url', - 'url' => 'https://google.com/' + 'url' => 'https://google.com/', ], ], ], @@ -379,9 +379,9 @@ class EntitiesTest extends MadelineTestCase 'offset' => 0, 'length' => 4, 'type' => 'text_url', - 'url' => 'https://transfer.sh/(/test/test.PNG,/test/test.MP4).zip' - ] - ] + 'url' => 'https://transfer.sh/(/test/test.PNG,/test/test.MP4).zip', + ], + ], ], [ 'markdown', @@ -392,7 +392,7 @@ class EntitiesTest extends MadelineTestCase 'offset' => 0, 'length' => 4, 'type' => 'text_url', - 'url' => 'https://google.com/' + 'url' => 'https://google.com/', ], ], ], @@ -405,7 +405,7 @@ class EntitiesTest extends MadelineTestCase 'offset' => 0, 'length' => 4, 'type' => 'text_url', - 'url' => 'https://google.com/?v=\\test' + 'url' => 'https://google.com/?v=\\test', ], ], ], @@ -418,7 +418,7 @@ class EntitiesTest extends MadelineTestCase 'offset' => 0, 'length' => 4, 'type' => 'text_url', - 'url' => 'https://google.com/' + 'url' => 'https://google.com/', ], ], ], @@ -431,7 +431,7 @@ class EntitiesTest extends MadelineTestCase 'offset' => 0, 'length' => 4, 'type' => 'text_url', - 'url' => 'https://google.com/' + 'url' => 'https://google.com/', ], ], ], @@ -450,7 +450,7 @@ class EntitiesTest extends MadelineTestCase 'offset' => 0, 'length' => 4, 'type' => 'text_url', - 'url' => 'https://google.com/' + 'url' => 'https://google.com/', ], ], 'link test', @@ -464,7 +464,7 @@ class EntitiesTest extends MadelineTestCase 'offset' => 0, 'length' => 4, 'type' => 'text_url', - 'url' => 'https://google.com/' + 'url' => 'https://google.com/', ], ], 'link ', diff --git a/tests/testing.php b/tests/testing.php index 06d4ece3e..9a09f5acd 100755 --- a/tests/testing.php +++ b/tests/testing.php @@ -61,7 +61,7 @@ if ($loader) { 'PhabelVendor\\Monolog\\Test\\TestCase', 'PhabelVendor\\Symfony\\Component\\DependencyInjection\\Compiler\\CompilerPassInterface', 'PhabelVendor\\Symfony\\Component\\String\\Slugger\\AsciiSlugger', - ])) { + ], true)) { continue; } if (str_starts_with($class, 'PhabelVendor\\Symfony\\Component\\Console') || str_starts_with($class, 'Phabel\\Symfony\\Component\\Console') || str_ends_with($class, 'Test') || class_exists($class) || interface_exists($class)) { @@ -296,18 +296,18 @@ function eq(string $file, string $contents, string $type, string $subtype): void function sendMedia(API $MadelineProto, array $media, string $message, string $mention, mixed $peer, string $type): void { $medias = [ - 'base' => $media + 'base' => $media, ]; if (isset($media['file']) && is_string($media['file'])) { $MadelineProto->sendDocument( peer: $peer, file: new ReadableBuffer(read($media['file'])), - callback: fn ($v) => $MadelineProto->logger($v), + callback: static fn ($v) => $MadelineProto->logger($v), fileName: basename($media['file']) ); $medias['callback'] = array_merge( $media, - ['file' => new FileCallback($media['file'], fn ($v) => $MadelineProto->logger(...))] + ['file' => new FileCallback($media['file'], static fn ($v) => $MadelineProto->logger(...))] ); $medias['stream'] = array_merge( $media, @@ -315,12 +315,12 @@ function sendMedia(API $MadelineProto, array $media, string $message, string $me ); $medias['callback stream'] = array_merge( $media, - ['file' => new FileCallback(new ReadableBuffer(read($media['file'])), fn ($v) => $MadelineProto->logger(...))] + ['file' => new FileCallback(new ReadableBuffer(read($media['file'])), static fn ($v) => $MadelineProto->logger(...))] ); } elseif (isset($media['url'])) { $medias['callback'] = array_merge( $media, - ['url' => new FileCallback($media['url'], fn ($v) => $MadelineProto->logger(...))] + ['url' => new FileCallback($media['url'], static fn ($v) => $MadelineProto->logger(...))] ); } foreach ($medias as $subtype => $m) { diff --git a/tools/build_docs.php b/tools/build_docs.php index d6c9aba05..82ce15f85 100755 --- a/tools/build_docs.php +++ b/tools/build_docs.php @@ -73,7 +73,7 @@ $doc = new \danog\MadelineProto\AnnotationsBuilder( $docs[0], [ 'API' => API::class, - 'MTProto' => MTProto::class + 'MTProto' => MTProto::class, ], 'danog\\MadelineProto' ); @@ -127,7 +127,7 @@ foreach ($files as $file) { if ($base === 'UPDATES_INTERNAL') { continue; } - $key = array_search($base, $order); + $key = array_search($base, $order, true); if ($key !== false) { $orderedfiles[$key] = $file; } @@ -170,7 +170,7 @@ function printTypes(array $types, string $type): string foreach ($orderedfiles as $key => $filename) { $lines = file_get_contents($filename); - $lines = preg_replace_callback('/\<\!--\s+cut_here\s+(\S+)\s+-->.*\<\!--\s+cut_here_end\s+\1\s+--\>/sim', function ($matches) { + $lines = preg_replace_callback('/\<\!--\s+cut_here\s+(\S+)\s+-->.*\<\!--\s+cut_here_end\s+\1\s+--\>/sim', static function ($matches) { [, $match] = $matches; if ($match === "concretefilters") { $result = ClassFinder::getClassesInNamespace( @@ -180,7 +180,7 @@ foreach ($orderedfiles as $key => $filename) { $result []= ServiceMessage::class; $result = array_filter( $result, - fn ($class) => is_subclass_of($class, Update::class) + static fn ($class) => is_subclass_of($class, Update::class) ); sort($result); $data = printTypes($result, $match); @@ -195,7 +195,7 @@ foreach ($orderedfiles as $key => $filename) { \danog\MadelineProto\EventHandler\Filter::class, ClassFinder::RECURSIVE_MODE | ClassFinder::ALLOW_ALL ); - $result = array_filter($result, fn (string $class) => (new ReflectionClass($class))->getAttributes()); + $result = array_filter($result, static fn (string $class) => (new ReflectionClass($class))->getAttributes()); $data = printTypes($result, $match); } elseif ($match === "plugins") { $result = ClassFinder::getClassesInNamespace( diff --git a/tools/phar.php b/tools/phar.php index 2e619d5b1..73fac1b15 100644 --- a/tools/phar.php +++ b/tools/phar.php @@ -14,8 +14,8 @@ if (!\defined('MADELINE_ALLOW_COMPOSER') && class_exists(\Composer\Autoload\Clas class Installer { - const RELEASE_TEMPLATE = 'https://phar.madelineproto.xyz/release%s?v=new'; - const PHAR_TEMPLATE = 'https://github.com/danog/MadelineProto/releases/latest/download/madeline%s.phar?v=%s'; + public const RELEASE_TEMPLATE = 'https://phar.madelineproto.xyz/release%s?v=new'; + public const PHAR_TEMPLATE = 'https://github.com/danog/MadelineProto/releases/latest/download/madeline%s.phar?v=%s'; /** * Phar lock instance. @@ -100,7 +100,7 @@ class Installer } foreach ($composer['packages'] as $dep) { $name = $dep['name']; - if (strpos($name, 'phabel/transpiler') === 0) { + if (str_starts_with($name, 'phabel/transpiler')) { $name = explode('/', $name, 3)[2]; } $version = $dep['version_normalized']; @@ -126,7 +126,7 @@ class Installer } $postData['downloads'][] = [ 'name' => $name, - 'version' => $version + 'version' => $version, ]; } @@ -144,7 +144,7 @@ class Installer $phpVersion, 'streams', getenv('CI') ? '; CI' : '' - ) + ), ], 'content' => json_encode($postData), 'timeout' => 6, @@ -221,7 +221,7 @@ class Installer if (!file_exists($madeline_phar)) { for ($x = 0; $x < 10; $x++) { $pharTest = file_get_contents(sprintf(self::PHAR_TEMPLATE, $this->version, $remote_release.$x)); - if ($pharTest && strpos($pharTest, $remote_release) !== false) { + if ($pharTest && str_contains($pharTest, $remote_release)) { $phar = $pharTest; unset($pharTest); break; diff --git a/tools/phpdoc.php b/tools/phpdoc.php index 32be26394..455702b6b 100644 --- a/tools/phpdoc.php +++ b/tools/phpdoc.php @@ -95,8 +95,8 @@ $ignore = [ // Disallow list \ArrayIterator::class, ]; -$filter = function (string $class) use ($ignore): bool { - if (in_array($class, $ignore)) { +$filter = static function (string $class) use ($ignore): bool { + if (in_array($class, $ignore, true)) { return false; } if (str_starts_with($class, 'danog\\MadelineProto\\Ipc') diff --git a/tools/std.php b/tools/std.php index d089e8615..85dee77d4 100644 --- a/tools/std.php +++ b/tools/std.php @@ -15,7 +15,7 @@ foreach ($classes as $class) { } $methods = array_unique($methods); -usort($methods, fn ($a, $b) => strlen($b->getName())-strlen($a->getName())); +usort($methods, static fn ($a, $b) => strlen($b->getName())-strlen($a->getName())); $find = []; $replace = []; @@ -23,7 +23,7 @@ $findDocs = []; $replaceDocs = []; foreach ($methods as $methodObj) { $method = $methodObj->getName(); - if (strpos($method, '__') === 0 || $method === 'async') { + if (str_starts_with($method, '__') || $method === 'async') { continue; } $method = Tools::fromCamelCase($method); @@ -31,7 +31,7 @@ foreach ($methods as $methodObj) { $new = Tools::fromSnakeCase($method); $new = str_ireplace(['mtproto', 'api'], ['MTProto', 'API'], $new); $new = preg_replace('/TL$/i', 'TL', $new); - if (!in_array($method, ['discardCallAsync', 'acceptCallAsync', 'requestCallAsync'])) { + if (!in_array($method, ['discardCallAsync', 'acceptCallAsync', 'requestCallAsync'], true)) { $new = preg_replace('/async$/i', '', $new); }