From 71647158d385349a86b87393a916bae9652d9a94 Mon Sep 17 00:00:00 2001 From: Pierre Rudloff Date: Tue, 21 Mar 2023 20:18:21 +0100 Subject: [PATCH] Stronger typying now that we target PHP 7.4 --- classes/Config.php | 38 +++++++++++++----------- classes/Controller/BaseController.php | 6 ++-- classes/LocaleManager.php | 6 ++-- classes/Stream/PlaylistArchiveStream.php | 8 ++--- classes/Stream/YoutubeChunkStream.php | 2 +- 5 files changed, 31 insertions(+), 29 deletions(-) diff --git a/classes/Config.php b/classes/Config.php index 919e1b4..5358564 100644 --- a/classes/Config.php +++ b/classes/Config.php @@ -24,84 +24,86 @@ class Config * * @var string */ - public $youtubedl = 'vendor/ytdl-org/youtube-dl/youtube_dl/__main__.py'; + public string $youtubedl = 'vendor/ytdl-org/youtube-dl/youtube_dl/__main__.py'; /** * python binary path. * * @var string */ - public $python = '/usr/bin/python'; + public string $python = '/usr/bin/python'; /** * youtube-dl parameters. * * @var string[] */ - public $params = ['--no-warnings', '--ignore-errors', '--flat-playlist', '--restrict-filenames', '--no-playlist']; + public array $params = [ + '--no-warnings', '--ignore-errors', '--flat-playlist', '--restrict-filenames', '--no-playlist' + ]; /** * Enable audio conversion. * * @var bool */ - public $convert = false; + public bool $convert = false; /** * Enable advanced conversion mode. * * @var bool */ - public $convertAdvanced = false; + public bool $convertAdvanced = false; /** * List of formats available in advanced conversion mode. * * @var string[] */ - public $convertAdvancedFormats = ['mp3', 'avi', 'flv', 'wav']; + public array $convertAdvancedFormats = ['mp3', 'avi', 'flv', 'wav']; /** * ffmpeg binary path. * * @var string */ - public $ffmpeg = '/usr/bin/ffmpeg'; + public string $ffmpeg = '/usr/bin/ffmpeg'; /** * Path to the directory that contains the phantomjs binary. * * @var string */ - public $phantomjsDir = '/usr/bin/'; + public string $phantomjsDir = '/usr/bin/'; /** * Disable URL rewriting. * * @var bool */ - public $uglyUrls = false; + public bool $uglyUrls = false; /** * Stream downloaded files trough server? * * @var bool */ - public $stream = false; + public bool $stream = false; /** * Allow to remux video + audio? * * @var bool */ - public $remux = false; + public bool $remux = false; /** * MP3 bitrate when converting (in kbit/s). * * @var int */ - public $audioBitrate = 128; + public int $audioBitrate = 128; /** * ffmpeg logging level. @@ -109,21 +111,21 @@ class Config * * @var string */ - public $ffmpegVerbosity = 'error'; + public string $ffmpegVerbosity = 'error'; /** * App name. * * @var string */ - public $appName = 'AllTube Download'; + public string $appName = 'AllTube Download'; /** * Generic formats supported by youtube-dl. * * @var string[] */ - public $genericFormats = [ + public array $genericFormats = [ 'best/bestvideo' => 'Best', 'bestvideo+bestaudio' => 'Remux best video with best audio', 'worst/worstvideo' => 'Worst', @@ -134,21 +136,21 @@ class Config * * @var bool */ - public $debug = false; + public bool $debug = false; /** * Default to audio. * * @var bool */ - public $defaultAudio = false; + public bool $defaultAudio = false; /** * Disable audio conversion from/to seeker. * * @var bool */ - public $convertSeek = true; + public bool $convertSeek = true; /** * Config constructor. diff --git a/classes/Controller/BaseController.php b/classes/Controller/BaseController.php index 9562bc3..ee16653 100644 --- a/classes/Controller/BaseController.php +++ b/classes/Controller/BaseController.php @@ -30,21 +30,21 @@ abstract class BaseController * * @var Video */ - protected $video; + protected Video $video; /** * Default youtube-dl format. * * @var string */ - protected $defaultFormat = 'best/bestvideo'; + protected string $defaultFormat = 'best/bestvideo'; /** * Slim dependency container. * * @var ContainerInterface */ - protected $container; + protected ContainerInterface $container; /** * Config instance. diff --git a/classes/LocaleManager.php b/classes/LocaleManager.php index 0b4c9a2..c8aff44 100644 --- a/classes/LocaleManager.php +++ b/classes/LocaleManager.php @@ -27,14 +27,14 @@ class LocaleManager * * @var Locale|null */ - private $curLocale; + private ?Locale $curLocale = null; /** * Session segment used to store session variables. * * @var Segment */ - private $sessionSegment; + private Segment $sessionSegment; /** * Default locale. @@ -48,7 +48,7 @@ class LocaleManager * * @var Translator */ - private $translator; + private Translator $translator; /** * LocaleManager constructor. diff --git a/classes/Stream/PlaylistArchiveStream.php b/classes/Stream/PlaylistArchiveStream.php index 58c052f..7f57ecf 100644 --- a/classes/Stream/PlaylistArchiveStream.php +++ b/classes/Stream/PlaylistArchiveStream.php @@ -24,7 +24,7 @@ class PlaylistArchiveStream extends ZipArchive implements StreamInterface * * @var Video[] */ - private $videos = []; + private array $videos = []; /** * Stream used to store data before it is sent to the browser. @@ -38,21 +38,21 @@ class PlaylistArchiveStream extends ZipArchive implements StreamInterface * * @var StreamInterface */ - protected $curVideoStream; + protected StreamInterface $curVideoStream; /** * True if the archive is complete. * * @var bool */ - private $isComplete = false; + private bool $isComplete = false; /** * Downloader object. * * @var Downloader */ - protected $downloader; + protected Downloader $downloader; /** * PlaylistArchiveStream constructor. diff --git a/classes/Stream/YoutubeChunkStream.php b/classes/Stream/YoutubeChunkStream.php index 6632eb2..950afae 100644 --- a/classes/Stream/YoutubeChunkStream.php +++ b/classes/Stream/YoutubeChunkStream.php @@ -20,7 +20,7 @@ class YoutubeChunkStream implements StreamInterface * * @var ResponseInterface */ - private $response; + private ResponseInterface $response; /** * YoutubeChunkStream constructor.