From 69d09b780e01ec0f3e6e3d123be14fa3b981b64e Mon Sep 17 00:00:00 2001 From: Pierre Rudloff Date: Sat, 17 Oct 2020 22:47:16 +0200 Subject: [PATCH] Lint --- classes/Downloader.php | 59 ++++++++++++------- classes/Exception/AvconvException.php | 2 +- .../InvalidProtocolConversionException.php | 2 +- classes/Exception/InvalidTimeException.php | 2 +- classes/Video.php | 16 ++--- 5 files changed, 50 insertions(+), 31 deletions(-) diff --git a/classes/Downloader.php b/classes/Downloader.php index ebf0a4a..ee810eb 100644 --- a/classes/Downloader.php +++ b/classes/Downloader.php @@ -4,6 +4,7 @@ namespace Alltube\Library; use Alltube\Library\Exception\AlltubeLibraryException; use Alltube\Library\Exception\AvconvException; +use Alltube\Library\Exception\EmptyUrlException; use Alltube\Library\Exception\InvalidProtocolConversionException; use Alltube\Library\Exception\InvalidTimeException; use Alltube\Library\Exception\PasswordException; @@ -111,10 +112,10 @@ class Downloader /** * @param string $webpageUrl URL of the page containing the video * @param string $requestedFormat Requested video format - * @param string $password Password + * @param string|null $password Password * @return Video */ - public function getVideo($webpageUrl, $requestedFormat = 'best/bestvideo', $password = null) + public function getVideo(string $webpageUrl, $requestedFormat = 'best/bestvideo', string $password = null) { return new Video($this, $webpageUrl, $requestedFormat, $password); } @@ -159,21 +160,24 @@ class Downloader * @param int $audioBitrate Audio bitrate of the converted file * @param string $filetype Filetype of the converted file * @param bool $audioOnly True to return an audio-only file - * @param string $from Start the conversion at this time - * @param string $to End the conversion at this time + * @param string|null $from Start the conversion at this time + * @param string|null $to End the conversion at this time * * @return Process Process - * @throws AlltubeLibraryException * @throws AvconvException If avconv/ffmpeg is missing + * @throws EmptyUrlException * @throws InvalidTimeException + * @throws PasswordException + * @throws WrongPasswordException + * @throws YoutubedlException */ private function getAvconvProcess( Video $video, - $audioBitrate, + int $audioBitrate, $filetype = 'mp3', $audioOnly = true, - $from = null, - $to = null + string $from = null, + string $to = null ) { if (!$this->checkCommand([$this->avconv, '-version'])) { throw new AvconvException($this->avconv); @@ -309,13 +313,22 @@ class Downloader * * @param Video $video Video object * @param int $audioBitrate MP3 bitrate when converting (in kbit/s) - * @param string $from Start the conversion at this time - * @param string $to End the conversion at this time + * @param string|null $from Start the conversion at this time + * @param string|null $to End the conversion at this time * * @return resource popen stream - * @throws AlltubeLibraryException + * @throws AvconvException + * @throws EmptyUrlException + * @throws InvalidProtocolConversionException + * @throws InvalidTimeException + * @throws PasswordException + * @throws PlaylistConversionException + * @throws PopenStreamException + * @throws RemuxException + * @throws WrongPasswordException + * @throws YoutubedlException */ - public function getAudioStream(Video $video, $audioBitrate = 128, $from = null, $to = null) + public function getAudioStream(Video $video, $audioBitrate = 128, string $from = null, string $to = null) { return $this->getConvertedStream($video, $audioBitrate, 'mp3', true, $from, $to); } @@ -402,22 +415,28 @@ class Downloader * @param int $audioBitrate Audio bitrate of the converted file * @param string $filetype Filetype of the converted file * @param bool $audioOnly True to return an audio-only file - * @param string $from Start the conversion at this time - * @param string $to End the conversion at this time + * @param string|null $from Start the conversion at this time + * @param string|null $to End the conversion at this time * * @return resource popen stream - * @throws AlltubeLibraryException - * @throws PopenStreamException If the popen stream was not created correctly + * @throws AvconvException + * @throws EmptyUrlException * @throws InvalidProtocolConversionException If you try to convert an M3U or Dash media + * @throws InvalidTimeException + * @throws PasswordException * @throws PlaylistConversionException If you try to convert a playlist + * @throws PopenStreamException If the popen stream was not created correctly + * @throws RemuxException + * @throws WrongPasswordException + * @throws YoutubedlException */ public function getConvertedStream( Video $video, - $audioBitrate, - $filetype, + int $audioBitrate, + string $filetype, $audioOnly = false, - $from = null, - $to = null + string $from = null, + string $to = null ) { if (isset($video->_type) && $video->_type == 'playlist') { throw new PlaylistConversionException(); diff --git a/classes/Exception/AvconvException.php b/classes/Exception/AvconvException.php index 760c8e9..70983e3 100644 --- a/classes/Exception/AvconvException.php +++ b/classes/Exception/AvconvException.php @@ -11,7 +11,7 @@ class AvconvException extends AlltubeLibraryException * AvconvException constructor. * @param string $path Path to avconv or ffmpeg. */ - public function __construct($path) + public function __construct(string $path) { parent::__construct("Can't find avconv or ffmpeg at " . $path . '.'); } diff --git a/classes/Exception/InvalidProtocolConversionException.php b/classes/Exception/InvalidProtocolConversionException.php index 8f5fbbc..e8cec37 100644 --- a/classes/Exception/InvalidProtocolConversionException.php +++ b/classes/Exception/InvalidProtocolConversionException.php @@ -11,7 +11,7 @@ class InvalidProtocolConversionException extends AlltubeLibraryException * InvalidProtocolConversionException constructor. * @param string $protocol Protocol */ - public function __construct($protocol) + public function __construct(string $protocol) { parent::__construct($protocol . ' protocol is not supported in conversions.'); } diff --git a/classes/Exception/InvalidTimeException.php b/classes/Exception/InvalidTimeException.php index 8fbfaa1..1e19188 100644 --- a/classes/Exception/InvalidTimeException.php +++ b/classes/Exception/InvalidTimeException.php @@ -12,7 +12,7 @@ class InvalidTimeException extends AlltubeLibraryException * InvalidTimeException constructor. * @param string $time Invalid time */ - public function __construct($time) + public function __construct(string $time) { parent::__construct('Invalid time: ' . $time); } diff --git a/classes/Video.php b/classes/Video.php index df6aced..9efb554 100644 --- a/classes/Video.php +++ b/classes/Video.php @@ -81,13 +81,13 @@ class Video * @param string $requestedFormat Requested video format * (can be any format string accepted by youtube-dl, * including selectors like "[height<=720]") - * @param string $password Password + * @param string|null $password Password */ public function __construct( Downloader $downloader, - $webpageUrl, - $requestedFormat, - $password = null + string $webpageUrl, + string $requestedFormat, + string $password = null ) { $this->downloader = $downloader; $this->webpageUrl = $webpageUrl; @@ -151,7 +151,7 @@ class Video * @throws WrongPasswordException * @throws YoutubedlException */ - public function __get($name) + public function __get(string $name) { if (isset($this->$name)) { return $this->getJson()->$name; @@ -170,7 +170,7 @@ class Video * @throws WrongPasswordException * @throws YoutubedlException */ - public function __isset($name) + public function __isset(string $name) { return isset($this->getJson()->$name); } @@ -225,7 +225,7 @@ class Video * @throws WrongPasswordException * @throws YoutubedlException */ - public function getFileNameWithExtension($extension) + public function getFileNameWithExtension(string $extension) { if (isset($this->ext)) { return str_replace('.' . $this->ext, '.' . $extension, $this->getFilename()); @@ -278,7 +278,7 @@ class Video * * @return Video */ - public function withFormat($format) + public function withFormat(string $format) { return new self($this->downloader, $this->webpageUrl, $format, $this->password); }