From b02e255cb419cf6afbe89e8a82cf4713f06a3aae Mon Sep 17 00:00:00 2001 From: Pierre Rudloff Date: Sun, 5 Jul 2020 11:22:55 +0200 Subject: [PATCH] Avoid magic numbers --- classes/Controller/DownloadController.php | 5 +++-- classes/Controller/FrontController.php | 5 +++-- classes/Controller/JsonController.php | 3 ++- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/classes/Controller/DownloadController.php b/classes/Controller/DownloadController.php index dd3e46f..834f48d 100644 --- a/classes/Controller/DownloadController.php +++ b/classes/Controller/DownloadController.php @@ -21,6 +21,7 @@ use Alltube\Stream\PlaylistArchiveStream; use Alltube\Stream\YoutubeStream; use Slim\Http\Request; use Slim\Http\Response; +use Slim\Http\StatusCode; use Slim\Http\Stream; /** @@ -203,8 +204,8 @@ class DownloadController extends BaseController $response = $response->withHeader('Content-Length', $stream->getHeader('Content-Length')); $response = $response->withHeader('Accept-Ranges', $stream->getHeader('Accept-Ranges')); $response = $response->withHeader('Content-Range', $stream->getHeader('Content-Range')); - if ($stream->getStatusCode() == 206) { - $response = $response->withStatus(206); + if ($stream->getStatusCode() == StatusCode::HTTP_PARTIAL_CONTENT) { + $response = $response->withStatus(StatusCode::HTTP_PARTIAL_CONTENT); } if (isset($this->video->downloader_options->http_chunk_size)) { diff --git a/classes/Controller/FrontController.php b/classes/Controller/FrontController.php index 2b6109a..9526c0c 100644 --- a/classes/Controller/FrontController.php +++ b/classes/Controller/FrontController.php @@ -11,6 +11,7 @@ use Alltube\Library\Exception\AlltubeLibraryException; use Alltube\Library\Exception\WrongPasswordException; use Alltube\Locale; use Exception; +use Slim\Http\StatusCode; use Symfony\Component\ErrorHandler\ErrorRenderer\HtmlErrorRenderer; use Throwable; use Psr\Container\ContainerInterface; @@ -142,7 +143,7 @@ class FrontController extends BaseController ] ); - return $response->withStatus(403); + return $response->withStatus(StatusCode::HTTP_FORBIDDEN); } /** @@ -256,7 +257,7 @@ class FrontController extends BaseController ] ); - return $response->withStatus(500); + return $response->withStatus(StatusCode::HTTP_INTERNAL_SERVER_ERROR); } /** diff --git a/classes/Controller/JsonController.php b/classes/Controller/JsonController.php index 9e37cc2..1247c6b 100644 --- a/classes/Controller/JsonController.php +++ b/classes/Controller/JsonController.php @@ -9,6 +9,7 @@ namespace Alltube\Controller; use Alltube\Library\Exception\AlltubeLibraryException; use Slim\Http\Request; use Slim\Http\Response; +use Slim\Http\StatusCode; /** * Controller that returns JSON. @@ -38,7 +39,7 @@ class JsonController extends BaseController return $response->withJson($this->video->getJson()); } else { return $response->withJson(['error' => 'You need to provide the url parameter']) - ->withStatus(400); + ->withStatus(StatusCode::HTTP_BAD_REQUEST); } } }