Improved typehints
This commit is contained in:
parent
76c4fe480c
commit
1da9cad6b9
@ -798,7 +798,9 @@ class MTProto extends AsyncConstruct implements TLCallback
|
||||
*
|
||||
* @param string $url URL
|
||||
*
|
||||
* @return \Generator<string>
|
||||
* @return \Generator
|
||||
*
|
||||
* @psalm-return \Generator<int, Promise<string>, mixed, string>
|
||||
*/
|
||||
public function fileGetContents(string $url): \Generator
|
||||
{
|
||||
@ -816,9 +818,9 @@ class MTProto extends AsyncConstruct implements TLCallback
|
||||
/**
|
||||
* Get main DC ID.
|
||||
*
|
||||
* @return int
|
||||
* @return int|string
|
||||
*/
|
||||
public function getDataCenterId(): int
|
||||
public function getDataCenterId()
|
||||
{
|
||||
return $this->datacenter->curdc;
|
||||
}
|
||||
@ -937,9 +939,11 @@ class MTProto extends AsyncConstruct implements TLCallback
|
||||
*
|
||||
* @internal
|
||||
*
|
||||
* @return void
|
||||
* @return \Generator
|
||||
*
|
||||
* @psalm-return \Generator<mixed, mixed, mixed, void>
|
||||
*/
|
||||
private function cleanupProperties()
|
||||
private function cleanupProperties(): \Generator
|
||||
{
|
||||
if (!$this->channels_state instanceof CombinedUpdatesState) {
|
||||
$this->channels_state = new CombinedUpdatesState($this->channels_state);
|
||||
|
@ -60,7 +60,9 @@ trait AuthKeyHandler
|
||||
*
|
||||
* @internal
|
||||
*
|
||||
* @return \Generator<AuthKey>
|
||||
* @return \Generator
|
||||
*
|
||||
* @psalm-return \Generator<mixed, mixed|string, mixed, \danog\MadelineProto\MTProto\PermAuthKey|\danog\MadelineProto\MTProto\TempAuthKey|null>
|
||||
*/
|
||||
public function createAuthKey(int $expires_in, string $datacenter): \Generator
|
||||
{
|
||||
@ -508,7 +510,9 @@ trait AuthKeyHandler
|
||||
*
|
||||
* @internal
|
||||
*
|
||||
* @return \Generator<bool>
|
||||
* @return \Generator
|
||||
*
|
||||
* @psalm-return \Generator<int|mixed, array|mixed, mixed, true>
|
||||
*/
|
||||
public function bindTempAuthKey(int $expires_in, string $datacenter): \Generator
|
||||
{
|
||||
@ -552,7 +556,9 @@ trait AuthKeyHandler
|
||||
*
|
||||
* @param string|integer $what Number to factorize
|
||||
*
|
||||
* @return \Generator<string|bool>
|
||||
* @return \Generator
|
||||
*
|
||||
* @psalm-return \Generator<int, \Amp\Promise<string>, mixed, false|int|string>
|
||||
*/
|
||||
private function wolframSingle($what): \Generator
|
||||
{
|
||||
|
@ -48,6 +48,7 @@ use function Amp\Promise\all;
|
||||
trait Files
|
||||
{
|
||||
use FilesLogic;
|
||||
|
||||
/**
|
||||
* Upload file from URL.
|
||||
*
|
||||
@ -1049,7 +1050,7 @@ trait Files
|
||||
} while (true);
|
||||
}
|
||||
private $cdn_hashes = [];
|
||||
private function addCdnHashes($file, $hashes)
|
||||
private function addCdnHashes($file, $hashes): void
|
||||
{
|
||||
if (!isset($this->cdn_hashes[$file])) {
|
||||
$this->cdn_hashes = [];
|
||||
@ -1075,7 +1076,10 @@ trait Files
|
||||
}
|
||||
return true;
|
||||
}
|
||||
private function clearCdnHashes($file)
|
||||
/**
|
||||
* @return true
|
||||
*/
|
||||
private function clearCdnHashes($file): bool
|
||||
{
|
||||
unset($this->cdn_hashes[$file]);
|
||||
return true;
|
||||
|
@ -137,7 +137,9 @@ trait FilesLogic
|
||||
* @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, ServerRequest $request, callable $cb = null): \Generator
|
||||
{
|
||||
@ -188,7 +190,7 @@ trait FilesLogic
|
||||
*
|
||||
* @return \Generator
|
||||
*
|
||||
* @psalm-return \Generator<int|mixed, \Amp\Promise|\Amp\Promise<\Amp\File\File>|array, mixed, mixed>
|
||||
* @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): \Generator
|
||||
{
|
||||
|
@ -45,7 +45,7 @@ trait PeerHandler
|
||||
*
|
||||
* @param int $id MTProto channel ID
|
||||
*
|
||||
* @return int
|
||||
* @return float|int
|
||||
*/
|
||||
public static function toSupergroup($id)
|
||||
{
|
||||
@ -56,9 +56,9 @@ trait PeerHandler
|
||||
*
|
||||
* @param int $id Bot API channel ID
|
||||
*
|
||||
* @return int
|
||||
* @return float|int
|
||||
*/
|
||||
public static function fromSupergroup($id): int
|
||||
public static function fromSupergroup($id)
|
||||
{
|
||||
return -$id - \pow(10, (int) \floor(\log(-$id, 10)));
|
||||
}
|
||||
@ -149,7 +149,9 @@ trait PeerHandler
|
||||
*
|
||||
* @internal
|
||||
*
|
||||
* @return \Generator<void>
|
||||
* @return \Generator
|
||||
*
|
||||
* @psalm-return \Generator<int, \Amp\Promise|null, mixed, void>
|
||||
*/
|
||||
public function addChat($chat): \Generator
|
||||
{
|
||||
@ -209,14 +211,14 @@ trait PeerHandler
|
||||
}
|
||||
}
|
||||
|
||||
private function cacheChatUsername(int $id, array $chat)
|
||||
private function cacheChatUsername(int $id, array $chat): void
|
||||
{
|
||||
if ($id && !empty($chat['username'])) {
|
||||
$this->usernames[\strtolower($chat['username'])] = $id;
|
||||
}
|
||||
}
|
||||
|
||||
private function cachePwrChat($id, $full_fetch, $send)
|
||||
private function cachePwrChat($id, $full_fetch, $send): void
|
||||
{
|
||||
\danog\MadelineProto\Tools::callFork((function () use ($id, $full_fetch, $send): \Generator {
|
||||
try {
|
||||
@ -233,7 +235,9 @@ trait PeerHandler
|
||||
*
|
||||
* @param mixed $id Peer
|
||||
*
|
||||
* @return \Generator<boolean>
|
||||
* @return \Generator
|
||||
*
|
||||
* @psalm-return \Generator<int|mixed, \Amp\Promise|array, mixed, bool>
|
||||
*/
|
||||
public function peerIsset($id): \Generator
|
||||
{
|
||||
@ -469,7 +473,9 @@ trait PeerHandler
|
||||
*
|
||||
* @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): \Generator
|
||||
{
|
||||
@ -627,7 +633,12 @@ trait PeerHandler
|
||||
}
|
||||
throw new \danog\MadelineProto\Exception('This peer is not present in the internal peer database');
|
||||
}
|
||||
private function genAll($constructor, $folder_id = null)
|
||||
/**
|
||||
* @return (((mixed|string)[]|mixed|string)[]|int|mixed|string)[]
|
||||
*
|
||||
* @psalm-return array{InputPeer: array{_: string, user_id?: mixed, access_hash?: mixed, min?: mixed, chat_id?: mixed, channel_id?: mixed}, Peer: array{_: string, user_id?: mixed, chat_id?: mixed, channel_id?: mixed}, DialogPeer: array{_: string, peer: array{_: string, user_id?: mixed, chat_id?: mixed, channel_id?: mixed}}, NotifyPeer: array{_: string, peer: array{_: string, user_id?: mixed, chat_id?: mixed, channel_id?: mixed}}, InputDialogPeer: array{_: string, peer: array{_: string, user_id?: mixed, access_hash?: mixed, min?: mixed, chat_id?: mixed, channel_id?: mixed}}, InputNotifyPeer: array{_: string, peer: array{_: string, user_id?: mixed, access_hash?: mixed, min?: mixed, chat_id?: mixed, channel_id?: mixed}}, bot_api_id: int|mixed, type: string}
|
||||
*/
|
||||
private function genAll($constructor, $folder_id = null): array
|
||||
{
|
||||
$res = [$this->TL->getConstructors()->findByPredicate($constructor['_'])['type'] => $constructor];
|
||||
switch ($constructor['_']) {
|
||||
@ -706,7 +717,9 @@ trait PeerHandler
|
||||
*
|
||||
* @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): \Generator
|
||||
{
|
||||
@ -714,6 +727,7 @@ trait PeerHandler
|
||||
if (\time() - (yield from $this->fullChatLastUpdated($partial['bot_api_id'])) < $this->getSettings()->getPeer()->getFullInfoCacheTime()) {
|
||||
return \array_merge($partial, yield $this->full_chats[$partial['bot_api_id']]);
|
||||
}
|
||||
$full = null;
|
||||
switch ($partial['type']) {
|
||||
case 'user':
|
||||
case 'bot':
|
||||
@ -992,7 +1006,7 @@ trait PeerHandler
|
||||
}
|
||||
return $has_more;
|
||||
}
|
||||
private function fetchParticipantsCache($channel, $filter, $q, $offset, $limit)
|
||||
private function fetchParticipantsCache($channel, $filter, $q, $offset, $limit): \Generator
|
||||
{
|
||||
return (yield $this->channel_participants[$channel['channel_id']])[$filter][$q][$offset][$limit];
|
||||
}
|
||||
|
@ -55,7 +55,9 @@ trait UpdateHandler
|
||||
*
|
||||
* @internal
|
||||
*
|
||||
* @return \Generator<array>
|
||||
* @return \Generator
|
||||
*
|
||||
* @psalm-return \Generator<int, \Amp\Promise<mixed|null>, mixed, list<array{update_id: mixed, update: mixed}>|mixed>
|
||||
*/
|
||||
public function getUpdates($params = []): \Generator
|
||||
{
|
||||
@ -152,7 +154,7 @@ trait UpdateHandler
|
||||
*
|
||||
* @internal
|
||||
*
|
||||
* @return UpdatesState|UpdatesState[]
|
||||
* @return \Generator
|
||||
*/
|
||||
public function loadUpdateState(): \Generator
|
||||
{
|
||||
|
@ -53,7 +53,7 @@ class RSA
|
||||
*
|
||||
* @return \Generator
|
||||
*
|
||||
* @psalm-return \Generator<mixed, string, mixed, self>
|
||||
* @psalm-return \Generator<int|mixed, array|mixed, mixed, self>
|
||||
*/
|
||||
public function load(TL $TL, string $rsa_key): \Generator
|
||||
{
|
||||
|
@ -125,6 +125,9 @@ trait MessageHandler
|
||||
$this->secret_chats[$message['message']['chat_id']]['incoming'][$this->secret_chats[$message['message']['chat_id']]['in_seq_no']] = $message['message'];
|
||||
yield from $this->handleDecryptedUpdate($message);
|
||||
}
|
||||
/**
|
||||
* @return false|string
|
||||
*/
|
||||
private function tryMTProtoV1Decrypt($message_key, $chat_id, $old, $encrypted_data)
|
||||
{
|
||||
list($aes_key, $aes_iv) = Crypt::oldAesCalculate($message_key, $this->secret_chats[$chat_id][$old ? 'old_key' : 'key']['auth_key'], true);
|
||||
@ -145,6 +148,9 @@ trait MessageHandler
|
||||
}
|
||||
return $message_data;
|
||||
}
|
||||
/**
|
||||
* @return false|string
|
||||
*/
|
||||
private function tryMTProtoV2Decrypt($message_key, $chat_id, $old, $encrypted_data)
|
||||
{
|
||||
list($aes_key, $aes_iv) = Crypt::aesCalculate($message_key, $this->secret_chats[$chat_id][$old ? 'old_key' : 'key']['auth_key'], !$this->secret_chats[$chat_id]['admin']);
|
||||
|
@ -36,9 +36,9 @@ trait BotAPI
|
||||
*
|
||||
* @param string $text Text
|
||||
*
|
||||
* @return int
|
||||
* @return float|int
|
||||
*/
|
||||
public static function mbStrlen(string $text): int
|
||||
public static function mbStrlen(string $text)
|
||||
{
|
||||
$length = 0;
|
||||
$textlength = \strlen($text);
|
||||
@ -107,7 +107,12 @@ trait BotAPI
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
private function parseButtons($rows)
|
||||
/**
|
||||
* @return ((bool|mixed|string)[][]|string)[][]
|
||||
*
|
||||
* @psalm-return array<int|int, array{_: string, buttons: array<int|int, array{_: string, text: mixed, same_peer?: bool, query?: mixed, data?: mixed, url?: mixed}>}>
|
||||
*/
|
||||
private function parseButtons($rows): array
|
||||
{
|
||||
$newrows = [];
|
||||
$key = 0;
|
||||
@ -190,6 +195,7 @@ trait BotAPI
|
||||
}
|
||||
return $newd;
|
||||
}
|
||||
$res = null;
|
||||
switch ($data['_']) {
|
||||
case 'updateShortSentMessage':
|
||||
$newd['message_id'] = $data['id'];
|
||||
@ -679,7 +685,12 @@ trait BotAPI
|
||||
}
|
||||
return $multiple_args;
|
||||
}
|
||||
private function multipleExplodeKeepDelimiters($delimiters, $string)
|
||||
/**
|
||||
* @return string[]
|
||||
*
|
||||
* @psalm-return list<string>
|
||||
*/
|
||||
private function multipleExplodeKeepDelimiters($delimiters, $string): array
|
||||
{
|
||||
$initialArray = \explode(\chr(1), \str_replace($delimiters, \chr(1), $string));
|
||||
$finalArray = [];
|
||||
@ -693,7 +704,7 @@ trait BotAPI
|
||||
}
|
||||
return $finalArray;
|
||||
}
|
||||
private function htmlFixtags($text)
|
||||
private function htmlFixtags($text): string
|
||||
{
|
||||
$diff = 0;
|
||||
\preg_match_all('#(.*?)(<(\\bu\\b|\\bs\\b|\\ba\\b|\\bb\\b|\\bstrong\\b|\\bblockquote\\b|\\bstrike\\b|\\bdel\\b|\\bem\\b|i|\\bcode\\b|\\bpre\\b)[^>]*>)(.*?)([<]\\s*/\\s*\\3[>])#is', $text, $matches, PREG_SET_ORDER | PREG_OFFSET_CAPTURE);
|
||||
@ -728,7 +739,12 @@ trait BotAPI
|
||||
}
|
||||
return \htmlentities($text);
|
||||
}
|
||||
private function buildRows($button_list)
|
||||
/**
|
||||
* @return ((array|string)[][]|string)[]
|
||||
*
|
||||
* @psalm-return array{_: string, rows: list<array{_: string, buttons: list<mixed>}>}
|
||||
*/
|
||||
private function buildRows($button_list): array
|
||||
{
|
||||
$end = false;
|
||||
$rows = [];
|
||||
|
@ -90,6 +90,7 @@ trait BotAPIFiles
|
||||
|
||||
$photoSize = $fileId->hasPhotoSizeSource() ? $fileId->getPhotoSizeSource() : null;
|
||||
|
||||
$res = null;
|
||||
switch ($fileId->getType()) {
|
||||
case PROFILE_PHOTO:
|
||||
/**
|
||||
|
@ -401,7 +401,9 @@ class TL
|
||||
* @param string $ctx Context
|
||||
* @param integer $layer Layer version
|
||||
*
|
||||
* @return \Generator<string>
|
||||
* @return \Generator
|
||||
*
|
||||
* @psalm-return \Generator<int|mixed, array|mixed, mixed, false|mixed|null|string>
|
||||
*/
|
||||
public function serializeObject(array $type, $object, $ctx, int $layer = -1): \Generator
|
||||
{
|
||||
@ -581,7 +583,9 @@ class TL
|
||||
* @param string $method Method name
|
||||
* @param mixed $arguments Arguments
|
||||
*
|
||||
* @return \Generator<string>
|
||||
* @return \Generator
|
||||
*
|
||||
* @psalm-return \Generator<int|mixed, Promise|Promise<\Amp\File\File>|Promise<\Amp\Ipc\Sync\ChannelledSocket>|Promise<int>|Promise<mixed>|Promise<null|string>|Promise<string>|\danog\MadelineProto\Stream\StreamInterface|array|int|mixed, mixed, string>
|
||||
*/
|
||||
public function serializeMethod(string $method, $arguments): \Generator
|
||||
{
|
||||
@ -662,7 +666,9 @@ class TL
|
||||
* @param string $ctx Context
|
||||
* @param integer $layer Layer
|
||||
*
|
||||
* @return \Generator<string>
|
||||
* @return \Generator
|
||||
*
|
||||
* @psalm-return \Generator<int|mixed, Promise|Promise<\Amp\File\File>|Promise<\Amp\Ipc\Sync\ChannelledSocket>|Promise<int>|Promise<mixed>|Promise<null|string>|\danog\MadelineProto\Stream\StreamInterface|array|int|mixed, mixed, string>
|
||||
*/
|
||||
private function serializeParams(array $tl, $arguments, $ctx, int $layer = -1): \Generator
|
||||
{
|
||||
|
@ -86,7 +86,7 @@ trait AuthKeyHandler
|
||||
*
|
||||
* @param mixed $user User
|
||||
*
|
||||
* @return void
|
||||
* @return \Generator
|
||||
*/
|
||||
public function requestCall($user): \Generator
|
||||
{
|
||||
@ -276,7 +276,7 @@ trait AuthKeyHandler
|
||||
* Discard call.
|
||||
*
|
||||
* @param array $call Call
|
||||
* @param string $reason Discard reason
|
||||
* @param array $reason
|
||||
* @param array $rating Rating
|
||||
* @param boolean $need_debug Need debug?
|
||||
*
|
||||
|
@ -33,7 +33,9 @@ trait DialogHandler
|
||||
*
|
||||
* @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): \Generator
|
||||
{
|
||||
|
@ -202,7 +202,9 @@ trait Login
|
||||
/**
|
||||
* Export authorization.
|
||||
*
|
||||
* @return \Generator<array>
|
||||
* @return \Generator
|
||||
*
|
||||
* @psalm-return \Generator<mixed, array|bool, mixed, array{0: int|string, 1: string}>
|
||||
*/
|
||||
public function exportAuthorization(): \Generator
|
||||
{
|
||||
|
@ -94,7 +94,7 @@ trait Loop
|
||||
*
|
||||
* @param callable|null $callback Async callable to run
|
||||
*
|
||||
* @return mixed
|
||||
* @return \Generator
|
||||
*/
|
||||
public function loop($callback = null): \Generator
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user