Add missing return typehints

This commit is contained in:
Daniil Gentili 2020-10-01 21:03:25 +02:00
parent 05a859ea50
commit ca2cbe4ecb
Signed by: danog
GPG Key ID: 8C1BE3B34B230CA7
35 changed files with 124 additions and 59 deletions

View File

@ -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;
}

View File

@ -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();

View File

@ -56,7 +56,7 @@ trait Templates
/**
* Set web API login HTML template string.
*
* @return string
* @return void
*/
public function setWebAPITemplate(string $template): void
{

View File

@ -319,7 +319,9 @@ class Connection extends Session
*
* @param ConnectionContext $ctx Connection context
*
* @return \Amp\Promise
* @return \Generator
*
* @psalm-return \Generator<mixed, StreamInterface, mixed, void>
*/
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;
}

View File

@ -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;

View File

@ -546,7 +546,9 @@ class DataCenter
*
* @param string $url URL to fetch
*
* @return \Generator<string>
* @return \Generator
*
* @psalm-return \Generator<int, \Amp\Promise<string>, mixed, string>
*/
public function fileGetContents(string $url): \Generator
{
@ -579,7 +581,9 @@ class DataCenter
*
* @param string $dc DC ID
*
* @return \Generator<Connection>
* @return \Generator
*
* @psalm-return \Generator<int, \Amp\Promise, mixed, Connection>
*/
public function waitGetConnection(string $dc): \Generator
{

View File

@ -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<Connection>
* @return \Generator
*
* @psalm-return \Generator<int, Promise, mixed, Connection>
*/
public function waitGetConnection(): \Generator
{

View File

@ -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<RedisRedis>
* @return \Generator
*
* @psalm-return \Generator<int, \Amp\Promise<void>, mixed, RedisRedis>
*/
public static function getConnection(DatabaseRedis $settings): \Generator
{

View File

@ -198,8 +198,11 @@ class MysqlArray extends SqlArray
/**
* Create table for property.
*
* @return array|null
* @return \Generator
*
* @throws \Throwable
*
* @psalm-return \Generator<int, Promise, mixed, mixed>
*/
protected function prepareTable(): \Generator
{

View File

@ -4,6 +4,9 @@ namespace danog\MadelineProto\Db\NullCache;
trait NullCacheTrait
{
/**
* @return void
*/
protected function getCache(string $key, $default = null)
{
}

View File

@ -78,8 +78,11 @@ class PostgresArray extends SqlArray
/**
* Create table for property.
*
* @return array|null
* @return \Generator
*
* @throws \Throwable
*
* @psalm-return \Generator<int, Promise, mixed, void>
*/
protected function prepareTable(): \Generator
{

View File

@ -22,6 +22,11 @@ class RedisArray extends SqlArray
// Legacy
protected array $settings;
/**
* @return Generator
*
* @psalm-return Generator<int, Success<null>, mixed, void>
*/
protected function prepareTable(): Generator
{
yield new Success;

View File

@ -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;

View File

@ -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);

View File

@ -24,7 +24,7 @@ use danog\MadelineProto\Tools;
trait Methods
{
public function mkMethods()
public function mkMethods(): void
{
static $bots;
if (!$bots) {

View File

@ -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);

View File

@ -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<array>
* @return \Generator
*
* @psalm-return \Generator<int, Promise<ChannelledSocket>|Promise<mixed>, 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<array>
* @return \Generator
*
* @psalm-return \Generator<int, Promise<ChannelledSocket>|Promise<mixed>, 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<string> Downloaded file path
* @return \Generator Downloaded file path
*
* @psalm-return \Generator<int, Promise<ChannelledSocket>|Promise<mixed>, 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<string> Downloaded file path
* @return \Generator Downloaded file path
*
* @psalm-return \Generator<int, Promise<ChannelledSocket>|Promise<mixed>, 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<bool>
* @return \Generator
*
* @psalm-return \Generator<int, Promise<ChannelledSocket>|Promise<mixed>, mixed, mixed>
*/
public function downloadToCallable($messageMedia, callable $callable, $cb = null, bool $seekable = true, int $offset = 0, int $end = -1, int $part_size = null): \Generator
{

View File

@ -116,7 +116,9 @@ abstract class ClientAbstract
/**
* Disconnect cleanly from main instance.
*
* @return Promise
* @return \Generator
*
* @psalm-return \Generator<int, Promise, mixed, void>
*/
public function disconnect(): \Generator
{

View File

@ -48,7 +48,7 @@ final class ExitFailure
}
}
public function getException()
public function getException(): object
{
$previous = $this->previous ? $this->previous->getException() : null;

View File

@ -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)) {

View File

@ -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;
}

View File

@ -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) {

View File

@ -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;
}

View File

@ -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'];

View File

@ -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;

View File

@ -91,7 +91,9 @@ trait FilesLogic
* @param int $offset Offset where to start downloading
* @param int $end Offset where to end download
*
* @return \Generator<bool>
* @return \Generator
*
* @psalm-return \Generator<int, \Amp\Promise<\Amp\Ipc\Sync\ChannelledSocket>|\Amp\Promise<mixed>|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<array>
* @return \Generator
*
* @psalm-return \Generator<int|mixed, \Amp\Promise|\Amp\Promise<\Amp\File\File>|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<array>
* @return \Generator
*
* @psalm-return \Generator<int|mixed, \Amp\Promise|\Amp\Promise<\Amp\File\File>|\Amp\Promise<\Amp\Ipc\Sync\ChannelledSocket>|\Amp\Promise<int>|\Amp\Promise<mixed>|\Amp\Promise<null|string>|\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<int|mixed, \Amp\Promise|\Amp\Promise<int>|\Amp\Promise<null|string>|\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
{

View File

@ -51,7 +51,9 @@ class RSA
* @param TL $TL TL serializer
* @param string $rsa_key RSA key
*
* @return \Generator<self>
* @return \Generator
*
* @psalm-return \Generator<mixed, string, mixed, self>
*/
public function load(TL $TL, string $rsa_key): \Generator
{

View File

@ -84,7 +84,7 @@ class BufferedRawStream implements BufferedStreamInterface, BufferInterface, Raw
/**
* Async close.
*
* @return \Generator
* @return void
*/
public function disconnect()
{

View File

@ -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<int, Promise, mixed, Failure<mixed>|Success<object>>
*/
public function getReadBuffer(&$length): Promise
public function getReadBuffer(&$length): \Generator
{
if (!$this->stream) {
return new Failure(new ClosedException("MadelineProto stream was disconnected"));

View File

@ -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 '';

View File

@ -57,6 +57,9 @@ class DefaultStream implements RawStreamInterface, ProxyStreamInterface
{
return $this->stream->setupTls($cancellationToken);
}
/**
* @return EncryptableSocket
*/
public function getStream()
{
return $this->stream;

View File

@ -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();
}

View File

@ -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)) {

View File

@ -665,7 +665,9 @@ abstract class Tools extends StrTools
*
* @internal Generator function
*
* @return \Generator<string>
* @return \Generator
*
* @psalm-return \Generator<int, Promise|Promise<null|string>, 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

View File

@ -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) {