diff options
| author | 2022-01-04 13:59:09 +0100 | |
|---|---|---|
| committer | 2022-01-04 13:59:09 +0100 | |
| commit | 1335a0e3cf11a0d4248e9eaaf748b89e6df741ef (patch) | |
| tree | ed6a8d17cef0581e5b0402dc8dfedd42fabfe9c7 /app/Controllers | |
| parent | 0988b0c2be911133f883313bc3a858670192cc69 (diff) | |
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
Diffstat (limited to 'app/Controllers')
| -rw-r--r-- | app/Controllers/apiController.php | 2 | ||||
| -rw-r--r-- | app/Controllers/authController.php | 2 | ||||
| -rw-r--r-- | app/Controllers/categoryController.php | 2 | ||||
| -rwxr-xr-x | app/Controllers/configureController.php | 9 | ||||
| -rwxr-xr-x | app/Controllers/entryController.php | 2 | ||||
| -rw-r--r-- | app/Controllers/errorController.php | 2 | ||||
| -rw-r--r-- | app/Controllers/extensionController.php | 2 | ||||
| -rwxr-xr-x | app/Controllers/feedController.php | 28 | ||||
| -rw-r--r-- | app/Controllers/importExportController.php | 10 | ||||
| -rwxr-xr-x | app/Controllers/indexController.php | 2 | ||||
| -rwxr-xr-x | app/Controllers/javascriptController.php | 6 | ||||
| -rw-r--r-- | app/Controllers/statsController.php | 2 | ||||
| -rw-r--r-- | app/Controllers/subscriptionController.php | 6 | ||||
| -rw-r--r-- | app/Controllers/tagController.php | 2 | ||||
| -rw-r--r-- | app/Controllers/updateController.php | 4 | ||||
| -rw-r--r-- | app/Controllers/userController.php | 6 |
16 files changed, 37 insertions, 50 deletions
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<string,string> $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 @@ <?php -class FreshRSS_javascript_Controller extends Minz_ActionController { +class FreshRSS_javascript_Controller extends FreshRSS_ActionController { public function firstAction() { $this->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 @@ <?php -class FreshRSS_update_Controller extends Minz_ActionController { +class FreshRSS_update_Controller extends FreshRSS_ActionController { public static function isGit() { return is_dir(FRESHRSS_PATH . '/.git/'); @@ -261,7 +261,7 @@ class FreshRSS_update_Controller extends Minz_ActionController { Minz_Request::forward(array( 'c' => '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', ''); |
