Improvements for static typing

This commit is contained in:
Daniil Gentili 2020-10-03 12:36:08 +02:00
parent 76ca2b19ab
commit 967c9b5a93
Signed by: danog
GPG Key ID: 8C1BE3B34B230CA7
12 changed files with 69 additions and 40 deletions

View File

@ -27,6 +27,30 @@ use phpDocumentor\Reflection\DocBlockFactory;
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)
{
$this->reflectionClasses = $reflectionClasses;

View File

@ -101,9 +101,9 @@ class Connection extends Session
/**
* Date of last chunk received.
*
* @var integer
* @var float
*/
private $lastChunk = 0;
private float $lastChunk = 0;
/**
* Logger instance.
*
@ -166,24 +166,6 @@ class Connection extends Session
{
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.
*
@ -191,7 +173,7 @@ class Connection extends Session
*
* @return void
*/
public function writing(bool $writing)
public function writing(bool $writing): void
{
$this->shared->writing($writing, $this->id);
}
@ -202,7 +184,7 @@ class Connection extends Session
*
* @return void
*/
public function reading(bool $reading)
public function reading(bool $reading): void
{
$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.
*
* @return int
* @return float
*/
public function getLastChunk(): int
public function getLastChunk(): float
{
return $this->lastChunk;
}

View File

@ -37,10 +37,10 @@ class ContextConnector implements Connector
$this->fromDns = $fromDns;
$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 {
$ctx = $ctx ?? new ConnectContext();
return Tools::call((function () use ($uri, $context, $token): \Generator {
$ctx = $context ?? new ConnectContext();
$token = $token ?? new NullCancellationToken();
$ctxs = $this->dataCenter->generateContexts(0, $uri, $ctx);
if (empty($ctxs)) {

View File

@ -62,7 +62,7 @@ class DataCenter
/**
* All socket connections to DCs.
*
* @var array<string, DataCenterConnection>
* @var array<string|int, DataCenterConnection>
*/
public $sockets = [];
/**
@ -138,11 +138,12 @@ class DataCenter
$array = [];
foreach ($this->sockets as $id => $socket) {
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;
}
if ($socket->auth_key) {
if (isset($socket->auth_key) && $socket->auth_key) {
$array[$id]['permAuthKey'] = $socket->auth_key;
/** @psalm-suppress UndefinedPropertyFetch */
$array[$id]['permAuthKey']['authorized'] = $socket->authorized;
}
}

View File

@ -179,7 +179,7 @@ class DataCenterConnection implements JsonSerializable
*
* @return void
*/
public function setAuthKey(?AuthKey $key, bool $temp = true)
public function setAuthKey(?AuthKey $key, bool $temp = true): void
{
$this->{$temp ? 'tempAuthKey' : 'permAuthKey'} = $key;
}
@ -226,9 +226,9 @@ class DataCenterConnection implements JsonSerializable
*
* @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.
@ -237,9 +237,9 @@ class DataCenterConnection implements JsonSerializable
*
* @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.

View File

@ -5,6 +5,11 @@ namespace danog\MadelineProto\Db;
use Amp\Loop;
use danog\MadelineProto\Logger;
/**
* Array caching trait
*
* @property string $table
*/
trait ArrayCacheTrait
{
/**

View File

@ -6,6 +6,11 @@ use danog\MadelineProto\Logger;
use danog\MadelineProto\SettingsAbstract;
use ReflectionClass;
/**
* Array caching trait
*
* @property string $table
*/
abstract class DriverArray implements DbArray
{
use ArrayCacheTrait;

View File

@ -19,6 +19,8 @@
namespace danog\MadelineProto\MTProtoSession;
use danog\MadelineProto\MTProto;
/**
* Manages MTProto session-specific data.
*

View File

@ -61,7 +61,7 @@ class PasswordCalculator
/**
* SRP b parameter for hashing.
*
* @var BigInteger
* @var string
*/
private $srp_BForHash;
/**

View File

@ -458,9 +458,14 @@ abstract class Tools extends StrTools
/**
* Convert generator, promise or any other value to a promise.
*
* @template TReturn
*
* @param \Generator|Promise|mixed $promise
*
* @psalm-param \Generator<mixed, mixed, mixed, TReturn>|Promise<TReturn>|TReturn $promise
*
* @return Promise
* @psalm-return Promise<TReturn>
*/
public static function call($promise): Promise
{
@ -512,7 +517,7 @@ abstract class Tools extends StrTools
*/
public static function callForkDefer($promise): void
{
Loop::defer([__CLASS__, 'callFork'], $promise);
Loop::defer([self::class, 'callFork'], $promise);
}
/**
* Rethrow error catched in strand.

View File

@ -46,7 +46,7 @@ trait Events
/**
* Event handler method list.
*
* @var array<string>
* @var array<string, callable>
*/
private $eventHandlerMethods = [];
/**

View File

@ -19,6 +19,7 @@
namespace danog\MadelineProto\Wrappers;
use danog\MadelineProto\Ipc\Client;
use danog\MadelineProto\Lang;
use danog\MadelineProto\MTProto;
use danog\MadelineProto\Settings;
@ -40,10 +41,14 @@ trait Start
public function start(): \Generator
{
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') {
$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 (\strpos(yield Tools::readLine(Lang::$current_lang['loginChoosePrompt']), 'b') !== false) {