From d7c3bd0528f28ca4108f2ac62f8ad06fcaa93f62 Mon Sep 17 00:00:00 2001 From: Le Philousophe Date: Mon, 11 Aug 2025 12:46:01 +0200 Subject: [PATCH] WEB: Various small fixes These are either cosmetic or spotted by PHPStan --- include/Controller.php | 2 +- include/FileUtils.php | 4 +++- include/Models/BasicModel.php | 2 +- include/Models/GameDownloadsModel.php | 2 +- include/Models/ScreenshotsModel.php | 2 +- include/Objects/BasicObject.php | 2 +- include/Objects/File.php | 4 ++-- include/Pages/ArticlePage.php | 2 +- include/Pages/SimplePage.php | 4 ++-- 9 files changed, 13 insertions(+), 11 deletions(-) diff --git a/include/Controller.php b/include/Controller.php index bb580344..30c8addc 100644 --- a/include/Controller.php +++ b/include/Controller.php @@ -105,7 +105,7 @@ class Controller private function isRtl($localeName) { $rtl_chars_pattern = '/[\x{0590}-\x{05ff}\x{0600}-\x{06ff}]/u'; - return preg_match($rtl_chars_pattern, $localeName); + return preg_match($rtl_chars_pattern, $localeName) === 1; } /** diff --git a/include/FileUtils.php b/include/FileUtils.php index b5afe195..0fe870a1 100644 --- a/include/FileUtils.php +++ b/include/FileUtils.php @@ -8,6 +8,8 @@ use DateTime; */ class FileUtils { + private const DOUBLE_EXTENSIONS = ['.bz2', '.gz', '.lz', '.xz', '.7z']; + /** * Returns whether or not the file exists and is readable * @@ -60,7 +62,7 @@ class FileUtils $extension = substr($path, (strrpos($path, '.'))); // For certain extensions, check for another extension (e.g. foo.tar.gz => tar.gz) - if ($extension == '.bz2' || $extension == '.gz' || $extension == '.lz' || $extension == '.xz' || $extension == '.7z') { + if (in_array($extension, self::DOUBLE_EXTENSIONS)) { $extension = substr($path, strrpos($path, '.', -(strlen($path) - strrpos($path, '.') + 1))); } return $extension; diff --git a/include/Models/BasicModel.php b/include/Models/BasicModel.php index 2dbfe8a1..02edc29e 100644 --- a/include/Models/BasicModel.php +++ b/include/Models/BasicModel.php @@ -14,7 +14,7 @@ abstract class BasicModel public function __construct() { - if (is_null(self::$cache)) { + if (!isset(self::$cache)) { try { $driver = extension_loaded('redis') ? 'redis' : 'predis'; $database = DEV_SERVER ? 7 : 8; diff --git a/include/Models/GameDownloadsModel.php b/include/Models/GameDownloadsModel.php index c986c911..2fc83c6a 100644 --- a/include/Models/GameDownloadsModel.php +++ b/include/Models/GameDownloadsModel.php @@ -24,7 +24,7 @@ class GameDownloadsModel extends BasicModel foreach ($categories as $category) { $sections[$category] = new DownloadsSection([ 'anchor' => $category, - 'title' => $sectionsData[$category]['title'], + 'title' => $sectionsData[$category]['title'] ?? null, 'notes' => $sectionsData[$category]['notes'] ?? null ]); } diff --git a/include/Models/ScreenshotsModel.php b/include/Models/ScreenshotsModel.php index b666184c..0a9db4fe 100644 --- a/include/Models/ScreenshotsModel.php +++ b/include/Models/ScreenshotsModel.php @@ -131,7 +131,7 @@ class ScreenshotsModel extends BasicModel $combined[$subcategory] = $screenshot; } } - \sort($combined, SORT_STRING); + \ksort($combined, SORT_STRING); return $combined; } diff --git a/include/Objects/BasicObject.php b/include/Objects/BasicObject.php index 8ae77ae4..aa41d792 100644 --- a/include/Objects/BasicObject.php +++ b/include/Objects/BasicObject.php @@ -18,7 +18,7 @@ abstract class BasicObject public function __toString() { - return $this->getName(); + return $this->getName() ?? ''; } /* Get the name. */ diff --git a/include/Objects/File.php b/include/Objects/File.php index a9697846..6a2d54ff 100644 --- a/include/Objects/File.php +++ b/include/Objects/File.php @@ -23,8 +23,8 @@ class File extends BasicObject $this->autoId = $data['auto_id'] ?? null; $this->category = $data['category']; $this->category_icon = $data['category_icon']; - $this->notes = isset($data['notes']) ? $data['notes'] : ''; - $this->user_agent = isset($data["user_agent"]) ? $data["user_agent"] : ""; + $this->notes = $data['notes'] ?? ''; + $this->user_agent = $data['user_agent'] ?? ''; $this->version = isset($data['version']) ? strtolower($data['version']) : null; /* If it's not an array, we didn't get any attributes. */ diff --git a/include/Pages/ArticlePage.php b/include/Pages/ArticlePage.php index 0803d739..dd9efab9 100644 --- a/include/Pages/ArticlePage.php +++ b/include/Pages/ArticlePage.php @@ -39,7 +39,7 @@ class ArticlePage extends Controller /* Display the index page. */ public function index($params) { - if (!$params['article']) { + if (empty($params['article'])) { throw new \ErrorException(self::ARTICLE_NAME_MISSING); } $filename = $params['article'] . '.markdown'; diff --git a/include/Pages/SimplePage.php b/include/Pages/SimplePage.php index 9ab5f4d6..582ab14b 100644 --- a/include/Pages/SimplePage.php +++ b/include/Pages/SimplePage.php @@ -28,7 +28,7 @@ class SimplePage extends Controller throw new \ErrorException(\sprintf(self::FILE_NOT_FOUND, $templateFile)); } if (array_key_exists($key, self::PAGE_MODELS)) { - [$model, $data] = self::PAGE_MODELS[$key]; + list($model, $data) = self::PAGE_MODELS[$key]; $this->model = new SimpleYamlModel($model, $data); } } @@ -36,7 +36,7 @@ class SimplePage extends Controller /* Display the index page. */ public function index($data = null) { - if ($this->model) { + if (isset($this->model)) { $data = $this->model->getAllData(); }