From ca2cbe4ecbe2cf1cb2cd3ccf4265552ebfbc07af Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Thu, 1 Oct 2020 21:03:25 +0200 Subject: [PATCH] Add missing return typehints --- src/danog/MadelineProto/APIWrapper.php | 4 ++-- .../MadelineProto/AnnotationsBuilder.php | 2 +- .../MadelineProto/ApiWrappers/Templates.php | 2 +- src/danog/MadelineProto/Connection.php | 8 +++++--- src/danog/MadelineProto/Coroutine.php | 8 +++++--- src/danog/MadelineProto/DataCenter.php | 8 ++++++-- .../MadelineProto/DataCenterConnection.php | 8 +++++--- src/danog/MadelineProto/Db/Driver/Redis.php | 5 +++-- src/danog/MadelineProto/Db/MysqlArray.php | 5 ++++- .../Db/NullCache/NullCacheTrait.php | 3 +++ src/danog/MadelineProto/Db/PostgresArray.php | 5 ++++- src/danog/MadelineProto/Db/RedisArray.php | 5 +++++ src/danog/MadelineProto/DocsBuilder.php | 4 ++-- .../DocsBuilder/Constructors.php | 2 +- .../MadelineProto/DocsBuilder/Methods.php | 2 +- src/danog/MadelineProto/Exception.php | 8 ++++++-- src/danog/MadelineProto/Ipc/Client.php | 20 ++++++++++++++----- .../MadelineProto/Ipc/ClientAbstract.php | 4 +++- src/danog/MadelineProto/Ipc/ExitFailure.php | 2 +- .../MadelineProto/Loop/Update/FeedLoop.php | 4 ++-- .../MadelineProto/Loop/Update/SeqLoop.php | 4 ++-- src/danog/MadelineProto/Lua.php | 9 ++++++--- .../MadelineProto/MTProto/TempAuthKey.php | 4 ++-- .../MTProtoSession/ResponseHandler.php | 5 ++++- .../MTProtoSession/SeqNoHandler.php | 4 ++-- .../MadelineProto/MTProtoTools/FilesLogic.php | 16 +++++++++++---- src/danog/MadelineProto/RSA.php | 4 +++- .../Stream/Common/BufferedRawStream.php | 2 +- .../Stream/Common/UdpBufferedStream.php | 6 ++++-- .../MadelineProto/Stream/Proxy/HttpProxy.php | 2 +- .../Stream/Transport/DefaultStream.php | 3 +++ .../Stream/Transport/PremadeStream.php | 4 ++-- src/danog/MadelineProto/TL/TLParams.php | 2 +- src/danog/MadelineProto/Tools.php | 7 +++++-- src/polyfill.php | 2 +- 35 files changed, 124 insertions(+), 59 deletions(-) diff --git a/src/danog/MadelineProto/APIWrapper.php b/src/danog/MadelineProto/APIWrapper.php index 0a780625..2a4ee6fa 100644 --- a/src/danog/MadelineProto/APIWrapper.php +++ b/src/danog/MadelineProto/APIWrapper.php @@ -131,9 +131,9 @@ final class APIWrapper /** * Get MTProto instance. * - * @return MTProto|null + * @return Client|MTProto|null */ - public function &getAPI(): ?MTProto + public function &getAPI() { return $this->API; } diff --git a/src/danog/MadelineProto/AnnotationsBuilder.php b/src/danog/MadelineProto/AnnotationsBuilder.php index f3d6d27b..4c382119 100644 --- a/src/danog/MadelineProto/AnnotationsBuilder.php +++ b/src/danog/MadelineProto/AnnotationsBuilder.php @@ -44,7 +44,7 @@ class AnnotationsBuilder $this->settings = $settings; $this->output = $output; } - public function mkAnnotations() + public function mkAnnotations(): void { \danog\MadelineProto\Logger::log('Generating annotations...', \danog\MadelineProto\Logger::NOTICE); $this->setProperties(); diff --git a/src/danog/MadelineProto/ApiWrappers/Templates.php b/src/danog/MadelineProto/ApiWrappers/Templates.php index 47c9439e..339d5d69 100644 --- a/src/danog/MadelineProto/ApiWrappers/Templates.php +++ b/src/danog/MadelineProto/ApiWrappers/Templates.php @@ -56,7 +56,7 @@ trait Templates /** * Set web API login HTML template string. * - * @return string + * @return void */ public function setWebAPITemplate(string $template): void { diff --git a/src/danog/MadelineProto/Connection.php b/src/danog/MadelineProto/Connection.php index 6095b681..ff5b6d73 100644 --- a/src/danog/MadelineProto/Connection.php +++ b/src/danog/MadelineProto/Connection.php @@ -319,7 +319,9 @@ class Connection extends Session * * @param ConnectionContext $ctx Connection context * - * @return \Amp\Promise + * @return \Generator + * + * @psalm-return \Generator */ public function connect(ConnectionContext $ctx): \Generator { @@ -475,9 +477,9 @@ class Connection extends Session /** * Get main instance. * - * @return MTProto + * @return MTProtoSession\MTProto */ - public function getExtra() + public function getExtra(): MTProtoSession\MTProto { return $this->API; } diff --git a/src/danog/MadelineProto/Coroutine.php b/src/danog/MadelineProto/Coroutine.php index 694f97f3..7662e705 100644 --- a/src/danog/MadelineProto/Coroutine.php +++ b/src/danog/MadelineProto/Coroutine.php @@ -176,8 +176,10 @@ final class Coroutine implements Promise, \ArrayAccess } /** * @param \Throwable $reason Failure reason. + * + * @return void */ - public function fail(\Throwable $reason) + public function fail(\Throwable $reason): void { $this->resolve(new Failure($reason)); } @@ -199,7 +201,7 @@ final class Coroutine implements Promise, \ArrayAccess return $result[$offset]; })()); } - public function offsetSet($offset, $value) + public function offsetSet($offset, $value): Promise { return Tools::call((function () use ($offset, $value): \Generator { $result = yield $this; @@ -209,7 +211,7 @@ final class Coroutine implements Promise, \ArrayAccess return $result[$offset] = $value; })()); } - public function offsetUnset($offset) + public function offsetUnset($offset): Promise { return Tools::call((function () use ($offset): \Generator { $result = yield $this; diff --git a/src/danog/MadelineProto/DataCenter.php b/src/danog/MadelineProto/DataCenter.php index 0a58c407..1b034d19 100644 --- a/src/danog/MadelineProto/DataCenter.php +++ b/src/danog/MadelineProto/DataCenter.php @@ -546,7 +546,9 @@ class DataCenter * * @param string $url URL to fetch * - * @return \Generator + * @return \Generator + * + * @psalm-return \Generator, mixed, string> */ public function fileGetContents(string $url): \Generator { @@ -579,7 +581,9 @@ class DataCenter * * @param string $dc DC ID * - * @return \Generator + * @return \Generator + * + * @psalm-return \Generator */ public function waitGetConnection(string $dc): \Generator { diff --git a/src/danog/MadelineProto/DataCenterConnection.php b/src/danog/MadelineProto/DataCenterConnection.php index 5a26115e..fa3aed64 100644 --- a/src/danog/MadelineProto/DataCenterConnection.php +++ b/src/danog/MadelineProto/DataCenterConnection.php @@ -507,16 +507,18 @@ class DataCenterConnection implements JsonSerializable * * @param integer $id Connection ID * - * @return boolean + * @return bool|int */ - public function hasConnection(int $id = -1): bool + public function hasConnection(int $id = -1) { return $id < 0 ? \count($this->connections) : isset($this->connections[$id]); } /** * Get best socket in round robin, asynchronously. * - * @return \Generator + * @return \Generator + * + * @psalm-return \Generator */ public function waitGetConnection(): \Generator { diff --git a/src/danog/MadelineProto/Db/Driver/Redis.php b/src/danog/MadelineProto/Db/Driver/Redis.php index 406bd9c9..a7970ad3 100644 --- a/src/danog/MadelineProto/Db/Driver/Redis.php +++ b/src/danog/MadelineProto/Db/Driver/Redis.php @@ -18,7 +18,6 @@ class Redis * @param string $user * @param string $password * @param string $db - * * @param int $maxConnections * @param int $idleTimeout * @@ -26,7 +25,9 @@ class Redis * @throws \Amp\Sql\FailureException * @throws \Throwable * - * @return \Generator + * @return \Generator + * + * @psalm-return \Generator, mixed, RedisRedis> */ public static function getConnection(DatabaseRedis $settings): \Generator { diff --git a/src/danog/MadelineProto/Db/MysqlArray.php b/src/danog/MadelineProto/Db/MysqlArray.php index 2519af6d..5474ec77 100644 --- a/src/danog/MadelineProto/Db/MysqlArray.php +++ b/src/danog/MadelineProto/Db/MysqlArray.php @@ -198,8 +198,11 @@ class MysqlArray extends SqlArray /** * Create table for property. * - * @return array|null + * @return \Generator + * * @throws \Throwable + * + * @psalm-return \Generator */ protected function prepareTable(): \Generator { diff --git a/src/danog/MadelineProto/Db/NullCache/NullCacheTrait.php b/src/danog/MadelineProto/Db/NullCache/NullCacheTrait.php index 322dbc3a..6ccbfd41 100644 --- a/src/danog/MadelineProto/Db/NullCache/NullCacheTrait.php +++ b/src/danog/MadelineProto/Db/NullCache/NullCacheTrait.php @@ -4,6 +4,9 @@ namespace danog\MadelineProto\Db\NullCache; trait NullCacheTrait { + /** + * @return void + */ protected function getCache(string $key, $default = null) { } diff --git a/src/danog/MadelineProto/Db/PostgresArray.php b/src/danog/MadelineProto/Db/PostgresArray.php index 1979b73a..8784aacb 100644 --- a/src/danog/MadelineProto/Db/PostgresArray.php +++ b/src/danog/MadelineProto/Db/PostgresArray.php @@ -78,8 +78,11 @@ class PostgresArray extends SqlArray /** * Create table for property. * - * @return array|null + * @return \Generator + * * @throws \Throwable + * + * @psalm-return \Generator */ protected function prepareTable(): \Generator { diff --git a/src/danog/MadelineProto/Db/RedisArray.php b/src/danog/MadelineProto/Db/RedisArray.php index 86324aae..8026d15f 100644 --- a/src/danog/MadelineProto/Db/RedisArray.php +++ b/src/danog/MadelineProto/Db/RedisArray.php @@ -22,6 +22,11 @@ class RedisArray extends SqlArray // Legacy protected array $settings; + /** + * @return Generator + * + * @psalm-return Generator, mixed, void> + */ protected function prepareTable(): Generator { yield new Success; diff --git a/src/danog/MadelineProto/DocsBuilder.php b/src/danog/MadelineProto/DocsBuilder.php index 0f38967a..568f6946 100644 --- a/src/danog/MadelineProto/DocsBuilder.php +++ b/src/danog/MadelineProto/DocsBuilder.php @@ -75,7 +75,7 @@ class DocsBuilder public $types = []; public $any = '*'; - public function mkDocs() + public function mkDocs(): void { \danog\MadelineProto\Logger::log('Generating documentation index...', \danog\MadelineProto\Logger::NOTICE); \file_put_contents($this->index, $this->template('index', $this->settings['title'], $this->settings['description'])); @@ -145,7 +145,7 @@ class DocsBuilder } \danog\MadelineProto\Logger::log('Done!', \danog\MadelineProto\Logger::NOTICE); } - public static function addToLang(string $key, string $value = '', bool $force = false) + public static function addToLang(string $key, string $value = '', bool $force = false): void { if (!isset(\danog\MadelineProto\Lang::$lang['en'][$key]) || $force) { \danog\MadelineProto\Lang::$lang['en'][$key] = $value; diff --git a/src/danog/MadelineProto/DocsBuilder/Constructors.php b/src/danog/MadelineProto/DocsBuilder/Constructors.php index 70684ae6..2899b02e 100644 --- a/src/danog/MadelineProto/DocsBuilder/Constructors.php +++ b/src/danog/MadelineProto/DocsBuilder/Constructors.php @@ -24,7 +24,7 @@ use danog\MadelineProto\Tools; trait Constructors { - public function mkConstructors() + public function mkConstructors(): void { foreach (\glob('constructors/'.$this->any) as $unlink) { \unlink($unlink); diff --git a/src/danog/MadelineProto/DocsBuilder/Methods.php b/src/danog/MadelineProto/DocsBuilder/Methods.php index 93bf674e..c69bd4b5 100644 --- a/src/danog/MadelineProto/DocsBuilder/Methods.php +++ b/src/danog/MadelineProto/DocsBuilder/Methods.php @@ -24,7 +24,7 @@ use danog\MadelineProto\Tools; trait Methods { - public function mkMethods() + public function mkMethods(): void { static $bots; if (!$bots) { diff --git a/src/danog/MadelineProto/Exception.php b/src/danog/MadelineProto/Exception.php index 0308d623..7e2e9181 100644 --- a/src/danog/MadelineProto/Exception.php +++ b/src/danog/MadelineProto/Exception.php @@ -75,8 +75,10 @@ class Exception extends \Exception * ExceptionErrorHandler. * * Error handler + * + * @return false */ - public static function exceptionErrorHandler($errno = 0, $errstr = null, $errfile = null, $errline = null) + public static function exceptionErrorHandler($errno = 0, $errstr = null, $errfile = null, $errline = null): bool { // If error is suppressed with @, don't throw an exception if (\error_reporting() === 0 || \strpos($errstr, 'headers already sent') || $errfile && (\strpos($errfile, 'vendor/amphp') !== false || \strpos($errfile, 'vendor/league') !== false)) { @@ -88,8 +90,10 @@ class Exception extends \Exception * ExceptionErrorHandler. * * Error handler + * + * @return void */ - public static function exceptionHandler($exception) + public static function exceptionHandler($exception): void { Logger::log($exception, Logger::FATAL_ERROR); Magic::shutdown(1); diff --git a/src/danog/MadelineProto/Ipc/Client.php b/src/danog/MadelineProto/Ipc/Client.php index f3a36943..8352b3ac 100644 --- a/src/danog/MadelineProto/Ipc/Client.php +++ b/src/danog/MadelineProto/Ipc/Client.php @@ -140,7 +140,9 @@ class Client extends ClientAbstract * @param boolean $seekable Whether chunks can be fetched out of order * @param boolean $encrypted Whether to encrypt file for secret chats * - * @return \Generator + * @return \Generator + * + * @psalm-return \Generator|Promise, mixed, mixed> */ public function uploadFromCallable(callable $callable, int $size, string $mime, string $fileName = '', $cb = null, bool $seekable = true, bool $encrypted = false): \Generator { @@ -161,7 +163,9 @@ class Client extends ClientAbstract * @param callable $cb Callback (DEPRECATED, use FileCallbackInterface) * @param boolean $encrypted Whether to encrypt file for secret chats * - * @return \Generator + * @return \Generator + * + * @psalm-return \Generator|Promise, mixed, mixed> */ public function uploadFromTgfile($media, $cb = null, bool $encrypted = false): \Generator { @@ -181,7 +185,9 @@ class Client extends ClientAbstract * @param string|FileCallbackInterface $dir Directory where to download the file * @param callable $cb Callback (DEPRECATED, use FileCallbackInterface) * - * @return \Generator Downloaded file path + * @return \Generator Downloaded file path + * + * @psalm-return \Generator|Promise, mixed, mixed> */ public function downloadToDir($messageMedia, $dir, $cb = null): \Generator { @@ -201,7 +207,9 @@ class Client extends ClientAbstract * @param string|FileCallbackInterface $file Downloaded file path * @param callable $cb Callback (DEPRECATED, use FileCallbackInterface) * - * @return \Generator Downloaded file path + * @return \Generator Downloaded file path + * + * @psalm-return \Generator|Promise, mixed, mixed> */ public function downloadToFile($messageMedia, $file, $cb = null): \Generator { @@ -228,7 +236,9 @@ class Client extends ClientAbstract * @param int $end Offset where to stop downloading (inclusive) * @param int $part_size Size of each chunk * - * @return \Generator + * @return \Generator + * + * @psalm-return \Generator|Promise, mixed, mixed> */ public function downloadToCallable($messageMedia, callable $callable, $cb = null, bool $seekable = true, int $offset = 0, int $end = -1, int $part_size = null): \Generator { diff --git a/src/danog/MadelineProto/Ipc/ClientAbstract.php b/src/danog/MadelineProto/Ipc/ClientAbstract.php index 12e9ac30..d167b0e3 100644 --- a/src/danog/MadelineProto/Ipc/ClientAbstract.php +++ b/src/danog/MadelineProto/Ipc/ClientAbstract.php @@ -116,7 +116,9 @@ abstract class ClientAbstract /** * Disconnect cleanly from main instance. * - * @return Promise + * @return \Generator + * + * @psalm-return \Generator */ public function disconnect(): \Generator { diff --git a/src/danog/MadelineProto/Ipc/ExitFailure.php b/src/danog/MadelineProto/Ipc/ExitFailure.php index 39773ace..95fddac4 100644 --- a/src/danog/MadelineProto/Ipc/ExitFailure.php +++ b/src/danog/MadelineProto/Ipc/ExitFailure.php @@ -48,7 +48,7 @@ final class ExitFailure } } - public function getException() + public function getException(): object { $previous = $this->previous ? $this->previous->getException() : null; diff --git a/src/danog/MadelineProto/Loop/Update/FeedLoop.php b/src/danog/MadelineProto/Loop/Update/FeedLoop.php index 657d0028..c0006a04 100644 --- a/src/danog/MadelineProto/Loop/Update/FeedLoop.php +++ b/src/danog/MadelineProto/Loop/Update/FeedLoop.php @@ -247,11 +247,11 @@ class FeedLoop extends ResumableSignalLoop $this->incomingUpdates[] = $update; return $this->channelId; } - public function save($update) + public function save($update): void { $this->parsedUpdates[] = $update; } - public function saveMessages($messages) + public function saveMessages($messages): void { foreach ($messages as $message) { if (!$this->API->checkMsgId($message)) { diff --git a/src/danog/MadelineProto/Loop/Update/SeqLoop.php b/src/danog/MadelineProto/Loop/Update/SeqLoop.php index 518150ef..e5189c9b 100644 --- a/src/danog/MadelineProto/Loop/Update/SeqLoop.php +++ b/src/danog/MadelineProto/Loop/Update/SeqLoop.php @@ -114,7 +114,7 @@ class SeqLoop extends ResumableSignalLoop yield from $this->save($update); } } - public function feed($updates) + public function feed($updates): void { $this->API->logger->logger('Was fed updates of type '.$updates['_'].'...', \danog\MadelineProto\Logger::VERBOSE); $this->incomingUpdates[] = $updates; @@ -123,7 +123,7 @@ class SeqLoop extends ResumableSignalLoop { $this->pendingWakeups += (yield from $this->feeder->feed($updates['updates'])); } - public function addPendingWakeups($wakeups) + public function addPendingWakeups($wakeups): void { $this->pendingWakeups += $wakeups; } diff --git a/src/danog/MadelineProto/Lua.php b/src/danog/MadelineProto/Lua.php index c6d86ae1..fa60f3ef 100644 --- a/src/danog/MadelineProto/Lua.php +++ b/src/danog/MadelineProto/Lua.php @@ -75,6 +75,9 @@ class Lua $this->MadelineProto->{$namespace}->lua = true; } } + /** + * @return \Generator|int + */ public function tdcliFunction($params, $cb = null, $cb_extra = null) { $params = $this->MadelineProto->td_to_mtproto($this->MadelineProto->tdcliToTd($params)); @@ -96,7 +99,7 @@ class Lua self::convertObjects($result); return $result; } - public function tdcliUpdateCallback($update) + public function tdcliUpdateCallback($update): void { $this->Lua->tdcliUpdateCallback($this->MadelineProto->mtproto_to_tdcli($update)); } @@ -111,7 +114,7 @@ class Lua }, \array_flip($array))); } } - private function isSequential(array $arr) + private function isSequential(array $arr): bool { if ([] === $arr) { return false; @@ -150,7 +153,7 @@ class Lua { return $this->Lua->{$name} = $value; } - public static function convertObjects(&$data) + public static function convertObjects(&$data): void { \array_walk_recursive($data, function (&$value, $key) { if (\is_object($value) && !$value instanceof \tgseclib\Math\BigInteger) { diff --git a/src/danog/MadelineProto/MTProto/TempAuthKey.php b/src/danog/MadelineProto/MTProto/TempAuthKey.php index 0abcfe0f..2f14f2f6 100644 --- a/src/danog/MadelineProto/MTProto/TempAuthKey.php +++ b/src/danog/MadelineProto/MTProto/TempAuthKey.php @@ -166,9 +166,9 @@ class TempAuthKey extends AuthKey implements JsonSerializable /** * Wakeup function. * - * @return array + * @return void */ - public function __wakeup() + public function __wakeup(): void { $this->inited = (bool) $this->inited; } diff --git a/src/danog/MadelineProto/MTProtoSession/ResponseHandler.php b/src/danog/MadelineProto/MTProtoSession/ResponseHandler.php index fa96d6c7..709d1e10 100644 --- a/src/danog/MadelineProto/MTProtoSession/ResponseHandler.php +++ b/src/danog/MadelineProto/MTProtoSession/ResponseHandler.php @@ -30,7 +30,7 @@ use danog\MadelineProto\MTProto; trait ResponseHandler { public $n = 0; - public function handleMessages() + public function handleMessages(): bool { $only_updates = true; while ($this->new_incoming) { @@ -287,6 +287,9 @@ trait ResponseHandler $this->logger->logger("Rejecting: {$data}"); } } + /** + * @return void + */ public function handleResponse($request_id, $response_id) { $response =& $this->incoming_messages[$response_id]['content']; diff --git a/src/danog/MadelineProto/MTProtoSession/SeqNoHandler.php b/src/danog/MadelineProto/MTProtoSession/SeqNoHandler.php index 5f11d11a..a3cd2bd5 100644 --- a/src/danog/MadelineProto/MTProtoSession/SeqNoHandler.php +++ b/src/danog/MadelineProto/MTProtoSession/SeqNoHandler.php @@ -37,7 +37,7 @@ trait SeqNoHandler //$this->API->logger->logger("OUT: $value + $in = ".$this->session_out_seq_no); return $value * 2 + $in; } - public function checkInSeqNo($current_msg_id) + public function checkInSeqNo($current_msg_id): void { $type = isset($this->incoming_messages[$current_msg_id]['content']['_']) ? $this->incoming_messages[$current_msg_id]['content']['_'] : '-'; if (isset($this->incoming_messages[$current_msg_id]['seq_no']) && ($seq_no = $this->generateInSeqNo($this->contentRelated($this->incoming_messages[$current_msg_id]['content']))) !== $this->incoming_messages[$current_msg_id]['seq_no']) { @@ -52,7 +52,7 @@ trait SeqNoHandler //$this->API->logger->logger("IN: $value + $in = ".$this->session_in_seq_no); return $value * 2 + $in; } - public function contentRelated($method) + public function contentRelated($method): bool { $method = \is_array($method) && isset($method['_']) ? $method['_'] : $method; return \is_string($method) ? !\in_array($method, MTProto::NOT_CONTENT_RELATED) : true; diff --git a/src/danog/MadelineProto/MTProtoTools/FilesLogic.php b/src/danog/MadelineProto/MTProtoTools/FilesLogic.php index 030cf813..78c7f6e4 100644 --- a/src/danog/MadelineProto/MTProtoTools/FilesLogic.php +++ b/src/danog/MadelineProto/MTProtoTools/FilesLogic.php @@ -91,7 +91,9 @@ trait FilesLogic * @param int $offset Offset where to start downloading * @param int $end Offset where to end download * - * @return \Generator + * @return \Generator + * + * @psalm-return \Generator|\Amp\Promise|mixed, mixed, mixed> */ public function downloadToStream($messageMedia, $stream, $cb = null, int $offset = 0, int $end = -1): \Generator { @@ -184,7 +186,9 @@ trait FilesLogic * @param string $fileName File name * @param callable $cb Callback (DEPRECATED, use FileCallbackInterface) * - * @return \Generator + * @return \Generator + * + * @psalm-return \Generator|array, mixed, mixed> */ public function uploadEncrypted($file, string $fileName = '', $cb = null): \Generator { @@ -199,7 +203,9 @@ trait FilesLogic * @param callable $cb Callback (DEPRECATED, use FileCallbackInterface) * @param boolean $encrypted Whether to encrypt file for secret chats * - * @return \Generator + * @return \Generator + * + * @psalm-return \Generator|\Amp\Promise<\Amp\Ipc\Sync\ChannelledSocket>|\Amp\Promise|\Amp\Promise|\Amp\Promise|\danog\MadelineProto\Stream\StreamInterface|array|int|mixed, mixed, mixed> */ public function upload($file, string $fileName = '', $cb = null, bool $encrypted = false): \Generator { @@ -251,7 +257,9 @@ trait FilesLogic * @param callable $cb Callback (DEPRECATED, use FileCallbackInterface) * @param boolean $encrypted Whether to encrypt file for secret chats * - * @return array + * @return \Generator + * + * @psalm-return \Generator|\Amp\Promise|\danog\MadelineProto\Stream\StreamInterface|array|int|mixed, mixed, mixed> */ public function uploadFromStream($stream, int $size, string $mime, string $fileName = '', $cb = null, bool $encrypted = false): \Generator { diff --git a/src/danog/MadelineProto/RSA.php b/src/danog/MadelineProto/RSA.php index 4cd7ce42..63b68a82 100644 --- a/src/danog/MadelineProto/RSA.php +++ b/src/danog/MadelineProto/RSA.php @@ -51,7 +51,9 @@ class RSA * @param TL $TL TL serializer * @param string $rsa_key RSA key * - * @return \Generator + * @return \Generator + * + * @psalm-return \Generator */ public function load(TL $TL, string $rsa_key): \Generator { diff --git a/src/danog/MadelineProto/Stream/Common/BufferedRawStream.php b/src/danog/MadelineProto/Stream/Common/BufferedRawStream.php index cd769bfa..6d8d869d 100644 --- a/src/danog/MadelineProto/Stream/Common/BufferedRawStream.php +++ b/src/danog/MadelineProto/Stream/Common/BufferedRawStream.php @@ -84,7 +84,7 @@ class BufferedRawStream implements BufferedStreamInterface, BufferInterface, Raw /** * Async close. * - * @return \Generator + * @return void */ public function disconnect() { diff --git a/src/danog/MadelineProto/Stream/Common/UdpBufferedStream.php b/src/danog/MadelineProto/Stream/Common/UdpBufferedStream.php index a7ed87a7..46f733f8 100644 --- a/src/danog/MadelineProto/Stream/Common/UdpBufferedStream.php +++ b/src/danog/MadelineProto/Stream/Common/UdpBufferedStream.php @@ -68,9 +68,11 @@ class UdpBufferedStream extends DefaultStream implements BufferedStreamInterface * * @param int $length Length of payload, as detected by this layer * - * @return Promise + * @return \Generator + * + * @psalm-return \Generator|Success> */ - public function getReadBuffer(&$length): Promise + public function getReadBuffer(&$length): \Generator { if (!$this->stream) { return new Failure(new ClosedException("MadelineProto stream was disconnected")); diff --git a/src/danog/MadelineProto/Stream/Proxy/HttpProxy.php b/src/danog/MadelineProto/Stream/Proxy/HttpProxy.php index f7df25f8..97bed8a8 100644 --- a/src/danog/MadelineProto/Stream/Proxy/HttpProxy.php +++ b/src/danog/MadelineProto/Stream/Proxy/HttpProxy.php @@ -166,7 +166,7 @@ class HttpProxy implements RawProxyStreamInterface, BufferedProxyStreamInterface { return $this->stream->write($data); } - private function getProxyAuthHeader() + private function getProxyAuthHeader(): string { if (!isset($this->extra['username']) || !isset($this->extra['password'])) { return ''; diff --git a/src/danog/MadelineProto/Stream/Transport/DefaultStream.php b/src/danog/MadelineProto/Stream/Transport/DefaultStream.php index 222df18c..17392f1d 100644 --- a/src/danog/MadelineProto/Stream/Transport/DefaultStream.php +++ b/src/danog/MadelineProto/Stream/Transport/DefaultStream.php @@ -57,6 +57,9 @@ class DefaultStream implements RawStreamInterface, ProxyStreamInterface { return $this->stream->setupTls($cancellationToken); } + /** + * @return EncryptableSocket + */ public function getStream() { return $this->stream; diff --git a/src/danog/MadelineProto/Stream/Transport/PremadeStream.php b/src/danog/MadelineProto/Stream/Transport/PremadeStream.php index 72ff5b99..1b31f24a 100644 --- a/src/danog/MadelineProto/Stream/Transport/PremadeStream.php +++ b/src/danog/MadelineProto/Stream/Transport/PremadeStream.php @@ -82,7 +82,7 @@ class PremadeStream implements RawStreamInterface, ProxyStreamInterface /** * Async close. * - * @return \Generator + * @return void */ public function disconnect() { @@ -97,7 +97,7 @@ class PremadeStream implements RawStreamInterface, ProxyStreamInterface \danog\MadelineProto\Logger::log('Got exception while closing stream: '.$e->getMessage()); } } - public function close() + public function close(): void { $this->disconnect(); } diff --git a/src/danog/MadelineProto/TL/TLParams.php b/src/danog/MadelineProto/TL/TLParams.php index 1aa7cdb1..a1d406d2 100644 --- a/src/danog/MadelineProto/TL/TLParams.php +++ b/src/danog/MadelineProto/TL/TLParams.php @@ -21,7 +21,7 @@ namespace danog\MadelineProto\TL; trait TLParams { - public function parseParams($key, $mtproto = false) + public function parseParams($key, $mtproto = false): void { foreach ($this->by_id[$key]['params'] as $kkey => $param) { if (\preg_match('/(\\w*)\\.(\\d*)\\?(.*)/', $param['type'], $matches)) { diff --git a/src/danog/MadelineProto/Tools.php b/src/danog/MadelineProto/Tools.php index dde4329a..51fe30da 100644 --- a/src/danog/MadelineProto/Tools.php +++ b/src/danog/MadelineProto/Tools.php @@ -665,7 +665,9 @@ abstract class Tools extends StrTools * * @internal Generator function * - * @return \Generator + * @return \Generator + * + * @psalm-return \Generator, mixed, mixed|null> */ public static function readLineGenerator(string $prompt = ''): \Generator { @@ -933,7 +935,8 @@ abstract class Tools extends StrTools * * @psalm-suppress InvalidScope * - * @return mixed + * @return void + * * @access public */ public static function setVar($obj, string $var, &$val): void diff --git a/src/polyfill.php b/src/polyfill.php index 83b2e9e6..8f25f272 100644 --- a/src/polyfill.php +++ b/src/polyfill.php @@ -13,7 +13,7 @@ function __coalesce($ifNotNull, $then) { return $ifNotNull ?: $then; } -function __destructure($list, $value) +function __destructure($list, $value): array { $res = []; foreach ($list as $key) {