From 314077a457f04cc2f0472e036af029e2676fbf02 Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Mon, 15 Jan 2024 10:36:30 +0100 Subject: 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. --- app/Controllers/updateController.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'app/Controllers/updateController.php') 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); -- cgit v1.2.3