diff options
| author | 2024-01-15 10:36:30 +0100 | |
|---|---|---|
| committer | 2024-01-15 10:36:30 +0100 | |
| commit | 314077a457f04cc2f0472e036af029e2676fbf02 (patch) | |
| tree | 1f38bb78761a56b8ee2034caba0dbda3912ef7c1 /app/Controllers/updateController.php | |
| parent | 52f6c8399b41e0c8be49dd56c89f451843189791 (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/updateController.php')
| -rw-r--r-- | app/Controllers/updateController.php | 18 |
1 files changed, 9 insertions, 9 deletions
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); |
