mirror of
https://github.com/danog/MadelineProto.git
synced 2024-11-27 04:35:12 +01:00
Use more consistent types for file functions
This commit is contained in:
parent
529206f347
commit
ae7cf4b9f0
@ -665,20 +665,11 @@
|
||||
<code>MTProtoToTd</code>
|
||||
<code>MTProtoToTdcli</code>
|
||||
<code>completePhoneLogin</code>
|
||||
<code>downloadToCallable</code>
|
||||
<code>downloadToDir</code>
|
||||
<code>downloadToStream</code>
|
||||
<code>end</code>
|
||||
<code>phoneLogin</code>
|
||||
<code>requestSecretChat</code>
|
||||
<code>start</code>
|
||||
<code>tdToTdcli</code>
|
||||
<code>upload</code>
|
||||
<code>uploadEncrypted</code>
|
||||
<code>uploadFromCallable</code>
|
||||
<code>uploadFromStream</code>
|
||||
<code>uploadFromTgfile</code>
|
||||
<code>uploadFromUrl</code>
|
||||
</MissingReturnType>
|
||||
<PossiblyInvalidPropertyAssignmentValue>
|
||||
<code><![CDATA[$this->account ??= new \danog\MadelineProto\Namespace\AbstractAPI('account')]]></code>
|
||||
@ -1336,17 +1327,15 @@
|
||||
<DocblockTypeContradiction>
|
||||
<code><![CDATA[$fingerprint !== $messageMedia['key_fingerprint']]]></code>
|
||||
</DocblockTypeContradiction>
|
||||
<InvalidNullableReturnType>
|
||||
<code>array</code>
|
||||
</InvalidNullableReturnType>
|
||||
<MissingParamType>
|
||||
<code>$data</code>
|
||||
<code>$media</code>
|
||||
</MissingParamType>
|
||||
<MissingReturnType>
|
||||
<code>downloadToCallable</code>
|
||||
<code>downloadToDir</code>
|
||||
<code>genAllFile</code>
|
||||
<code>uploadFromCallable</code>
|
||||
<code>uploadFromTgfile</code>
|
||||
<code>uploadFromUrl</code>
|
||||
</MissingReturnType>
|
||||
<PossiblyInvalidArrayOffset>
|
||||
<code><![CDATA[$this->read[$offset]]]></code>
|
||||
@ -1412,12 +1401,6 @@
|
||||
<code>static function (int $offset, int $size) use ($stream, $seekable, $lock) {</code>
|
||||
<code>static function (string $payload, int $offset) use ($stream, $seekable, $lock) {</code>
|
||||
</MissingClosureReturnType>
|
||||
<MissingReturnType>
|
||||
<code>downloadToStream</code>
|
||||
<code>upload</code>
|
||||
<code>uploadEncrypted</code>
|
||||
<code>uploadFromStream</code>
|
||||
</MissingReturnType>
|
||||
<PossiblyInvalidArgument>
|
||||
<code>$file</code>
|
||||
<code>$file</code>
|
||||
@ -1426,9 +1409,6 @@
|
||||
<code>$body</code>
|
||||
<code>$size</code>
|
||||
</PossiblyNullArgument>
|
||||
<PossiblyUndefinedArrayOffset>
|
||||
<code><![CDATA[$_SERVER['REQUEST_METHOD']]]></code>
|
||||
</PossiblyUndefinedArrayOffset>
|
||||
<PossiblyUndefinedMethod>
|
||||
<code>seek</code>
|
||||
<code>seek</code>
|
||||
@ -1485,9 +1465,6 @@
|
||||
</RedundantCastGivenDocblockType>
|
||||
</file>
|
||||
<file src="src/MTProtoTools/PeerHandler.php">
|
||||
<InvalidArgument>
|
||||
<code><![CDATA[self::isSupergroupOrChannel($peer) && $this->getInfo($peer, \danog\MadelineProto\API::INFO_TYPE_CONSTRUCTOR)['forum']]]></code>
|
||||
</InvalidArgument>
|
||||
<InvalidArrayOffset>
|
||||
<code><![CDATA[$this->getInfo($peer, \danog\MadelineProto\API::INFO_TYPE_CONSTRUCTOR)['forum']]]></code>
|
||||
</InvalidArrayOffset>
|
||||
|
@ -423,9 +423,9 @@ abstract class InternalDoc
|
||||
* @param int $end Offset where to stop downloading (inclusive)
|
||||
* @param int $part_size Size of each chunk
|
||||
*/
|
||||
public function downloadToCallable(mixed $messageMedia, callable $callable, ?callable $cb = null, bool $seekable = true, int $offset = 0, int $end = -1, ?int $part_size = null)
|
||||
public function downloadToCallable(mixed $messageMedia, callable $callable, ?callable $cb = null, bool $seekable = true, int $offset = 0, int $end = -1, ?int $part_size = null): void
|
||||
{
|
||||
return $this->wrapper->getAPI()->downloadToCallable($messageMedia, $callable, $cb, $seekable, $offset, $end, $part_size);
|
||||
$this->wrapper->getAPI()->downloadToCallable($messageMedia, $callable, $cb, $seekable, $offset, $end, $part_size);
|
||||
}
|
||||
/**
|
||||
* Download file to directory.
|
||||
@ -433,8 +433,10 @@ abstract class InternalDoc
|
||||
* @param mixed $messageMedia File to download
|
||||
* @param string|FileCallbackInterface $dir Directory where to download the file
|
||||
* @param callable $cb Callback
|
||||
*
|
||||
* @return non-empty-string Downloaded file name
|
||||
*/
|
||||
public function downloadToDir(mixed $messageMedia, \danog\MadelineProto\FileCallbackInterface|string $dir, ?callable $cb = null)
|
||||
public function downloadToDir(mixed $messageMedia, \danog\MadelineProto\FileCallbackInterface|string $dir, ?callable $cb = null): string
|
||||
{
|
||||
return $this->wrapper->getAPI()->downloadToDir($messageMedia, $dir, $cb);
|
||||
}
|
||||
@ -444,8 +446,10 @@ abstract class InternalDoc
|
||||
* @param mixed $messageMedia File to download
|
||||
* @param string|FileCallbackInterface $file Downloaded file path
|
||||
* @param callable $cb Callback
|
||||
*
|
||||
* @return non-empty-string Downloaded file name
|
||||
*/
|
||||
public function downloadToFile(mixed $messageMedia, \danog\MadelineProto\FileCallbackInterface|string $file, ?callable $cb = null): string|false
|
||||
public function downloadToFile(mixed $messageMedia, \danog\MadelineProto\FileCallbackInterface|string $file, ?callable $cb = null): string
|
||||
{
|
||||
return $this->wrapper->getAPI()->downloadToFile($messageMedia, $file, $cb);
|
||||
}
|
||||
@ -486,9 +490,9 @@ abstract class InternalDoc
|
||||
* @param int $offset Offset where to start downloading
|
||||
* @param int $end Offset where to end download
|
||||
*/
|
||||
public function downloadToStream(mixed $messageMedia, mixed $stream, ?callable $cb = null, int $offset = 0, int $end = -1)
|
||||
public function downloadToStream(mixed $messageMedia, mixed $stream, ?callable $cb = null, int $offset = 0, int $end = -1): void
|
||||
{
|
||||
return $this->wrapper->getAPI()->downloadToStream($messageMedia, $stream, $cb, $offset, $end);
|
||||
$this->wrapper->getAPI()->downloadToStream($messageMedia, $stream, $cb, $offset, $end);
|
||||
}
|
||||
/**
|
||||
* Asynchronously write to stdout/browser.
|
||||
@ -1948,8 +1952,10 @@ abstract class InternalDoc
|
||||
* @param string $fileName File name
|
||||
* @param callable $cb Callback
|
||||
* @param boolean $encrypted Whether to encrypt file for secret chats
|
||||
*
|
||||
* @return array InputFile constructor
|
||||
*/
|
||||
public function upload($file, string $fileName = '', ?callable $cb = null, bool $encrypted = false)
|
||||
public function upload($file, string $fileName = '', ?callable $cb = null, bool $encrypted = false): array
|
||||
{
|
||||
return $this->wrapper->getAPI()->upload($file, $fileName, $cb, $encrypted);
|
||||
}
|
||||
@ -1959,8 +1965,10 @@ abstract class InternalDoc
|
||||
* @param FileCallbackInterface|string|array $file File, URL or Telegram file to upload
|
||||
* @param string $fileName File name
|
||||
* @param callable $cb Callback
|
||||
*
|
||||
* @return array InputFile constructor
|
||||
*/
|
||||
public function uploadEncrypted(\danog\MadelineProto\FileCallbackInterface|array|string $file, string $fileName = '', ?callable $cb = null)
|
||||
public function uploadEncrypted(\danog\MadelineProto\FileCallbackInterface|array|string $file, string $fileName = '', ?callable $cb = null): array
|
||||
{
|
||||
return $this->wrapper->getAPI()->uploadEncrypted($file, $fileName, $cb);
|
||||
}
|
||||
@ -1977,8 +1985,10 @@ abstract class InternalDoc
|
||||
* @param callable $cb Callback
|
||||
* @param boolean $seekable Whether chunks can be fetched out of order
|
||||
* @param boolean $encrypted Whether to encrypt file for secret chats
|
||||
*
|
||||
* @return array InputFile constructor
|
||||
*/
|
||||
public function uploadFromCallable(callable $callable, int $size = 0, string $mime = 'application/octet-stream', string $fileName = '', ?callable $cb = null, bool $seekable = true, bool $encrypted = false)
|
||||
public function uploadFromCallable(callable $callable, int $size = 0, string $mime = 'application/octet-stream', string $fileName = '', ?callable $cb = null, bool $seekable = true, bool $encrypted = false): array
|
||||
{
|
||||
return $this->wrapper->getAPI()->uploadFromCallable($callable, $size, $mime, $fileName, $cb, $seekable, $encrypted);
|
||||
}
|
||||
@ -1991,8 +2001,10 @@ abstract class InternalDoc
|
||||
* @param string $fileName File name
|
||||
* @param callable $cb Callback
|
||||
* @param boolean $encrypted Whether to encrypt file for secret chats
|
||||
*
|
||||
* @return array InputFile constructor
|
||||
*/
|
||||
public function uploadFromStream(mixed $stream, int $size = 0, string $mime = 'application/octet-stream', string $fileName = '', ?callable $cb = null, bool $encrypted = false)
|
||||
public function uploadFromStream(mixed $stream, int $size = 0, string $mime = 'application/octet-stream', string $fileName = '', ?callable $cb = null, bool $encrypted = false): array
|
||||
{
|
||||
return $this->wrapper->getAPI()->uploadFromStream($stream, $size, $mime, $fileName, $cb, $encrypted);
|
||||
}
|
||||
@ -2002,8 +2014,10 @@ abstract class InternalDoc
|
||||
* @param mixed $media Telegram file
|
||||
* @param callable $cb Callback
|
||||
* @param boolean $encrypted Whether to encrypt file for secret chats
|
||||
*
|
||||
* @return array InputFile constructor
|
||||
*/
|
||||
public function uploadFromTgfile(mixed $media, ?callable $cb = null, bool $encrypted = false)
|
||||
public function uploadFromTgfile(mixed $media, ?callable $cb = null, bool $encrypted = false): array
|
||||
{
|
||||
return $this->wrapper->getAPI()->uploadFromTgfile($media, $cb, $encrypted);
|
||||
}
|
||||
@ -2015,8 +2029,9 @@ abstract class InternalDoc
|
||||
* @param string $fileName File name
|
||||
* @param callable $cb Callback
|
||||
* @param boolean $encrypted Whether to encrypt file for secret chats
|
||||
* @return array InputFile constructor
|
||||
*/
|
||||
public function uploadFromUrl(\danog\MadelineProto\FileCallbackInterface|string $url, int $size = 0, string $fileName = '', ?callable $cb = null, bool $encrypted = false)
|
||||
public function uploadFromUrl(\danog\MadelineProto\FileCallbackInterface|string $url, int $size = 0, string $fileName = '', ?callable $cb = null, bool $encrypted = false): array
|
||||
{
|
||||
return $this->wrapper->getAPI()->uploadFromUrl($url, $size, $fileName, $cb, $encrypted);
|
||||
}
|
||||
|
@ -67,8 +67,9 @@ trait Files
|
||||
* @param string $fileName File name
|
||||
* @param callable $cb Callback
|
||||
* @param boolean $encrypted Whether to encrypt file for secret chats
|
||||
* @return array InputFile constructor
|
||||
*/
|
||||
public function uploadFromUrl(string|FileCallbackInterface $url, int $size = 0, string $fileName = '', ?callable $cb = null, bool $encrypted = false)
|
||||
public function uploadFromUrl(string|FileCallbackInterface $url, int $size = 0, string $fileName = '', ?callable $cb = null, bool $encrypted = false): array
|
||||
{
|
||||
if (\is_object($url) && $url instanceof FileCallbackInterface) {
|
||||
$cb = $url;
|
||||
@ -99,8 +100,10 @@ trait Files
|
||||
* @param callable $cb Callback
|
||||
* @param boolean $seekable Whether chunks can be fetched out of order
|
||||
* @param boolean $encrypted Whether to encrypt file for secret chats
|
||||
*
|
||||
* @return array InputFile constructor
|
||||
*/
|
||||
public function uploadFromCallable(callable $callable, int $size = 0, string $mime = 'application/octet-stream', string $fileName = '', ?callable $cb = null, bool $seekable = true, bool $encrypted = false)
|
||||
public function uploadFromCallable(callable $callable, int $size = 0, string $mime = 'application/octet-stream', string $fileName = '', ?callable $cb = null, bool $seekable = true, bool $encrypted = false): array
|
||||
{
|
||||
if (\is_object($callable) && $callable instanceof FileCallbackInterface) {
|
||||
$cb = $callable;
|
||||
@ -262,8 +265,10 @@ trait Files
|
||||
* @param mixed $media Telegram file
|
||||
* @param callable $cb Callback
|
||||
* @param boolean $encrypted Whether to encrypt file for secret chats
|
||||
*
|
||||
* @return array InputFile constructor
|
||||
*/
|
||||
public function uploadFromTgfile(mixed $media, ?callable $cb = null, bool $encrypted = false)
|
||||
public function uploadFromTgfile(mixed $media, ?callable $cb = null, bool $encrypted = false): array
|
||||
{
|
||||
if (\is_object($media) && $media instanceof FileCallbackInterface) {
|
||||
$cb = $media;
|
||||
@ -815,8 +820,10 @@ trait Files
|
||||
* @param mixed $messageMedia File to download
|
||||
* @param string|FileCallbackInterface $dir Directory where to download the file
|
||||
* @param callable $cb Callback
|
||||
*
|
||||
* @return non-empty-string Downloaded file name
|
||||
*/
|
||||
public function downloadToDir(mixed $messageMedia, string|FileCallbackInterface $dir, ?callable $cb = null)
|
||||
public function downloadToDir(mixed $messageMedia, string|FileCallbackInterface $dir, ?callable $cb = null): string
|
||||
{
|
||||
if (\is_object($dir) && $dir instanceof FileCallbackInterface) {
|
||||
$cb = $dir;
|
||||
@ -831,8 +838,10 @@ trait Files
|
||||
* @param mixed $messageMedia File to download
|
||||
* @param string|FileCallbackInterface $file Downloaded file path
|
||||
* @param callable $cb Callback
|
||||
*
|
||||
* @return non-empty-string Downloaded file name
|
||||
*/
|
||||
public function downloadToFile(mixed $messageMedia, string|FileCallbackInterface $file, ?callable $cb = null): false|string
|
||||
public function downloadToFile(mixed $messageMedia, string|FileCallbackInterface $file, ?callable $cb = null): string
|
||||
{
|
||||
if (\is_object($file) && $file instanceof FileCallbackInterface) {
|
||||
$cb = $file;
|
||||
@ -843,6 +852,7 @@ trait Files
|
||||
\touch($file);
|
||||
}
|
||||
$file = \realpath($file);
|
||||
Assert::notEmpty($file);
|
||||
$messageMedia = ($this->getDownloadInfo($messageMedia));
|
||||
$size = getSize($file);
|
||||
$stream = openFile($file, 'cb');
|
||||
@ -874,7 +884,7 @@ trait Files
|
||||
* @param int $end Offset where to stop downloading (inclusive)
|
||||
* @param int $part_size Size of each chunk
|
||||
*/
|
||||
public function downloadToCallable(mixed $messageMedia, callable $callable, ?callable $cb = null, bool $seekable = true, int $offset = 0, int $end = -1, ?int $part_size = null)
|
||||
public function downloadToCallable(mixed $messageMedia, callable $callable, ?callable $cb = null, bool $seekable = true, int $offset = 0, int $end = -1, ?int $part_size = null): void
|
||||
{
|
||||
$messageMedia = ($this->getDownloadInfo($messageMedia));
|
||||
if (\is_object($callable) && $callable instanceof FileCallbackInterface) {
|
||||
@ -919,7 +929,7 @@ trait Files
|
||||
}
|
||||
if ($offset === $end) {
|
||||
$cb(100.0, 0.0, 0);
|
||||
return true;
|
||||
return;
|
||||
}
|
||||
$params = [];
|
||||
$start_at = $offset % $part_size;
|
||||
@ -939,7 +949,7 @@ trait Files
|
||||
}
|
||||
if (!$params) {
|
||||
$cb(100, 0, 0);
|
||||
return true;
|
||||
return;
|
||||
}
|
||||
$count = \count($params);
|
||||
$time = 0.0;
|
||||
@ -958,7 +968,7 @@ trait Files
|
||||
if ($initParam['part_end_at'] - $initParam['part_start_at'] !== $size) {
|
||||
// Premature end for undefined length files
|
||||
$origCb(100, 0, 0);
|
||||
return true;
|
||||
return;
|
||||
}
|
||||
$parallel_chunks = $seekable ? $parallel_chunks : 1;
|
||||
if ($params) {
|
||||
@ -1002,7 +1012,6 @@ trait Files
|
||||
if (!isset($messageMedia['size'])) {
|
||||
$origCb(100.0, $time, $speed);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
/**
|
||||
* Download file part.
|
||||
|
@ -157,7 +157,7 @@ trait FilesLogic
|
||||
* @param int $offset Offset where to start downloading
|
||||
* @param int $end Offset where to end download
|
||||
*/
|
||||
public function downloadToStream(mixed $messageMedia, mixed $stream, ?callable $cb = null, int $offset = 0, int $end = -1)
|
||||
public function downloadToStream(mixed $messageMedia, mixed $stream, ?callable $cb = null, int $offset = 0, int $end = -1): void
|
||||
{
|
||||
$messageMedia = $this->getDownloadInfo($messageMedia);
|
||||
if (\is_object($stream) && $stream instanceof FileCallbackInterface) {
|
||||
@ -195,7 +195,7 @@ trait FilesLogic
|
||||
}
|
||||
return \strlen($payload);
|
||||
};
|
||||
return $this->downloadToCallable($messageMedia, $callable, $cb, $seekable, $offset, $end);
|
||||
$this->downloadToCallable($messageMedia, $callable, $cb, $seekable, $offset, $end);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -252,8 +252,10 @@ trait FilesLogic
|
||||
* @param FileCallbackInterface|string|array $file File, URL or Telegram file to upload
|
||||
* @param string $fileName File name
|
||||
* @param callable $cb Callback
|
||||
*
|
||||
* @return array InputFile constructor
|
||||
*/
|
||||
public function uploadEncrypted(FileCallbackInterface|string|array $file, string $fileName = '', ?callable $cb = null)
|
||||
public function uploadEncrypted(FileCallbackInterface|string|array $file, string $fileName = '', ?callable $cb = null): array
|
||||
{
|
||||
return $this->upload($file, $fileName, $cb, true);
|
||||
}
|
||||
@ -265,8 +267,10 @@ trait FilesLogic
|
||||
* @param string $fileName File name
|
||||
* @param callable $cb Callback
|
||||
* @param boolean $encrypted Whether to encrypt file for secret chats
|
||||
*
|
||||
* @return array InputFile constructor
|
||||
*/
|
||||
public function upload($file, string $fileName = '', ?callable $cb = null, bool $encrypted = false)
|
||||
public function upload($file, string $fileName = '', ?callable $cb = null, bool $encrypted = false): array
|
||||
{
|
||||
if (\is_object($file) && $file instanceof FileCallbackInterface) {
|
||||
$cb = $file;
|
||||
@ -328,8 +332,10 @@ trait FilesLogic
|
||||
* @param string $fileName File name
|
||||
* @param callable $cb Callback
|
||||
* @param boolean $encrypted Whether to encrypt file for secret chats
|
||||
*
|
||||
* @return array InputFile constructor
|
||||
*/
|
||||
public function uploadFromStream(mixed $stream, int $size = 0, string $mime = 'application/octet-stream', string $fileName = '', ?callable $cb = null, bool $encrypted = false)
|
||||
public function uploadFromStream(mixed $stream, int $size = 0, string $mime = 'application/octet-stream', string $fileName = '', ?callable $cb = null, bool $encrypted = false): array
|
||||
{
|
||||
if (\is_object($stream) && $stream instanceof FileCallbackInterface) {
|
||||
$cb = $stream;
|
||||
|
Loading…
Reference in New Issue
Block a user