From 71d49ad74ffb25e7f6be4eea1890c4fc64136887 Mon Sep 17 00:00:00 2001 From: Pierre Rudloff Date: Wed, 13 May 2020 21:18:32 +0200 Subject: [PATCH] Lint --- classes/Config.php | 21 ++++++------- classes/Locale.php | 4 ++- classes/LocaleManager.php | 1 - classes/LocaleMiddleware.php | 4 ++- classes/Video.php | 26 +++++++++++++--- classes/ViewFactory.php | 4 ++- .../ConvertedPlaylistArchiveStream.php | 2 ++ classes/streams/PlaylistArchiveStream.php | 6 ++-- classes/streams/YoutubeChunkStream.php | 8 ++--- composer.json | 4 ++- composer.lock | 7 +++-- controllers/DownloadController.php | 31 ++++++++++++++----- controllers/FrontController.php | 4 +-- 13 files changed, 83 insertions(+), 39 deletions(-) diff --git a/classes/Config.php b/classes/Config.php index 270d394..88fc0cc 100644 --- a/classes/Config.php +++ b/classes/Config.php @@ -7,6 +7,7 @@ namespace Alltube; use Exception; +use Jawira\CaseConverter\CaseConverterException; use Symfony\Component\Yaml\Yaml; use Jawira\CaseConverter\Convert; @@ -121,13 +122,6 @@ class Config */ public $appName = 'AllTube Download'; - /** - * YAML config file path. - * - * @var string - */ - private $file; - /** * Generic formats supported by youtube-dl. * @@ -156,9 +150,9 @@ class Config if (empty($this->genericFormats)) { // We don't put this in the class definition so it can be detected by xgettext. $this->genericFormats = [ - 'best' => $localeManager->t('Best'), + 'best' => $localeManager->t('Best'), 'bestvideo+bestaudio' => $localeManager->t('Remux best video with best audio'), - 'worst' => $localeManager->t('Worst'), + 'worst' => $localeManager->t('Worst'), ]; } @@ -195,10 +189,10 @@ class Config /** * Throw an exception if some of the options are invalid. * - * @throws Exception If youtube-dl is missing + * @return void * @throws Exception If Python is missing * - * @return void + * @throws Exception If youtube-dl is missing */ private function validateOptions() { @@ -235,6 +229,7 @@ class Config * If the value is an array, you should use the YAML format: "CONVERT_ADVANCED_FORMATS='[foo, bar]'" * * @return void + * @throws CaseConverterException */ private function getEnv() { @@ -265,6 +260,7 @@ class Config * Set options from a YAML file. * * @param string $file Path to the YAML file + * @throws Exception */ public static function setFile($file) { @@ -281,7 +277,8 @@ class Config * Manually set some options. * * @param array $options Options (see `config/config.example.yml` for available options) - * @param bool $update True to update an existing instance + * @param bool $update True to update an existing instance + * @throws Exception */ public static function setOptions(array $options, $update = true) { diff --git a/classes/Locale.php b/classes/Locale.php index 50e9055..2d27721 100644 --- a/classes/Locale.php +++ b/classes/Locale.php @@ -104,12 +104,14 @@ class Locale /** * Get country information from locale. * - * @return Country|array + * @return Country|array|null */ public function getCountry() { if (isset($this->region)) { return country($this->getIso3166()); } + + return null; } } diff --git a/classes/LocaleManager.php b/classes/LocaleManager.php index e34e6f5..12c14dd 100644 --- a/classes/LocaleManager.php +++ b/classes/LocaleManager.php @@ -7,7 +7,6 @@ namespace Alltube; use Aura\Session\Segment; -use Symfony\Component\Process\Process; use Symfony\Component\Translation\Translator; use Symfony\Component\Translation\Loader\PoFileLoader; diff --git a/classes/LocaleMiddleware.php b/classes/LocaleMiddleware.php index f1ba610..5d0aac5 100644 --- a/classes/LocaleMiddleware.php +++ b/classes/LocaleMiddleware.php @@ -38,7 +38,7 @@ class LocaleMiddleware * * @param array $proposedLocale Locale array created by AcceptLanguage::parse() * - * @return Locale Locale if chosen, nothing otherwise + * @return Locale|null Locale if chosen, nothing otherwise */ public function testLocale(array $proposedLocale) { @@ -52,6 +52,8 @@ class LocaleMiddleware return new Locale($proposedLocale['language'] . '_' . $proposedLocale['region']); } } + + return null; } /** diff --git a/classes/Video.php b/classes/Video.php index eb794cb..3bfdede 100644 --- a/classes/Video.php +++ b/classes/Video.php @@ -10,6 +10,7 @@ use Alltube\Exception\EmptyUrlException; use Alltube\Exception\PasswordException; use Exception; use GuzzleHttp\Client; +use GuzzleHttp\Exception\GuzzleException; use GuzzleHttp\Psr7\Response; use stdClass; use Symfony\Component\Process\Process; @@ -124,7 +125,9 @@ class Video * List all extractors. * * @return string[] Extractors - * */ + * + * @throws PasswordException + */ public static function getExtractors() { $video = new self(''); @@ -172,6 +175,7 @@ class Video * @param string $prop Property * * @return string + * @throws PasswordException */ private function getProp($prop = 'dump-json') { @@ -196,7 +200,9 @@ class Video * Get all information about a video. * * @return stdClass Decoded JSON - * */ + * + * @throws PasswordException + */ public function getJson() { if (!isset($this->json)) { @@ -212,12 +218,15 @@ class Video * @param string $name Property * * @return mixed + * @throws PasswordException */ public function __get($name) { if (isset($this->$name)) { return $this->getJson()->$name; } + + return null; } /** @@ -226,6 +235,7 @@ class Video * @param string $name Property * * @return bool + * @throws PasswordException */ public function __isset($name) { @@ -240,7 +250,9 @@ class Video * (eg. bestvideo+bestaudio). * * @return string[] URLs of video - * */ + * @throws EmptyUrlException + * @throws PasswordException + */ public function getUrl() { // Cache the URLs. @@ -259,7 +271,9 @@ class Video * Get filename of video file from URL of page. * * @return string Filename of extracted video - * */ + * + * @throws PasswordException + */ public function getFilename() { return trim($this->getProp('get-filename')); @@ -271,6 +285,7 @@ class Video * @param string $extension New file extension * * @return string Filename of extracted video with specified extension + * @throws PasswordException */ public function getFileNameWithExtension($extension) { @@ -601,6 +616,9 @@ class Video * @param array $headers HTTP headers of the request * * @return Response + * @throws EmptyUrlException + * @throws PasswordException + * @throws GuzzleException */ public function getHttpResponse(array $headers = []) { diff --git a/classes/ViewFactory.php b/classes/ViewFactory.php index 835b471..89e52ec 100644 --- a/classes/ViewFactory.php +++ b/classes/ViewFactory.php @@ -10,6 +10,7 @@ use Psr\Container\ContainerInterface; use Slim\Http\Request; use Slim\Views\Smarty; use Slim\Views\SmartyPlugins; +use SmartyException; /** * Create Smarty view object. @@ -20,9 +21,10 @@ class ViewFactory * Create Smarty view object. * * @param ContainerInterface $container Slim dependency container - * @param Request $request PSR-7 request + * @param Request $request PSR-7 request * * @return Smarty + * @throws SmartyException */ public static function create(ContainerInterface $container, Request $request = null) { diff --git a/classes/streams/ConvertedPlaylistArchiveStream.php b/classes/streams/ConvertedPlaylistArchiveStream.php index fcc206c..c336663 100644 --- a/classes/streams/ConvertedPlaylistArchiveStream.php +++ b/classes/streams/ConvertedPlaylistArchiveStream.php @@ -7,6 +7,7 @@ namespace Alltube\Stream; use Alltube\Video; +use Exception; use Slim\Http\Stream; /** @@ -20,6 +21,7 @@ class ConvertedPlaylistArchiveStream extends PlaylistArchiveStream * @param Video $video Video to stream * * @return void + * @throws Exception */ protected function startVideoStream(Video $video) { diff --git a/classes/streams/PlaylistArchiveStream.php b/classes/streams/PlaylistArchiveStream.php index 7a0871e..8fe4878 100644 --- a/classes/streams/PlaylistArchiveStream.php +++ b/classes/streams/PlaylistArchiveStream.php @@ -86,7 +86,7 @@ class PlaylistArchiveStream extends ZipArchive implements StreamInterface * * @param string $string The string that is to be written * - * @return int + * @return void */ public function write($string) { @@ -96,7 +96,7 @@ class PlaylistArchiveStream extends ZipArchive implements StreamInterface /** * Get the size of the stream if known. * - * @return null + * @return void */ public function getSize() { @@ -170,6 +170,8 @@ class PlaylistArchiveStream extends ZipArchive implements StreamInterface if (isset($meta[$key])) { return $meta[$key]; } + + return null; } /** diff --git a/classes/streams/YoutubeChunkStream.php b/classes/streams/YoutubeChunkStream.php index 6328fb9..69ee98a 100644 --- a/classes/streams/YoutubeChunkStream.php +++ b/classes/streams/YoutubeChunkStream.php @@ -124,21 +124,21 @@ class YoutubeChunkStream implements StreamInterface * @param int $offset Stream offset * @param int $whence Specifies how the cursor position will be calculated * - * @return mixed + * @return void */ public function seek($offset, $whence = SEEK_SET) { - return $this->response->getBody()->seek($offset, $whence); + $this->response->getBody()->seek($offset, $whence); } /** * Seek to the beginning of the stream. * - * @return mixed + * @return void */ public function rewind() { - return $this->response->getBody()->rewind(); + $this->response->getBody()->rewind(); } /** diff --git a/composer.json b/composer.json index 43b064b..db707a8 100644 --- a/composer.json +++ b/composer.json @@ -16,7 +16,9 @@ "symfony/process": "^4.0", "symfony/translation": "^4.0", "symfony/yaml": "^4.0", - "zonuexe/http-accept-language": "~0.4.1" + "zonuexe/http-accept-language": "~0.4.1", + "ext-intl": "*", + "ext-json": "*" }, "require-dev": { "anam/phantomjs-linux-x86-binary": "~2.1.1", diff --git a/composer.lock b/composer.lock index 4a82444..8e38216 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "84661260029cd1e5b182272542fe65fa", + "content-hash": "e2043abf0f043d0ef514f2e517b3b8fc", "packages": [ { "name": "aura/session", @@ -6034,7 +6034,10 @@ }, "prefer-stable": false, "prefer-lowest": false, - "platform": [], + "platform": { + "ext-intl": "*", + "ext-json": "*" + }, "platform-dev": [], "platform-overrides": { "php": "7.3.11" diff --git a/controllers/DownloadController.php b/controllers/DownloadController.php index e9e2fca..b765a39 100644 --- a/controllers/DownloadController.php +++ b/controllers/DownloadController.php @@ -13,6 +13,7 @@ use Alltube\Stream\PlaylistArchiveStream; use Alltube\Stream\YoutubeStream; use Alltube\Video; use Exception; +use GuzzleHttp\Exception\GuzzleException; use Slim\Http\Request; use Slim\Http\Response; use Slim\Http\Stream; @@ -66,10 +67,12 @@ class DownloadController extends BaseController /** * Return a converted MP3 file. * - * @param Request $request PSR-7 request + * @param Request $request PSR-7 request * @param Response $response PSR-7 response * * @return Response HTTP response + * @throws PasswordException + * @throws Exception */ private function getConvertedAudioResponse(Request $request, Response $response) { @@ -100,10 +103,11 @@ class DownloadController extends BaseController /** * Return the MP3 file. * - * @param Request $request PSR-7 request + * @param Request $request PSR-7 request * @param Response $response PSR-7 response * * @return Response HTTP response + * @throws PasswordException */ private function getAudioResponse(Request $request, Response $response) { @@ -139,10 +143,13 @@ class DownloadController extends BaseController /** * Get a video/audio stream piped through the server. * - * @param Response $response PSR-7 response - * @param Request $request PSR-7 request + * @param Request $request PSR-7 request * + * @param Response $response PSR-7 response * @return Response HTTP response + * @throws EmptyUrlException + * @throws PasswordException + * @throws GuzzleException */ private function getStream(Request $request, Response $response) { @@ -205,9 +212,11 @@ class DownloadController extends BaseController * Get a remuxed stream piped through the server. * * @param Response $response PSR-7 response - * @param Request $request PSR-7 request + * @param Request $request PSR-7 request * * @return Response HTTP response + * @throws PasswordException + * @throws Exception */ private function getRemuxStream(Request $request, Response $response) { @@ -230,10 +239,14 @@ class DownloadController extends BaseController * Get approriate HTTP response to download query. * Depends on whether we want to stream, remux or simply redirect. * - * @param Response $response PSR-7 response - * @param Request $request PSR-7 request + * @param Request $request PSR-7 request * + * @param Response $response PSR-7 response * @return Response HTTP response + * @throws EmptyUrlException + * @throws GuzzleException + * @throws PasswordException + * @throws Exception */ private function getDownloadResponse(Request $request, Response $response) { @@ -262,10 +275,12 @@ class DownloadController extends BaseController /** * Return a converted video file. * - * @param Request $request PSR-7 request + * @param Request $request PSR-7 request * @param Response $response PSR-7 response * * @return Response HTTP response + * @throws PasswordException + * @throws Exception */ private function getConvertedResponse(Request $request, Response $response) { diff --git a/controllers/FrontController.php b/controllers/FrontController.php index e5e8b47..e5f4536 100644 --- a/controllers/FrontController.php +++ b/controllers/FrontController.php @@ -12,7 +12,6 @@ use Alltube\Video; use Throwable; use Exception; use Psr\Container\ContainerInterface; -use Slim\Container; use Slim\Http\Request; use Slim\Http\Response; use Slim\Views\Smarty; @@ -92,10 +91,11 @@ class FrontController extends BaseController /** * Display a list of extractors. * - * @param Request $request PSR-7 request + * @param Request $request PSR-7 request * @param Response $response PSR-7 response * * @return Response HTTP response + * @throws PasswordException */ public function extractors(Request $request, Response $response) {