mirror of
https://github.com/FreshRSS/FreshRSS.git
synced 2026-04-04 14:43:32 -04:00
PHPStan 6 for remaining controllers (#5279)
Contributes to https://github.com/FreshRSS/FreshRSS/issues/4112
This commit is contained in:
committed by
GitHub
parent
73057f6646
commit
74bf894db0
@@ -27,18 +27,14 @@ class FreshRSS_feed_Controller extends FreshRSS_ActionController {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $url
|
||||
* @param string $title
|
||||
* @param int $cat_id
|
||||
* @param string $new_cat_name
|
||||
* @param string $http_auth
|
||||
* @return FreshRSS_Feed
|
||||
* @param array<string,mixed> $attributes
|
||||
* @throws FreshRSS_AlreadySubscribed_Exception
|
||||
* @throws FreshRSS_FeedNotAdded_Exception
|
||||
* @throws FreshRSS_Feed_Exception
|
||||
* @throws Minz_FileNotExistException
|
||||
*/
|
||||
public static function addFeed($url, $title = '', $cat_id = 0, $new_cat_name = '', $http_auth = '', $attributes = array(), $kind = FreshRSS_Feed::KIND_RSS) {
|
||||
public static function addFeed(string $url, string $title = '', int $cat_id = 0, string $new_cat_name = '',
|
||||
string $http_auth = '', array $attributes = [], int $kind = FreshRSS_Feed::KIND_RSS): FreshRSS_Feed {
|
||||
FreshRSS_UserDAO::touch();
|
||||
@set_time_limit(300);
|
||||
|
||||
@@ -131,7 +127,7 @@ class FreshRSS_feed_Controller extends FreshRSS_ActionController {
|
||||
*
|
||||
* If url_rss is false, nothing happened.
|
||||
*/
|
||||
public function addAction() {
|
||||
public function addAction(): void {
|
||||
$url = Minz_Request::paramString('url_rss');
|
||||
|
||||
if ($url == '') {
|
||||
@@ -294,7 +290,7 @@ class FreshRSS_feed_Controller extends FreshRSS_ActionController {
|
||||
* Parameter is:
|
||||
* - id (default: false)
|
||||
*/
|
||||
public function truncateAction() {
|
||||
public function truncateAction(): void {
|
||||
$id = Minz_Request::paramInt('id');
|
||||
$url_redirect = array(
|
||||
'c' => 'subscription',
|
||||
@@ -318,14 +314,9 @@ class FreshRSS_feed_Controller extends FreshRSS_ActionController {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $feed_id
|
||||
* @param string $feed_url
|
||||
* @param bool $force
|
||||
* @param SimplePie|null $simplePiePush
|
||||
* @param bool $noCommit
|
||||
* @param int $maxFeeds
|
||||
* @return array{0:int,1:FreshRSS_Feed|false,2:int}
|
||||
*/
|
||||
public static function actualizeFeed($feed_id, $feed_url, $force, $simplePiePush = null, $noCommit = false, $maxFeeds = 10) {
|
||||
public static function actualizeFeed(int $feed_id, string $feed_url, bool $force, ?SimplePie $simplePiePush = null, bool $noCommit = false, int $maxFeeds = 10) {
|
||||
@set_time_limit(300);
|
||||
|
||||
$feedDAO = FreshRSS_Factory::createFeedDao();
|
||||
@@ -644,7 +635,7 @@ class FreshRSS_feed_Controller extends FreshRSS_ActionController {
|
||||
* If id and url are not specified, all the feeds are actualized. But if force is
|
||||
* false, process stops at 10 feeds to avoid time execution problem.
|
||||
*/
|
||||
public function actualizeAction() {
|
||||
public function actualizeAction(): int {
|
||||
Minz_Session::_param('actualize_feeds', false);
|
||||
$id = Minz_Request::paramInt('id');
|
||||
$url = Minz_Request::paramString('url');
|
||||
@@ -691,16 +682,16 @@ class FreshRSS_feed_Controller extends FreshRSS_ActionController {
|
||||
return $updated_feeds;
|
||||
}
|
||||
|
||||
public static function renameFeed(int $feed_id, string $feed_name) {
|
||||
public static function renameFeed(int $feed_id, string $feed_name): bool {
|
||||
if ($feed_id <= 0 || $feed_name == '') {
|
||||
return false;
|
||||
}
|
||||
FreshRSS_UserDAO::touch();
|
||||
$feedDAO = FreshRSS_Factory::createFeedDao();
|
||||
return $feedDAO->updateFeed($feed_id, array('name' => $feed_name));
|
||||
return $feedDAO->updateFeed($feed_id, array('name' => $feed_name)) === 1;
|
||||
}
|
||||
|
||||
public static function moveFeed(int $feed_id, int $cat_id, string $new_cat_name = '') {
|
||||
public static function moveFeed(int $feed_id, int $cat_id, string $new_cat_name = ''): bool {
|
||||
if ($feed_id <= 0 || ($cat_id <= 0 && $new_cat_name == '')) {
|
||||
return false;
|
||||
}
|
||||
@@ -720,7 +711,7 @@ class FreshRSS_feed_Controller extends FreshRSS_ActionController {
|
||||
}
|
||||
|
||||
$feedDAO = FreshRSS_Factory::createFeedDao();
|
||||
return $feedDAO->updateFeed($feed_id, array('category' => $cat_id));
|
||||
return $feedDAO->updateFeed($feed_id, array('category' => $cat_id)) === 1;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -735,7 +726,7 @@ class FreshRSS_feed_Controller extends FreshRSS_ActionController {
|
||||
*
|
||||
* @todo should handle order of the feed inside the category.
|
||||
*/
|
||||
public function moveAction() {
|
||||
public function moveAction(): void {
|
||||
if (!Minz_Request::isPost()) {
|
||||
Minz_Request::forward(array('c' => 'subscription'), true);
|
||||
}
|
||||
@@ -753,7 +744,7 @@ class FreshRSS_feed_Controller extends FreshRSS_ActionController {
|
||||
}
|
||||
}
|
||||
|
||||
public static function deleteFeed($feed_id) {
|
||||
public static function deleteFeed(int $feed_id): bool {
|
||||
FreshRSS_UserDAO::touch();
|
||||
$feedDAO = FreshRSS_Factory::createFeedDao();
|
||||
if ($feedDAO->deleteFeed($feed_id)) {
|
||||
@@ -782,7 +773,7 @@ class FreshRSS_feed_Controller extends FreshRSS_ActionController {
|
||||
*
|
||||
* @todo handle "r" redirection in Minz_Request::forward()?
|
||||
*/
|
||||
public function deleteAction() {
|
||||
public function deleteAction(): void {
|
||||
$from = Minz_Request::paramString('from');
|
||||
$id = Minz_Request::paramInt('id');
|
||||
|
||||
@@ -822,7 +813,7 @@ class FreshRSS_feed_Controller extends FreshRSS_ActionController {
|
||||
* - id (mandatory - no default): Feed ID
|
||||
*
|
||||
*/
|
||||
public function clearCacheAction() {
|
||||
public function clearCacheAction(): void {
|
||||
//Get Feed.
|
||||
$id = Minz_Request::paramInt('id');
|
||||
|
||||
@@ -848,7 +839,7 @@ class FreshRSS_feed_Controller extends FreshRSS_ActionController {
|
||||
* - id (mandatory - no default): Feed ID
|
||||
*
|
||||
*/
|
||||
public function reloadAction() {
|
||||
public function reloadAction(): void {
|
||||
@set_time_limit(300);
|
||||
|
||||
//Get Feed ID.
|
||||
@@ -905,7 +896,7 @@ class FreshRSS_feed_Controller extends FreshRSS_ActionController {
|
||||
* - selector (mandatory - no default): Selector to preview
|
||||
*
|
||||
*/
|
||||
public function contentSelectorPreviewAction() {
|
||||
public function contentSelectorPreviewAction(): void {
|
||||
|
||||
//Configure.
|
||||
$this->view->fatalError = '';
|
||||
|
||||
@@ -10,15 +10,16 @@ class FreshRSS_user_Controller extends FreshRSS_ActionController {
|
||||
*/
|
||||
const USERNAME_PATTERN = '([0-9a-zA-Z_][0-9a-zA-Z_.@-]{1,38}|[0-9a-zA-Z])';
|
||||
|
||||
public static function checkUsername($username) {
|
||||
public static function checkUsername(string $username): bool {
|
||||
return preg_match('/^' . self::USERNAME_PATTERN . '$/', $username) === 1;
|
||||
}
|
||||
|
||||
public static function userExists($username) {
|
||||
public static function userExists(string $username): bool {
|
||||
return @file_exists(USERS_PATH . '/' . $username . '/config.php');
|
||||
}
|
||||
|
||||
public static function updateUser($user, $email, $passwordPlain, $userConfigUpdated = array()) {
|
||||
/** @param array<string,mixed> $userConfigUpdated */
|
||||
public static function updateUser(string $user, ?string $email, string $passwordPlain, array $userConfigUpdated = []): bool {
|
||||
$userConfig = get_user_configuration($user);
|
||||
if ($userConfig === null) {
|
||||
return false;
|
||||
@@ -52,7 +53,7 @@ class FreshRSS_user_Controller extends FreshRSS_ActionController {
|
||||
return $ok;
|
||||
}
|
||||
|
||||
public function updateAction() {
|
||||
public function updateAction(): void {
|
||||
if (!FreshRSS_Auth::hasAccess('admin')) {
|
||||
Minz_Error::error(403);
|
||||
}
|
||||
@@ -83,7 +84,7 @@ class FreshRSS_user_Controller extends FreshRSS_ActionController {
|
||||
/**
|
||||
* This action displays the user profile page.
|
||||
*/
|
||||
public function profileAction() {
|
||||
public function profileAction(): void {
|
||||
if (!FreshRSS_Auth::hasAccess()) {
|
||||
Minz_Error::error(403);
|
||||
}
|
||||
@@ -148,7 +149,7 @@ class FreshRSS_user_Controller extends FreshRSS_ActionController {
|
||||
}
|
||||
}
|
||||
|
||||
public function purgeAction() {
|
||||
public function purgeAction(): void {
|
||||
if (!FreshRSS_Auth::hasAccess('admin')) {
|
||||
Minz_Error::error(403);
|
||||
}
|
||||
@@ -168,7 +169,7 @@ class FreshRSS_user_Controller extends FreshRSS_ActionController {
|
||||
/**
|
||||
* This action displays the user management page.
|
||||
*/
|
||||
public function manageAction() {
|
||||
public function manageAction(): void {
|
||||
if (!FreshRSS_Auth::hasAccess('admin')) {
|
||||
Minz_Error::error(403);
|
||||
}
|
||||
@@ -210,7 +211,9 @@ class FreshRSS_user_Controller extends FreshRSS_ActionController {
|
||||
}
|
||||
}
|
||||
|
||||
public static function createUser($new_user_name, $email, $passwordPlain, $userConfigOverride = [], $insertDefaultFeeds = true) {
|
||||
/** @param array<string,mixed> $userConfigOverride */
|
||||
public static function createUser(string $new_user_name, string $email, string $passwordPlain,
|
||||
array $userConfigOverride = [], bool $insertDefaultFeeds = true): bool {
|
||||
$userConfig = [];
|
||||
|
||||
$customUserConfigPath = join_path(DATA_PATH, 'config-user.custom.php');
|
||||
@@ -265,7 +268,7 @@ class FreshRSS_user_Controller extends FreshRSS_ActionController {
|
||||
|
||||
$ok &= self::updateUser($new_user_name, $email, $passwordPlain);
|
||||
}
|
||||
return $ok;
|
||||
return (bool)$ok;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -281,7 +284,7 @@ class FreshRSS_user_Controller extends FreshRSS_ActionController {
|
||||
* @todo clean up this method. Idea: write a method to init a user with basic information.
|
||||
* @todo handle r redirection in Minz_Request::forward directly?
|
||||
*/
|
||||
public function createAction() {
|
||||
public function createAction(): void {
|
||||
if (!FreshRSS_Auth::hasAccess('admin') && max_registrations_reached()) {
|
||||
Minz_Error::error(403);
|
||||
}
|
||||
@@ -380,7 +383,7 @@ class FreshRSS_user_Controller extends FreshRSS_ActionController {
|
||||
Minz_Request::forward($redirect_url, true);
|
||||
}
|
||||
|
||||
public static function deleteUser($username) {
|
||||
public static function deleteUser(string $username): bool {
|
||||
$ok = self::checkUsername($username);
|
||||
if ($ok) {
|
||||
$default_user = FreshRSS_Context::$system_conf->default_user;
|
||||
@@ -395,7 +398,7 @@ class FreshRSS_user_Controller extends FreshRSS_ActionController {
|
||||
$ok &= recursive_unlink($user_data);
|
||||
array_map('unlink', glob(PSHB_PATH . '/feeds/*/' . $username . '.txt'));
|
||||
}
|
||||
return $ok;
|
||||
return (bool)$ok;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -415,7 +418,7 @@ class FreshRSS_user_Controller extends FreshRSS_ActionController {
|
||||
*
|
||||
* It returns 403 if user isn’t logged in and `username` param isn’t passed.
|
||||
*/
|
||||
public function validateEmailAction() {
|
||||
public function validateEmailAction(): void {
|
||||
if (!FreshRSS_Context::$system_conf->force_email_validation) {
|
||||
Minz_Error::error(404);
|
||||
}
|
||||
@@ -480,7 +483,7 @@ class FreshRSS_user_Controller extends FreshRSS_ActionController {
|
||||
* not POST. Else it redirects silently to the index if user has already
|
||||
* validated its email, or to the user#validateEmail route.
|
||||
*/
|
||||
public function sendValidationEmailAction() {
|
||||
public function sendValidationEmailAction(): void {
|
||||
if (!FreshRSS_Auth::hasAccess()) {
|
||||
Minz_Error::error(403);
|
||||
}
|
||||
@@ -524,7 +527,7 @@ class FreshRSS_user_Controller extends FreshRSS_ActionController {
|
||||
*
|
||||
* @todo clean up this method. Idea: create a User->clean() method.
|
||||
*/
|
||||
public function deleteAction() {
|
||||
public function deleteAction(): void {
|
||||
$username = Minz_Request::paramString('username');
|
||||
$self_deletion = Minz_User::name() === $username;
|
||||
|
||||
@@ -568,23 +571,23 @@ class FreshRSS_user_Controller extends FreshRSS_ActionController {
|
||||
Minz_Request::forward($redirect_url, true);
|
||||
}
|
||||
|
||||
public function promoteAction() {
|
||||
public function promoteAction(): void {
|
||||
$this->toggleAction('is_admin', true);
|
||||
}
|
||||
|
||||
public function demoteAction() {
|
||||
public function demoteAction(): void {
|
||||
$this->toggleAction('is_admin', false);
|
||||
}
|
||||
|
||||
public function enableAction() {
|
||||
public function enableAction(): void {
|
||||
$this->toggleAction('enabled', true);
|
||||
}
|
||||
|
||||
public function disableAction() {
|
||||
public function disableAction(): void {
|
||||
$this->toggleAction('enabled', false);
|
||||
}
|
||||
|
||||
private function toggleAction($field, $value) {
|
||||
private function toggleAction(string $field, bool $value): void {
|
||||
if (!FreshRSS_Auth::hasAccess('admin')) {
|
||||
Minz_Error::error(403);
|
||||
}
|
||||
@@ -615,7 +618,7 @@ class FreshRSS_user_Controller extends FreshRSS_ActionController {
|
||||
}
|
||||
}
|
||||
|
||||
public function detailsAction() {
|
||||
public function detailsAction(): void {
|
||||
if (!FreshRSS_Auth::hasAccess('admin')) {
|
||||
Minz_Error::error(403);
|
||||
}
|
||||
@@ -629,8 +632,8 @@ class FreshRSS_user_Controller extends FreshRSS_ActionController {
|
||||
$this->view->details = $this->retrieveUserDetails($username);
|
||||
}
|
||||
|
||||
/** @return array<string,int|string|bool> */
|
||||
private function retrieveUserDetails($username): array {
|
||||
/** @return array{'feed_count':int|false,'article_count':int|false,'database_size':int,'language':string,'mail_login':string,'enabled':bool,'is_admin':bool,'last_user_activity':string,'is_default':bool} */
|
||||
private function retrieveUserDetails(string $username): array {
|
||||
$feedDAO = FreshRSS_Factory::createFeedDao($username);
|
||||
$entryDAO = FreshRSS_Factory::createEntryDao($username);
|
||||
$databaseDAO = FreshRSS_Factory::createDatabaseDAO($username);
|
||||
|
||||
@@ -4,8 +4,6 @@
|
||||
# Can be regenerated with something like:
|
||||
# find . -type d -name 'vendor' -prune -o -name '*.php' -exec sh -c 'vendor/bin/phpstan analyse --level 6 --memory-limit 512M {} >/dev/null 2>/dev/null || echo {}' \;
|
||||
|
||||
./app/Controllers/feedController.php
|
||||
./app/Controllers/userController.php
|
||||
./app/install.php
|
||||
./app/Models/Category.php
|
||||
./app/Models/CategoryDAO.php
|
||||
|
||||
Reference in New Issue
Block a user