aboutsummaryrefslogtreecommitdiff
path: root/app/Models
diff options
context:
space:
mode:
authorGravatar Alexandre Alapetite <alexandre@alapetite.fr> 2023-04-08 17:37:42 +0200
committerGravatar GitHub <noreply@github.com> 2023-04-08 17:37:42 +0200
commit743ca371bbd8c412c2cd4ded6a5a44544abc5a65 (patch)
tree7b12b205c09ae335134d4c4ea2d8d9f04fc60e9d /app/Models
parentb2ee8a660f719ee3e523988bf536197d4bbe46a1 (diff)
PHPStan Level 6 for more files (#5275)
Contributes to https://github.com/FreshRSS/FreshRSS/issues/4112
Diffstat (limited to 'app/Models')
-rw-r--r--app/Models/FilterAction.php20
-rw-r--r--app/Models/Themes.php27
-rw-r--r--app/Models/View.php2
3 files changed, 34 insertions, 15 deletions
diff --git a/app/Models/FilterAction.php b/app/Models/FilterAction.php
index 394b573a4..44ff5674a 100644
--- a/app/Models/FilterAction.php
+++ b/app/Models/FilterAction.php
@@ -4,22 +4,26 @@ class FreshRSS_FilterAction {
/** @var FreshRSS_BooleanSearch */
private $booleanSearch = null;
+ /** @var array<string>|null */
private $actions = null;
- private function __construct($booleanSearch, $actions) {
+ /** @param array<string> $actions */
+ private function __construct(FreshRSS_BooleanSearch $booleanSearch, array $actions) {
$this->booleanSearch = $booleanSearch;
$this->_actions($actions);
}
- public function booleanSearch() {
+ public function booleanSearch(): FreshRSS_BooleanSearch {
return $this->booleanSearch;
}
- public function actions() {
- return $this->actions;
+ /** @return array<string> */
+ public function actions(): array {
+ return $this->actions ?? [];
}
- public function _actions($actions) {
+ /** @param array<string> $actions */
+ public function _actions(?array $actions): void {
if (is_array($actions)) {
$this->actions = array_unique($actions);
} else {
@@ -27,7 +31,8 @@ class FreshRSS_FilterAction {
}
}
- public function toJSON() {
+ /** @return array{'search'?:string,'actions'?:array<string>} */
+ public function toJSON(): array {
if (is_array($this->actions) && $this->booleanSearch != null) {
return array(
'search' => $this->booleanSearch->getRawInput(),
@@ -37,7 +42,8 @@ class FreshRSS_FilterAction {
return [];
}
- public static function fromJSON($json) {
+ /** @param array|mixed|null $json */
+ public static function fromJSON($json): ?FreshRSS_FilterAction {
if (!empty($json['search']) && !empty($json['actions']) && is_array($json['actions'])) {
return new FreshRSS_FilterAction(new FreshRSS_BooleanSearch($json['search']), $json['actions']);
}
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 @@
<?php
class FreshRSS_Themes extends Minz_Model {
+ /** @var string */
private static $themesUrl = '/themes/';
+ /** @var string */
private static $defaultIconsUrl = '/themes/icons/';
+ /** @var string */
public static $defaultTheme = 'Origine';
- public static function getList() {
+ /** @return array<string> */
+ public static function getList(): array {
return array_values(array_diff(
scandir(PUBLIC_PATH . self::$themesUrl),
array('..', '.')
));
}
- public static function get() {
+ /** @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 = 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<string>,'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<string,int> */
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<string>,'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+
diff --git a/app/Models/View.php b/app/Models/View.php
index 28e6dbb35..e908bdfad 100644
--- a/app/Models/View.php
+++ b/app/Models/View.php
@@ -81,7 +81,7 @@ class FreshRSS_View extends Minz_View {
public $size_user;
// Display
- /** @var array<string> */
+ /** @var 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 $themes;
// Shortcuts