A free, self-hostable news aggregator…
PHPStan 7 configureController (#5318)
Alexandre Alapetiteecd956c73608
diff --git a/app/Controllers/configureController.php b/app/Controllers/configureController.phpindex 87d9e4426..76675f545 100644--- a/app/Controllers/configureController.php+++ b/app/Controllers/configureController.php@@ -294,17 +294,19 @@ class FreshRSS_configure_Controller extends FreshRSS_ActionController {$tag_dao = FreshRSS_Factory::createTagDao();if (Minz_Request::isPost()) {+ /** @var array<int,array<string,string>> $params */$params = Minz_Request::paramArray('queries');$queries = [];foreach ($params as $key => $query) {- if (!$query['name']) {+ $key = (int)$key;+ if (empty($query['name'])) {$query['name'] = _t('conf.query.number', $key + 1);}- if ($query['search']) {+ if (!empty($query['search'])) {$query['search'] = urldecode($query['search']);}- $queries[intval($key)] = new FreshRSS_UserQuery($query, $feed_dao, $category_dao, $tag_dao);+ $queries[$key] = (new FreshRSS_UserQuery($query, $feed_dao, $category_dao, $tag_dao))->toArray();}FreshRSS_Context::$user_conf->queries = $queries;FreshRSS_Context::$user_conf->save();@@ -317,9 +319,9 @@ class FreshRSS_configure_Controller extends FreshRSS_ActionController {}}- $this->view->categories = $category_dao->listCategories(false);+ $this->view->categories = $category_dao->listCategories(false) ?: [];$this->view->feeds = $feed_dao->listFeeds();- $this->view->tags = $tag_dao->listTags();+ $this->view->tags = $tag_dao->listTags() ?: [];$id = Minz_Request::paramInt('id');$this->view->displaySlider = false;@@ -341,7 +343,7 @@ class FreshRSS_configure_Controller extends FreshRSS_ActionController {$this->view->_layout(null);$id = Minz_Request::paramInt('id');- if ($id !== 0 || !isset(FreshRSS_Context::$user_conf->queries[$id])) {+ if (Minz_Request::paramTernary('id') === null || empty(FreshRSS_Context::$user_conf->queries[$id])) {Minz_Error::error(404);return;}@@ -353,27 +355,29 @@ class FreshRSS_configure_Controller extends FreshRSS_ActionController {$query = new FreshRSS_UserQuery(FreshRSS_Context::$user_conf->queries[$id], $feed_dao, $category_dao, $tag_dao);$this->view->query = $query;$this->view->queryId = $id;- $this->view->categories = $category_dao->listCategories(false);+ $this->view->categories = $category_dao->listCategories(false) ?: [];$this->view->feeds = $feed_dao->listFeeds();- $this->view->tags = $tag_dao->listTags();+ $this->view->tags = $tag_dao->listTags() ?: [];if (Minz_Request::isPost()) {+ /** @var array<string,string|array<string,string>> $params */$params = array_filter(Minz_Request::paramArray('query'));- if (!empty($params['search'])) {- $params['search'] = htmlspecialchars_decode($params['search'], ENT_QUOTES);+ $queryParams = [];+ if (!empty($params['search']) && is_string($params['search'])) {+ $queryParams['search'] = htmlspecialchars_decode($params['search'], ENT_QUOTES);}- if (!empty($params['state'])) {- $params['state'] = array_sum($params['state']);+ if (!empty($params['state']) && is_array($params['state'])) {+ $queryParams['state'] = (int)(array_sum($params['state']));}- $params['url'] = Minz_Url::display(['params' => $params]);+ $queryParams['url'] = Minz_Url::display(['params' => $params]);$name = Minz_Request::paramString('name') ?: _t('conf.query.number', $id + 1);if ('' === $name) {$name = _t('conf.query.number', $id + 1);}- $params['name'] = $name;+ $queryParams['name'] = $name;$queries = FreshRSS_Context::$user_conf->queries;- $queries[$id] = new FreshRSS_UserQuery($params, $feed_dao, $category_dao, $tag_dao);+ $queries[$id] = (new FreshRSS_UserQuery($queryParams, $feed_dao, $category_dao, $tag_dao))->toArray();FreshRSS_Context::$user_conf->queries = $queries;FreshRSS_Context::$user_conf->save();@@ -388,7 +392,7 @@ class FreshRSS_configure_Controller extends FreshRSS_ActionController {*/public function deleteQueryAction(): void {$id = Minz_Request::paramInt('id');- if ($id === 0 || empty(FreshRSS_Context::$user_conf->queries[$id])) {+ if (Minz_Request::paramTernary('id') === null || empty(FreshRSS_Context::$user_conf->queries[$id])) {Minz_Error::error(404);return;}@@ -414,13 +418,13 @@ class FreshRSS_configure_Controller extends FreshRSS_ActionController {$tag_dao = FreshRSS_Factory::createTagDao();$queries = array();foreach (FreshRSS_Context::$user_conf->queries as $key => $query) {- $queries[$key] = new FreshRSS_UserQuery($query, $feed_dao, $category_dao, $tag_dao);+ $queries[$key] = (new FreshRSS_UserQuery($query, $feed_dao, $category_dao, $tag_dao))->toArray();}$params = $_GET;unset($params['rid']);$params['url'] = Minz_Url::display(array('params' => $params));$params['name'] = _t('conf.query.number', count($queries) + 1);- $queries[] = new FreshRSS_UserQuery($params, $feed_dao, $category_dao, $tag_dao);+ $queries[] = (new FreshRSS_UserQuery($params, $feed_dao, $category_dao, $tag_dao))->toArray();FreshRSS_Context::$user_conf->queries = $queries;FreshRSS_Context::$user_conf->save();diff --git a/app/Models/UserConfiguration.php b/app/Models/UserConfiguration.phpindex df19d95e7..173ab78b9 100644--- a/app/Models/UserConfiguration.php+++ b/app/Models/UserConfiguration.php@@ -39,7 +39,7 @@* @property bool $onread_jump_next* @property string $passwordHash* @property int $posts_per_page- * @property array<array<string,string>> $queries+ * @property array<array<string,string|int>> $queries* @property bool $reading_confirm* @property int $since_hours_posts_per_rss* @property bool $show_fav_unreaddiff --git a/lib/lib_rss.php b/lib/lib_rss.phpindex d4dd1635d..de9ca421e 100644--- a/lib/lib_rss.php+++ b/lib/lib_rss.php@@ -793,8 +793,8 @@ function recursive_unlink(string $dir): bool {/*** Remove queries where $get is appearing.* @param string $get the get attribute which should be removed.- * @param array<int,array<string,string>> $queries an array of queries.- * @return array<int,array<string,string>> without queries where $get is appearing.+ * @param array<int,array<string,string|int>> $queries an array of queries.+ * @return array<int,array<string,string|int>> without queries where $get is appearing.*/function remove_query_by_get(string $get, array $queries): array {$final_queries = array();diff --git a/tests/phpstan-next.txt b/tests/phpstan-next.txtindex f61cc4b22..878be4f8c 100644--- a/tests/phpstan-next.txt+++ b/tests/phpstan-next.txt@@ -3,7 +3,6 @@# Can be regenerated with something like:# find . -type d -name 'vendor' -prune -o -name '*.php' -exec sh -c 'vendor/bin/phpstan analyse --level 7 --memory-limit 512M {} >/dev/null 2>/dev/null || echo {}' \;-./app/Controllers/configureController.php./app/Controllers/feedController.php./app/Controllers/importExportController.php./app/Controllers/indexController.php