aboutsummaryrefslogtreecommitdiff
path: root/app/Controllers
diff options
context:
space:
mode:
authorGravatar Alexandre Alapetite <alexandre@alapetite.fr> 2024-01-15 10:36:30 +0100
committerGravatar GitHub <noreply@github.com> 2024-01-15 10:36:30 +0100
commit314077a457f04cc2f0472e036af029e2676fbf02 (patch)
tree1f38bb78761a56b8ee2034caba0dbda3912ef7c1 /app/Controllers
parent52f6c8399b41e0c8be49dd56c89f451843189791 (diff)
PHPStan prepare exceptions (#6037)
Take advantage of https://phpstan.org/blog/bring-your-exceptions-under-control Minimum changes to pass `tooWideThrowType` and `implicitThrows`. Revert some mistakes from: https://github.com/FreshRSS/FreshRSS/pull/5504 Preparation needed before new PRs of the same type: https://github.com/FreshRSS/FreshRSS/pull/5962 Fix several wrong PHPDocs and catches: > Method ... has ...Exception in PHPDoc @throws tag but it's not thrown. > Dead catch - ...Exception is never thrown in the try block.
Diffstat (limited to 'app/Controllers')
-rw-r--r--app/Controllers/authController.php1
-rw-r--r--app/Controllers/feedController.php4
-rw-r--r--app/Controllers/indexController.php1
-rw-r--r--app/Controllers/tagController.php2
-rw-r--r--app/Controllers/updateController.php18
-rw-r--r--app/Controllers/userController.php6
6 files changed, 18 insertions, 14 deletions
diff --git a/app/Controllers/authController.php b/app/Controllers/authController.php
index 82dfefddd..7b0462888 100644
--- a/app/Controllers/authController.php
+++ b/app/Controllers/authController.php
@@ -65,7 +65,6 @@ class FreshRSS_auth_Controller extends FreshRSS_ActionController {
*
* It forwards to the correct login page (form) or main page if
* the user is already connected.
- * @throws Minz_ConfigurationParamException
*/
public function loginAction(): void {
if (FreshRSS_Auth::hasAccess() && Minz_Request::paramString('u') === '') {
diff --git a/app/Controllers/feedController.php b/app/Controllers/feedController.php
index 018bdb382..c194baf95 100644
--- a/app/Controllers/feedController.php
+++ b/app/Controllers/feedController.php
@@ -30,8 +30,9 @@ class FreshRSS_feed_Controller extends FreshRSS_ActionController {
/**
* @param array<string,mixed> $attributes
* @throws FreshRSS_AlreadySubscribed_Exception
- * @throws FreshRSS_FeedNotAdded_Exception
+ * @throws FreshRSS_BadUrl_Exception
* @throws FreshRSS_Feed_Exception
+ * @throws FreshRSS_FeedNotAdded_Exception
* @throws Minz_FileNotExistException
*/
public static function addFeed(string $url, string $title = '', int $cat_id = 0, string $new_cat_name = '',
@@ -874,7 +875,6 @@ class FreshRSS_feed_Controller extends FreshRSS_ActionController {
/**
* @throws Minz_ConfigurationNamespaceException
- * @throws JsonException
* @throws Minz_PDOConnectionException
*/
public static function renameFeed(int $feed_id, string $feed_name): bool {
diff --git a/app/Controllers/indexController.php b/app/Controllers/indexController.php
index a83307714..20223d340 100644
--- a/app/Controllers/indexController.php
+++ b/app/Controllers/indexController.php
@@ -241,6 +241,7 @@ class FreshRSS_index_Controller extends FreshRSS_ActionController {
/**
* This method returns a list of entries based on the Context object.
* @return Traversable<FreshRSS_Entry>
+ * @throws FreshRSS_EntriesGetter_Exception
*/
public static function listEntriesByContext(): Traversable {
$entryDAO = FreshRSS_Factory::createEntryDao();
diff --git a/app/Controllers/tagController.php b/app/Controllers/tagController.php
index da90b3f1c..6233207ed 100644
--- a/app/Controllers/tagController.php
+++ b/app/Controllers/tagController.php
@@ -160,7 +160,7 @@ class FreshRSS_tag_Controller extends FreshRSS_ActionController {
/**
* @throws Minz_ConfigurationNamespaceException
- * @throws Minz_PDOConnectionException|JsonException
+ * @throws Minz_PDOConnectionException
*/
public function renameAction(): void {
if (!FreshRSS_Auth::hasAccess()) {
diff --git a/app/Controllers/updateController.php b/app/Controllers/updateController.php
index 78f28e493..eeac7eb09 100644
--- a/app/Controllers/updateController.php
+++ b/app/Controllers/updateController.php
@@ -11,18 +11,19 @@ class FreshRSS_update_Controller extends FreshRSS_ActionController {
/**
* Automatic change to the new name of edge branch since FreshRSS 1.18.0.
+ * @throws Minz_Exception
*/
public static function migrateToGitEdge(): bool {
$errorMessage = 'Error during git checkout to edge branch. Please change branch manually!';
if (!is_writable(FRESHRSS_PATH . '/.git/config')) {
- throw new Exception($errorMessage);
+ throw new Minz_Exception($errorMessage);
}
//Note `git branch --show-current` requires git 2.22+
exec('git symbolic-ref --short HEAD', $output, $return);
if ($return != 0) {
- throw new Exception($errorMessage);
+ throw new Minz_Exception($errorMessage);
}
$line = implode('', $output);
if ($line !== 'master' && $line !== 'dev') {
@@ -33,13 +34,13 @@ class FreshRSS_update_Controller extends FreshRSS_ActionController {
unset($output);
exec('git checkout edge --guess -f', $output, $return);
if ($return != 0) {
- throw new Exception($errorMessage);
+ throw new Minz_Exception($errorMessage);
}
unset($output);
exec('git reset --hard FETCH_HEAD', $output, $return);
if ($return != 0) {
- throw new Exception($errorMessage);
+ throw new Minz_Exception($errorMessage);
}
return true;
@@ -64,6 +65,7 @@ class FreshRSS_update_Controller extends FreshRSS_ActionController {
chdir(FRESHRSS_PATH);
$output = [];
try {
+ /** @throws ValueError */
exec('git fetch --prune', $output, $return);
if ($return == 0) {
$output = [];
@@ -72,7 +74,7 @@ class FreshRSS_update_Controller extends FreshRSS_ActionController {
$line = implode('; ', $output);
Minz_Log::warning('git fetch warning: ' . $line);
}
- } catch (Exception $e) {
+ } catch (Throwable $e) {
Minz_Log::warning('git fetch error: ' . $e->getMessage());
}
chdir($cwd);
@@ -101,11 +103,9 @@ class FreshRSS_update_Controller extends FreshRSS_ActionController {
$output = [];
self::migrateToGitEdge();
- } catch (Exception $e) {
+ } catch (Throwable $e) {
Minz_Log::warning('Git error: ' . $e->getMessage());
- if (empty($output)) {
- $output = $e->getMessage();
- }
+ $output = $e->getMessage();
$return = 1;
}
chdir($cwd);
diff --git a/app/Controllers/userController.php b/app/Controllers/userController.php
index 126eb60a2..fdf57b5f9 100644
--- a/app/Controllers/userController.php
+++ b/app/Controllers/userController.php
@@ -208,7 +208,11 @@ class FreshRSS_user_Controller extends FreshRSS_ActionController {
}
}
- /** @param array<string,mixed> $userConfigOverride */
+ /**
+ * @param array<string,mixed> $userConfigOverride
+ * @throws Minz_ConfigurationNamespaceException
+ * @throws Minz_PDOConnectionException
+ */
public static function createUser(string $new_user_name, ?string $email, string $passwordPlain,
array $userConfigOverride = [], bool $insertDefaultFeeds = true): bool {
$userConfig = [];