From 7cd3ff2331a03daff9e455e93ffc7f121756df8c Mon Sep 17 00:00:00 2001 From: Le Philousophe Date: Fri, 6 Sep 2024 08:59:34 +0000 Subject: [PATCH] WEB: Various PHPStan fixes These fixes are only for correctness. --- include/ExceptionHandler.php | 2 +- include/FileUtils.php | 12 ++++++------ include/Models/ScreenshotsModel.php | 13 +++++++++---- include/Objects/File.php | 4 ++-- include/Pages/CompatibilityPage.php | 2 +- phpstan.neon | 13 +++++++------ 6 files changed, 26 insertions(+), 20 deletions(-) diff --git a/include/ExceptionHandler.php b/include/ExceptionHandler.php index b1397826..fddcc21d 100644 --- a/include/ExceptionHandler.php +++ b/include/ExceptionHandler.php @@ -21,7 +21,7 @@ abstract class ExceptionHandler $skip_menus = true; } else { foreach ($e->getTrace() as $t) { - if (basename($t['file']) == 'MenuModel.php') { + if (basename($t['file'] ?? '') == 'MenuModel.php') { $skip_menus = true; break; } diff --git a/include/FileUtils.php b/include/FileUtils.php index 1d152b35..b5afe195 100644 --- a/include/FileUtils.php +++ b/include/FileUtils.php @@ -12,7 +12,7 @@ class FileUtils * Returns whether or not the file exists and is readable * * @param $path the path to the file that will be analyzed - * @return whether or not the file exists + * @return bool whether or not the file exists */ public static function exists($path) { @@ -24,7 +24,7 @@ class FileUtils * Returns the file size in a human-readable form (e.g. 75.2M). * * @param $path the path to the file that will be analyzed - * @return the file size in a human-readable form + * @return string the file size in a human-readable form */ public static function getFileSize($path) { @@ -51,7 +51,7 @@ class FileUtils * Returns the extension of the given file. * * @param $path the path to the file that will be analyzed - * @return the extension + * @return string the extension */ public static function getExtension($path) { @@ -70,7 +70,7 @@ class FileUtils * Returns the SHA-256 hash of the given file. * * @param $path the path to the file that will be analyzed - * @return the SHA-256 hash + * @return string the SHA-256 hash */ public static function getSha256($path) { @@ -93,7 +93,7 @@ class FileUtils * Returns the date (in ISO 8601 format) that the given file was last modified. * * @param $path the path to the file that will be analyzed - * @return the date + * @return string the date */ public static function getLastModified($path) { @@ -112,7 +112,7 @@ class FileUtils * that code will work in both environments. * * @param $path the relative path to the file that will be analyzed - * @return the path of the file, either relative or absolute + * @return string the path of the file, either relative or absolute */ private static function toAbsolutePathIfOnServer($relativePath) { diff --git a/include/Models/ScreenshotsModel.php b/include/Models/ScreenshotsModel.php index 1c2af126..884adf6a 100644 --- a/include/Models/ScreenshotsModel.php +++ b/include/Models/ScreenshotsModel.php @@ -2,7 +2,9 @@ namespace ScummVM\Models; use ScummVM\OrmObjects\GameQuery; +use ScummVM\OrmObjects\Screenshot; use ScummVM\OrmObjects\ScreenshotQuery; +use Propel\Runtime\Collection\Collection; use Propel\Runtime\Collection\ObjectCollection; /** @@ -19,7 +21,10 @@ class ScreenshotsModel extends BasicModel $categories = ScreenshotQuery::create()->findCategories(); $data = []; foreach ($categories as $category) { - extract($category); + $category_key = $category['category_key']; + $category_name = $category['category_name']; + $subcategory_key = $category['subcategory_key']; + $subcategory_name = $category['subcategory_name']; if (!isset($data[$category_key])) { $data[$category_key] = [ 'title' => "$category_name Games", @@ -84,7 +89,7 @@ class ScreenshotsModel extends BasicModel /** * Combines multiple screenshots into a single screenshot * - * @param ObjectCollection $screenshots + * @param Collection $screenshots * @return Screenshot|bool */ private function combineScreenshots(iterable $screenshots) @@ -108,7 +113,7 @@ class ScreenshotsModel extends BasicModel /** * combineSubcategories * - * @param ObjectCollection $screenshots + * @param Collection $screenshots * @return Screenshot[] */ private function combineSubcategories(iterable $screenshots) @@ -131,7 +136,7 @@ class ScreenshotsModel extends BasicModel /** * Returns the number of screenshot files associated with a given game or series of games * @param $gameOrSeriesId the id of a game or a game series - * @return the number of screenshot files + * @return int the number of screenshot files */ private function getScreenshotCount(string $gameOrSeriesId) { diff --git a/include/Objects/File.php b/include/Objects/File.php index 8b30fc49..bdfb716c 100644 --- a/include/Objects/File.php +++ b/include/Objects/File.php @@ -14,7 +14,7 @@ class File extends BasicObject private $url; private $extra_info; private $notes; - private $subcategory; + //private $subcategory; private $user_agent; private $version; @@ -25,7 +25,7 @@ class File extends BasicObject $this->category = $data['category']; $this->category_icon = $data['category_icon']; $this->notes = isset($data['notes']) ? $data['notes'] : ''; - $this->subcategory = $data['subcategory'] ?? null; + //$this->subcategory = $data['subcategory'] ?? null; $this->user_agent = isset($data["user_agent"]) ? $data["user_agent"] : ""; $this->version = isset($data['version']) ? strtolower($data['version']) : null; diff --git a/include/Pages/CompatibilityPage.php b/include/Pages/CompatibilityPage.php index 6d604a8f..18778cc3 100644 --- a/include/Pages/CompatibilityPage.php +++ b/include/Pages/CompatibilityPage.php @@ -55,7 +55,7 @@ class CompatibilityPage extends Controller $version = $args['version'] ?? null; $target = $args['game'] ?? null; - $versions = VersionQuery::create() + $versions = VersionQuery::create() // @phpstan-ignore method.notFound ->orderByMajor('desc') ->orderByMinor('desc') ->orderByPatch('desc') diff --git a/phpstan.neon b/phpstan.neon index 50d8c5df..253c31f6 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,13 +1,14 @@ parameters: level: 5 + treatPhpDocTypesAsCertain: false bootstrapFiles: - include/Constants.php paths: - public_html/index.php - include/ - excludes_analyse: - - include/LocalizationUtils.php - - include/DataUtils.php - - include/Constants.php - - + excludePaths: + analyse: + - include/OrmObjects/Map/* + - include/OrmObjects/Base/* + universalObjectCratesClasses: + - Spatie\YamlFrontMatter\Document