Strictly typed API

This commit is contained in:
Daniil Gentili 2019-12-28 17:11:08 +01:00
parent a83c40b762
commit 2850c5acfa
Signed by: danog
GPG Key ID: 8C1BE3B34B230CA7
9 changed files with 52 additions and 61 deletions

2
docs

@ -1 +1 @@
Subproject commit 1979018e600cdc12750fcc751661090e64a2b695 Subproject commit 757d12fbdda97d22a20d565be8e0aea64ed34cad

View File

@ -223,6 +223,8 @@ class AnnotationsBuilder
} }
$doc .= $type->getName(); $doc .= $type->getName();
$doc .= ' '; $doc .= ' ';
} else {
Logger::log($name.'.'.$param->getName()." has no type!", Logger::WARNING);
} }
if ($param->isVariadic()) { if ($param->isVariadic()) {
$doc .= '...'; $doc .= '...';

View File

@ -4291,17 +4291,6 @@ class InternalDoc extends APIFactory
{ {
return $this->__call(__FUNCTION__, [$expires_in, $datacenter, $extra]); return $this->__call(__FUNCTION__, [$expires_in, $datacenter, $extra]);
} }
/**
* Factorize number asynchronously using the wolfram API.
*
* @param string|integer $what Number to factorize
*
* @return \Generator<string|bool>
*/
public function wolframSingle($what, array $extra = [])
{
return $this->__call(__FUNCTION__, [$what, $extra]);
}
/** /**
* Asynchronously create, bind and check auth keys for all DCs. * Asynchronously create, bind and check auth keys for all DCs.
* *
@ -4794,11 +4783,11 @@ class InternalDoc extends APIFactory
/** /**
* Rekey secret chat. * Rekey secret chat.
* *
* @param mixed $chat Secret chat to rekey * @param int $chat Secret chat to rekey
* *
* @return \Generator * @return \Generator
*/ */
public function rekey($chat, array $extra = []) public function rekey(int $chat, array $extra = [])
{ {
return $this->__call(__FUNCTION__, [$chat, $extra]); return $this->__call(__FUNCTION__, [$chat, $extra]);
} }
@ -4838,11 +4827,11 @@ class InternalDoc extends APIFactory
/** /**
* Discard secret chat. * Discard secret chat.
* *
* @param array|int $chat Secret chat ID * @param int $chat Secret chat ID
* *
* @return \Generator * @return \Generator
*/ */
public function discardSecretChat($chat, array $extra = []) public function discardSecretChat(int $chat, array $extra = [])
{ {
return $this->__call(__FUNCTION__, [$chat, $extra]); return $this->__call(__FUNCTION__, [$chat, $extra]);
} }
@ -5059,7 +5048,7 @@ class InternalDoc extends APIFactory
* *
* @return int * @return int
*/ */
public function randomInt($modulus = false): int public function randomInt(int $modulus = 0): int
{ {
return \danog\MadelineProto\MTProto::randomInt($modulus); return \danog\MadelineProto\MTProto::randomInt($modulus);
} }
@ -5094,7 +5083,7 @@ class InternalDoc extends APIFactory
* *
* @return integer * @return integer
*/ */
public function unpackSignedInt($value): int public function unpackSignedInt(string $value): int
{ {
return \danog\MadelineProto\MTProto::unpackSignedInt($value); return \danog\MadelineProto\MTProto::unpackSignedInt($value);
} }
@ -5105,7 +5094,7 @@ class InternalDoc extends APIFactory
* *
* @return integer * @return integer
*/ */
public function unpackSignedLong($value): int public function unpackSignedLong(string $value): int
{ {
return \danog\MadelineProto\MTProto::unpackSignedLong($value); return \danog\MadelineProto\MTProto::unpackSignedLong($value);
} }
@ -5505,8 +5494,8 @@ class InternalDoc extends APIFactory
* *
* @return \Generator * @return \Generator
*/ */
public function discardCall($call, $reason, $rating = [ public function discardCall(array $call, string $reason, array $rating = [
], $need_debug = true, array $extra = []) ], bool $need_debug = true, array $extra = [])
{ {
return $this->__call(__FUNCTION__, [$call, $reason, $rating, $need_debug, $extra]); return $this->__call(__FUNCTION__, [$call, $reason, $rating, $need_debug, $extra]);
} }
@ -5528,7 +5517,7 @@ class InternalDoc extends APIFactory
* *
* @return \Generator * @return \Generator
*/ */
public function acceptCall($call, array $extra = []) public function acceptCall(array $call, array $extra = [])
{ {
return $this->__call(__FUNCTION__, [$call, $extra]); return $this->__call(__FUNCTION__, [$call, $extra]);
} }
@ -5539,7 +5528,7 @@ class InternalDoc extends APIFactory
* *
* @return \Generator * @return \Generator
*/ */
public function confirmCall($params, array $extra = []) public function confirmCall(array $params, array $extra = [])
{ {
return $this->__call(__FUNCTION__, [$params, $extra]); return $this->__call(__FUNCTION__, [$params, $extra]);
} }
@ -5550,29 +5539,29 @@ class InternalDoc extends APIFactory
* *
* @return \Generator * @return \Generator
*/ */
public function completeCall($params, array $extra = []) public function completeCall(array $params, array $extra = [])
{ {
return $this->__call(__FUNCTION__, [$params, $extra]); return $this->__call(__FUNCTION__, [$params, $extra]);
} }
/** /**
* Get call status. * Get call status.
* *
* @param array $id Call ID * @param int $id Call ID
* *
* @return integer * @return integer
*/ */
public function callStatus($id, array $extra = []): int public function callStatus(int $id, array $extra = []): int
{ {
return $this->__call(__FUNCTION__, [$id, $extra]); return $this->__call(__FUNCTION__, [$id, $extra]);
} }
/** /**
* Get call info. * Get call info.
* *
* @param mixed $call Call ID * @param int $call Call ID
* *
* @return array * @return array
*/ */
public function getCall($call, array $extra = []): array public function getCall(int $call, array $extra = []): array
{ {
return $this->__call(__FUNCTION__, [$call, $extra]); return $this->__call(__FUNCTION__, [$call, $extra]);
} }
@ -5592,7 +5581,7 @@ class InternalDoc extends APIFactory
* *
* @return \Generator<array<Peer>> * @return \Generator<array<Peer>>
*/ */
public function getDialogs($force = true, array $extra = []) public function getDialogs(bool $force = true, array $extra = [])
{ {
return $this->__call(__FUNCTION__, [$force, $extra]); return $this->__call(__FUNCTION__, [$force, $extra]);
} }
@ -5603,7 +5592,7 @@ class InternalDoc extends APIFactory
* *
* @return \Generator * @return \Generator
*/ */
public function getFullDialogs($force = true, array $extra = []) public function getFullDialogs(bool $force = true, array $extra = [])
{ {
return $this->__call(__FUNCTION__, [$force, $extra]); return $this->__call(__FUNCTION__, [$force, $extra]);
} }
@ -5635,7 +5624,7 @@ class InternalDoc extends APIFactory
* *
* @return void * @return void
*/ */
public function setWebhook($hook_url, $pem_path = null, array $extra = []): void public function setWebhook(string $hook_url, string $pem_path = '', array $extra = []): void
{ {
$this->__call(__FUNCTION__, [$hook_url, $pem_path, $extra]); $this->__call(__FUNCTION__, [$hook_url, $pem_path, $extra]);
} }

View File

@ -589,7 +589,7 @@ trait AuthKeyHandler
* *
* @return \Generator<string|bool> * @return \Generator<string|bool>
*/ */
public function wolframSingle($what): \Generator private function wolframSingle($what): \Generator
{ {
$code = yield $this->datacenter->fileGetContents('http://www.wolframalpha.com/api/v1/code'); $code = yield $this->datacenter->fileGetContents('http://www.wolframalpha.com/api/v1/code');
$query = 'Do prime factorization of '.$what; $query = 'Do prime factorization of '.$what;

View File

@ -111,7 +111,7 @@ trait AuthKeyHandler
* *
* @return \Generator * @return \Generator
*/ */
private function completeSecretChat($params): \Generator private function completeSecretChat(array $params): \Generator
{ {
if ($this->secretChatStatus($params['id']) !== 1) { if ($this->secretChatStatus($params['id']) !== 1) {
//$this->logger->logger($this->secretChatStatus($params['id'])); //$this->logger->logger($this->secretChatStatus($params['id']));
@ -153,11 +153,11 @@ trait AuthKeyHandler
/** /**
* Rekey secret chat. * Rekey secret chat.
* *
* @param mixed $chat Secret chat to rekey * @param int $chat Secret chat to rekey
* *
* @return \Generator * @return \Generator
*/ */
public function rekey($chat): \Generator public function rekey(int $chat): \Generator
{ {
if ($this->secret_chats[$chat]['rekeying'][0] !== 0) { if ($this->secret_chats[$chat]['rekeying'][0] !== 0) {
return; return;
@ -181,12 +181,12 @@ trait AuthKeyHandler
/** /**
* Accept rekeying. * Accept rekeying.
* *
* @param mixed $chat Chat * @param int $chat Chat
* @param array $params Parameters * @param array $params Parameters
* *
* @return \Generator * @return \Generator
*/ */
private function acceptRekey($chat, array $params): \Generator private function acceptRekey(int $chat, array $params): \Generator
{ {
if ($this->secret_chats[$chat]['rekeying'][0] !== 0) { if ($this->secret_chats[$chat]['rekeying'][0] !== 0) {
$my_exchange_id = new \tgseclib\Math\BigInteger($this->secret_chats[$chat]['rekeying'][1], -256); $my_exchange_id = new \tgseclib\Math\BigInteger($this->secret_chats[$chat]['rekeying'][1], -256);
@ -222,12 +222,12 @@ trait AuthKeyHandler
/** /**
* Commit rekeying of secret chat. * Commit rekeying of secret chat.
* *
* @param mixed $chat Chat * @param int $chat Chat
* @param array $params Parameters * @param array $params Parameters
* *
* @return \Generator * @return \Generator
*/ */
private function commitRekey($chat, array $params): \Generator private function commitRekey(int $chat, array $params): \Generator
{ {
if ($this->secret_chats[$chat]['rekeying'][0] !== 1 || !isset($this->temp_rekeyed_secret_chats[$params['exchange_id']])) { if ($this->secret_chats[$chat]['rekeying'][0] !== 1 || !isset($this->temp_rekeyed_secret_chats[$params['exchange_id']])) {
$this->secret_chats[$chat]['rekeying'] = [0]; $this->secret_chats[$chat]['rekeying'] = [0];
@ -260,12 +260,12 @@ trait AuthKeyHandler
/** /**
* Complete rekeying. * Complete rekeying.
* *
* @param mixed $chat Chat * @param int $chat Chat
* @param array $params Parameters * @param array $params Parameters
* *
* @return \Generator * @return \Generator
*/ */
private function completeRekey($chat, array $params): \Generator private function completeRekey(int $chat, array $params): \Generator
{ {
if ($this->secret_chats[$chat]['rekeying'][0] !== 2 || !isset($this->temp_rekeyed_secret_chats['fingerprint'])) { if ($this->secret_chats[$chat]['rekeying'][0] !== 2 || !isset($this->temp_rekeyed_secret_chats['fingerprint'])) {
return; return;
@ -334,11 +334,11 @@ trait AuthKeyHandler
/** /**
* Discard secret chat. * Discard secret chat.
* *
* @param array|int $chat Secret chat ID * @param int $chat Secret chat ID
* *
* @return \Generator * @return \Generator
*/ */
public function discardSecretChat($chat): \Generator public function discardSecretChat(int $chat): \Generator
{ {
$this->logger->logger('Discarding secret chat '.$chat.'...', \danog\MadelineProto\Logger::VERBOSE); $this->logger->logger('Discarding secret chat '.$chat.'...', \danog\MadelineProto\Logger::VERBOSE);
if (isset($this->secret_chats[$chat])) { if (isset($this->secret_chats[$chat])) {

View File

@ -95,9 +95,9 @@ trait Tools
* *
* @return int * @return int
*/ */
public static function randomInt($modulus = false): int public static function randomInt(int $modulus = 0): int
{ {
if ($modulus === false) { if ($modulus === 0) {
$modulus = PHP_INT_MAX; $modulus = PHP_INT_MAX;
} }
@ -158,7 +158,7 @@ trait Tools
* *
* @return integer * @return integer
*/ */
public static function unpackSignedInt($value): int public static function unpackSignedInt(string $value): int
{ {
if (\strlen($value) !== 4) { if (\strlen($value) !== 4) {
throw new TL\Exception(\danog\MadelineProto\Lang::$current_lang['length_not_4']); throw new TL\Exception(\danog\MadelineProto\Lang::$current_lang['length_not_4']);
@ -174,7 +174,7 @@ trait Tools
* *
* @return integer * @return integer
*/ */
public static function unpackSignedLong($value): int public static function unpackSignedLong(string $value): int
{ {
if (\strlen($value) !== 8) { if (\strlen($value) !== 8) {
throw new TL\Exception(\danog\MadelineProto\Lang::$current_lang['length_not_8']); throw new TL\Exception(\danog\MadelineProto\Lang::$current_lang['length_not_8']);

View File

@ -46,13 +46,13 @@ trait AuthKeyHandler
/** /**
* Accept call (synchronous). * Accept call (synchronous).
* *
* @param mixed $user Accept call * @param array $user Accept call
* *
* @internal * @internal
* *
* @return bool * @return bool
*/ */
public function acceptCall($user): bool public function acceptCall(array $user): bool
{ {
return \danog\MadelineProto\Tools::wait($this->acceptCallAsync($user)); return \danog\MadelineProto\Tools::wait($this->acceptCallAsync($user));
} }
@ -67,7 +67,7 @@ trait AuthKeyHandler
* *
* @return array * @return array
*/ */
public function discardCall($call, $reason, $rating = [], $need_debug = true): void public function discardCall(array $call, string $reason, array $rating = [], bool $need_debug = true): void
{ {
\danog\MadelineProto\Tools::wait($this->discardCallAsync($call, $reason, $rating, $need_debug)); \danog\MadelineProto\Tools::wait($this->discardCallAsync($call, $reason, $rating, $need_debug));
} }
@ -113,7 +113,7 @@ trait AuthKeyHandler
* *
* @return \Generator * @return \Generator
*/ */
public function acceptCallAsync($call): \Generator public function acceptCallAsync(array $call): \Generator
{ {
if (!\class_exists('\\danog\\MadelineProto\\VoIP')) { if (!\class_exists('\\danog\\MadelineProto\\VoIP')) {
throw new \danog\MadelineProto\Exception(); throw new \danog\MadelineProto\Exception();
@ -160,7 +160,7 @@ trait AuthKeyHandler
* *
* @return \Generator * @return \Generator
*/ */
public function confirmCall($params): \Generator public function confirmCall(array $params): \Generator
{ {
if (!\class_exists('\\danog\\MadelineProto\\VoIP')) { if (!\class_exists('\\danog\\MadelineProto\\VoIP')) {
throw \danog\MadelineProto\Exception::extension('libtgvoip'); throw \danog\MadelineProto\Exception::extension('libtgvoip');
@ -216,7 +216,7 @@ trait AuthKeyHandler
* *
* @return \Generator * @return \Generator
*/ */
public function completeCall($params): \Generator public function completeCall(array $params): \Generator
{ {
if (!\class_exists('\\danog\\MadelineProto\\VoIP')) { if (!\class_exists('\\danog\\MadelineProto\\VoIP')) {
throw \danog\MadelineProto\Exception::extension('libtgvoip'); throw \danog\MadelineProto\Exception::extension('libtgvoip');
@ -254,11 +254,11 @@ trait AuthKeyHandler
/** /**
* Get call status. * Get call status.
* *
* @param array $id Call ID * @param int $id Call ID
* *
* @return integer * @return integer
*/ */
public function callStatus($id): int public function callStatus(int $id): int
{ {
if (!\class_exists('\\danog\\MadelineProto\\VoIP')) { if (!\class_exists('\\danog\\MadelineProto\\VoIP')) {
throw \danog\MadelineProto\Exception::extension('libtgvoip'); throw \danog\MadelineProto\Exception::extension('libtgvoip');
@ -273,11 +273,11 @@ trait AuthKeyHandler
/** /**
* Get call info. * Get call info.
* *
* @param mixed $call Call ID * @param int $call Call ID
* *
* @return array * @return array
*/ */
public function getCall($call): array public function getCall(int $call): array
{ {
if (!\class_exists('\\danog\\MadelineProto\\VoIP')) { if (!\class_exists('\\danog\\MadelineProto\\VoIP')) {
throw \danog\MadelineProto\Exception::extension('libtgvoip'); throw \danog\MadelineProto\Exception::extension('libtgvoip');
@ -296,7 +296,7 @@ trait AuthKeyHandler
* *
* @return \Generator * @return \Generator
*/ */
public function discardCallAsync($call, $reason, $rating = [], $need_debug = true): \Generator public function discardCallAsync(array $call, string $reason, array $rating = [], bool $need_debug = true): \Generator
{ {
if (!\class_exists('\\danog\\MadelineProto\\VoIP')) { if (!\class_exists('\\danog\\MadelineProto\\VoIP')) {
throw \danog\MadelineProto\Exception::extension('libtgvoip'); throw \danog\MadelineProto\Exception::extension('libtgvoip');

View File

@ -28,7 +28,7 @@ trait DialogHandler
* *
* @return \Generator<array<Peer>> * @return \Generator<array<Peer>>
*/ */
public function getDialogs($force = true): \Generator public function getDialogs(bool $force = true): \Generator
{ {
if ($this->authorization['user']['bot']) { if ($this->authorization['user']['bot']) {
$res = []; $res = [];
@ -53,7 +53,7 @@ trait DialogHandler
* *
* @return \Generator * @return \Generator
*/ */
public function getFullDialogs($force = true): \Generator public function getFullDialogs(bool $force = true): \Generator
{ {
if ($force || !isset($this->dialog_params['offset_date']) || \is_null($this->dialog_params['offset_date']) || !isset($this->dialog_params['offset_id']) || \is_null($this->dialog_params['offset_id']) || !isset($this->dialog_params['offset_peer']) || \is_null($this->dialog_params['offset_peer']) || !isset($this->dialog_params['count']) || \is_null($this->dialog_params['count'])) { if ($force || !isset($this->dialog_params['offset_date']) || \is_null($this->dialog_params['offset_date']) || !isset($this->dialog_params['offset_id']) || \is_null($this->dialog_params['offset_id']) || !isset($this->dialog_params['offset_peer']) || \is_null($this->dialog_params['offset_peer']) || !isset($this->dialog_params['count']) || \is_null($this->dialog_params['count'])) {
$this->dialog_params = ['limit' => 100, 'offset_date' => 0, 'offset_id' => 0, 'offset_peer' => ['_' => 'inputPeerEmpty'], 'count' => 0, 'hash' => 0]; $this->dialog_params = ['limit' => 100, 'offset_date' => 0, 'offset_id' => 0, 'offset_peer' => ['_' => 'inputPeerEmpty'], 'count' => 0, 'hash' => 0];

View File

@ -32,7 +32,7 @@ trait Webhook
* *
* @return void * @return void
*/ */
public function setWebhook($hook_url, $pem_path = null): void public function setWebhook(string $hook_url, string $pem_path = ''): void
{ {
$this->pem_path = $pem_path; $this->pem_path = $pem_path;
$this->hook_url = $hook_url; $this->hook_url = $hook_url;