From d23d10bcde1a9b86c784d58b891f61e740e0124e Mon Sep 17 00:00:00 2001 From: Luc SANCHEZ <4697568+ColonelMoutarde@users.noreply.github.com> Date: Fri, 7 Apr 2023 12:32:10 +0200 Subject: Phpstan Level6 for View.php (#5269) * Remarque's from Alkarex * indentation * indentation * Apply suggestions from code review Co-authored-by: Alexandre Alapetite * 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 Co-authored-by: Alexandre Alapetite --- app/Models/CategoryDAO.php | 16 ++++---- app/Models/Entry.php | 6 ++- app/Models/EntryDAO.php | 5 +-- app/Models/TagDAO.php | 27 +++++++++----- app/Models/UserConfiguration.php | 4 +- app/Models/View.php | 80 +++++++++++++++++++++++++++++++++++----- 6 files changed, 105 insertions(+), 33 deletions(-) (limited to 'app/Models') 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|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 $listDAO + * @return array + */ + 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 */ + 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 */ + 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|false + * @return array|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|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> $entries + * @return array|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 $entries + * @return array> + */ + 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 */ + 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 */ public $categories; @@ -22,80 +25,115 @@ class FreshRSS_View extends Minz_View { public $feeds; /** @var int */ public $nbUnreadTags; + /** @var array */ public $tags; + /** @var array */ + public $tagsForEntry; + /** @var array> */ + public $tagsForEntries; /** @var array */ 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 */ public $details; + /** @var bool */ public $disable_aside; + /** @var bool */ public $show_email_field; /** @var string */ public $username; + /** @var array */ public $users; // Updates + /** @var string */ public $last_update_time; + /** @var array */ public $status_files; + /** @var array */ public $status_php; + /** @var bool */ public $update_to_apply; + /** @var array */ public $status_database; // Archiving + /** @var int|false */ public $nb_total; + /** @var int */ public $size_total; + /** @var int */ public $size_user; // Display + /** @var array */ public $themes; // Shortcuts + /** @var array */ public $list_keys; // User queries - /** - * @var array - */ + /** @var array */ public $queries; - /** - * @var FreshRSS_UserQuery|null - */ + /** @var FreshRSS_UserQuery|null */ public $query; // Export / Import + /** @var string */ public $content; + /** @var array> */ 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 */ public $message; // Statistics + /** @var float */ public $average; + /** @var float */ public $averageDayOfWeek; + /** @var float */ public $averageHour; + /** @var float */ public $averageMonth; + /** @var array */ public $days; + /** @var array> */ public $entryByCategory; + /** @var array */ public $entryCount; + /** @var array> */ public $feedByCategory; + /** @var array */ public $hours24Labels; + /** @var array>> */ public $idleFeeds; + /** @var array */ public $last30DaysLabel; + /** @var array */ public $last30DaysLabels; + /** @var array */ public $months; + /** @var array>|array */ public $repartition; + /** @var array */ public $repartitionDayOfWeek; + /** @var array|array */ public $repartitionHour; + /** @var array */ public $repartitionMonth; + /** @var array> */ public $topFeed; } -- cgit v1.2.3