From 743ca371bbd8c412c2cd4ded6a5a44544abc5a65 Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Sat, 8 Apr 2023 17:37:42 +0200 Subject: PHPStan Level 6 for more files (#5275) Contributes to https://github.com/FreshRSS/FreshRSS/issues/4112 --- app/Models/Themes.php | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) (limited to 'app/Models/Themes.php') diff --git a/app/Models/Themes.php b/app/Models/Themes.php index 86125c5f5..ce63b24b2 100644 --- a/app/Models/Themes.php +++ b/app/Models/Themes.php @@ -1,18 +1,23 @@ */ + public static function getList(): array { return array_values(array_diff( scandir(PUBLIC_PATH . self::$themesUrl), array('..', '.') )); } - public static function get() { + /** @return array,'theme-color'?:string|array{'dark'?:string,'light'?:string,'default'?:string}}> */ + public static function get(): array { $themes_list = self::getList(); $list = array(); foreach ($themes_list as $theme_dir) { @@ -24,7 +29,10 @@ class FreshRSS_Themes extends Minz_Model { return $list; } - public static function get_infos($theme_id) { + /** + * @return false|array{'id':string,'name':string,'author':string,'description':string,'version':float|string,'files':array,'theme-color'?:string|array{'dark'?:string,'light'?:string,'default'?:string}} + */ + public static function get_infos(string $theme_id) { $theme_dir = PUBLIC_PATH . self::$themesUrl . $theme_id; if (is_dir($theme_dir)) { $json_filename = $theme_dir . '/metadata.json'; @@ -43,10 +51,15 @@ class FreshRSS_Themes extends Minz_Model { return false; } + /** @var string */ private static $themeIconsUrl; + /** @var array */ private static $themeIcons; - public static function load($theme_id) { + /** + * @return false|array{'id':string,'name':string,'author':string,'description':string,'version':float|string,'files':array,'theme-color'?:string|array{'dark'?:string,'light'?:string,'default'?:string}} + */ + public static function load(string $theme_id) { $infos = self::get_infos($theme_id); if (!$infos) { if ($theme_id !== self::$defaultTheme) { //Fall-back to default theme @@ -68,14 +81,14 @@ class FreshRSS_Themes extends Minz_Model { return $infos; } - public static function title($name) { + public static function title(string $name): string { static $titles = [ 'opml-dyn' => 'sub.category.dynamic_opml', ]; return $titles[$name] ?? ''; } - public static function alt($name) { + public static function alt(string $name): string { static $alts = array( 'add' => '➕', //✚ 'all' => '☰', @@ -119,7 +132,7 @@ class FreshRSS_Themes extends Minz_Model { 'view-reader' => '📜', 'warning' => '⚠️', //△ ); - return isset($name) ? $alts[$name] : ''; + return $alts[$name] ?? ''; } // TODO: Change for enum in PHP 8.1+ -- cgit v1.2.3