aboutsummaryrefslogtreecommitdiff
path: root/p/ext.php
diff options
context:
space:
mode:
authorGravatar Alexandre Alapetite <alexandre@alapetite.fr> 2023-01-29 18:53:51 +0100
committerGravatar GitHub <noreply@github.com> 2023-01-29 18:53:51 +0100
commit4f316b2ed397bb331ef89f2cd2d8ce92a725ccba (patch)
tree6d74cfa825724d483d43b23fdf90aadb1e46262a /p/ext.php
parent2303b29e68d16fbf0a173ab2b4b0ac736041905c (diff)
PHPStan level 9 for ./p/ and lib_rss.php (#5049)
And app/FreshRSS.php Contributes to https://github.com/FreshRSS/FreshRSS/issues/4112
Diffstat (limited to 'p/ext.php')
-rw-r--r--p/ext.php16
1 files changed, 9 insertions, 7 deletions
diff --git a/p/ext.php b/p/ext.php
index 9427f8c20..abc07ad12 100644
--- a/p/ext.php
+++ b/p/ext.php
@@ -13,10 +13,7 @@ const SUPPORTED_TYPES = [
'svg' => 'image/svg+xml',
];
-/**
- * @return string
- */
-function get_absolute_filename(string $file_name) {
+function get_absolute_filename(string $file_name): string {
$core_extension = realpath(CORE_EXTENSIONS_PATH . '/' . $file_name);
if (false !== $core_extension) {
return $core_extension;
@@ -40,9 +37,12 @@ function get_absolute_filename(string $file_name) {
return '';
}
-function is_valid_path_extension($path, $extensionPath, $isStatic = true) {
+function is_valid_path_extension(string $path, string $extensionPath, bool $isStatic = true): bool {
// It must be under the extension path.
$real_ext_path = realpath($extensionPath);
+ if ($real_ext_path == false) {
+ return false;
+ }
//Windows compatibility
$real_ext_path = str_replace('\\', '/', $real_ext_path);
@@ -60,7 +60,7 @@ function is_valid_path_extension($path, $extensionPath, $isStatic = true) {
// Static files to serve must be under a `ext_dir/static/` directory.
$path_relative_to_ext = substr($path, strlen($real_ext_path) + 1);
- list(,$static,$file) = sscanf($path_relative_to_ext, '%[^/]/%[^/]/%s');
+ list(, $static, $file) = sscanf($path_relative_to_ext, '%[^/]/%[^/]/%s') ?? [null, null, null];
if (null === $file || 'static' !== $static) {
return false;
}
@@ -78,16 +78,18 @@ function is_valid_path_extension($path, $extensionPath, $isStatic = true) {
* @return bool true if it can be served, false otherwise.
*
*/
-function is_valid_path($path) {
+function is_valid_path(string $path): bool {
return is_valid_path_extension($path, CORE_EXTENSIONS_PATH) || is_valid_path_extension($path, THIRDPARTY_EXTENSIONS_PATH)
|| is_valid_path_extension($path, USERS_PATH, false);
}
+/** @return never */
function sendBadRequestResponse(string $message = null) {
header('HTTP/1.1 400 Bad Request');
die($message);
}
+/** @return never */
function sendNotFoundResponse() {
header('HTTP/1.1 404 Not Found');
die();