From 2038d50110468d95ff978ba2e8f997175f25ff3b Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Mon, 15 May 2023 19:26:48 +0200 Subject: PHPStan Level 7 for Minz_Request, FreshRSS_Feed, Minz_Error (#5400) * PHPStan Level 7 for Minz_Request * PHPStan Level 7 for FreshRSS_Feed * PHPStan Level 7 for Minz_Error --- lib/Minz/Request.php | 35 +++++++++++++++-------------------- 1 file changed, 15 insertions(+), 20 deletions(-) (limited to 'lib/Minz/Request.php') diff --git a/lib/Minz/Request.php b/lib/Minz/Request.php index f8f9d750e..95cb220bf 100644 --- a/lib/Minz/Request.php +++ b/lib/Minz/Request.php @@ -20,8 +20,8 @@ class Minz_Request { /** @var string */ private static $default_action_name = 'index'; - /** @var array{'c':string,'a':string,'params':array}|null */ - private static $originalRequest = null; + /** @var array{'c'?:string,'a'?:string,'params'?:array} */ + private static $originalRequest = []; /** * Getteurs @@ -121,7 +121,7 @@ class Minz_Request { */ public static function paramTextToArray(string $key, array $default = []): array { if (isset(self::$params[$key])) { - return preg_split('/\R/', self::$params[$key]); + return preg_split('/\R/', self::$params[$key]) ?: []; } return $default; } @@ -141,8 +141,8 @@ class Minz_Request { ]; } - /** @return array{'c':string,'a':string,'params':array}|null */ - public static function originalRequest(): ?array { + /** @return array{'c'?:string,'a'?:string,'params'?:array} */ + public static function originalRequest() { return self::$originalRequest; } @@ -219,7 +219,7 @@ class Minz_Request { $prefix = self::extractPrefix(); $path = self::extractPath(); - return filter_var("{$protocol}://{$host}{$port}{$prefix}{$path}", FILTER_SANITIZE_URL); + return filter_var("{$protocol}://{$host}{$port}{$prefix}{$path}", FILTER_SANITIZE_URL) ?: ''; } private static function extractProtocol(): string { @@ -231,11 +231,11 @@ class Minz_Request { private static function extractHost(): string { if ('' != $host = ($_SERVER['HTTP_X_FORWARDED_HOST'] ?? '')) { - return parse_url("http://{$host}", PHP_URL_HOST); + return parse_url("http://{$host}", PHP_URL_HOST) ?: 'localhost'; } if ('' != $host = ($_SERVER['HTTP_HOST'] ?? '')) { // Might contain a port number, and mind IPv6 addresses - return parse_url("http://{$host}", PHP_URL_HOST); + return parse_url("http://{$host}", PHP_URL_HOST) ?: 'localhost'; } if ('' != $host = ($_SERVER['SERVER_NAME'] ?? '')) { return $host; @@ -276,7 +276,7 @@ class Minz_Request { private static function extractPath(): string { $path = $_SERVER['REQUEST_URI'] ?? ''; if ($path != '') { - $path = parse_url($path, PHP_URL_PATH); + $path = parse_url($path, PHP_URL_PATH) ?: ''; return substr($path, -1) === '/' ? rtrim($path, '/') : dirname($path); } return ''; @@ -288,7 +288,7 @@ class Minz_Request { public static function getBaseUrl(): string { $conf = Minz_Configuration::get('system'); $url = trim($conf->base_url, ' /\\"'); - return filter_var($url, FILTER_SANITIZE_URL); + return filter_var($url, FILTER_SANITIZE_URL) ?: ''; } /** @@ -374,21 +374,15 @@ class Minz_Request { } /** - * Relance une requête - * @param string|array{'c'?:string,'a'?:string,'params'?:array} $url l'url vers laquelle est relancée la requête - * @param bool $redirect si vrai, force la redirection http - * > sinon, le dispatcher recharge en interne + * Restart a request + * @param array{'c'?:string,'a'?:string,'params'?:array} $url an array presentation of the URL to route to + * @param bool $redirect If true, uses an HTTP redirection, and if false (default), performs an internal dispatcher redirection. */ public static function forward($url = [], bool $redirect = false): void { if (empty(Minz_Request::originalRequest())) { self::$originalRequest = $url; } - if (!is_array($url)) { - header('Location: ' . $url); - exit(); - } - $url = Minz_Url::checkControllerUrl($url); $url['params']['rid'] = self::requestId(); @@ -433,7 +427,8 @@ class Minz_Request { if ('application/json' !== self::extractContentType()) { return; } - if ('' === $ORIGINAL_INPUT = file_get_contents('php://input', false, null, 0, 1048576)) { + $ORIGINAL_INPUT = file_get_contents('php://input', false, null, 0, 1048576); + if ($ORIGINAL_INPUT == false) { return; } if (null === $json = json_decode($ORIGINAL_INPUT, true)) { -- cgit v1.2.3