Manual psalm fixes

This commit is contained in:
Daniil Gentili 2020-10-02 16:13:19 +02:00
parent 1da9cad6b9
commit 76ca2b19ab
Signed by: danog
GPG Key ID: 8C1BE3B34B230CA7
13 changed files with 114 additions and 58 deletions

View File

@ -477,9 +477,9 @@ class Connection extends Session
/**
* Get main instance.
*
* @return MTProtoSession\MTProto
* @return MTProto
*/
public function getExtra(): MTProtoSession\MTProto
public function getExtra(): MTProto
{
return $this->API;
}

View File

@ -34,7 +34,7 @@ use danog\MadelineProto\Stream\Transport\WssStream;
use JsonSerializable;
/**
* Datacenter connection
* Datacenter connection.
*/
class DataCenterConnection implements JsonSerializable
{

View File

@ -31,7 +31,7 @@ abstract class DriverArray implements DbArray
throw new \RuntimeException('Native isset not support promises. Use isset method');
}
abstract public function initConnection($settings): \Generator;
abstract public function initConnection(\danog\MadelineProto\Settings\Database\DatabaseAbstract $settings): \Generator;
abstract public function initStartup(): \Generator;
/**

View File

@ -4781,7 +4781,7 @@ class InternalDoc extends APIFactory
* Discard call.
*
* @param array $call Call
* @param string $reason Discard reason
* @param array $reason
* @param array $rating Rating
* @param boolean $need_debug Need debug?
*
@ -4831,7 +4831,9 @@ class InternalDoc extends APIFactory
* @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|mixed, \Amp\Promise|array, mixed, true>
*/
public function downloadToCallable($messageMedia, callable $callable, $cb = null, bool $seekable = true, int $offset = 0, int $end = -1, ?int $part_size = null, array $extra = [])
{
@ -4844,7 +4846,9 @@ class InternalDoc extends APIFactory
* @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
*
* @psalm-return \Generator<int|mixed, \Amp\Promise|\Amp\Promise<\Amp\File\File>|\Amp\Promise<\Amp\Ipc\Sync\ChannelledSocket>|\Amp\Promise<callable|null>|\Amp\Promise<mixed>|array|bool|mixed, mixed, false|string>
*/
public function downloadToDir($messageMedia, $dir, $cb = null, array $extra = [])
{
@ -4857,7 +4861,9 @@ class InternalDoc extends APIFactory
* @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|mixed, \Amp\Promise|\Amp\Promise<\Amp\File\File>|\Amp\Promise<\Amp\Ipc\Sync\ChannelledSocket>|\Amp\Promise<callable|null>|\Amp\Promise<mixed>|array|bool|mixed, mixed, false|string>
*/
public function downloadToFile($messageMedia, $file, $cb = null, array $extra = [])
{
@ -4872,7 +4878,9 @@ class InternalDoc extends APIFactory
* @param ServerRequest $request Request
* @param callable $cb Status callback (can also use FileCallback)
*
* @return \Generator<Response> Returned response
* @return \Generator Returned response
*
* @psalm-return \Generator<mixed, array, mixed, \Amp\Http\Server\Response>
*/
public function downloadToResponse($messageMedia, \Amp\Http\Server\Request $request, ?callable $cb = null, array $extra = [])
{
@ -4887,7 +4895,9 @@ class InternalDoc extends APIFactory
* @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, array $extra = [])
{
@ -4918,7 +4928,9 @@ class InternalDoc extends APIFactory
/**
* Export authorization.
*
* @return \Generator<array>
* @return \Generator
*
* @psalm-return \Generator<mixed, array|bool, mixed, array{0: int|string, 1: string}>
*/
public function exportAuthorization(array $extra = [])
{
@ -4940,7 +4952,9 @@ class InternalDoc extends APIFactory
*
* @param string $url URL
*
* @return \Generator<string>
* @return \Generator
*
* @psalm-return \Generator<int, Promise<string>, mixed, string>
*/
public function fileGetContents(string $url, array $extra = [])
{
@ -4978,11 +4992,11 @@ class InternalDoc extends APIFactory
*
* @param int $id Bot API channel ID
*
* @return int
* @return float|int
*/
public function fromSupergroup($id): int
public function fromSupergroup($id)
{
return \danog\MadelineProto\MTProto::fromSupergroup($id);
return $this->__call(__FUNCTION__, [$id]);
}
/**
* When were full info for this chat last cached.
@ -5099,18 +5113,20 @@ class InternalDoc extends APIFactory
/**
* Get main DC ID.
*
* @return int
* @return int|string
*/
public function getDataCenterId(): int
public function getDataCenterId(array $extra = [])
{
return $this->API->getDataCenterId();
return $this->__call(__FUNCTION__, [$extra]);
}
/**
* Get dialog peers.
*
* @param boolean $force Whether to refetch all dialogs ignoring cache
*
* @return \Generator<array<array>>
* @return \Generator
*
* @psalm-return \Generator<int, \Amp\Promise<bool>, mixed, list<mixed>>
*/
public function getDialogs(bool $force = true, array $extra = [])
{
@ -5205,7 +5221,9 @@ class InternalDoc extends APIFactory
*
* @see https://docs.madelineproto.xyz/FullInfo.html
*
* @return \Generator<array> FullInfo object
* @return \Generator FullInfo object
*
* @psalm-return \Generator<int|mixed, \Amp\Promise|array, mixed, array>
*/
public function getFullInfo($id, array $extra = [])
{
@ -5239,7 +5257,9 @@ class InternalDoc extends APIFactory
*
* @see https://docs.madelineproto.xyz/Info.html
*
* @return \Generator<array> Info object
* @return \Generator Info object
*
* @psalm-return \Generator<int|mixed, \Amp\Promise|\Amp\Promise<string>|array, mixed, array|mixed>
*/
public function getInfo($id, $recursive = true, array $extra = [])
{
@ -5570,7 +5590,7 @@ class InternalDoc extends APIFactory
*
* @param callable|null $callback Async callable to run
*
* @return mixed
* @return \Generator
*/
public function loop($callback = null, array $extra = [])
{
@ -5613,11 +5633,11 @@ class InternalDoc extends APIFactory
*
* @param string $text Text
*
* @return int
* @return float|int
*/
public function mbStrlen(string $text): int
public function mbStrlen(string $text)
{
return \danog\MadelineProto\MTProto::mbStrlen($text);
return $this->__call(__FUNCTION__, [$text]);
}
/**
* Telegram UTF-8 multibyte substring.
@ -5726,7 +5746,9 @@ class InternalDoc extends APIFactory
*
* @param mixed $id Peer
*
* @return \Generator<boolean>
* @return \Generator
*
* @psalm-return \Generator<int|mixed, \Amp\Promise|array, mixed, bool>
*/
public function peerIsset($id, array $extra = [])
{
@ -5818,7 +5840,7 @@ class InternalDoc extends APIFactory
*
* @param mixed $user User
*
* @return void
* @return \Generator
*/
public function requestCall($user, array $extra = [])
{
@ -5973,7 +5995,8 @@ class InternalDoc extends APIFactory
*
* @psalm-suppress InvalidScope
*
* @return mixed
* @return void
*
* @access public
*/
public function setVar($obj, string $var, &$val): void
@ -6154,7 +6177,7 @@ class InternalDoc extends APIFactory
*
* @param int $id MTProto channel ID
*
* @return int
* @return float|int
*/
public function toSupergroup($id)
{
@ -6269,7 +6292,9 @@ class InternalDoc extends APIFactory
* @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, array $extra = [])
{
@ -6282,7 +6307,9 @@ class InternalDoc extends APIFactory
* @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>|\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 uploadEncrypted($file, string $fileName = '', $cb = null, array $extra = [])
{
@ -6302,7 +6329,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<array>
* @return \Generator
*
* @psalm-return \Generator<int, \Amp\Promise|\Amp\Promise<array>, mixed, array{_: string, id: string, parts: int, name: string, mime_type: string, key_fingerprint?: mixed, key?: mixed, iv?: mixed, md5_checksum: string}>
*/
public function uploadFromCallable(callable $callable, int $size, string $mime, string $fileName = '', $cb = null, bool $seekable = true, bool $encrypted = false, array $extra = [])
{
@ -6318,7 +6347,9 @@ class InternalDoc extends APIFactory
* @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, array $extra = [])
{
@ -6331,7 +6362,9 @@ class InternalDoc extends APIFactory
* @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|array, mixed, mixed>
*/
public function uploadFromTgfile($media, $cb = null, bool $encrypted = false, array $extra = [])
{
@ -6346,7 +6379,9 @@ class InternalDoc extends APIFactory
* @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<\Amp\Http\Client\Response>|\Amp\Promise<int>|\Amp\Promise<null|string>|\danog\MadelineProto\Stream\StreamInterface|array|int|mixed, mixed, mixed>
*/
public function uploadFromUrl($url, int $size = 0, string $fileName = '', $cb = null, bool $encrypted = false, array $extra = [])
{

View File

@ -108,7 +108,7 @@ class FeedLoop extends ResumableSignalLoop
}
}
}
public function parse($updates): \Generator
public function parse(array $updates): \Generator
{
\reset($updates);
while ($updates) {

View File

@ -82,7 +82,7 @@ class SeqLoop extends ResumableSignalLoop
}
}
}
public function parse($updates): \Generator
public function parse(array $updates): \Generator
{
\reset($updates);
while ($updates) {

View File

@ -403,12 +403,6 @@ class MTProto extends AsyncConstruct implements TLCallback
* @var array<\danog\MadelineProto\Loop\Update\UpdateLoop>
*/
public $updaters = [];
/**
* Boolean to avoid problems with exceptions thrown by forked strands, see tools.
*
* @var boolean
*/
public bool $destructing = false;
/**
* DataCenter instance.
*

View File

@ -20,7 +20,6 @@
namespace danog\MadelineProto\MTProtoSession;
use Amp\Deferred;
use Amp\Promise;
use danog\MadelineProto\Async\AsyncParameters;
use danog\MadelineProto\TL\Exception;
use danog\MadelineProto\Tools;

View File

@ -22,7 +22,6 @@ namespace danog\MadelineProto\MTProtoTools;
use Amp\Http\Client\Request;
use danog\MadelineProto\DataCenterConnection;
use danog\MadelineProto\MTProto;
use danog\MadelineProto\MTProto\AuthKey;
use danog\MadelineProto\MTProto\PermAuthKey;
use danog\MadelineProto\MTProto\TempAuthKey;
use danog\MadelineProto\Settings;

View File

@ -48,7 +48,6 @@ use function Amp\Promise\all;
trait Files
{
use FilesLogic;
/**
* Upload file from URL.
*
@ -58,7 +57,9 @@ trait Files
* @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<\Amp\Http\Client\Response>|\Amp\Promise<int>|\Amp\Promise<null|string>|\danog\MadelineProto\Stream\StreamInterface|array|int|mixed, mixed, mixed>
*/
public function uploadFromUrl($url, int $size = 0, string $fileName = '', $cb = null, bool $encrypted = false): \Generator
{
@ -106,7 +107,9 @@ trait Files
* @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, \Amp\Promise|\Amp\Promise<array>, mixed, array{_: string, id: string, parts: int, name: string, mime_type: string, key_fingerprint?: mixed, key?: mixed, iv?: mixed, md5_checksum: string}>
*/
public function uploadFromCallable(callable $callable, int $size, string $mime, string $fileName = '', $cb = null, bool $seekable = true, bool $encrypted = false): \Generator
{
@ -134,6 +137,9 @@ trait Files
$constructor = 'input'.($encrypted === true ? 'Encrypted' : '').($size > 10 * 1024 * 1024 ? 'FileBig' : 'File').($encrypted === true ? 'Uploaded' : '');
$file_id = Tools::random(8);
$ige = null;
$fingerprint = null;
$iv = null;
$key = null;
if ($encrypted === true) {
$key = Tools::random(32);
$iv = Tools::random(32);
@ -227,7 +233,9 @@ trait Files
* @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|array, mixed, mixed>
*/
public function uploadFromTgfile($media, $cb = null, bool $encrypted = false): \Generator
{
@ -756,7 +764,9 @@ trait Files
* @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
*
* @psalm-return \Generator<int|mixed, \Amp\Promise|\Amp\Promise<\Amp\File\File>|\Amp\Promise<\Amp\Ipc\Sync\ChannelledSocket>|\Amp\Promise<callable|null>|\Amp\Promise<mixed>|array|bool|mixed, mixed, false|string>
*/
public function downloadToDir($messageMedia, $dir, $cb = null): \Generator
{
@ -774,7 +784,9 @@ trait Files
* @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|mixed, \Amp\Promise|\Amp\Promise<\Amp\File\File>|\Amp\Promise<\Amp\Ipc\Sync\ChannelledSocket>|\Amp\Promise<callable|null>|\Amp\Promise<mixed>|array|bool|mixed, mixed, false|string>
*/
public function downloadToFile($messageMedia, $file, $cb = null): \Generator
{
@ -817,7 +829,9 @@ trait Files
* @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|mixed, \Amp\Promise|array, mixed, true>
*/
public function downloadToCallable($messageMedia, callable $callable, $cb = null, bool $seekable = true, int $offset = 0, int $end = -1, int $part_size = null): \Generator
{

View File

@ -23,6 +23,7 @@ use Amp\Deferred;
use Amp\Loop;
use Amp\Promise;
use danog\MadelineProto\Db\DriverArray;
use danog\MadelineProto\Ipc\Client;
use danog\MadelineProto\Ipc\Server;
use danog\MadelineProto\MTProtoSession\Session;
@ -102,6 +103,8 @@ abstract class Serialization
* @internal
*
* @return \Generator
*
* @psalm-return \Generator<void, mixed, mixed, array{0: callable|null, 1: Client|MTProto}>
*/
public static function unserialize(SessionPaths $session, bool $forceFull = false): \Generator
{

View File

@ -1366,7 +1366,8 @@ class InternalDoc extends APIFactory
*
* @psalm-suppress InvalidScope
*
* @return mixed
* @return void
*
* @access public
*/
public function setVar($obj, string $var, &$val): void

View File

@ -46,6 +46,12 @@ use function Amp\Promise\wait;
*/
abstract class Tools extends StrTools
{
/**
* Boolean to avoid problems with exceptions thrown by forked strands, see tools.
*
* @var boolean
*/
public bool $destructing = false;
/**
* Sanify TL obtained from JSON for TL serialization.
*
@ -412,15 +418,20 @@ abstract class Tools extends StrTools
*
* If the timeout expires before the promise is resolved, a default value is returned
*
* @template TReturnAlt
* @template TReturn
* @template TGenerator as Generator<mixed, mixed, mixed, TReturn>
*
* @param Promise<TReturn>|\Generator $promise Promise to which the timeout is applied.
* @param int $timeout Timeout in milliseconds.
* @param TReturn $default
* @param mixed $default
*
* @return Promise<TReturn>
* @psalm-param Promise<TReturn>|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<TReturn|TReturnAlt>
*
* @throws \TypeError If $promise is not an instance of \Amp\Promise, \Generator or \React\Promise\PromiseInterface.
*/
public static function timeoutWithDefault($promise, int $timeout, $default = null): Promise
{
@ -547,7 +558,7 @@ abstract class Tools extends StrTools
*/
public static function after($a, $b): Promise
{
$a = self::call($a());
$a = self::call($a);
$deferred = new Deferred();
$a->onResolve(static function ($e, $res) use ($b, $deferred) {
if ($e) {
@ -558,7 +569,7 @@ abstract class Tools extends StrTools
}
return;
}
$b = self::call($b());
$b = self::call($b);
$b->onResolve(function ($e, $res) use ($deferred) {
if ($e) {
if (isset($this)) {