diff --git a/src/danog/MadelineProto/AnnotationsBuilder.php b/src/danog/MadelineProto/AnnotationsBuilder.php index c42ca892..56b344d4 100644 --- a/src/danog/MadelineProto/AnnotationsBuilder.php +++ b/src/danog/MadelineProto/AnnotationsBuilder.php @@ -28,27 +28,27 @@ use phpDocumentor\Reflection\DocBlockFactory; class AnnotationsBuilder { /** - * Reflection classes + * Reflection classes. */ private array $reflectionClasses = []; /** - * Logger + * Logger. */ private Logger $logger; /** - * Namespace + * Namespace. */ private string $namespace; /** - * TL instance + * TL instance. */ private TL $TL; /** - * Settings + * Settings. */ private array $settings; /** - * Output file + * Output file. */ private string $output; public function __construct(Logger $logger, array $settings, string $output, array $reflectionClasses, string $namespace) @@ -309,7 +309,15 @@ class AnnotationsBuilder if (!$type) { Logger::log("{$name} has no return type!", Logger::FATAL_ERROR); } - $internalDoc['InternalDoc'][$name]['method'] = $method->getDocComment() ?? ''; + $promise = '\\'.Promise::class; + $phpdoc = $method->getDocComment() ?? ''; + $phpdoc = \str_replace("@return \\Generator", "@return $promise", $phpdoc); + $phpdoc = \preg_replace( + "/@psalm-return \\\\Generator<(?:[^,]+), (?:[^,]+), (?:[^,]+), (.+)>/", + "@psalm-return $promise<$1>", + $phpdoc + ); + $internalDoc['InternalDoc'][$name]['method'] = $phpdoc; $internalDoc['InternalDoc'][$name]['method'] .= "\n ".\implode("\n ", \explode("\n", $doc)); } \fwrite($handle, " + * @return array */ public function getDataCenterConnections(): array { diff --git a/src/danog/MadelineProto/Db/ArrayCacheTrait.php b/src/danog/MadelineProto/Db/ArrayCacheTrait.php index a6afdfb0..e8837ce4 100644 --- a/src/danog/MadelineProto/Db/ArrayCacheTrait.php +++ b/src/danog/MadelineProto/Db/ArrayCacheTrait.php @@ -6,8 +6,8 @@ use Amp\Loop; use danog\MadelineProto\Logger; /** - * Array caching trait - * + * Array caching trait. + * * @property string $table */ trait ArrayCacheTrait diff --git a/src/danog/MadelineProto/Db/DbArray.php b/src/danog/MadelineProto/Db/DbArray.php index f98a7991..dc8f4951 100644 --- a/src/danog/MadelineProto/Db/DbArray.php +++ b/src/danog/MadelineProto/Db/DbArray.php @@ -5,14 +5,70 @@ namespace danog\MadelineProto\Db; use Amp\Producer; use Amp\Promise; +/** + * DB array interface. + * + * @template T as mixed + */ interface DbArray extends DbType, \ArrayAccess, \Countable { + /** + * Get Array copy. + * + * @psalm-return Promise $value + * + * @return Promise + */ public function getArrayCopy(): Promise; + /** + * Check if element is set. + * + * @param string|int $key + * + * @psalm-return Promise + * + * @return Promise + */ public function isset($key): Promise; + /** + * Get element. + * + * @param string|int $offset + * + * @psalm-return Promise + * + * @return Promise + */ public function offsetGet($offset): Promise; + /** + * Set element. + * + * @param string|int $offset + * @param mixed $value + * + * @psalm-param T $value + * + * @return void + */ public function offsetSet($offset, $value); + /** + * Unset element. + * + * @param string|int $offset Offset + * @return Promise + */ public function offsetUnset($offset): Promise; + /** + * Count number of elements. + * + * @return Promise + */ public function count(): Promise; + /** + * Get iterator. + * + * @return Producer + */ public function getIterator(): Producer; /** diff --git a/src/danog/MadelineProto/Db/DriverArray.php b/src/danog/MadelineProto/Db/DriverArray.php index 51599271..9c8c026a 100644 --- a/src/danog/MadelineProto/Db/DriverArray.php +++ b/src/danog/MadelineProto/Db/DriverArray.php @@ -7,8 +7,8 @@ use danog\MadelineProto\SettingsAbstract; use ReflectionClass; /** - * Array caching trait - * + * Array caching trait. + * * @property string $table */ abstract class DriverArray implements DbArray diff --git a/src/danog/MadelineProto/DocsBuilder.php b/src/danog/MadelineProto/DocsBuilder.php index 568f6946..c49c680e 100644 --- a/src/danog/MadelineProto/DocsBuilder.php +++ b/src/danog/MadelineProto/DocsBuilder.php @@ -155,11 +155,11 @@ class DocsBuilder * Get formatted template string. * * @param string $name Template name - * @param string[] ...$params Params + * @param string ...$params Params * * @return string */ - protected function template(string $name, ...$params): string + protected function template(string $name, string ...$params): string { return \sprintf($this->templates[$name], ...$params); } diff --git a/src/danog/MadelineProto/InternalDoc.php b/src/danog/MadelineProto/InternalDoc.php index 500ac279..dc28470e 100644 --- a/src/danog/MadelineProto/InternalDoc.php +++ b/src/danog/MadelineProto/InternalDoc.php @@ -4450,7 +4450,7 @@ class InternalDoc extends APIFactory * * @param array $data Data * - * @return \Generator + * @return \Amp\Promise */ public function MTProtoToBotAPI(array $data, array $extra = []) { @@ -4461,7 +4461,7 @@ class InternalDoc extends APIFactory * * @param mixed $params Params * - * @return \Generator + * @return \Amp\Promise */ public function MTProtoToTd(&$params, array $extra = []) { @@ -4472,7 +4472,7 @@ class InternalDoc extends APIFactory * * @param mixed $params Params * - * @return \Generator + * @return \Amp\Promise */ public function MTProtoToTdcli($params, array $extra = []) { @@ -4483,7 +4483,7 @@ class InternalDoc extends APIFactory * * @param array $call Call * - * @return \Generator + * @return \Amp\Promise */ public function acceptCall(array $call, array $extra = []) { @@ -4494,7 +4494,7 @@ class InternalDoc extends APIFactory * * @param array $params Secret chat ID * - * @return \Generator + * @return \Amp\Promise */ public function acceptSecretChat($params, array $extra = []) { @@ -4503,7 +4503,7 @@ class InternalDoc extends APIFactory /** * Accept terms of service update. * - * @return \Generator + * @return \Amp\Promise */ public function acceptTos(array $extra = []) { @@ -4514,7 +4514,7 @@ class InternalDoc extends APIFactory * * @param array $user User info * - * @return \Generator + * @return \Amp\Promise * @throws \danog\MadelineProto\Exception */ public function addUser(array $user, array $extra = []) @@ -4596,7 +4596,7 @@ class InternalDoc extends APIFactory * * @param array $arguments Arguments * - * @return \Generator + * @return \Amp\Promise */ public function botAPIToMTProto(array $arguments, array $extra = []) { @@ -4607,7 +4607,7 @@ class InternalDoc extends APIFactory * * @param string $token Bot token * - * @return \Generator + * @return \Amp\Promise */ public function botLogin(string $token, array $extra = []) { @@ -4618,7 +4618,11 @@ class InternalDoc extends APIFactory * * @param \Generator|Promise|mixed $promise * + * @template TReturn + * @psalm-param \Generator|Promise|TReturn $promise + * * @return Promise + * @psalm-return Promise */ public function call($promise) { @@ -4673,7 +4677,7 @@ class InternalDoc extends APIFactory /** * Check for terms of service update. * - * @return \Generator + * @return \Amp\Promise */ public function checkTos(array $extra = []) { @@ -4704,7 +4708,7 @@ class InternalDoc extends APIFactory * * @param string $password Password * - * @return \Generator + * @return \Amp\Promise */ public function complete2faLogin(string $password, array $extra = []) { @@ -4715,7 +4719,7 @@ class InternalDoc extends APIFactory * * @param array $params Params * - * @return \Generator + * @return \Amp\Promise */ public function completeCall(array $params, array $extra = []) { @@ -4726,7 +4730,7 @@ class InternalDoc extends APIFactory * * @param string $code Login code * - * @return \Generator + * @return \Amp\Promise */ public function completePhoneLogin($code, array $extra = []) { @@ -4738,7 +4742,7 @@ class InternalDoc extends APIFactory * @param string $first_name First name * @param string $last_name Last name * - * @return \Generator + * @return \Amp\Promise */ public function completeSignup(string $first_name, string $last_name = '', array $extra = []) { @@ -4749,7 +4753,7 @@ class InternalDoc extends APIFactory * * @param array $params Params * - * @return \Generator + * @return \Amp\Promise */ public function confirmCall(array $params, array $extra = []) { @@ -4760,7 +4764,7 @@ class InternalDoc extends APIFactory * * @param boolean $reconnectAll Whether to reconnect to all DCs * - * @return \Generator + * @return \Amp\Promise */ public function connectToAllDcs(bool $reconnectAll = true, array $extra = []) { @@ -4771,7 +4775,7 @@ class InternalDoc extends APIFactory * * THIS WILL DELETE YOUR ACCOUNT! * - * @return \Generator + * @return \Amp\Promise */ public function declineTos(array $extra = []) { @@ -4785,7 +4789,7 @@ class InternalDoc extends APIFactory * @param array $rating Rating * @param boolean $need_debug Need debug? * - * @return \Generator + * @return \Amp\Promise */ public function discardCall(array $call, array $reason, array $rating = [ ], bool $need_debug = true, array $extra = []) @@ -4797,7 +4801,7 @@ class InternalDoc extends APIFactory * * @param int $chat Secret chat ID * - * @return \Generator + * @return \Amp\Promise */ public function discardSecretChat(int $chat, array $extra = []) { @@ -4811,7 +4815,7 @@ class InternalDoc extends APIFactory * @param array|string $messageMedia File to download * @param callable $cb Status callback (can also use FileCallback) * - * @return \Generator + * @return \Amp\Promise */ public function downloadToBrowser($messageMedia, ?callable $cb = null, array $extra = []) { @@ -4831,9 +4835,9 @@ class InternalDoc extends APIFactory * @param int $end Offset where to stop downloading (inclusive) * @param int $part_size Size of each chunk * - * @return \Generator + * @return \Amp\Promise * - * @psalm-return \Generator + * @psalm-return \Amp\Promise */ public function downloadToCallable($messageMedia, callable $callable, $cb = null, bool $seekable = true, int $offset = 0, int $end = -1, ?int $part_size = null, array $extra = []) { @@ -4846,9 +4850,9 @@ class InternalDoc extends APIFactory * @param string|FileCallbackInterface $dir Directory where to download the file * @param callable $cb Callback (DEPRECATED, use FileCallbackInterface) * - * @return \Generator + * @return \Amp\Promise * - * @psalm-return \Generator|\Amp\Promise<\Amp\Ipc\Sync\ChannelledSocket>|\Amp\Promise|\Amp\Promise|array|bool|mixed, mixed, false|string> + * @psalm-return \Amp\Promise */ public function downloadToDir($messageMedia, $dir, $cb = null, array $extra = []) { @@ -4861,9 +4865,9 @@ class InternalDoc extends APIFactory * @param string|FileCallbackInterface $file Downloaded file path * @param callable $cb Callback (DEPRECATED, use FileCallbackInterface) * - * @return \Generator Downloaded file path + * @return \Amp\Promise Downloaded file path * - * @psalm-return \Generator|\Amp\Promise<\Amp\Ipc\Sync\ChannelledSocket>|\Amp\Promise|\Amp\Promise|array|bool|mixed, mixed, false|string> + * @psalm-return \Amp\Promise */ public function downloadToFile($messageMedia, $file, $cb = null, array $extra = []) { @@ -4878,9 +4882,9 @@ class InternalDoc extends APIFactory * @param ServerRequest $request Request * @param callable $cb Status callback (can also use FileCallback) * - * @return \Generator Returned response + * @return \Amp\Promise Returned response * - * @psalm-return \Generator + * @psalm-return \Amp\Promise<\Amp\Http\Server\Response> */ public function downloadToResponse($messageMedia, \Amp\Http\Server\Request $request, ?callable $cb = null, array $extra = []) { @@ -4895,9 +4899,9 @@ class InternalDoc extends APIFactory * @param int $offset Offset where to start downloading * @param int $end Offset where to end download * - * @return \Generator + * @return \Amp\Promise * - * @psalm-return \Generator|\Amp\Promise|mixed, mixed, mixed> + * @psalm-return \Amp\Promise */ public function downloadToStream($messageMedia, $stream, $cb = null, int $offset = 0, int $end = -1, array $extra = []) { @@ -4928,9 +4932,9 @@ class InternalDoc extends APIFactory /** * Export authorization. * - * @return \Generator + * @return \Amp\Promise * - * @psalm-return \Generator + * @psalm-return \Amp\Promise */ public function exportAuthorization(array $extra = []) { @@ -4952,9 +4956,9 @@ class InternalDoc extends APIFactory * * @param string $url URL * - * @return \Generator + * @return \Amp\Promise * - * @psalm-return \Generator, mixed, string> + * @psalm-return \Amp\Promise */ public function fileGetContents(string $url, array $extra = []) { @@ -5003,7 +5007,7 @@ class InternalDoc extends APIFactory * * @param mixed $id Chat ID * - * @return \Generator + * @return \Amp\Promise */ public function fullChatLastUpdated($id, array $extra = []) { @@ -5012,7 +5016,7 @@ class InternalDoc extends APIFactory /** * Get info about the logged-in user, not cached. * - * @return \Generator + * @return \Amp\Promise */ public function fullGetSelf(array $extra = []) { @@ -5072,7 +5076,7 @@ class InternalDoc extends APIFactory * * @param string $datacenter DC ID * - * @return \Generator + * @return \Amp\Promise */ public function getCdnConfig(string $datacenter, array $extra = []) { @@ -5084,7 +5088,7 @@ class InternalDoc extends APIFactory * @param array $config Current config * @param array $options Options for method call * - * @return \Generator + * @return \Amp\Promise */ public function getConfig(array $config = [ ], array $options = [ @@ -5124,9 +5128,9 @@ class InternalDoc extends APIFactory * * @param boolean $force Whether to refetch all dialogs ignoring cache * - * @return \Generator + * @return \Amp\Promise * - * @psalm-return \Generator, mixed, list> + * @psalm-return \Amp\Promise> */ public function getDialogs(bool $force = true, array $extra = []) { @@ -5143,7 +5147,7 @@ class InternalDoc extends APIFactory * * @param mixed $messageMedia File ID * - * @return \Generator + * @return \Amp\Promise */ public function getDownloadInfo($messageMedia, array $extra = []) { @@ -5186,7 +5190,7 @@ class InternalDoc extends APIFactory * * @param mixed $constructor File ID * - * @return \Generator + * @return \Amp\Promise */ public function getFileInfo($constructor, array $extra = []) { @@ -5208,7 +5212,7 @@ class InternalDoc extends APIFactory * * @param boolean $force Whether to refetch all dialogs ignoring cache * - * @return \Generator + * @return \Amp\Promise */ public function getFullDialogs(bool $force = true, array $extra = []) { @@ -5221,9 +5225,9 @@ class InternalDoc extends APIFactory * * @see https://docs.madelineproto.xyz/FullInfo.html * - * @return \Generator FullInfo object + * @return \Amp\Promise FullInfo object * - * @psalm-return \Generator + * @psalm-return \Amp\Promise */ public function getFullInfo($id, array $extra = []) { @@ -5238,6 +5242,15 @@ class InternalDoc extends APIFactory { return $this->API->getHTTPClient(); } + /** + * Get current password hint. + * + * @return string + */ + public function getHint(): string + { + return $this->API->getHint(); + } /** * Get bot API ID from peer object. * @@ -5257,9 +5270,9 @@ class InternalDoc extends APIFactory * * @see https://docs.madelineproto.xyz/Info.html * - * @return \Generator Info object + * @return \Amp\Promise Info object * - * @psalm-return \Generator|array, mixed, array|mixed> + * @psalm-return \Amp\Promise */ public function getInfo($id, $recursive = true, array $extra = []) { @@ -5335,7 +5348,7 @@ class InternalDoc extends APIFactory * * @param mixed $messageMedia File ID * - * @return \Generator + * @return \Amp\Promise */ public function getPropicInfo($data, array $extra = []) { @@ -5355,7 +5368,7 @@ class InternalDoc extends APIFactory * * @see https://docs.madelineproto.xyz/Chat.html * - * @return \Generator Chat object + * @return \Amp\Promise Chat object */ public function getPwrChat($id, bool $fullfetch = true, bool $send = true, array $extra = []) { @@ -5486,7 +5499,7 @@ class InternalDoc extends APIFactory * * @param mixed $authorization Authorization info * - * @return \Generator + * @return \Amp\Promise */ public function importAuthorization($authorization, array $extra = []) { @@ -5508,7 +5521,7 @@ class InternalDoc extends APIFactory * * @param MTProto $MadelineProto * @param boolean $reset - * @return \Generator + * @return \Amp\Promise */ public function initDb(\danog\MadelineProto\MTProto $MadelineProto, bool $reset = false, array $extra = []) { @@ -5579,7 +5592,7 @@ class InternalDoc extends APIFactory /** * Log out currently logged in user. * - * @return \Generator + * @return \Amp\Promise */ public function logout(array $extra = []) { @@ -5590,7 +5603,7 @@ class InternalDoc extends APIFactory * * @param callable|null $callback Async callable to run * - * @return \Generator + * @return \Amp\Promise */ public function loop($callback = null, array $extra = []) { @@ -5661,7 +5674,7 @@ class InternalDoc extends APIFactory * @param array $args Arguments * @param array $aargs Additional arguments * - * @return \Generator + * @return \Amp\Promise */ public function methodCall(string $method, $args = [ ], array $aargs = [ @@ -5677,7 +5690,7 @@ class InternalDoc extends APIFactory * @param array $args Arguments * @param array $aargs Additional arguments * - * @return \Generator + * @return \Amp\Promise */ public function methodCallWrite(string $method, $args = [ ], array $aargs = [ @@ -5746,9 +5759,9 @@ class InternalDoc extends APIFactory * * @param mixed $id Peer * - * @return \Generator + * @return \Amp\Promise * - * @psalm-return \Generator + * @psalm-return \Amp\Promise */ public function peerIsset($id, array $extra = []) { @@ -5760,7 +5773,7 @@ class InternalDoc extends APIFactory * @param string $number Phone number * @param integer $sms_type SMS type * - * @return \Generator + * @return \Amp\Promise */ public function phoneLogin($number, $sms_type = 5, array $extra = []) { @@ -5817,7 +5830,7 @@ class InternalDoc extends APIFactory * * @param int $chat Secret chat to rekey * - * @return \Generator + * @return \Amp\Promise */ public function rekey(int $chat, array $extra = []) { @@ -5829,7 +5842,7 @@ class InternalDoc extends APIFactory * @param string $message Error to report * @param string $parseMode Parse mode * - * @return \Generator + * @return \Amp\Promise */ public function report(string $message, string $parseMode = '', array $extra = []) { @@ -5840,7 +5853,7 @@ class InternalDoc extends APIFactory * * @param mixed $user User * - * @return \Generator + * @return \Amp\Promise */ public function requestCall($user, array $extra = []) { @@ -5851,7 +5864,7 @@ class InternalDoc extends APIFactory * * @param mixed $user User to start secret chat with * - * @return \Generator + * @return \Amp\Promise */ public function requestSecretChat($user, array $extra = []) { @@ -5871,7 +5884,7 @@ class InternalDoc extends APIFactory * * @param string $username Username * - * @return \Generator + * @return \Amp\Promise */ public function resolveUsername(string $username, array $extra = []) { @@ -5960,7 +5973,7 @@ class InternalDoc extends APIFactory * * @param class-string $eventHandler Event handler * - * @return \Generator + * @return \Amp\Promise */ public function setEventHandler(string $eventHandler, array $extra = []) { @@ -5980,7 +5993,7 @@ class InternalDoc extends APIFactory * * @param int|string $userOrId Username(s) or peer ID(s) * - * @return \Generator + * @return \Amp\Promise */ public function setReportPeers($userOrId, array $extra = []) { @@ -6068,7 +6081,7 @@ class InternalDoc extends APIFactory /** * Log in to telegram (via CLI or web). * - * @return \Generator + * @return \Amp\Promise */ public function start(array $extra = []) { @@ -6088,7 +6101,7 @@ class InternalDoc extends APIFactory * * @param array $params Parameters * - * @return \Generator + * @return \Amp\Promise */ public function tdToMTProto(array $params, array $extra = []) { @@ -6136,15 +6149,20 @@ class InternalDoc extends APIFactory * * If the timeout expires before the promise is resolved, a default value is returned * + * @template TReturnAlt * @template TReturn + * @template TGenerator as \Generator * * @param Promise|\Generator $promise Promise to which the timeout is applied. * @param int $timeout Timeout in milliseconds. - * @param TReturn $default + * @param mixed $default * - * @return Promise + * @psalm-param Promise|TGenerator $promise Promise to which the timeout is applied. + * @psalm-param TReturnAlt $timeout * - * @throws \TypeError If $promise is not an instance of \Amp\Promise or \React\Promise\PromiseInterface. + * @return Promise + * + * @throws \TypeError If $promise is not an instance of \Amp\Promise, \Generator or \React\Promise\PromiseInterface. */ public function timeoutWithDefault($promise, int $timeout, $default = null) { @@ -6267,7 +6285,7 @@ class InternalDoc extends APIFactory * * @param array $params The params * - * @return \Generator + * @return \Amp\Promise */ public function update2fa(array $params, array $extra = []) { @@ -6278,7 +6296,7 @@ class InternalDoc extends APIFactory * * @param SettingsAbstract $settings Settings * - * @return \Generator + * @return \Amp\Promise */ public function updateSettings(\danog\MadelineProto\SettingsAbstract $settings, array $extra = []) { @@ -6292,9 +6310,9 @@ class InternalDoc extends APIFactory * @param callable $cb Callback (DEPRECATED, use FileCallbackInterface) * @param boolean $encrypted Whether to encrypt file for secret chats * - * @return \Generator + * @return \Amp\Promise * - * @psalm-return \Generator|\Amp\Promise<\Amp\Ipc\Sync\ChannelledSocket>|\Amp\Promise|\Amp\Promise|\Amp\Promise|\danog\MadelineProto\Stream\StreamInterface|array|int|mixed, mixed, mixed> + * @psalm-return \Amp\Promise */ public function upload($file, string $fileName = '', $cb = null, bool $encrypted = false, array $extra = []) { @@ -6307,9 +6325,9 @@ class InternalDoc extends APIFactory * @param string $fileName File name * @param callable $cb Callback (DEPRECATED, use FileCallbackInterface) * - * @return \Generator + * @return \Amp\Promise * - * @psalm-return \Generator|\Amp\Promise<\Amp\Ipc\Sync\ChannelledSocket>|\Amp\Promise|\Amp\Promise|\Amp\Promise|\danog\MadelineProto\Stream\StreamInterface|array|int|mixed, mixed, mixed> + * @psalm-return \Amp\Promise */ public function uploadEncrypted($file, string $fileName = '', $cb = null, array $extra = []) { @@ -6329,9 +6347,9 @@ class InternalDoc extends APIFactory * @param boolean $seekable Whether chunks can be fetched out of order * @param boolean $encrypted Whether to encrypt file for secret chats * - * @return \Generator + * @return \Amp\Promise * - * @psalm-return \Generator, mixed, array{_: string, id: string, parts: int, name: string, mime_type: string, key_fingerprint?: mixed, key?: mixed, iv?: mixed, md5_checksum: string}> + * @psalm-return \Amp\Promise */ public function uploadFromCallable(callable $callable, int $size, string $mime, string $fileName = '', $cb = null, bool $seekable = true, bool $encrypted = false, array $extra = []) { @@ -6347,9 +6365,9 @@ class InternalDoc extends APIFactory * @param callable $cb Callback (DEPRECATED, use FileCallbackInterface) * @param boolean $encrypted Whether to encrypt file for secret chats * - * @return \Generator + * @return \Amp\Promise * - * @psalm-return \Generator|\Amp\Promise|\danog\MadelineProto\Stream\StreamInterface|array|int|mixed, mixed, mixed> + * @psalm-return \Amp\Promise */ public function uploadFromStream($stream, int $size, string $mime, string $fileName = '', $cb = null, bool $encrypted = false, array $extra = []) { @@ -6362,9 +6380,9 @@ class InternalDoc extends APIFactory * @param callable $cb Callback (DEPRECATED, use FileCallbackInterface) * @param boolean $encrypted Whether to encrypt file for secret chats * - * @return \Generator + * @return \Amp\Promise * - * @psalm-return \Generator + * @psalm-return \Amp\Promise */ public function uploadFromTgfile($media, $cb = null, bool $encrypted = false, array $extra = []) { @@ -6379,9 +6397,9 @@ class InternalDoc extends APIFactory * @param callable $cb Callback (DEPRECATED, use FileCallbackInterface) * @param boolean $encrypted Whether to encrypt file for secret chats * - * @return \Generator + * @return \Amp\Promise * - * @psalm-return \Generator|\Amp\Promise|\Amp\Promise|\danog\MadelineProto\Stream\StreamInterface|array|int|mixed, mixed, mixed> + * @psalm-return \Amp\Promise */ public function uploadFromUrl($url, int $size = 0, string $fileName = '', $cb = null, bool $encrypted = false, array $extra = []) { diff --git a/src/danog/MadelineProto/MTProto.php b/src/danog/MadelineProto/MTProto.php index 42cf8814..cc103c4d 100644 --- a/src/danog/MadelineProto/MTProto.php +++ b/src/danog/MadelineProto/MTProto.php @@ -263,7 +263,8 @@ class MTProto extends AsyncConstruct implements TLCallback /** * Whether we're authorized. * - * @var integer + * @var int + * @psalm-var self::NOT_LOGGED_IN|self::WAITING_*|self::LOGGED_IN */ public $authorized = self::NOT_LOGGED_IN; /** @@ -387,6 +388,10 @@ class MTProto extends AsyncConstruct implements TLCallback * RPC reporting loop. */ private ?PeriodicLoopInternal $rpcLoop = null; + /** + * SEQ update loop. + */ + private ?SeqLoop $seqUpdater = null; /** * IPC server. */ @@ -1678,6 +1683,18 @@ class MTProto extends AsyncConstruct implements TLCallback { return $this->authorized; } + /** + * Get current password hint. + * + * @return string + */ + public function getHint(): string + { + if ($this->authorized !== self::WAITING_PASSWORD) { + throw new Exception("Not waiting for the password!"); + } + return $this->authorization['hint']; + } /** * IDs of peers where to report errors. * diff --git a/src/danog/MadelineProto/MTProtoSession/ResponseHandler.php b/src/danog/MadelineProto/MTProtoSession/ResponseHandler.php index a73a994f..f79baf16 100644 --- a/src/danog/MadelineProto/MTProtoSession/ResponseHandler.php +++ b/src/danog/MadelineProto/MTProtoSession/ResponseHandler.php @@ -26,6 +26,8 @@ use danog\MadelineProto\MTProto; /** * Manages responses. + * + * @extend Session */ trait ResponseHandler { @@ -357,7 +359,7 @@ trait ResponseHandler $socket->setPermAuthKey(null); $socket->resetSession(); } - if (in_array($response['error_message'],['USER_DEACTIVATED', 'USER_DEACTIVATED_BAN'], true)) { + if (\in_array($response['error_message'], ['USER_DEACTIVATED', 'USER_DEACTIVATED_BAN'], true)) { $this->logger->logger('!!!!!!! WARNING !!!!!!!', \danog\MadelineProto\Logger::FATAL_ERROR); $this->logger->logger("Telegram's flood prevention system suspended this account.", \danog\MadelineProto\Logger::ERROR); $this->logger->logger('To continue, manual verification is required.', \danog\MadelineProto\Logger::FATAL_ERROR); diff --git a/src/danog/MadelineProto/MTProtoTools/UpdateHandler.php b/src/danog/MadelineProto/MTProtoTools/UpdateHandler.php index 54de5119..3c8efb6e 100644 --- a/src/danog/MadelineProto/MTProtoTools/UpdateHandler.php +++ b/src/danog/MadelineProto/MTProtoTools/UpdateHandler.php @@ -33,6 +33,7 @@ use danog\MadelineProto\Tools; /** * Manages updates. * + * @extend MTProto * @property Settings $settings Settings */ trait UpdateHandler diff --git a/src/danog/MadelineProto/Serialization.php b/src/danog/MadelineProto/Serialization.php index 2efabcd1..e1c0afc4 100644 --- a/src/danog/MadelineProto/Serialization.php +++ b/src/danog/MadelineProto/Serialization.php @@ -103,7 +103,7 @@ abstract class Serialization * @internal * * @return \Generator - * + * * @psalm-return \Generator */ public static function unserialize(SessionPaths $session, bool $forceFull = false): \Generator diff --git a/src/danog/MadelineProto/Stream/Common/UdpBufferedStream.php b/src/danog/MadelineProto/Stream/Common/UdpBufferedStream.php index 46f733f8..b982bb7f 100644 --- a/src/danog/MadelineProto/Stream/Common/UdpBufferedStream.php +++ b/src/danog/MadelineProto/Stream/Common/UdpBufferedStream.php @@ -115,7 +115,7 @@ class UdpBufferedStream extends DefaultStream implements BufferedStreamInterface /** * Destructor function. */ - public function __destruct(): void + public function __destruct() { \fclose($this->buffer); } diff --git a/src/danog/MadelineProto/Stream/Proxy/HttpProxy.php b/src/danog/MadelineProto/Stream/Proxy/HttpProxy.php index 3496b943..e2cc893c 100644 --- a/src/danog/MadelineProto/Stream/Proxy/HttpProxy.php +++ b/src/danog/MadelineProto/Stream/Proxy/HttpProxy.php @@ -36,6 +36,12 @@ use danog\MadelineProto\Stream\RawStreamInterface; class HttpProxy implements RawProxyStreamInterface, BufferedProxyStreamInterface { use RawStream; + /** + * Stream. + * + * @var RawStreamInterface + */ + protected $stream; private $extra; /** * Connect to stream. diff --git a/src/danog/MadelineProto/Stream/Proxy/SocksProxy.php b/src/danog/MadelineProto/Stream/Proxy/SocksProxy.php index ebcdd9f5..dba835e7 100644 --- a/src/danog/MadelineProto/Stream/Proxy/SocksProxy.php +++ b/src/danog/MadelineProto/Stream/Proxy/SocksProxy.php @@ -37,6 +37,12 @@ class SocksProxy implements RawProxyStreamInterface, BufferedProxyStreamInterfac { const REPS = [0 => 'succeeded', 1 => 'general SOCKS server failure', 2 => 'connection not allowed by ruleset', 3 => 'Network unreachable', 4 => 'Host unreachable', 5 => 'Connection refused', 6 => 'TTL expired', 7 => 'Command not supported', 8 => 'Address type not supported']; use RawStream; + /** + * Stream. + * + * @var RawStreamInterface + */ + protected $stream; private $extra; /** * Connect to stream. diff --git a/src/danog/MadelineProto/TON/API.php b/src/danog/MadelineProto/TON/API.php index 022c3372..802a61f3 100644 --- a/src/danog/MadelineProto/TON/API.php +++ b/src/danog/MadelineProto/TON/API.php @@ -20,6 +20,7 @@ namespace danog\MadelineProto\TON; use danog\MadelineProto\Magic; +use danog\MadelineProto\Settings\Logger; /** * TON API. @@ -29,9 +30,9 @@ class API extends InternalDoc /** * Construct API. * - * @param array $settings Settings + * @param Logger $settings Settings */ - public function __construct(array $settings) + public function __construct(Logger $settings) { Magic::classExists(); $this->API = new Lite($settings); diff --git a/src/danog/MadelineProto/TON/InternalDoc.php b/src/danog/MadelineProto/TON/InternalDoc.php index 00bf3831..e01ce61d 100644 --- a/src/danog/MadelineProto/TON/InternalDoc.php +++ b/src/danog/MadelineProto/TON/InternalDoc.php @@ -987,7 +987,7 @@ class InternalDoc extends APIFactory * * @param array $parameters Parameters * - * @return \Generator + * @return \Amp\Promise */ public function botAPItoMTProto(array $parameters, array $extra = []) { @@ -998,7 +998,11 @@ class InternalDoc extends APIFactory * * @param \Generator|Promise|mixed $promise * + * @template TReturn + * @psalm-param \Generator|Promise|TReturn $promise + * * @return Promise + * @psalm-return Promise */ public function call($promise) { @@ -1035,7 +1039,7 @@ class InternalDoc extends APIFactory * * @param string $config Path to config file * - * @return \Generator + * @return \Amp\Promise */ public function connect(string $config, array $extra = []) { @@ -1189,7 +1193,7 @@ class InternalDoc extends APIFactory * * @param callable $func Function * - * @return \Generator + * @return \Amp\Promise */ public function loop(callable $func, array $extra = []) { @@ -1212,7 +1216,7 @@ class InternalDoc extends APIFactory * @param string $methodName Method name * @param array $args Arguments * - * @return \Generator + * @return \Amp\Promise */ public function methodCall(string $methodName, array $args = [ ], array $aargs = [ @@ -1416,15 +1420,20 @@ class InternalDoc extends APIFactory * * If the timeout expires before the promise is resolved, a default value is returned * + * @template TReturnAlt * @template TReturn + * @template TGenerator as \Generator * * @param Promise|\Generator $promise Promise to which the timeout is applied. * @param int $timeout Timeout in milliseconds. - * @param TReturn $default + * @param mixed $default * - * @return Promise + * @psalm-param Promise|TGenerator $promise Promise to which the timeout is applied. + * @psalm-param TReturnAlt $timeout * - * @throws \TypeError If $promise is not an instance of \Amp\Promise or \React\Promise\PromiseInterface. + * @return Promise + * + * @throws \TypeError If $promise is not an instance of \Amp\Promise, \Generator or \React\Promise\PromiseInterface. */ public function timeoutWithDefault($promise, int $timeout, $default = null) { diff --git a/src/danog/MadelineProto/TON/Lite.php b/src/danog/MadelineProto/TON/Lite.php index 09b7c792..8261e348 100644 --- a/src/danog/MadelineProto/TON/Lite.php +++ b/src/danog/MadelineProto/TON/Lite.php @@ -20,6 +20,8 @@ namespace danog\MadelineProto\TON; use danog\MadelineProto\Logger; +use danog\MadelineProto\Settings\Logger as SettingsLogger; +use danog\MadelineProto\Settings\TLSchema; use danog\MadelineProto\TL\TL; use danog\MadelineProto\Tools; use function Amp\File\get; @@ -38,9 +40,9 @@ class Lite /** * Misc settings. * - * @var array + * @var SettingsLogger */ - private $settings = []; + private SettingsLogger $settings; /** * TL serializer instance. * @@ -62,14 +64,17 @@ class Lite /** * Construct settings. * - * @param array $settings + * @param SettingsLogger $settings */ - public function __construct(array $settings) + public function __construct(SettingsLogger $settings) { $this->settings = $settings; - $this->logger = Logger::getLoggerFromSettings($this->settings); + $this->logger = Logger::constructorFromSettings($this->settings); + $schema = new TLSchema; + $schema->setOther(['lite_api' => __DIR__.'/../../../../schemas/TON/lite_api.tl', 'ton_api' => __DIR__.'/../../../../schemas/TON/ton_api.tl']); + /** @psalm-suppress InvalidArgument */ $this->TL = new TL($this); - $this->TL->init(['lite_api' => __DIR__.'/../../../../schemas/TON/lite_api.tl', 'ton_api' => __DIR__.'/../../../../schemas/TON/ton_api.tl']); + $this->TL->init($schema); } /** * Connect to the lite endpoints specified in the config file. diff --git a/src/danog/MadelineProto/Tools.php b/src/danog/MadelineProto/Tools.php index b53a0394..053cb47c 100644 --- a/src/danog/MadelineProto/Tools.php +++ b/src/danog/MadelineProto/Tools.php @@ -420,7 +420,7 @@ abstract class Tools extends StrTools * * @template TReturnAlt * @template TReturn - * @template TGenerator as Generator + * @template TGenerator as \Generator * * @param Promise|\Generator $promise Promise to which the timeout is applied. * @param int $timeout Timeout in milliseconds. @@ -458,10 +458,9 @@ abstract class Tools extends StrTools /** * Convert generator, promise or any other value to a promise. * - * @template TReturn - * * @param \Generator|Promise|mixed $promise * + * @template TReturn * @psalm-param \Generator|Promise|TReturn $promise * * @return Promise @@ -517,7 +516,7 @@ abstract class Tools extends StrTools */ public static function callForkDefer($promise): void { - Loop::defer([self::class, 'callFork'], $promise); + Loop::defer(fn () => self::callFork($promise)); } /** * Rethrow error catched in strand. @@ -616,7 +615,7 @@ abstract class Tools extends StrTools * * @internal Generator function * - * @return \Generator + * @return \Generator */ public static function flockGenerator(string $file, int $operation, float $polling, ?Promise $token = null, $failureCb = null): \Generator { diff --git a/src/danog/MadelineProto/Wrappers/DialogHandler.php b/src/danog/MadelineProto/Wrappers/DialogHandler.php index 4ce6872a..500f2c85 100644 --- a/src/danog/MadelineProto/Wrappers/DialogHandler.php +++ b/src/danog/MadelineProto/Wrappers/DialogHandler.php @@ -41,7 +41,7 @@ trait DialogHandler { if ($this->authorization['user']['bot']) { $res = []; - /** @uses DbArray::getIterator() */ + /** @uses DbArray::getIterator() */ $iterator = $this->chats->getIterator(); while (yield $iterator->advance()) { [$id, $chat] = $iterator->getCurrent(); diff --git a/src/danog/MadelineProto/Wrappers/Events.php b/src/danog/MadelineProto/Wrappers/Events.php index 0b89c80d..80b4e0a6 100644 --- a/src/danog/MadelineProto/Wrappers/Events.php +++ b/src/danog/MadelineProto/Wrappers/Events.php @@ -49,19 +49,6 @@ trait Events * @var array */ private $eventHandlerMethods = []; - /** - * Initialize existing event handler. - * - * @internal - * - * @return void - */ - public function initExistingEventHandler(): void - { - if ($this->event_handler && \class_exists($this->event_handler) && \is_subclass_of($this->API->event_handler, EventHandler::class)) { - $this->initEventHandler($this->API->event_handler); - } - } /** * Initialize event handler. * diff --git a/src/danog/MadelineProto/Wrappers/Start.php b/src/danog/MadelineProto/Wrappers/Start.php index ec51440f..161a05c4 100644 --- a/src/danog/MadelineProto/Wrappers/Start.php +++ b/src/danog/MadelineProto/Wrappers/Start.php @@ -45,10 +45,11 @@ trait Start } if ($this->getWebTemplate() === 'legacy') { if ($this instanceof Client) { - $this->setWebTemplate(yield from $this->getSettings()); + $settings = yield from $this->getSettings(); } else { - $this->setWebTemplate($this->settings); + $settings = $this->settings; } + $this->setWebTemplate($settings->getTemplates()->getHtmlTemplate()); } if (PHP_SAPI === 'cli' || PHP_SAPI === 'phpdbg') { if (\strpos(yield Tools::readLine(Lang::$current_lang['loginChoosePrompt']), 'b') !== false) { diff --git a/src/danog/MadelineProto/Wrappers/Templates.php b/src/danog/MadelineProto/Wrappers/Templates.php index 7fb6f0d3..33aa9047 100644 --- a/src/danog/MadelineProto/Wrappers/Templates.php +++ b/src/danog/MadelineProto/Wrappers/Templates.php @@ -20,6 +20,7 @@ namespace danog\MadelineProto\Wrappers; use \danog\MadelineProto\MTProto; +use danog\MadelineProto\Ipc\Client; use danog\MadelineProto\Lang; use function Amp\ByteStream\getOutputBufferStream; @@ -59,7 +60,10 @@ trait Templates $form = ""; } elseif ($auth === MTProto::WAITING_PASSWORD) { $title = Lang::$current_lang['loginUserPassWeb']; - $hint = \htmlentities(\sprintf(Lang::$current_lang['loginUserPassHint'], $this->authorization['hint'])); + $hint = \htmlentities(\sprintf( + Lang::$current_lang['loginUserPassHint'], + $this instanceof Client ? yield from $this->getHint() : $this->getHint() + )); $form = ""; } elseif ($auth === MTProto::WAITING_SIGNUP) { $title = Lang::$current_lang['signupWeb']; diff --git a/ton/lite-client.php b/ton/lite-client.php index 2ea6bf50..6b42995f 100644 --- a/ton/lite-client.php +++ b/ton/lite-client.php @@ -1,17 +1,11 @@ [ - 'logger' => Logger::ECHO_LOGGER - ] - ] -); +$API = new API(new SettingsLogger); $API->async(true); $API->loop(