aboutsummaryrefslogtreecommitdiff
path: root/app/Models
diff options
context:
space:
mode:
authorGravatar Luc SANCHEZ <4697568+ColonelMoutarde@users.noreply.github.com> 2023-04-07 12:32:10 +0200
committerGravatar GitHub <noreply@github.com> 2023-04-07 12:32:10 +0200
commitd23d10bcde1a9b86c784d58b891f61e740e0124e (patch)
tree6f907e5d13a04832b3350286b1b847fbb3842ee7 /app/Models
parent6c01e4e7d6c177ac345c826059e585bffdd1d517 (diff)
Phpstan Level6 for View.php (#5269)
* Remarque's from Alkarex * indentation * indentation * Apply suggestions from code review Co-authored-by: Alexandre Alapetite <alexandre@alapetite.fr> * Remarque's from Alkarex * A few improvements * Remarque's from Alkarex * Remarque's from Alkarex * Remarque's from Alkarex * Remarque's from Alkarex * Fixes and improvments * Fix getTagsForEntry --------- Co-authored-by: Luc <sanchezluc+freshrss@gmail.com> Co-authored-by: Alexandre Alapetite <alexandre@alapetite.fr>
Diffstat (limited to 'app/Models')
-rw-r--r--app/Models/CategoryDAO.php16
-rw-r--r--app/Models/Entry.php6
-rw-r--r--app/Models/EntryDAO.php5
-rw-r--r--app/Models/TagDAO.php27
-rw-r--r--app/Models/UserConfiguration.php4
-rw-r--r--app/Models/View.php80
6 files changed, 105 insertions, 33 deletions
diff --git a/app/Models/CategoryDAO.php b/app/Models/CategoryDAO.php
index dd97bd6cc..a67567f33 100644
--- a/app/Models/CategoryDAO.php
+++ b/app/Models/CategoryDAO.php
@@ -281,7 +281,8 @@ SQL;
return $categories;
}
- public function listCategories($prePopulateFeeds = true, $details = false) {
+ /** @return array<FreshRSS_Category>|false */
+ public function listCategories(bool $prePopulateFeeds = true, bool $details = false) {
if ($prePopulateFeeds) {
$sql = 'SELECT c.id AS c_id, c.name AS c_name, c.kind AS c_kind, c.`lastUpdate` AS c_last_update, c.error AS c_error, c.attributes AS c_attributes, '
. ($details ? 'f.* ' : 'f.id, f.name, f.url, f.website, f.priority, f.error, f.`cache_nbEntries`, f.`cache_nbUnreads`, f.ttl ')
@@ -435,13 +436,12 @@ SQL;
return $n;
}
- public static function daoToCategoryPrepopulated($listDAO) {
+ /**
+ * @param array<string,mixed> $listDAO
+ * @return array<int,FreshRSS_Category>
+ */
+ private static function daoToCategoryPrepopulated(array $listDAO) {
$list = array();
-
- if (!is_array($listDAO)) {
- $listDAO = array($listDAO);
- }
-
$previousLine = null;
$feedsDao = array();
$feedDao = FreshRSS_Factory::createFeedDAO();
@@ -481,7 +481,7 @@ SQL;
return $list;
}
- public static function daoToCategory($listDAO) {
+ private static function daoToCategory($listDAO) {
$list = array();
if (!is_array($listDAO)) {
diff --git a/app/Models/Entry.php b/app/Models/Entry.php
index 4a0f12c94..36c581746 100644
--- a/app/Models/Entry.php
+++ b/app/Models/Entry.php
@@ -48,7 +48,8 @@ class FreshRSS_Entry extends Minz_Model {
*/
private $feed;
- private $tags;
+ /** @var array<string> */
+ private $tags = [];
private $attributes = [];
public function __construct(int $feedId = 0, string $guid = '', string $title = '', string $authors = '', string $content = '',
@@ -347,7 +348,8 @@ HTML;
return $this->feedId;
}
- public function tags($asString = false) {
+ /** @return string|array<string> */
+ public function tags(bool $asString = false) {
if ($asString) {
return $this->tags == null ? '' : '#' . implode(' #', $this->tags);
} else {
diff --git a/app/Models/EntryDAO.php b/app/Models/EntryDAO.php
index 6bb5394b2..cf5550573 100644
--- a/app/Models/EntryDAO.php
+++ b/app/Models/EntryDAO.php
@@ -1214,9 +1214,8 @@ SQL;
}
/**
- * For API
* @param int $id category/feed/tag ID
- * @return array<string>|false
+ * @return array<numeric-string>|false
*/
public function listIdsWhere(string $type = 'a', int $id = 0, int $state = FreshRSS_Entry::STATE_ALL,
string $order = 'DESC', int $limit = 1, string $firstId = '', ?FreshRSS_BooleanSearch $filters = null) {
@@ -1225,7 +1224,7 @@ SQL;
$stm = $this->pdo->prepare($sql);
$stm->execute($values);
- return $stm->fetchAll(PDO::FETCH_COLUMN, 0) ?: [];
+ return $stm->fetchAll(PDO::FETCH_COLUMN, 0);
}
/**
diff --git a/app/Models/TagDAO.php b/app/Models/TagDAO.php
index 68d87efad..5c0a4482f 100644
--- a/app/Models/TagDAO.php
+++ b/app/Models/TagDAO.php
@@ -208,10 +208,7 @@ SQL;
return isset($tag[0]) ? $tag[0] : null;
}
- /**
- * @return FreshRSS_Tag|null
- */
- public function searchByName($name) {
+ public function searchByName(string $name): ?FreshRSS_Tag {
$sql = 'SELECT * FROM `_tag` WHERE name=?';
$stm = $this->pdo->prepare($sql);
$values = array($name);
@@ -342,7 +339,10 @@ SQL;
}
}
- public function getTagsForEntry(int $id_entry) {
+ /**
+ * @return array<int,array{'id':int,'name':string,'id_entry':string,'checked':bool}>|false
+ */
+ public function getTagsForEntry(string $id_entry) {
$sql = 'SELECT t.id, t.name, et.id_entry IS NOT NULL as checked '
. 'FROM `_tag` t '
. 'LEFT OUTER JOIN `_entrytag` et ON et.id_tag = t.id AND et.id_entry=? '
@@ -368,7 +368,11 @@ SQL;
}
}
- public function getTagsForEntries($entries) {
+ /**
+ * @param array<FreshRSS_Entry|numeric-string|array<string,string>> $entries
+ * @return array<array{'id_entry':string,'id_tag':int,'name':string}>|false
+ */
+ public function getTagsForEntries(array $entries) {
$sql = 'SELECT et.id_entry, et.id_tag, t.name '
. 'FROM `_tag` t '
. 'INNER JOIN `_entrytag` et ON et.id_tag = t.id';
@@ -412,8 +416,12 @@ SQL;
}
}
- //For API
- public function getEntryIdsTagNames($entries) {
+ /**
+ * For API
+ * @param array<FreshRSS_Entry|numeric-string> $entries
+ * @return array<string,array<string>>
+ */
+ public function getEntryIdsTagNames(array $entries): array {
$result = array();
foreach ($this->getTagsForEntries($entries) as $line) {
$entryId = 'e_' . $line['id_entry'];
@@ -426,7 +434,8 @@ SQL;
return $result;
}
- public static function daoToTag($listDAO) {
+ /** @return array<FreshRSS_Tag> */
+ private static function daoToTag($listDAO) {
$list = array();
if (!is_array($listDAO)) {
$listDAO = array($listDAO);
diff --git a/app/Models/UserConfiguration.php b/app/Models/UserConfiguration.php
index d76f5bcf5..9a77c4761 100644
--- a/app/Models/UserConfiguration.php
+++ b/app/Models/UserConfiguration.php
@@ -21,11 +21,11 @@
* @property string $show_feed_name
* @property bool $display_posts
* @property string $email_validation_token
- * @property-read string $enabled
+ * @property-read bool $enabled
* @property string $feverKey
* @property bool $hide_read_feeds
* @property int $html5_notif_timeout
- * @property-read string $is_admin
+ * @property-read bool $is_admin
* @property int|null $keep_history_default
* @property string $language
* @property string $timezone
diff --git a/app/Models/View.php b/app/Models/View.php
index 7e7afd124..28e6dbb35 100644
--- a/app/Models/View.php
+++ b/app/Models/View.php
@@ -3,8 +3,11 @@
class FreshRSS_View extends Minz_View {
// Main views
+ /** @var callable */
public $callbackBeforeEntries;
+ /** @var callable|null */
public $callbackBeforeFeeds;
+ /** @var callable */
public $callbackBeforePagination;
/** @var array<FreshRSS_Category> */
public $categories;
@@ -22,80 +25,115 @@ class FreshRSS_View extends Minz_View {
public $feeds;
/** @var int */
public $nbUnreadTags;
+ /** @var array<FreshRSS_Tag> */
public $tags;
+ /** @var array<int,array{'id':int,'name':string,'id_entry':string,'checked':bool}> */
+ public $tagsForEntry;
+ /** @var array<string,array<string>> */
+ public $tagsForEntries;
/** @var array<string,string> */
public $notification;
/** @var bool */
public $excludeMutedFeeds;
// Substriptions
+ /** @var FreshRSS_Category|null */
public $default_category;
+ /** @var bool */
public $displaySlider;
+ /** @var bool */
public $load_ok;
+ /** @var bool */
public $onlyFeedsWithError;
+ /** @var bool */
public $signalError;
// Manage users
+ /** @var array<string,string|int|bool> */
public $details;
+ /** @var bool */
public $disable_aside;
+ /** @var bool */
public $show_email_field;
/** @var string */
public $username;
+ /** @var array<array{'last_user_activity':int, 'language':string,'enabled':bool,'is_admin':bool, 'enabled':bool, 'article_count':int, 'database_size':int, 'last_user_activity', 'mail_login':string, 'feed_count':int, 'is_default':bool}> */
public $users;
// Updates
+ /** @var string */
public $last_update_time;
+ /** @var array<string,bool> */
public $status_files;
+ /** @var array<string,bool> */
public $status_php;
+ /** @var bool */
public $update_to_apply;
+ /** @var array<string,bool> */
public $status_database;
// Archiving
+ /** @var int|false */
public $nb_total;
+ /** @var int */
public $size_total;
+ /** @var int */
public $size_user;
// Display
+ /** @var array<string> */
public $themes;
// Shortcuts
+ /** @var array<int, string> */
public $list_keys;
// User queries
- /**
- * @var array<int,FreshRSS_UserQuery>
- */
+ /** @var array<int,FreshRSS_UserQuery> */
public $queries;
- /**
- * @var FreshRSS_UserQuery|null
- */
+ /** @var FreshRSS_UserQuery|null */
public $query;
// Export / Import
+ /** @var string */
public $content;
+ /** @var array<string,array<string>> */
public $entryIdsTagNames;
+ /** @var string */
public $list_title;
+ /** @var int */
public $queryId;
+ /** @var string */
public $type;
// Form login
+ /** @var int */
public $cookie_days;
+ /** @var string */
public $nonce;
+ /** @var string */
public $salt1;
// Registration
+ /** @var bool */
public $can_register;
+ /** @var string */
public $preferred_language;
+ /** @var bool */
public $show_tos_checkbox;
+ /** @var string */
public $terms_of_service;
-
- // Email validation
+ /** @var string */
public $site_title;
+ /** @var string */
public $validation_url;
// Logs
+ /** @var int */
public $currentPage;
+ /** @var Minz_Paginator */
public $logsPaginator;
+ /** @var int */
public $nbPage;
// RSS view
@@ -105,12 +143,15 @@ class FreshRSS_View extends Minz_View {
public $rss_url = '';
/** @var string */
public $rss_base = '';
- /** @var boolean */
+ /** @var bool */
public $internal_rendering = false;
// Content preview
+ /** @var string */
public $fatalError;
+ /** @var string */
public $htmlContent;
+ /** @var bool */
public $selectorSuccess;
// Extensions
@@ -126,28 +167,49 @@ class FreshRSS_View extends Minz_View {
public $extensions_installed;
// Errors
+ /** @var string */
public $code;
+ /** @var string */
public $errorMessage;
+ /** @var array<string,string> */
public $message;
// Statistics
+ /** @var float */
public $average;
+ /** @var float */
public $averageDayOfWeek;
+ /** @var float */
public $averageHour;
+ /** @var float */
public $averageMonth;
+ /** @var array<string> */
public $days;
+ /** @var array<string,array<int,int|string>> */
public $entryByCategory;
+ /** @var array<int,int> */
public $entryCount;
+ /** @var array<string,array<int,int|string>> */
public $feedByCategory;
+ /** @var array<int, string> */
public $hours24Labels;
+ /** @var array<string,array<int,array<string,int|string>>> */
public $idleFeeds;
+ /** @var array<int,string> */
public $last30DaysLabel;
+ /** @var array<int,string> */
public $last30DaysLabels;
+ /** @var array<string,string> */
public $months;
+ /** @var array<string,array<string,int>>|array<string,int> */
public $repartition;
+ /** @var array<int,int> */
public $repartitionDayOfWeek;
+ /** @var array<string,int>|array<int,int> */
public $repartitionHour;
+ /** @var array<int,int> */
public $repartitionMonth;
+ /** @var array<array<string,int|string>> */
public $topFeed;
}