diff options
| author | 2024-12-27 12:12:49 +0100 | |
|---|---|---|
| committer | 2024-12-27 12:12:49 +0100 | |
| commit | b1d24fbdb7d1cc948c946295035dad6df550fb7e (patch) | |
| tree | 7b4365a04097a779659474fbb9281a9661512522 /app/Models/Themes.php | |
| parent | 897e4a3f4a273d50c28157edb67612b2d7fa2e6f (diff) | |
PHPStan 2.0 (#7131)
* PHPStan 2.0
fix https://github.com/FreshRSS/FreshRSS/issues/6989
https://github.com/phpstan/phpstan/releases/tag/2.0.0
https://github.com/phpstan/phpstan/blob/2.0.x/UPGRADING.md
* More
* More
* Done
* fix i18n CLI
* Restore a PHPStan Next test
For work towards PHPStan Level 10
* 4 more on Level 10
* fix getTagsForEntry
* API at Level 10
* More Level 10
* Finish Minz at Level 10
* Finish CLI at Level 10
* Finish Controllers at Level 10
* More Level 10
* More
* Pass bleedingEdge
* Clean PHPStan options and add TODOs
* Level 10 for main config
* More
* Consitency array vs. list
* Sanitize themes get_infos
* Simplify TagDAO->getTagsForEntries()
* Finish reportAnyTypeWideningInVarTag
* Prepare checkBenevolentUnionTypes and checkImplicitMixed
* Fixes
* Refix
* Another fix
* Casing of __METHOD__ constant
Diffstat (limited to 'app/Models/Themes.php')
| -rw-r--r-- | app/Models/Themes.php | 33 |
1 files changed, 22 insertions, 11 deletions
diff --git a/app/Models/Themes.php b/app/Models/Themes.php index 2a55a84db..cd66723bf 100644 --- a/app/Models/Themes.php +++ b/app/Models/Themes.php @@ -7,7 +7,7 @@ class FreshRSS_Themes extends Minz_Model { private static string $defaultIconsUrl = '/themes/icons/'; public static string $defaultTheme = 'Origine'; - /** @return array<string> */ + /** @return list<string> */ public static function getList(): array { return array_values(array_diff( scandir(PUBLIC_PATH . self::$themesUrl) ?: [], @@ -15,7 +15,7 @@ class FreshRSS_Themes extends Minz_Model { )); } - /** @return array<string,array{'id':string,'name':string,'author':string,'description':string,'version':float|string,'files':array<string>,'theme-color'?:string|array{'dark'?:string,'light'?:string,'default'?:string}}> */ + /** @return array<string,array{id:string,name:string,author:string,description:string,version:float|string,files:array<string>,theme-color?:string|array{dark?:string,light?:string,default?:string}}> */ public static function get(): array { $themes_list = self::getList(); $list = []; @@ -29,7 +29,7 @@ class FreshRSS_Themes extends Minz_Model { } /** - * @return false|array{'id':string,'name':string,'author':string,'description':string,'version':float|string,'files':array<string>,'theme-color'?:string|array{'dark'?:string,'light'?:string,'default'?:string}} + * @return false|array{id:string,name:string,author:string,description:string,version:float|string,files:array<string>,theme-color?:string|array{dark?:string,light?:string,default?:string}} */ public static function get_infos(string $theme_id): array|false { $theme_dir = PUBLIC_PATH . self::$themesUrl . $theme_id; @@ -38,13 +38,24 @@ class FreshRSS_Themes extends Minz_Model { if (file_exists($json_filename)) { $content = file_get_contents($json_filename) ?: ''; $res = json_decode($content, true); - if (is_array($res) && - !empty($res['name']) && - isset($res['files']) && - is_array($res['files'])) { - $res['id'] = $theme_id; - /** @var array{'id':string,'name':string,'author':string,'description':string,'version':float|string,'files':array<string>,'theme-color'?:string|array{'dark'?:string,'light'?:string,'default'?:string}} */ - return $res; + if (is_array($res)) { + $result = [ + 'id' => $theme_id, + 'name' => is_string($res['name'] ?? null) ? $res['name'] : '', + 'author' => is_string($res['author'] ?? null) ? $res['author'] : '', + 'description' => is_string($res['description'] ?? null) ? $res['description'] : '', + 'version' => is_string($res['version'] ?? null) || is_numeric($res['version'] ?? null) ? $res['version'] : '0', + 'files' => is_array($res['files']) && is_array_values_string($res['files']) ? array_values($res['files']) : [], + 'theme-color' => is_string($res['theme-color'] ?? null) ? $res['theme-color'] : '', + ]; + if (empty($result['theme-color']) && is_array($res['theme-color'])) { + $result['theme-color'] = [ + 'dark' => is_string($res['theme-color']['dark'] ?? null) ? $res['theme-color']['dark'] : '', + 'light' => is_string($res['theme-color']['light'] ?? null) ? $res['theme-color']['light'] : '', + 'default' => is_string($res['theme-color']['default'] ?? null) ? $res['theme-color']['default'] : '', + ]; + } + return $result; } } } @@ -56,7 +67,7 @@ class FreshRSS_Themes extends Minz_Model { private static array $themeIcons; /** - * @return false|array{'id':string,'name':string,'author':string,'description':string,'version':float|string,'files':array<string>,'theme-color'?:string|array{'dark'?:string,'light'?:string,'default'?:string}} + * @return false|array{id:string,name:string,author:string,description:string,version:float|string,files:array<string>,theme-color?:string|array{dark?:string,light?:string,default?:string}} */ public static function load(string $theme_id): array|false { $infos = self::get_infos($theme_id); |
