From 1335a0e3cf11a0d4248e9eaaf748b89e6df741ef Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Tue, 4 Jan 2022 13:59:09 +0100 Subject: PHPStan level 5 (#4110) * Fix most PHPDocs errors Contributes to https://github.com/FreshRSS/FreshRSS/issues/4103 https://phpstan.org/writing-php-code/phpdoc-types * Avoid func_get_args Use variadic syntax instead https://php.net/manual/functions.arguments#functions.variable-arg-list And avoid dynamic functions names when possible to more easily identify calls and unused functions. Contributes to https://github.com/FreshRSS/FreshRSS/issues/4103 * PHPStan level 3 * PHPStand level 4 * Update default to PHPStan level 4 * Towards level 5 * Fix level 4 regression * Towards level 5 * Pass PHPStan level 5 * Towards level 6 * Remove erronenous regression from changelog https://github.com/FreshRSS/FreshRSS/pull/4116 --- app/Controllers/apiController.php | 2 +- app/Controllers/authController.php | 2 +- app/Controllers/categoryController.php | 2 +- app/Controllers/configureController.php | 9 ++-- app/Controllers/entryController.php | 2 +- app/Controllers/errorController.php | 2 +- app/Controllers/extensionController.php | 2 +- app/Controllers/feedController.php | 28 ++++------ app/Controllers/importExportController.php | 10 ++-- app/Controllers/indexController.php | 2 +- app/Controllers/javascriptController.php | 6 +-- app/Controllers/statsController.php | 2 +- app/Controllers/subscriptionController.php | 6 +-- app/Controllers/tagController.php | 2 +- app/Controllers/updateController.php | 4 +- app/Controllers/userController.php | 6 +-- app/Exceptions/FeedNotAddedException.php | 10 ++-- app/Mailers/UserMailer.php | 6 +++ app/Models/ActionController.php | 9 ++++ app/Models/Auth.php | 2 +- app/Models/ConfigurationSetter.php | 1 + app/Models/Context.php | 21 +++++++- app/Models/Entry.php | 13 ++++- app/Models/EntryDAO.php | 12 ++--- app/Models/EntryDAOSQLite.php | 10 ++-- app/Models/Feed.php | 7 +-- app/Models/FormAuth.php | 2 +- app/Models/ReadingMode.php | 4 +- app/Models/Share.php | 2 +- app/Models/StatsDAO.php | 16 +++--- app/Models/StatsDAOPGSQL.php | 8 +-- app/Models/SystemConfiguration.php | 28 ++++++++++ app/Models/TagDAO.php | 8 +-- app/Models/UserConfiguration.php | 64 +++++++++++++++++++++++ app/Models/UserQuery.php | 4 +- app/Models/View.php | 12 +++++ app/Services/ImportService.php | 4 -- app/actualize_script.php | 2 + app/install.php | 3 ++ app/views/configure/queries.phtml | 4 +- app/views/helpers/index/normal/entry_bottom.phtml | 1 + app/views/helpers/pagination.phtml | 6 +-- app/views/index/rss.phtml | 2 +- app/views/subscription/index.phtml | 2 +- app/views/user/profile.phtml | 3 +- 45 files changed, 244 insertions(+), 109 deletions(-) create mode 100644 app/Models/ActionController.php create mode 100644 app/Models/SystemConfiguration.php create mode 100644 app/Models/UserConfiguration.php (limited to 'app') diff --git a/app/Controllers/apiController.php b/app/Controllers/apiController.php index 14dac938c..7843a33f1 100644 --- a/app/Controllers/apiController.php +++ b/app/Controllers/apiController.php @@ -3,7 +3,7 @@ /** * This controller manage API-related features. */ -class FreshRSS_api_Controller extends Minz_ActionController { +class FreshRSS_api_Controller extends FreshRSS_ActionController { /** * Update the user API password. diff --git a/app/Controllers/authController.php b/app/Controllers/authController.php index 085278a4f..fedabea8e 100644 --- a/app/Controllers/authController.php +++ b/app/Controllers/authController.php @@ -3,7 +3,7 @@ /** * This controller handles action about authentication. */ -class FreshRSS_auth_Controller extends Minz_ActionController { +class FreshRSS_auth_Controller extends FreshRSS_ActionController { /** * This action handles authentication management page. * diff --git a/app/Controllers/categoryController.php b/app/Controllers/categoryController.php index 3ec88460a..7226e44af 100644 --- a/app/Controllers/categoryController.php +++ b/app/Controllers/categoryController.php @@ -4,7 +4,7 @@ * Controller to handle actions relative to categories. * User needs to be connected. */ -class FreshRSS_category_Controller extends Minz_ActionController { +class FreshRSS_category_Controller extends FreshRSS_ActionController { /** * This action is called before every other action in that class. It is * the common boiler plate for every action. It is triggered by the diff --git a/app/Controllers/configureController.php b/app/Controllers/configureController.php index b8bf97e77..a263db99c 100755 --- a/app/Controllers/configureController.php +++ b/app/Controllers/configureController.php @@ -3,7 +3,7 @@ /** * Controller to handle every configuration options. */ -class FreshRSS_configure_Controller extends Minz_ActionController { +class FreshRSS_configure_Controller extends FreshRSS_ActionController { /** * This action is called before every other action in that class. It is * the common boiler plate for every action. It is triggered by the @@ -249,7 +249,7 @@ class FreshRSS_configure_Controller extends Minz_ActionController { $volatile = [ 'enable_keep_period' => true, 'keep_period_count' => $matches['count'], - 'keep_period_unit' => str_replace($matches['count'], 1, $keepPeriod), + 'keep_period_unit' => str_replace($matches['count'], '1', $keepPeriod), ]; } FreshRSS_Context::$user_conf->volatile = $volatile; @@ -295,7 +295,7 @@ class FreshRSS_configure_Controller extends Minz_ActionController { if ($query['search']) { $query['search'] = urldecode($query['search']); } - $queries[] = new FreshRSS_UserQuery($query, $feed_dao, $category_dao, $tag_dao); + $queries[intval($key)] = new FreshRSS_UserQuery($query, $feed_dao, $category_dao, $tag_dao); } FreshRSS_Context::$user_conf->queries = $queries; FreshRSS_Context::$user_conf->save(); @@ -304,7 +304,7 @@ class FreshRSS_configure_Controller extends Minz_ActionController { } else { $this->view->queries = array(); foreach (FreshRSS_Context::$user_conf->queries as $key => $query) { - $this->view->queries[$key] = new FreshRSS_UserQuery($query, $feed_dao, $category_dao, $tag_dao); + $this->view->queries[intval($key)] = new FreshRSS_UserQuery($query, $feed_dao, $category_dao, $tag_dao); } } @@ -315,6 +315,7 @@ class FreshRSS_configure_Controller extends Minz_ActionController { $id = Minz_Request::param('id'); $this->view->displaySlider = false; if (false !== $id) { + $id = intval($id); $this->view->displaySlider = true; $this->view->query = $this->view->queries[$id]; $this->view->queryId = $id; diff --git a/app/Controllers/entryController.php b/app/Controllers/entryController.php index 2f5c6594c..5afd24a91 100755 --- a/app/Controllers/entryController.php +++ b/app/Controllers/entryController.php @@ -3,7 +3,7 @@ /** * Controller to handle every entry actions. */ -class FreshRSS_entry_Controller extends Minz_ActionController { +class FreshRSS_entry_Controller extends FreshRSS_ActionController { /** * JavaScript request or not. diff --git a/app/Controllers/errorController.php b/app/Controllers/errorController.php index 658cc71af..999236031 100644 --- a/app/Controllers/errorController.php +++ b/app/Controllers/errorController.php @@ -3,7 +3,7 @@ /** * Controller to handle error page. */ -class FreshRSS_error_Controller extends Minz_ActionController { +class FreshRSS_error_Controller extends FreshRSS_ActionController { /** * This action is the default one for the controller. * diff --git a/app/Controllers/extensionController.php b/app/Controllers/extensionController.php index 69f52cebf..3a3affb99 100644 --- a/app/Controllers/extensionController.php +++ b/app/Controllers/extensionController.php @@ -3,7 +3,7 @@ /** * The controller to manage extensions. */ -class FreshRSS_extension_Controller extends Minz_ActionController { +class FreshRSS_extension_Controller extends FreshRSS_ActionController { /** * This action is called before every other action in that class. It is * the common boiler plate for every action. It is triggered by the diff --git a/app/Controllers/feedController.php b/app/Controllers/feedController.php index e95bd8763..de243501b 100755 --- a/app/Controllers/feedController.php +++ b/app/Controllers/feedController.php @@ -3,7 +3,7 @@ /** * Controller to handle every feed actions. */ -class FreshRSS_feed_Controller extends Minz_ActionController { +class FreshRSS_feed_Controller extends FreshRSS_ActionController { /** * This action is called before every other action in that class. It is * the common boiler plate for every action. It is triggered by the @@ -46,10 +46,10 @@ class FreshRSS_feed_Controller extends Minz_ActionController { $url = trim($url); - /** @var string $url */ + /** @var string|null $url */ $url = Minz_ExtensionManager::callHook('check_url_before_add', $url); if (null === $url) { - throw new FreshRSS_FeedNotAdded_Exception($url, $title); + throw new FreshRSS_FeedNotAdded_Exception($url); } $cat = null; @@ -77,10 +77,10 @@ class FreshRSS_feed_Controller extends Minz_ActionController { throw new FreshRSS_AlreadySubscribed_Exception($url, $feed->name()); } - /** @var FreshRSS_Feed $feed */ + /** @var FreshRSS_Feed|null $feed */ $feed = Minz_ExtensionManager::callHook('feed_before_insert', $feed); if ($feed === null) { - throw new FreshRSS_FeedNotAdded_Exception($url, $feed->name()); + throw new FreshRSS_FeedNotAdded_Exception($url); } $values = array( @@ -97,7 +97,7 @@ class FreshRSS_feed_Controller extends Minz_ActionController { $id = $feedDAO->addFeed($values); if (!$id) { // There was an error in database... we cannot say what here. - throw new FreshRSS_FeedNotAdded_Exception($url, $feed->name()); + throw new FreshRSS_FeedNotAdded_Exception($url); } $feed->_id($id); @@ -186,7 +186,7 @@ class FreshRSS_feed_Controller extends Minz_ActionController { $attributes['timeout'] = $timeout > 0 ? $timeout : null; try { - $feed = self::addFeed($url, '', $cat, null, $http_auth, $attributes); + $feed = self::addFeed($url, '', $cat, '', $http_auth, $attributes); } catch (FreshRSS_BadUrl_Exception $e) { // Given url was not a valid url! Minz_Log::warning($e->getMessage()); @@ -202,7 +202,7 @@ class FreshRSS_feed_Controller extends Minz_ActionController { } catch (FreshRSS_AlreadySubscribed_Exception $e) { return Minz_Request::bad(_t('feedback.sub.feed.already_subscribed', $e->feedName()), $url_redirect); } catch (FreshRSS_FeedNotAdded_Exception $e) { - return Minz_Request::bad(_t('feedback.sub.feed.not_added', $e->feedName()), $url_redirect); + return Minz_Request::bad(_t('feedback.sub.feed.not_added', $e->url()), $url_redirect); } // Entries are in DB, we redirect to feed configuration page. @@ -296,7 +296,7 @@ class FreshRSS_feed_Controller extends Minz_ActionController { $updated_feeds = 0; $nb_new_articles = 0; foreach ($feeds as $feed) { - /** @var FreshRSS_Feed $feed */ + /** @var FreshRSS_Feed|null $feed */ $feed = Minz_ExtensionManager::callHook('feed_before_actualize', $feed); if (null === $feed) { continue; @@ -874,14 +874,4 @@ class FreshRSS_feed_Controller extends Minz_ActionController { $this->view->fatalError = _t('feedback.sub.feed.selector_preview.http_error'); } } - - /** - * This method update TTL values for feeds if needed. - * It changes the old default value (-2) to the new default value (0). - * It changes the old disabled value (-1) to the default disabled value. - */ - private function updateTTL() { - $feedDAO = FreshRSS_Factory::createFeedDao(); - $feedDAO->updateTTL(); - } } diff --git a/app/Controllers/importExportController.php b/app/Controllers/importExportController.php index 0634bf54c..c19cf7831 100644 --- a/app/Controllers/importExportController.php +++ b/app/Controllers/importExportController.php @@ -3,9 +3,8 @@ /** * Controller to handle every import and export actions. */ -class FreshRSS_importExport_Controller extends Minz_ActionController { +class FreshRSS_importExport_Controller extends FreshRSS_ActionController { - private $catDAO; private $entryDAO; private $feedDAO; @@ -21,7 +20,6 @@ class FreshRSS_importExport_Controller extends Minz_ActionController { require_once(LIB_PATH . '/lib_opml.php'); - $this->catDAO = FreshRSS_Factory::createCategoryDao(); $this->entryDAO = FreshRSS_Factory::createEntryDao(); $this->feedDAO = FreshRSS_Factory::createFeedDao(); } @@ -54,7 +52,6 @@ class FreshRSS_importExport_Controller extends Minz_ActionController { public function importFile($name, $path, $username = null) { self::minimumMemory(256); - $this->catDAO = FreshRSS_Factory::createCategoryDao($username); $this->entryDAO = FreshRSS_Factory::createEntryDao($username); $this->feedDAO = FreshRSS_Factory::createFeedDao($username); @@ -492,9 +489,8 @@ class FreshRSS_importExport_Controller extends Minz_ActionController { /** * This method import a JSON-based feed (Google Reader format). * - * @param array $origin represents a feed. - * @return FreshRSS_Feed if feed is in database at the end of the process, - * else null. + * @param array $origin represents a feed. + * @return FreshRSS_Feed|null if feed is in database at the end of the process, else null. */ private function addFeedJson($origin) { $return = null; diff --git a/app/Controllers/indexController.php b/app/Controllers/indexController.php index eadfe252b..c6200f868 100755 --- a/app/Controllers/indexController.php +++ b/app/Controllers/indexController.php @@ -3,7 +3,7 @@ /** * This class handles main actions of FreshRSS. */ -class FreshRSS_index_Controller extends Minz_ActionController { +class FreshRSS_index_Controller extends FreshRSS_ActionController { /** * This action only redirect on the default view mode (normal or global) diff --git a/app/Controllers/javascriptController.php b/app/Controllers/javascriptController.php index 4a79da27a..3eaae486a 100755 --- a/app/Controllers/javascriptController.php +++ b/app/Controllers/javascriptController.php @@ -1,6 +1,6 @@ view->_layout(false); } @@ -36,7 +36,7 @@ class FreshRSS_javascript_Controller extends Minz_ActionController { if (strlen($s) >= 60) { //CRYPT_BLOWFISH Salt: "$2a$", a two digit cost parameter, "$", and 22 characters from the alphabet "./0-9A-Za-z". $this->view->salt1 = substr($s, 0, 29); - $this->view->nonce = sha1($salt . uniqid(mt_rand(), true)); + $this->view->nonce = sha1($salt . uniqid('' . mt_rand(), true)); Minz_Session::_param('nonce', $this->view->nonce); return; //Success } @@ -52,6 +52,6 @@ class FreshRSS_javascript_Controller extends Minz_ActionController { for ($i = 22; $i > 0; $i--) { $this->view->salt1 .= $alphabet[mt_rand(0, 63)]; } - $this->view->nonce = sha1(mt_rand()); + $this->view->nonce = sha1('' . mt_rand()); } } diff --git a/app/Controllers/statsController.php b/app/Controllers/statsController.php index 980f3532d..2815af4a5 100644 --- a/app/Controllers/statsController.php +++ b/app/Controllers/statsController.php @@ -3,7 +3,7 @@ /** * Controller to handle application statistics. */ -class FreshRSS_stats_Controller extends Minz_ActionController { +class FreshRSS_stats_Controller extends FreshRSS_ActionController { /** * This action is called before every other action in that class. It is diff --git a/app/Controllers/subscriptionController.php b/app/Controllers/subscriptionController.php index c01e01843..7545035cc 100644 --- a/app/Controllers/subscriptionController.php +++ b/app/Controllers/subscriptionController.php @@ -3,7 +3,7 @@ /** * Controller to handle subscription actions. */ -class FreshRSS_subscription_Controller extends Minz_ActionController { +class FreshRSS_subscription_Controller extends FreshRSS_ActionController { /** * This action is called before every other action in that class. It is * the common boiler plate for every action. It is triggered by the @@ -175,7 +175,7 @@ class FreshRSS_subscription_Controller extends Minz_ActionController { if ($enableRetentionPeriod = Minz_Request::paramBoolean('enable_keep_period')) { $keepPeriod = FreshRSS_Feed::ARCHIVING_RETENTION_PERIOD; if (is_numeric(Minz_Request::param('keep_period_count')) && preg_match('/^PT?1[YMWDH]$/', Minz_Request::param('keep_period_unit'))) { - $keepPeriod = str_replace(1, Minz_Request::param('keep_period_count'), Minz_Request::param('keep_period_unit')); + $keepPeriod = str_replace('1', Minz_Request::param('keep_period_count'), Minz_Request::param('keep_period_unit')); } } else { $keepPeriod = false; @@ -244,7 +244,7 @@ class FreshRSS_subscription_Controller extends Minz_ActionController { if ($enableRetentionPeriod = Minz_Request::paramBoolean('enable_keep_period')) { $keepPeriod = FreshRSS_Feed::ARCHIVING_RETENTION_PERIOD; if (is_numeric(Minz_Request::param('keep_period_count')) && preg_match('/^PT?1[YMWDH]$/', Minz_Request::param('keep_period_unit'))) { - $keepPeriod = str_replace(1, Minz_Request::param('keep_period_count'), Minz_Request::param('keep_period_unit')); + $keepPeriod = str_replace('1', Minz_Request::param('keep_period_count'), Minz_Request::param('keep_period_unit')); } } else { $keepPeriod = false; diff --git a/app/Controllers/tagController.php b/app/Controllers/tagController.php index 077be9700..8f399988d 100644 --- a/app/Controllers/tagController.php +++ b/app/Controllers/tagController.php @@ -3,7 +3,7 @@ /** * Controller to handle every tag actions. */ -class FreshRSS_tag_Controller extends Minz_ActionController { +class FreshRSS_tag_Controller extends FreshRSS_ActionController { /** * JavaScript request or not. diff --git a/app/Controllers/updateController.php b/app/Controllers/updateController.php index 16ab7e427..0f67fe64c 100644 --- a/app/Controllers/updateController.php +++ b/app/Controllers/updateController.php @@ -1,6 +1,6 @@ 'update', 'a' => 'apply', - 'params' => array('post_conf' => true) + 'params' => array('post_conf' => '1') ), true); } else { Minz_Request::bad(_t('feedback.update.error', $res), [ 'c' => 'update', 'a' => 'index' ]); diff --git a/app/Controllers/userController.php b/app/Controllers/userController.php index b1f34ce61..c5e1b30ab 100644 --- a/app/Controllers/userController.php +++ b/app/Controllers/userController.php @@ -3,7 +3,7 @@ /** * Controller to handle user actions. */ -class FreshRSS_user_Controller extends Minz_ActionController { +class FreshRSS_user_Controller extends FreshRSS_ActionController { /** * The username is also used as folder name, file name, and part of SQL table name. * '_' is a reserved internal username. @@ -29,7 +29,7 @@ class FreshRSS_user_Controller extends Minz_ActionController { if (FreshRSS_Context::$system_conf->force_email_validation) { $salt = FreshRSS_Context::$system_conf->salt; - $userConfig->email_validation_token = sha1($salt . uniqid(mt_rand(), true)); + $userConfig->email_validation_token = sha1($salt . uniqid('' . mt_rand(), true)); $mailer = new FreshRSS_User_Mailer(); $mailer->send_email_need_validation($user, $userConfig); } @@ -536,7 +536,7 @@ class FreshRSS_user_Controller extends Minz_ActionController { if (Minz_Request::isPost()) { $ok = true; - if ($ok && $self_deletion) { + if ($self_deletion) { // We check the password if it's a self-destruction $nonce = Minz_Session::param('nonce'); $challenge = Minz_Request::param('challenge', ''); diff --git a/app/Exceptions/FeedNotAddedException.php b/app/Exceptions/FeedNotAddedException.php index 350a17c56..59fa74b16 100644 --- a/app/Exceptions/FeedNotAddedException.php +++ b/app/Exceptions/FeedNotAddedException.php @@ -1,14 +1,14 @@ feedName = $feedName; + $this->url = $url; } - public function feedName() { - return $this->feedName; + public function url() { + return $this->url; } } diff --git a/app/Mailers/UserMailer.php b/app/Mailers/UserMailer.php index f1618303a..4450bd96c 100644 --- a/app/Mailers/UserMailer.php +++ b/app/Mailers/UserMailer.php @@ -4,6 +4,12 @@ * Manage the emails sent to the users. */ class FreshRSS_User_Mailer extends Minz_Mailer { + + /** + * @var FreshRSS_View + */ + protected $view; + public function send_email_need_validation($username, $user_config) { Minz_Translate::reset($user_config->language); diff --git a/app/Models/ActionController.php b/app/Models/ActionController.php new file mode 100644 index 000000000..2e0aaa730 --- /dev/null +++ b/app/Models/ActionController.php @@ -0,0 +1,9 @@ +salt; - $csrf = sha1($salt . uniqid(mt_rand(), true)); + $csrf = sha1($salt . uniqid('' . mt_rand(), true)); Minz_Session::_param('csrf', $csrf); } return $csrf; diff --git a/app/Models/ConfigurationSetter.php b/app/Models/ConfigurationSetter.php index 3c07db4a0..336a93351 100644 --- a/app/Models/ConfigurationSetter.php +++ b/app/Models/ConfigurationSetter.php @@ -371,6 +371,7 @@ class FreshRSS_ConfigurationSetter { $value = intval($value); $limits = $limits_keys[$key]; + // @phpstan-ignore-next-line if ((!isset($limits['min']) || $value >= $limits['min']) && (!isset($limits['max']) || $value <= $limits['max']) ) { diff --git a/app/Models/Context.php b/app/Models/Context.php index 6b2043bd3..62dc53774 100644 --- a/app/Models/Context.php +++ b/app/Models/Context.php @@ -5,8 +5,17 @@ * useful functions associated to the current view state. */ class FreshRSS_Context { + + /** + * @var FreshRSS_UserConfiguration|null + */ public static $user_conf = null; + + /** + * @var FreshRSS_SystemConfiguration|null + */ public static $system_conf = null; + public static $categories = array(); public static $tags = array(); @@ -49,7 +58,11 @@ class FreshRSS_Context { if ($reload || FreshRSS_Context::$system_conf == null) { //TODO: Keep in session what we need instead of always reloading from disk Minz_Configuration::register('system', DATA_PATH . '/config.php', FRESHRSS_PATH . '/config.default.php'); - FreshRSS_Context::$system_conf = Minz_Configuration::get('system'); + /** + * @var FreshRSS_SystemConfiguration $system_conf + */ + $system_conf = Minz_Configuration::get('system'); + FreshRSS_Context::$system_conf = $system_conf; // Register the configuration setter for the system configuration $configurationSetter = new FreshRSS_ConfigurationSetter(); FreshRSS_Context::$system_conf->_configurationSetter($configurationSetter); @@ -80,7 +93,11 @@ class FreshRSS_Context { FreshRSS_Context::$system_conf->configurationSetter()); Minz_Session::_param('currentUser', $username); - FreshRSS_Context::$user_conf = Minz_Configuration::get('user'); + /** + * @var FreshRSS_UserConfiguration $user_conf + */ + $user_conf = Minz_Configuration::get('user'); + FreshRSS_Context::$user_conf = $user_conf; } catch (Exception $ex) { Minz_Log::warning($ex->getMessage(), USERS_PATH . '/_/log.txt'); } diff --git a/app/Models/Entry.php b/app/Models/Entry.php index d3aa13327..cc1f4d9bc 100644 --- a/app/Models/Entry.php +++ b/app/Models/Entry.php @@ -260,7 +260,7 @@ class FreshRSS_Entry extends Minz_Model { } foreach ($booleanSearch->searches() as $filter) { $ok = true; - if ($ok && $filter->getMinDate()) { + if ($filter->getMinDate()) { $ok &= strnatcmp($this->id, $filter->getMinDate() . '000000') >= 0; } if ($ok && $filter->getNotMinDate()) { @@ -451,12 +451,18 @@ class FreshRSS_Entry extends Minz_Model { Minz_Log::warning('Error fetching content: HTTP code ' . $c_status . ': ' . $c_error . ' ' . $url); } - if ($html) { + if (is_string($html) && strlen($html) > 0) { require_once(LIB_PATH . '/lib_phpQuery.php'); + /** + * @var phpQueryObject @doc + */ $doc = phpQuery::newDocument($html); if ($maxRedirs > 0) { //Follow any HTML redirection + /** + * @var phpQueryObject @metas + */ $metas = $doc->find('meta[http-equiv][content]'); foreach ($metas as $meta) { if (strtolower(trim($meta->getAttribute('http-equiv'))) === 'refresh') { @@ -470,6 +476,9 @@ class FreshRSS_Entry extends Minz_Model { } } + /** + * @var phpQueryObject @content + */ $content = $doc->find($path); $html = trim(sanitizeHTML($content->__toString(), $url)); phpQuery::unloadDocuments(); diff --git a/app/Models/EntryDAO.php b/app/Models/EntryDAO.php index 2e4f52d0b..ff5777bb0 100644 --- a/app/Models/EntryDAO.php +++ b/app/Models/EntryDAO.php @@ -310,7 +310,7 @@ SQL; $hasWhere = false; $values = array(); if ($feedId !== false) { - $sql .= $hasWhere ? ' AND' : ' WHERE'; + $sql .= ' WHERE'; $hasWhere = true; $sql .= ' f.id=?'; $values[] = $feedId; @@ -342,7 +342,7 @@ SQL; * * @param integer|array $ids * @param boolean $is_read - * @return integer affected rows + * @return integer|false affected rows */ public function markRead($ids, $is_read = true) { FreshRSS_UserDAO::touch(); @@ -415,7 +415,7 @@ SQL; * @param integer $idMax fail safe article ID * @param boolean $onlyFavorites * @param integer $priorityMin - * @return integer affected rows + * @return integer|false affected rows */ public function markReadEntries($idMax = 0, $onlyFavorites = false, $priorityMin = 0, $filters = null, $state = 0, $is_read = true) { FreshRSS_UserDAO::touch(); @@ -458,7 +458,7 @@ SQL; * * @param integer $id category ID * @param integer $idMax fail safe article ID - * @return integer affected rows + * @return integer|false affected rows */ public function markReadCat($id, $idMax = 0, $filters = null, $state = 0, $is_read = true) { FreshRSS_UserDAO::touch(); @@ -496,7 +496,7 @@ SQL; * * @param integer $id_feed feed ID * @param integer $idMax fail safe article ID - * @return integer affected rows + * @return integer|false affected rows */ public function markReadFeed($id_feed, $idMax = 0, $filters = null, $state = 0, $is_read = true) { FreshRSS_UserDAO::touch(); @@ -544,7 +544,7 @@ SQL; * Mark all the articles in a tag as read. * @param integer $id tag ID, or empty for targetting any tag * @param integer $idMax max article ID - * @return integer affected rows + * @return integer|false affected rows */ public function markReadTag($id = 0, $idMax = 0, $filters = null, $state = 0, $is_read = true) { FreshRSS_UserDAO::touch(); diff --git a/app/Models/EntryDAOSQLite.php b/app/Models/EntryDAOSQLite.php index 65df483ff..649536bdf 100644 --- a/app/Models/EntryDAOSQLite.php +++ b/app/Models/EntryDAOSQLite.php @@ -77,7 +77,7 @@ DROP TABLE IF EXISTS `tmp`; $hasWhere = false; $values = array(); if ($feedId !== false) { - $sql .= $hasWhere ? ' AND' : ' WHERE'; + $sql .= ' WHERE'; $hasWhere = true; $sql .= ' id=?'; $values[] = $feedId; @@ -109,7 +109,7 @@ DROP TABLE IF EXISTS `tmp`; * * @param integer|array $ids * @param boolean $is_read - * @return integer affected rows + * @return integer|false affected rows */ public function markRead($ids, $is_read = true) { FreshRSS_UserDAO::touch(); @@ -169,7 +169,7 @@ DROP TABLE IF EXISTS `tmp`; * @param integer $idMax fail safe article ID * @param boolean $onlyFavorites * @param integer $priorityMin - * @return integer affected rows + * @return integer|false affected rows */ public function markReadEntries($idMax = 0, $onlyFavorites = false, $priorityMin = 0, $filters = null, $state = 0, $is_read = true) { FreshRSS_UserDAO::touch(); @@ -210,7 +210,7 @@ DROP TABLE IF EXISTS `tmp`; * * @param integer $id category ID * @param integer $idMax fail safe article ID - * @return integer affected rows + * @return integer|false affected rows */ public function markReadCat($id, $idMax = 0, $filters = null, $state = 0, $is_read = true) { FreshRSS_UserDAO::touch(); @@ -244,7 +244,7 @@ DROP TABLE IF EXISTS `tmp`; * Mark all the articles in a tag as read. * @param integer $id tag ID, or empty for targetting any tag * @param integer $idMax max article ID - * @return integer affected rows + * @return integer|false affected rows */ public function markReadTag($id = 0, $idMax = 0, $filters = null, $state = 0, $is_read = true) { FreshRSS_UserDAO::touch(); diff --git a/app/Models/Feed.php b/app/Models/Feed.php index 3dc965b32..972983384 100644 --- a/app/Models/Feed.php +++ b/app/Models/Feed.php @@ -259,6 +259,7 @@ class FreshRSS_Feed extends Minz_Model { public function load($loadDetails = false, $noCache = false) { if ($this->url !== null) { + // @phpstan-ignore-next-line if (CACHE_PATH === false) { throw new Minz_FileNotExistException( 'CACHE_PATH', @@ -462,10 +463,10 @@ class FreshRSS_Feed extends Minz_Model { $entry = new FreshRSS_Entry( $this->id(), $hasBadGuids ? '' : $guid, - $title === null ? '' : $title, + $title == '' ? '' : $title, $author_names, - $content === null ? '' : $content, - $link === null ? '' : $link, + $content == '' ? '' : $content, + $link == '' ? '' : $link, $date ? $date : time() ); $entry->_tags($tags); diff --git a/app/Models/FormAuth.php b/app/Models/FormAuth.php index 5211fd5d1..d6da637d1 100644 --- a/app/Models/FormAuth.php +++ b/app/Models/FormAuth.php @@ -50,7 +50,7 @@ class FreshRSS_FormAuth { public static function makeCookie($username, $password_hash) { do { - $token = sha1(FreshRSS_Context::$system_conf->salt . $username . uniqid(mt_rand(), true)); + $token = sha1(FreshRSS_Context::$system_conf->salt . $username . uniqid('' . mt_rand(), true)); $token_file = DATA_PATH . '/tokens/' . $token . '.txt'; } while (file_exists($token_file)); diff --git a/app/Models/ReadingMode.php b/app/Models/ReadingMode.php index 06af1704c..ddb413315 100644 --- a/app/Models/ReadingMode.php +++ b/app/Models/ReadingMode.php @@ -81,14 +81,14 @@ class FreshRSS_ReadingMode { } /** - * @return string + * @return array */ public function getUrlParams() { return $this->urlParams; } /** - * @param string $urlParams + * @param array $urlParams * @return FreshRSS_ReadingMode */ public function setUrlParams($urlParams) { diff --git a/app/Models/Share.php b/app/Models/Share.php index 695b16eca..0a341fa55 100644 --- a/app/Models/Share.php +++ b/app/Models/Share.php @@ -11,7 +11,7 @@ class FreshRSS_Share { /** * Register a new sharing option. - * @param array $share_options is an array defining the share option. + * @param array> $share_options is an array defining the share option. */ public static function register($share_options) { $type = $share_options['type']; diff --git a/app/Models/StatsDAO.php b/app/Models/StatsDAO.php index 33e5426b5..612fe5cab 100644 --- a/app/Models/StatsDAO.php +++ b/app/Models/StatsDAO.php @@ -133,7 +133,7 @@ SQL; * * @param string $period format string to use for grouping * @param integer $feed id - * @return array + * @return array */ protected function calculateEntryRepartitionPerFeedPerPeriod($period, $feed = null) { $restrict = ''; @@ -178,7 +178,7 @@ SQL; * Calculates the average number of article per hour per feed * * @param integer $feed id - * @return integer + * @return float */ public function calculateEntryAveragePerFeedPerHour($feed = null) { return $this->calculateEntryAveragePerFeedPerPeriod(1 / 24, $feed); @@ -188,7 +188,7 @@ SQL; * Calculates the average number of article per day of week per feed * * @param integer $feed id - * @return integer + * @return float */ public function calculateEntryAveragePerFeedPerDayOfWeek($feed = null) { return $this->calculateEntryAveragePerFeedPerPeriod(7, $feed); @@ -198,7 +198,7 @@ SQL; * Calculates the average number of article per month per feed * * @param integer $feed id - * @return integer + * @return float */ public function calculateEntryAveragePerFeedPerMonth($feed = null) { return $this->calculateEntryAveragePerFeedPerPeriod(30, $feed); @@ -209,7 +209,7 @@ SQL; * * @param float $period number used to divide the number of day in the period * @param integer $feed id - * @return integer + * @return float */ protected function calculateEntryAveragePerFeedPerPeriod($period, $feed = null) { $restrict = ''; @@ -337,7 +337,7 @@ SQL; /** * Gets days ready for graphs * - * @return string + * @return array */ public function getDays() { return $this->convertToTranslatedJson(array( @@ -354,7 +354,7 @@ SQL; /** * Gets months ready for graphs * - * @return string + * @return array */ public function getMonths() { return $this->convertToTranslatedJson(array( @@ -377,7 +377,7 @@ SQL; * Translates array content * * @param array $data - * @return array + * @return array */ private function convertToTranslatedJson($data = array()) { $translated = array_map(function($a) { diff --git a/app/Models/StatsDAOPGSQL.php b/app/Models/StatsDAOPGSQL.php index f36d29770..85f9d63f3 100644 --- a/app/Models/StatsDAOPGSQL.php +++ b/app/Models/StatsDAOPGSQL.php @@ -6,7 +6,7 @@ class FreshRSS_StatsDAOPGSQL extends FreshRSS_StatsDAO { * Calculates the number of article per hour of the day per feed * * @param integer $feed id - * @return string + * @return array */ public function calculateEntryRepartitionPerFeedPerHour($feed = null) { return $this->calculateEntryRepartitionPerFeedPerPeriod('hour', $feed); @@ -16,7 +16,7 @@ class FreshRSS_StatsDAOPGSQL extends FreshRSS_StatsDAO { * Calculates the number of article per day of week per feed * * @param integer $feed id - * @return string + * @return array */ public function calculateEntryRepartitionPerFeedPerDayOfWeek($feed = null) { return $this->calculateEntryRepartitionPerFeedPerPeriod('day', $feed); @@ -26,7 +26,7 @@ class FreshRSS_StatsDAOPGSQL extends FreshRSS_StatsDAO { * Calculates the number of article per month per feed * * @param integer $feed - * @return string + * @return array */ public function calculateEntryRepartitionPerFeedPerMonth($feed = null) { return $this->calculateEntryRepartitionPerFeedPerPeriod('month', $feed); @@ -37,7 +37,7 @@ class FreshRSS_StatsDAOPGSQL extends FreshRSS_StatsDAO { * * @param string $period format string to use for grouping * @param integer $feed id - * @return string + * @return array */ protected function calculateEntryRepartitionPerFeedPerPeriod($period, $feed = null) { $restrict = ''; diff --git a/app/Models/SystemConfiguration.php b/app/Models/SystemConfiguration.php new file mode 100644 index 000000000..3b07bc9ff --- /dev/null +++ b/app/Models/SystemConfiguration.php @@ -0,0 +1,28 @@ + $curl_options + * @property string $default_user + * @property string $email_validation_token + * @property bool $force_email_validation + * @property-read bool $http_auth_auto_register + * @property-read string $http_auth_auto_register_email_field + * @property-read string $language + * @property array $limits + * @property-read string $meta_description + * @property-read bool $pubsubhubbub_enabled + * @property-read string $salt + * @property-read bool $simplepie_syslog_enabled + * @property string $unsafe_autologin_enabled + */ +class FreshRSS_SystemConfiguration extends Minz_Configuration { + +} diff --git a/app/Models/TagDAO.php b/app/Models/TagDAO.php index a0e492739..2b24921a2 100644 --- a/app/Models/TagDAO.php +++ b/app/Models/TagDAO.php @@ -74,8 +74,8 @@ SQL; * @param FreshRSS_Tag $tag */ public function addTagObject($tag) { - $tag = $this->searchByName($tag->name()); - if (!$tag) { + $tag0 = $this->searchByName($tag->name()); + if (!$tag0) { $values = array( 'name' => $tag->name(), 'attributes' => $tag->attributes(), @@ -198,7 +198,7 @@ SQL; } /** - * @return FreshRSS_Tag + * @return FreshRSS_Tag|null */ public function searchById($id) { $sql = 'SELECT * FROM `_tag` WHERE id=?'; @@ -211,7 +211,7 @@ SQL; } /** - * @return FreshRSS_Tag + * @return FreshRSS_Tag|null */ public function searchByName($name) { $sql = 'SELECT * FROM `_tag` WHERE name=?'; diff --git a/app/Models/UserConfiguration.php b/app/Models/UserConfiguration.php new file mode 100644 index 000000000..864bf4ec8 --- /dev/null +++ b/app/Models/UserConfiguration.php @@ -0,0 +1,64 @@ + $archiving + * @property bool $auto_load_more + * @property bool $auto_remove_article + * @property bool $bottomline_date + * @property bool $bottomline_favorite + * @property bool $bottomline_link + * @property bool $bottomline_read + * @property bool $bottomline_sharing + * @property bool $bottomline_tags + * @property string $content_width + * @property-read string $default_state + * @property string $default_view + * @property string|bool $display_categories + * @property bool $display_posts + * @property string $email_validation_token + * @property-read string $enabled + * @property string $feverKey + * @property bool $hide_read_feeds + * @property int $html5_notif_timeout + * @property-read string $is_admin + * @property int|null $keep_history_default + * @property string $language + * @property bool $lazyload + * @property string $mail_login + * @property bool $mark_updated_article_unread + * @property array $mark_when + * @property int $max_posts_per_rss + * @property-read array $limits + * @property int|null $old_entries + * @property bool $onread_jump_next + * @property string $passwordHash + * @property int $posts_per_page + * @property array> $queries + * @property bool $reading_confirm + * @property int $since_hours_posts_per_rss + * @property bool $show_fav_unread + * @property bool $show_favicons + * @property bool $show_nav_buttons + * @property string $sort_order + * @property array> $sharing + * @property array $shortcuts + * @property bool $sides_close_article + * @property bool $sticky_post + * @property string $theme + * @property string $token + * @property bool $topline_date + * @property bool $topline_display_authors + * @property bool $topline_favorite + * @property bool $topline_link + * @property bool $topline_read + * @property bool $topline_summary + * @property string $topline_thumbnail + * @property int $ttl_default + * @property-read bool $unsafe_autologin_enabled + * @property string $view_mode + * @property array $volatile + */ +class FreshRSS_UserConfiguration extends Minz_Configuration { + +} diff --git a/app/Models/UserQuery.php b/app/Models/UserQuery.php index 88ddd3629..7f8aa07ef 100644 --- a/app/Models/UserQuery.php +++ b/app/Models/UserQuery.php @@ -22,7 +22,7 @@ class FreshRSS_UserQuery { private $tag_dao; /** - * @param array $query + * @param array $query * @param FreshRSS_Searchable $feed_dao * @param FreshRSS_Searchable $category_dao */ @@ -55,7 +55,7 @@ class FreshRSS_UserQuery { /** * Convert the current object to an array. * - * @return array + * @return array */ public function toArray() { return array_filter(array( diff --git a/app/Models/View.php b/app/Models/View.php index 22bc2c49a..e3a591155 100644 --- a/app/Models/View.php +++ b/app/Models/View.php @@ -4,9 +4,11 @@ class FreshRSS_View extends Minz_View { // Main views public $callbackBeforeEntries; + public $callbackBeforeFeeds; public $callbackBeforePagination; public $categories; public $category; + public $current_user; public $entries; public $entry; public $feed; @@ -33,6 +35,7 @@ class FreshRSS_View extends Minz_View { public $status_files; public $status_php; public $update_to_apply; + public $status_database; // Archiving public $nb_total; @@ -46,12 +49,19 @@ class FreshRSS_View extends Minz_View { public $list_keys; // User queries + /** + * @var array + */ public $queries; + /** + * @var FreshRSS_UserQuery|null + */ public $query; // Export / Import public $content; public $entriesRaw; + public $entriesId; public $entryIdsTagNames; public $list_title; public $queryId; @@ -87,6 +97,7 @@ class FreshRSS_View extends Minz_View { public $selectorSuccess; // Extensions + public $available_extensions; public $ext_details; public $extension_list; public $extension; @@ -95,6 +106,7 @@ class FreshRSS_View extends Minz_View { // Errors public $code; public $errorMessage; + public $message; // Statistics public $average; diff --git a/app/Services/ImportService.php b/app/Services/ImportService.php index 5db640455..4cc38c15c 100644 --- a/app/Services/ImportService.php +++ b/app/Services/ImportService.php @@ -4,9 +4,6 @@ * Provide methods to import files. */ class FreshRSS_Import_Service { - /** @var string */ - private $username; - /** @var FreshRSS_CategoryDAO */ private $catDAO; @@ -21,7 +18,6 @@ class FreshRSS_Import_Service { public function __construct($username) { require_once(LIB_PATH . '/lib_opml.php'); - $this->username = $username; $this->catDAO = FreshRSS_Factory::createCategoryDao($username); $this->feedDAO = FreshRSS_Factory::createFeedDao($username); } diff --git a/app/actualize_script.php b/app/actualize_script.php index 721376f62..e3ee5a5e5 100755 --- a/app/actualize_script.php +++ b/app/actualize_script.php @@ -27,9 +27,11 @@ define('SIMPLEPIE_SYSLOG_ENABLED', FreshRSS_Context::$system_conf->simplepie_sys */ function notice($message) { Minz_Log::notice($message, ADMIN_LOG); + // @phpstan-ignore-next-line if (!COPY_LOG_TO_SYSLOG && SIMPLEPIE_SYSLOG_ENABLED) { syslog(LOG_NOTICE, $message); } + // @phpstan-ignore-next-line if (defined('STDOUT') && !COPY_SYSLOG_TO_STDERR) { fwrite(STDOUT, $message . "\n"); //Unbuffered } diff --git a/app/install.php b/app/install.php index 295be8b76..c9faffd4c 100644 --- a/app/install.php +++ b/app/install.php @@ -276,6 +276,9 @@ function freshrss_already_installed() { $system_conf = null; try { Minz_Configuration::register('system', $conf_path); + /** + * @var FreshRSS_SystemConfiguration $system_conf + */ $system_conf = Minz_Configuration::get('system'); } catch (Minz_FileNotExistException $e) { return false; diff --git a/app/views/configure/queries.phtml b/app/views/configure/queries.phtml index 3f15f299b..3e4b3684b 100644 --- a/app/views/configure/queries.phtml +++ b/app/views/configure/queries.phtml @@ -16,7 +16,7 @@
- getName() ?> + getName() ?> @@ -66,7 +66,7 @@
> query)) { + if ($this->query != null) { $this->renderHelper('configure/query'); } ?> diff --git a/app/views/helpers/index/normal/entry_bottom.phtml b/app/views/helpers/index/normal/entry_bottom.phtml index 07e68ed92..5f105c6c9 100644 --- a/app/views/helpers/index/normal/entry_bottom.phtml +++ b/app/views/helpers/index/normal/entry_bottom.phtml @@ -35,6 +35,7 @@ ?>
  • - +
    diff --git a/app/views/index/rss.phtml b/app/views/index/rss.phtml index f0772cc86..eedb31fa4 100755 --- a/app/views/index/rss.phtml +++ b/app/views/index/rss.phtml @@ -3,7 +3,7 @@ <?= $this->rss_title ?> - + rss_title) ?> GMT diff --git a/app/views/subscription/index.phtml b/app/views/subscription/index.phtml index e16d6ad95..92b1c7ec9 100644 --- a/app/views/subscription/index.phtml +++ b/app/views/subscription/index.phtml @@ -22,7 +22,7 @@ onlyFeedsWithError && $this->signalError){ ?>
    - +
    diff --git a/app/views/user/profile.phtml b/app/views/user/profile.phtml index 99ebcb326..5acb241ed 100644 --- a/app/views/user/profile.phtml +++ b/app/views/user/profile.phtml @@ -57,8 +57,7 @@ token; ?>
    - data-leave-validation=""/> +

    'rss', 'params' => array('user' => Minz_Session::param('currentUser'), 'token' => $token, 'hours' => FreshRSS_Context::$user_conf->since_hours_posts_per_rss)), 'html', true) ?> -- cgit v1.2.3