Improvements for static typing
This commit is contained in:
parent
76ca2b19ab
commit
967c9b5a93
@ -27,6 +27,30 @@ use phpDocumentor\Reflection\DocBlockFactory;
|
|||||||
|
|
||||||
class AnnotationsBuilder
|
class AnnotationsBuilder
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* Reflection classes
|
||||||
|
*/
|
||||||
|
private array $reflectionClasses = [];
|
||||||
|
/**
|
||||||
|
* Logger
|
||||||
|
*/
|
||||||
|
private Logger $logger;
|
||||||
|
/**
|
||||||
|
* Namespace
|
||||||
|
*/
|
||||||
|
private string $namespace;
|
||||||
|
/**
|
||||||
|
* TL instance
|
||||||
|
*/
|
||||||
|
private TL $TL;
|
||||||
|
/**
|
||||||
|
* Settings
|
||||||
|
*/
|
||||||
|
private array $settings;
|
||||||
|
/**
|
||||||
|
* Output file
|
||||||
|
*/
|
||||||
|
private string $output;
|
||||||
public function __construct(Logger $logger, array $settings, string $output, array $reflectionClasses, string $namespace)
|
public function __construct(Logger $logger, array $settings, string $output, array $reflectionClasses, string $namespace)
|
||||||
{
|
{
|
||||||
$this->reflectionClasses = $reflectionClasses;
|
$this->reflectionClasses = $reflectionClasses;
|
||||||
|
@ -101,9 +101,9 @@ class Connection extends Session
|
|||||||
/**
|
/**
|
||||||
* Date of last chunk received.
|
* Date of last chunk received.
|
||||||
*
|
*
|
||||||
* @var integer
|
* @var float
|
||||||
*/
|
*/
|
||||||
private $lastChunk = 0;
|
private float $lastChunk = 0;
|
||||||
/**
|
/**
|
||||||
* Logger instance.
|
* Logger instance.
|
||||||
*
|
*
|
||||||
@ -166,24 +166,6 @@ class Connection extends Session
|
|||||||
{
|
{
|
||||||
return $this->needsReconnect;
|
return $this->needsReconnect;
|
||||||
}
|
}
|
||||||
/**
|
|
||||||
* Check if the socket is writing stuff.
|
|
||||||
*
|
|
||||||
* @return boolean
|
|
||||||
*/
|
|
||||||
public function isWriting(): bool
|
|
||||||
{
|
|
||||||
return $this->writing;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* Check if the socket is reading stuff.
|
|
||||||
*
|
|
||||||
* @return boolean
|
|
||||||
*/
|
|
||||||
public function isReading(): bool
|
|
||||||
{
|
|
||||||
return $this->reading;
|
|
||||||
}
|
|
||||||
/**
|
/**
|
||||||
* Set writing boolean.
|
* Set writing boolean.
|
||||||
*
|
*
|
||||||
@ -191,7 +173,7 @@ class Connection extends Session
|
|||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function writing(bool $writing)
|
public function writing(bool $writing): void
|
||||||
{
|
{
|
||||||
$this->shared->writing($writing, $this->id);
|
$this->shared->writing($writing, $this->id);
|
||||||
}
|
}
|
||||||
@ -202,7 +184,7 @@ class Connection extends Session
|
|||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function reading(bool $reading)
|
public function reading(bool $reading): void
|
||||||
{
|
{
|
||||||
$this->shared->reading($reading, $this->id);
|
$this->shared->reading($reading, $this->id);
|
||||||
}
|
}
|
||||||
@ -218,9 +200,9 @@ class Connection extends Session
|
|||||||
/**
|
/**
|
||||||
* Get the receive date of the latest chunk of data from the socket.
|
* Get the receive date of the latest chunk of data from the socket.
|
||||||
*
|
*
|
||||||
* @return int
|
* @return float
|
||||||
*/
|
*/
|
||||||
public function getLastChunk(): int
|
public function getLastChunk(): float
|
||||||
{
|
{
|
||||||
return $this->lastChunk;
|
return $this->lastChunk;
|
||||||
}
|
}
|
||||||
|
@ -37,10 +37,10 @@ class ContextConnector implements Connector
|
|||||||
$this->fromDns = $fromDns;
|
$this->fromDns = $fromDns;
|
||||||
$this->logger = $dataCenter->getAPI()->getLogger();
|
$this->logger = $dataCenter->getAPI()->getLogger();
|
||||||
}
|
}
|
||||||
public function connect(string $uri, ?ConnectContext $ctx = null, ?CancellationToken $token = null): Promise
|
public function connect(string $uri, ?ConnectContext $context = null, ?CancellationToken $token = null): Promise
|
||||||
{
|
{
|
||||||
return Tools::call((function () use ($uri, $ctx, $token): \Generator {
|
return Tools::call((function () use ($uri, $context, $token): \Generator {
|
||||||
$ctx = $ctx ?? new ConnectContext();
|
$ctx = $context ?? new ConnectContext();
|
||||||
$token = $token ?? new NullCancellationToken();
|
$token = $token ?? new NullCancellationToken();
|
||||||
$ctxs = $this->dataCenter->generateContexts(0, $uri, $ctx);
|
$ctxs = $this->dataCenter->generateContexts(0, $uri, $ctx);
|
||||||
if (empty($ctxs)) {
|
if (empty($ctxs)) {
|
||||||
|
@ -62,7 +62,7 @@ class DataCenter
|
|||||||
/**
|
/**
|
||||||
* All socket connections to DCs.
|
* All socket connections to DCs.
|
||||||
*
|
*
|
||||||
* @var array<string, DataCenterConnection>
|
* @var array<string|int, DataCenterConnection>
|
||||||
*/
|
*/
|
||||||
public $sockets = [];
|
public $sockets = [];
|
||||||
/**
|
/**
|
||||||
@ -138,11 +138,12 @@ class DataCenter
|
|||||||
$array = [];
|
$array = [];
|
||||||
foreach ($this->sockets as $id => $socket) {
|
foreach ($this->sockets as $id => $socket) {
|
||||||
if ($socket instanceof \danog\MadelineProto\Connection) {
|
if ($socket instanceof \danog\MadelineProto\Connection) {
|
||||||
if ($socket->temp_auth_key) {
|
if (isset($socket->temp_auth_key) && $socket->temp_auth_key) {
|
||||||
$array[$id]['tempAuthKey'] = $socket->temp_auth_key;
|
$array[$id]['tempAuthKey'] = $socket->temp_auth_key;
|
||||||
}
|
}
|
||||||
if ($socket->auth_key) {
|
if (isset($socket->auth_key) && $socket->auth_key) {
|
||||||
$array[$id]['permAuthKey'] = $socket->auth_key;
|
$array[$id]['permAuthKey'] = $socket->auth_key;
|
||||||
|
/** @psalm-suppress UndefinedPropertyFetch */
|
||||||
$array[$id]['permAuthKey']['authorized'] = $socket->authorized;
|
$array[$id]['permAuthKey']['authorized'] = $socket->authorized;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -179,7 +179,7 @@ class DataCenterConnection implements JsonSerializable
|
|||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function setAuthKey(?AuthKey $key, bool $temp = true)
|
public function setAuthKey(?AuthKey $key, bool $temp = true): void
|
||||||
{
|
{
|
||||||
$this->{$temp ? 'tempAuthKey' : 'permAuthKey'} = $key;
|
$this->{$temp ? 'tempAuthKey' : 'permAuthKey'} = $key;
|
||||||
}
|
}
|
||||||
@ -226,9 +226,9 @@ class DataCenterConnection implements JsonSerializable
|
|||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function setTempAuthKey(?TempAuthKey $key)
|
public function setTempAuthKey(?TempAuthKey $key): void
|
||||||
{
|
{
|
||||||
return $this->setAuthKey($key, true);
|
$this->setAuthKey($key, true);
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Set permanent authorization key.
|
* Set permanent authorization key.
|
||||||
@ -237,9 +237,9 @@ class DataCenterConnection implements JsonSerializable
|
|||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function setPermAuthKey(?PermAuthKey $key)
|
public function setPermAuthKey(?PermAuthKey $key): void
|
||||||
{
|
{
|
||||||
return $this->setAuthKey($key, false);
|
$this->setAuthKey($key, false);
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Bind temporary and permanent auth keys.
|
* Bind temporary and permanent auth keys.
|
||||||
|
@ -5,6 +5,11 @@ namespace danog\MadelineProto\Db;
|
|||||||
use Amp\Loop;
|
use Amp\Loop;
|
||||||
use danog\MadelineProto\Logger;
|
use danog\MadelineProto\Logger;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Array caching trait
|
||||||
|
*
|
||||||
|
* @property string $table
|
||||||
|
*/
|
||||||
trait ArrayCacheTrait
|
trait ArrayCacheTrait
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
|
@ -6,6 +6,11 @@ use danog\MadelineProto\Logger;
|
|||||||
use danog\MadelineProto\SettingsAbstract;
|
use danog\MadelineProto\SettingsAbstract;
|
||||||
use ReflectionClass;
|
use ReflectionClass;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Array caching trait
|
||||||
|
*
|
||||||
|
* @property string $table
|
||||||
|
*/
|
||||||
abstract class DriverArray implements DbArray
|
abstract class DriverArray implements DbArray
|
||||||
{
|
{
|
||||||
use ArrayCacheTrait;
|
use ArrayCacheTrait;
|
||||||
|
@ -19,6 +19,8 @@
|
|||||||
|
|
||||||
namespace danog\MadelineProto\MTProtoSession;
|
namespace danog\MadelineProto\MTProtoSession;
|
||||||
|
|
||||||
|
use danog\MadelineProto\MTProto;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Manages MTProto session-specific data.
|
* Manages MTProto session-specific data.
|
||||||
*
|
*
|
||||||
|
@ -61,7 +61,7 @@ class PasswordCalculator
|
|||||||
/**
|
/**
|
||||||
* SRP b parameter for hashing.
|
* SRP b parameter for hashing.
|
||||||
*
|
*
|
||||||
* @var BigInteger
|
* @var string
|
||||||
*/
|
*/
|
||||||
private $srp_BForHash;
|
private $srp_BForHash;
|
||||||
/**
|
/**
|
||||||
|
@ -458,9 +458,14 @@ abstract class Tools extends StrTools
|
|||||||
/**
|
/**
|
||||||
* Convert generator, promise or any other value to a promise.
|
* Convert generator, promise or any other value to a promise.
|
||||||
*
|
*
|
||||||
|
* @template TReturn
|
||||||
|
*
|
||||||
* @param \Generator|Promise|mixed $promise
|
* @param \Generator|Promise|mixed $promise
|
||||||
*
|
*
|
||||||
|
* @psalm-param \Generator<mixed, mixed, mixed, TReturn>|Promise<TReturn>|TReturn $promise
|
||||||
|
*
|
||||||
* @return Promise
|
* @return Promise
|
||||||
|
* @psalm-return Promise<TReturn>
|
||||||
*/
|
*/
|
||||||
public static function call($promise): Promise
|
public static function call($promise): Promise
|
||||||
{
|
{
|
||||||
@ -512,7 +517,7 @@ abstract class Tools extends StrTools
|
|||||||
*/
|
*/
|
||||||
public static function callForkDefer($promise): void
|
public static function callForkDefer($promise): void
|
||||||
{
|
{
|
||||||
Loop::defer([__CLASS__, 'callFork'], $promise);
|
Loop::defer([self::class, 'callFork'], $promise);
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Rethrow error catched in strand.
|
* Rethrow error catched in strand.
|
||||||
|
@ -46,7 +46,7 @@ trait Events
|
|||||||
/**
|
/**
|
||||||
* Event handler method list.
|
* Event handler method list.
|
||||||
*
|
*
|
||||||
* @var array<string>
|
* @var array<string, callable>
|
||||||
*/
|
*/
|
||||||
private $eventHandlerMethods = [];
|
private $eventHandlerMethods = [];
|
||||||
/**
|
/**
|
||||||
|
@ -19,6 +19,7 @@
|
|||||||
|
|
||||||
namespace danog\MadelineProto\Wrappers;
|
namespace danog\MadelineProto\Wrappers;
|
||||||
|
|
||||||
|
use danog\MadelineProto\Ipc\Client;
|
||||||
use danog\MadelineProto\Lang;
|
use danog\MadelineProto\Lang;
|
||||||
use danog\MadelineProto\MTProto;
|
use danog\MadelineProto\MTProto;
|
||||||
use danog\MadelineProto\Settings;
|
use danog\MadelineProto\Settings;
|
||||||
@ -40,10 +41,14 @@ trait Start
|
|||||||
public function start(): \Generator
|
public function start(): \Generator
|
||||||
{
|
{
|
||||||
if ((yield $this->getAuthorization()) === MTProto::LOGGED_IN) {
|
if ((yield $this->getAuthorization()) === MTProto::LOGGED_IN) {
|
||||||
return $this instanceof \danog\MadelineProto\Ipc\Client ? yield from $this->getSelf() : yield from $this->fullGetSelf();
|
return $this instanceof Client ? yield from $this->getSelf() : yield from $this->fullGetSelf();
|
||||||
}
|
}
|
||||||
if ($this->getWebTemplate() === 'legacy') {
|
if ($this->getWebTemplate() === 'legacy') {
|
||||||
$this->setWebTemplate((yield $this->getSettings())->getTemplates()->getHtmlTemplate());
|
if ($this instanceof Client) {
|
||||||
|
$this->setWebTemplate(yield from $this->getSettings());
|
||||||
|
} else {
|
||||||
|
$this->setWebTemplate($this->settings);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (PHP_SAPI === 'cli' || PHP_SAPI === 'phpdbg') {
|
if (PHP_SAPI === 'cli' || PHP_SAPI === 'phpdbg') {
|
||||||
if (\strpos(yield Tools::readLine(Lang::$current_lang['loginChoosePrompt']), 'b') !== false) {
|
if (\strpos(yield Tools::readLine(Lang::$current_lang['loginChoosePrompt']), 'b') !== false) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user