phpstan update

Better typying
This commit is contained in:
Pierre Rudloff 2020-05-13 22:28:05 +02:00
parent 74db3b9ad0
commit 6adc1df213
17 changed files with 166 additions and 158 deletions

View file

@ -6,6 +6,8 @@
namespace Alltube\Stream;
use Alltube\Exception\EmptyUrlException;
use Alltube\Exception\PasswordException;
use Alltube\Video;
use Barracuda\ArchiveStream\ZipArchive;
use Psr\Http\Message\StreamInterface;
@ -86,20 +88,21 @@ class PlaylistArchiveStream extends ZipArchive implements StreamInterface
*
* @param string $string The string that is to be written
*
* @return void
* @return int|false
*/
public function write($string)
{
fwrite($this->buffer, $string);
return fwrite($this->buffer, $string);
}
/**
* Get the size of the stream if known.
*
* @return void
* @return int|null
*/
public function getSize()
{
return null;
}
/**
@ -145,7 +148,7 @@ class PlaylistArchiveStream extends ZipArchive implements StreamInterface
/**
* Returns the remaining contents in a string.
*
* @return string
* @return string|false
*/
public function getContents()
{
@ -196,7 +199,7 @@ class PlaylistArchiveStream extends ZipArchive implements StreamInterface
{
$this->rewind();
return $this->getContents();
return strval($this->getContents());
}
/**
@ -238,6 +241,8 @@ class PlaylistArchiveStream extends ZipArchive implements StreamInterface
* @param Video $video Video to stream
*
* @return void
* @throws PasswordException
* @throws EmptyUrlException
*/
protected function startVideoStream(Video $video)
{
@ -248,7 +253,7 @@ class PlaylistArchiveStream extends ZipArchive implements StreamInterface
$this->init_file_stream_transfer(
$video->getFilename(),
$contentLengthHeaders[0]
intval($contentLengthHeaders[0])
);
}

View file

@ -41,7 +41,7 @@ class YoutubeChunkStream implements StreamInterface
*/
public function read($length)
{
$size = $this->response->getHeader('Content-Length')[0];
$size = intval($this->response->getHeader('Content-Length')[0]);
if ($size - $this->tell() < $length) {
// Don't try to read further than the end of the stream.
$length = $size - $this->tell();
@ -55,7 +55,7 @@ class YoutubeChunkStream implements StreamInterface
*/
public function __toString()
{
return (string) $this->response->getBody();
return (string)$this->response->getBody();
}
/**

View file

@ -6,6 +6,8 @@
namespace Alltube\Stream;
use Alltube\Exception\EmptyUrlException;
use Alltube\Exception\PasswordException;
use Alltube\Video;
use GuzzleHttp\Psr7\AppendStream;
@ -19,6 +21,8 @@ class YoutubeStream extends AppendStream
* YoutubeStream constructor.
*
* @param Video $video Video to stream
* @throws EmptyUrlException
* @throws PasswordException
*/
public function __construct(Video $video)
{
@ -31,7 +35,7 @@ class YoutubeStream extends AppendStream
while ($rangeStart < $contentLenghtHeader[0]) {
$rangeEnd = $rangeStart + $video->downloader_options->http_chunk_size;
if ($rangeEnd >= $contentLenghtHeader[0]) {
$rangeEnd = $contentLenghtHeader[0] - 1;
$rangeEnd = intval($contentLenghtHeader[0]) - 1;
}
$response = $video->getHttpResponse(['Range' => 'bytes=' . $rangeStart . '-' . $rangeEnd]);
$this->addStream(new YoutubeChunkStream($response));