diff options
| author | 2023-04-07 12:32:10 +0200 | |
|---|---|---|
| committer | 2023-04-07 12:32:10 +0200 | |
| commit | d23d10bcde1a9b86c784d58b891f61e740e0124e (patch) | |
| tree | 6f907e5d13a04832b3350286b1b847fbb3842ee7 /app | |
| parent | 6c01e4e7d6c177ac345c826059e585bffdd1d517 (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')
| -rw-r--r-- | app/Controllers/authController.php | 2 | ||||
| -rw-r--r-- | app/Controllers/entryController.php | 6 | ||||
| -rw-r--r-- | app/Controllers/subscriptionController.php | 2 | ||||
| -rw-r--r-- | app/Controllers/tagController.php | 4 | ||||
| -rw-r--r-- | app/Controllers/userController.php | 3 | ||||
| -rw-r--r-- | app/Models/CategoryDAO.php | 16 | ||||
| -rw-r--r-- | app/Models/Entry.php | 6 | ||||
| -rw-r--r-- | app/Models/EntryDAO.php | 5 | ||||
| -rw-r--r-- | app/Models/TagDAO.php | 27 | ||||
| -rw-r--r-- | app/Models/UserConfiguration.php | 4 | ||||
| -rw-r--r-- | app/Models/View.php | 80 | ||||
| -rw-r--r-- | app/Services/ExportService.php | 6 | ||||
| -rw-r--r-- | app/views/configure/display.phtml | 3 | ||||
| -rwxr-xr-x | app/views/entry/read.phtml | 8 | ||||
| -rw-r--r-- | app/views/index/logs.phtml | 4 | ||||
| -rw-r--r-- | app/views/tag/getTagsForEntry.phtml | 2 |
16 files changed, 125 insertions, 53 deletions
diff --git a/app/Controllers/authController.php b/app/Controllers/authController.php index e499f0b8a..fa5cb0d53 100644 --- a/app/Controllers/authController.php +++ b/app/Controllers/authController.php @@ -111,7 +111,7 @@ class FreshRSS_auth_Controller extends FreshRSS_ActionController { FreshRSS_View::appendScript(Minz_Url::display('/scripts/bcrypt.min.js?' . @filemtime(PUBLIC_PATH . '/scripts/bcrypt.min.js'))); $limits = FreshRSS_Context::$system_conf->limits; - $this->view->cookie_days = round($limits['cookie_duration'] / 86400, 1); + $this->view->cookie_days = (int)round($limits['cookie_duration'] / 86400, 1); $isPOST = Minz_Request::isPost() && !Minz_Session::param('POST_to_GET'); Minz_Session::_param('POST_to_GET'); diff --git a/app/Controllers/entryController.php b/app/Controllers/entryController.php index 9faf20331..7a30f94de 100644 --- a/app/Controllers/entryController.php +++ b/app/Controllers/entryController.php @@ -59,8 +59,8 @@ class FreshRSS_entry_Controller extends FreshRSS_ActionController { FreshRSS_Context::$state = 0; } - $params = array(); - $this->view->tags = array(); + $params = []; + $this->view->tagsForEntries = []; $entryDAO = FreshRSS_Factory::createEntryDao(); if ($id == false) { @@ -112,7 +112,7 @@ class FreshRSS_entry_Controller extends FreshRSS_ActionController { foreach ($tagsForEntries as $line) { $tags['t_' . $line['id_tag']][] = $line['id_entry']; } - $this->view->tags = $tags; + $this->view->tagsForEntries = $tags; } if (!$this->ajax) { diff --git a/app/Controllers/subscriptionController.php b/app/Controllers/subscriptionController.php index 70614708b..ff88aee9d 100644 --- a/app/Controllers/subscriptionController.php +++ b/app/Controllers/subscriptionController.php @@ -48,7 +48,7 @@ class FreshRSS_subscription_Controller extends FreshRSS_ActionController { FreshRSS_View::appendScript(Minz_Url::display('/scripts/feed.js?' . @filemtime(PUBLIC_PATH . '/scripts/feed.js'))); FreshRSS_View::prependTitle(_t('sub.title') . ' ยท '); - $this->view->onlyFeedsWithError = Minz_Request::paramTernary('error'); + $this->view->onlyFeedsWithError = Minz_Request::paramBoolean('error'); $id = Minz_Request::paramInt('id'); $this->view->displaySlider = false; diff --git a/app/Controllers/tagController.php b/app/Controllers/tagController.php index 86ff53cfa..e4048238c 100644 --- a/app/Controllers/tagController.php +++ b/app/Controllers/tagController.php @@ -85,9 +85,9 @@ class FreshRSS_tag_Controller extends FreshRSS_ActionController { $this->view->_layout(false); header('Content-Type: application/json; charset=UTF-8'); header('Cache-Control: private, no-cache, no-store, must-revalidate'); - $id_entry = Minz_Request::paramInt('id_entry'); + $id_entry = Minz_Request::paramString('id_entry'); $tagDAO = FreshRSS_Factory::createTagDao(); - $this->view->tags = $tagDAO->getTagsForEntry($id_entry); + $this->view->tagsForEntry = $tagDAO->getTagsForEntry($id_entry); } public function addAction(): void { diff --git a/app/Controllers/userController.php b/app/Controllers/userController.php index 3777a7b4f..6d8d510db 100644 --- a/app/Controllers/userController.php +++ b/app/Controllers/userController.php @@ -629,7 +629,8 @@ class FreshRSS_user_Controller extends FreshRSS_ActionController { $this->view->details = $this->retrieveUserDetails($username); } - private function retrieveUserDetails($username) { + /** @return array<string,int|string|bool> */ + private function retrieveUserDetails($username): array { $feedDAO = FreshRSS_Factory::createFeedDao($username); $entryDAO = FreshRSS_Factory::createEntryDao($username); $databaseDAO = FreshRSS_Factory::createDatabaseDAO($username); 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; } diff --git a/app/Services/ExportService.php b/app/Services/ExportService.php index 697e091e7..949556700 100644 --- a/app/Services/ExportService.php +++ b/app/Services/ExportService.php @@ -75,9 +75,7 @@ class FreshRSS_Export_Service { $view->list_title = _t('sub.import_export.starred_list'); $view->type = 'starred'; - $entriesId = $this->entry_dao->listIdsWhere( - $type, 0, FreshRSS_Entry::STATE_ALL, 'ASC', -1 - ); + $entriesId = $this->entry_dao->listIdsWhere($type, 0, FreshRSS_Entry::STATE_ALL, 'ASC', -1) ?: []; $view->entryIdsTagNames = $this->tag_dao->getEntryIdsTagNames($entriesId); // The following is a streamable query, i.e. must be last $view->entries = $this->entry_dao->listWhere( @@ -115,7 +113,7 @@ class FreshRSS_Export_Service { $view->type = 'feed/' . $feed->id(); $entriesId = $this->entry_dao->listIdsWhere( 'f', $feed->id(), FreshRSS_Entry::STATE_ALL, 'ASC', $max_number_entries - ); + ) ?: []; $view->entryIdsTagNames = $this->tag_dao->getEntryIdsTagNames($entriesId); // The following is a streamable query, i.e. must be last $view->entries = $this->entry_dao->listWhere( diff --git a/app/views/configure/display.phtml b/app/views/configure/display.phtml index de880579e..1c415390a 100644 --- a/app/views/configure/display.phtml +++ b/app/views/configure/display.phtml @@ -49,7 +49,8 @@ <div class="group-controls"> <ul class="slides"> <?php $slides = count($this->themes); $i = 1; $themeAvailable = false; ?> - <?php foreach($this->themes as $theme) { ?> + <?php /** @var array{'id':string, 'deprecated':bool, 'author':string, 'name':string, 'description':string} $theme */ + foreach($this->themes as $theme) { ?> <?php if (FreshRSS_Context::$user_conf->theme === $theme['id']) { $checked = 'checked="checked"'; $themeAvailable = true; diff --git a/app/views/entry/read.phtml b/app/views/entry/read.phtml index 0d87bf583..2d1760b87 100755 --- a/app/views/entry/read.phtml +++ b/app/views/entry/read.phtml @@ -1,8 +1,8 @@ -<?php /** @var FreshRSS_View $this */ ?> <?php +/** @var FreshRSS_View $this */ header('Content-Type: application/json; charset=UTF-8'); FreshRSS::loadStylesAndScripts(); -echo json_encode(array( - 'tags' => $this->tags, - )); +echo json_encode([ + 'tags' => $this->tagsForEntries, + ]); diff --git a/app/views/index/logs.phtml b/app/views/index/logs.phtml index 896a19765..54b7e1c6b 100644 --- a/app/views/index/logs.phtml +++ b/app/views/index/logs.phtml @@ -14,7 +14,7 @@ ?> <?php if (!empty($items)) { ?> - <?php $this->logsPaginator->render('logs_pagination.phtml', 'page'); ?> + <?php $this->logsPaginator->render('logs_pagination.phtml', 0); ?> <div id="loglist-wrapper" class="table-wrapper"> <table id="loglist"> <thead> @@ -41,7 +41,7 @@ </tbody> </table> </div> - <?php $this->logsPaginator->render('logs_pagination.phtml', 'page'); ?> + <?php $this->logsPaginator->render('logs_pagination.phtml', 0); ?> diff --git a/app/views/tag/getTagsForEntry.phtml b/app/views/tag/getTagsForEntry.phtml index 9125ae84b..46a82ca68 100644 --- a/app/views/tag/getTagsForEntry.phtml +++ b/app/views/tag/getTagsForEntry.phtml @@ -1,3 +1,3 @@ <?php /** @var FreshRSS_View $this */ ?> <?php -echo json_encode($this->tags); +echo json_encode($this->tagsForEntry); |
