From 1764d12fc0131247cde90fadb720fad5443fc058 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=94=A1=E9=8A=98=E5=87=B1?= Date: Thu, 17 Aug 2023 00:12:41 +0800 Subject: [PATCH] Fix: Remove the system-Exception ignore errors. --- phpstan-baseline.php | 110 -------------------- system/Exceptions/CastException.php | 3 + system/Exceptions/ConfigException.php | 3 + system/Exceptions/DownloadException.php | 15 +++ system/Exceptions/FrameworkException.php | 18 ++++ system/Exceptions/ModelException.php | 9 ++ system/Exceptions/PageNotFoundException.php | 15 +++ system/Exceptions/TestException.php | 3 + 8 files changed, 66 insertions(+), 110 deletions(-) diff --git a/phpstan-baseline.php b/phpstan-baseline.php index 457f762607af..f09ce499faca 100644 --- a/phpstan-baseline.php +++ b/phpstan-baseline.php @@ -726,116 +726,6 @@ 'count' => 1, 'path' => __DIR__ . '/system/Events/Events.php', ]; -$ignoreErrors[] = [ - 'message' => '#^Method CodeIgniter\\\\Exceptions\\\\CastException\\:\\:forInvalidJsonFormatException\\(\\) has no return type specified\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/system/Exceptions/CastException.php', -]; -$ignoreErrors[] = [ - 'message' => '#^Method CodeIgniter\\\\Exceptions\\\\ConfigException\\:\\:forDisabledMigrations\\(\\) has no return type specified\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/system/Exceptions/ConfigException.php', -]; -$ignoreErrors[] = [ - 'message' => '#^Method CodeIgniter\\\\Exceptions\\\\DownloadException\\:\\:forCannotSetBinary\\(\\) has no return type specified\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/system/Exceptions/DownloadException.php', -]; -$ignoreErrors[] = [ - 'message' => '#^Method CodeIgniter\\\\Exceptions\\\\DownloadException\\:\\:forCannotSetCache\\(\\) has no return type specified\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/system/Exceptions/DownloadException.php', -]; -$ignoreErrors[] = [ - 'message' => '#^Method CodeIgniter\\\\Exceptions\\\\DownloadException\\:\\:forCannotSetFilePath\\(\\) has no return type specified\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/system/Exceptions/DownloadException.php', -]; -$ignoreErrors[] = [ - 'message' => '#^Method CodeIgniter\\\\Exceptions\\\\DownloadException\\:\\:forCannotSetStatusCode\\(\\) has no return type specified\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/system/Exceptions/DownloadException.php', -]; -$ignoreErrors[] = [ - 'message' => '#^Method CodeIgniter\\\\Exceptions\\\\DownloadException\\:\\:forNotFoundDownloadSource\\(\\) has no return type specified\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/system/Exceptions/DownloadException.php', -]; -$ignoreErrors[] = [ - 'message' => '#^Method CodeIgniter\\\\Exceptions\\\\FrameworkException\\:\\:forCopyError\\(\\) has no return type specified\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/system/Exceptions/FrameworkException.php', -]; -$ignoreErrors[] = [ - 'message' => '#^Method CodeIgniter\\\\Exceptions\\\\FrameworkException\\:\\:forEnabledZlibOutputCompression\\(\\) has no return type specified\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/system/Exceptions/FrameworkException.php', -]; -$ignoreErrors[] = [ - 'message' => '#^Method CodeIgniter\\\\Exceptions\\\\FrameworkException\\:\\:forFabricatorCreateFailed\\(\\) has no return type specified\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/system/Exceptions/FrameworkException.php', -]; -$ignoreErrors[] = [ - 'message' => '#^Method CodeIgniter\\\\Exceptions\\\\FrameworkException\\:\\:forInvalidFile\\(\\) has no return type specified\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/system/Exceptions/FrameworkException.php', -]; -$ignoreErrors[] = [ - 'message' => '#^Method CodeIgniter\\\\Exceptions\\\\FrameworkException\\:\\:forMissingExtension\\(\\) has no return type specified\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/system/Exceptions/FrameworkException.php', -]; -$ignoreErrors[] = [ - 'message' => '#^Method CodeIgniter\\\\Exceptions\\\\FrameworkException\\:\\:forNoHandlers\\(\\) has no return type specified\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/system/Exceptions/FrameworkException.php', -]; -$ignoreErrors[] = [ - 'message' => '#^Method CodeIgniter\\\\Exceptions\\\\ModelException\\:\\:forMethodNotAvailable\\(\\) has no return type specified\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/system/Exceptions/ModelException.php', -]; -$ignoreErrors[] = [ - 'message' => '#^Method CodeIgniter\\\\Exceptions\\\\ModelException\\:\\:forNoDateFormat\\(\\) has no return type specified\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/system/Exceptions/ModelException.php', -]; -$ignoreErrors[] = [ - 'message' => '#^Method CodeIgniter\\\\Exceptions\\\\ModelException\\:\\:forNoPrimaryKey\\(\\) has no return type specified\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/system/Exceptions/ModelException.php', -]; -$ignoreErrors[] = [ - 'message' => '#^Method CodeIgniter\\\\Exceptions\\\\PageNotFoundException\\:\\:forControllerNotFound\\(\\) has no return type specified\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/system/Exceptions/PageNotFoundException.php', -]; -$ignoreErrors[] = [ - 'message' => '#^Method CodeIgniter\\\\Exceptions\\\\PageNotFoundException\\:\\:forEmptyController\\(\\) has no return type specified\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/system/Exceptions/PageNotFoundException.php', -]; -$ignoreErrors[] = [ - 'message' => '#^Method CodeIgniter\\\\Exceptions\\\\PageNotFoundException\\:\\:forLocaleNotSupported\\(\\) has no return type specified\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/system/Exceptions/PageNotFoundException.php', -]; -$ignoreErrors[] = [ - 'message' => '#^Method CodeIgniter\\\\Exceptions\\\\PageNotFoundException\\:\\:forMethodNotFound\\(\\) has no return type specified\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/system/Exceptions/PageNotFoundException.php', -]; -$ignoreErrors[] = [ - 'message' => '#^Method CodeIgniter\\\\Exceptions\\\\PageNotFoundException\\:\\:forPageNotFound\\(\\) has no return type specified\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/system/Exceptions/PageNotFoundException.php', -]; -$ignoreErrors[] = [ - 'message' => '#^Method CodeIgniter\\\\Exceptions\\\\TestException\\:\\:forInvalidMockClass\\(\\) has no return type specified\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/system/Exceptions/TestException.php', -]; $ignoreErrors[] = [ 'message' => '#^Property CodeIgniter\\\\Files\\\\File\\:\\:\\$size \\(int\\) on left side of \\?\\? is not nullable\\.$#', 'count' => 1, diff --git a/system/Exceptions/CastException.php b/system/Exceptions/CastException.php index e1f4e1231eef..8dfb29543a78 100644 --- a/system/Exceptions/CastException.php +++ b/system/Exceptions/CastException.php @@ -27,6 +27,9 @@ public function getExitCode(): int return EXIT_CONFIG; } + /** + * @return static + */ public static function forInvalidJsonFormatException(int $error) { switch ($error) { diff --git a/system/Exceptions/ConfigException.php b/system/Exceptions/ConfigException.php index 0a0a6656362e..6eea2638c5e0 100644 --- a/system/Exceptions/ConfigException.php +++ b/system/Exceptions/ConfigException.php @@ -23,6 +23,9 @@ public function getExitCode(): int return EXIT_CONFIG; } + /** + * @return static + */ public static function forDisabledMigrations() { return new static(lang('Migrations.disabled')); diff --git a/system/Exceptions/DownloadException.php b/system/Exceptions/DownloadException.php index c830891ed5a9..5626cfefa806 100644 --- a/system/Exceptions/DownloadException.php +++ b/system/Exceptions/DownloadException.php @@ -20,26 +20,41 @@ class DownloadException extends RuntimeException implements ExceptionInterface { use DebugTraceableTrait; + /** + * @return static + */ public static function forCannotSetFilePath(string $path) { return new static(lang('HTTP.cannotSetFilepath', [$path])); } + /** + * @return static + */ public static function forCannotSetBinary() { return new static(lang('HTTP.cannotSetBinary')); } + /** + * @return static + */ public static function forNotFoundDownloadSource() { return new static(lang('HTTP.notFoundDownloadSource')); } + /** + * @return static + */ public static function forCannotSetCache() { return new static(lang('HTTP.cannotSetCache')); } + /** + * @return static + */ public static function forCannotSetStatusCode(int $code, string $reason) { return new static(lang('HTTP.cannotSetStatusCode', [$code, $reason])); diff --git a/system/Exceptions/FrameworkException.php b/system/Exceptions/FrameworkException.php index 333f999df84a..7d71147c18de 100644 --- a/system/Exceptions/FrameworkException.php +++ b/system/Exceptions/FrameworkException.php @@ -23,21 +23,33 @@ class FrameworkException extends RuntimeException implements ExceptionInterface { use DebugTraceableTrait; + /** + * @return static + */ public static function forEnabledZlibOutputCompression() { return new static(lang('Core.enabledZlibOutputCompression')); } + /** + * @return static + */ public static function forInvalidFile(string $path) { return new static(lang('Core.invalidFile', [$path])); } + /** + * @return static + */ public static function forCopyError(string $path) { return new static(lang('Core.copyError', [$path])); } + /** + * @return static + */ public static function forMissingExtension(string $extension) { if (strpos($extension, 'intl') !== false) { @@ -54,11 +66,17 @@ public static function forMissingExtension(string $extension) return new static($message); } + /** + * @return static + */ public static function forNoHandlers(string $class) { return new static(lang('Core.noHandlers', [$class])); } + /** + * @return static + */ public static function forFabricatorCreateFailed(string $table, string $reason) { return new static(lang('Fabricator.createFailed', [$table, $reason])); diff --git a/system/Exceptions/ModelException.php b/system/Exceptions/ModelException.php index 3bdc283649ed..39590a60ea13 100644 --- a/system/Exceptions/ModelException.php +++ b/system/Exceptions/ModelException.php @@ -16,16 +16,25 @@ */ class ModelException extends FrameworkException { + /** + * @return static + */ public static function forNoPrimaryKey(string $modelName) { return new static(lang('Database.noPrimaryKey', [$modelName])); } + /** + * @return static + */ public static function forNoDateFormat(string $modelName) { return new static(lang('Database.noDateFormat', [$modelName])); } + /** + * @return static + */ public static function forMethodNotAvailable(string $modelName, string $methodName) { return new static(lang('Database.methodNotAvailable', [$modelName, $methodName])); diff --git a/system/Exceptions/PageNotFoundException.php b/system/Exceptions/PageNotFoundException.php index e41ae6ac868d..69e93f9b9bf1 100644 --- a/system/Exceptions/PageNotFoundException.php +++ b/system/Exceptions/PageNotFoundException.php @@ -25,26 +25,41 @@ class PageNotFoundException extends OutOfBoundsException implements ExceptionInt */ protected $code = 404; + /** + * @return static + */ public static function forPageNotFound(?string $message = null) { return new static($message ?? self::lang('HTTP.pageNotFound')); } + /** + * @return static + */ public static function forEmptyController() { return new static(self::lang('HTTP.emptyController')); } + /** + * @return static + */ public static function forControllerNotFound(string $controller, string $method) { return new static(self::lang('HTTP.controllerNotFound', [$controller, $method])); } + /** + * @return static + */ public static function forMethodNotFound(string $method) { return new static(self::lang('HTTP.methodNotFound', [$method])); } + /** + * @return static + */ public static function forLocaleNotSupported(string $locale) { return new static(self::lang('HTTP.localeNotSupported', [$locale])); diff --git a/system/Exceptions/TestException.php b/system/Exceptions/TestException.php index a1c4c51cf814..dadbbc002b9a 100644 --- a/system/Exceptions/TestException.php +++ b/system/Exceptions/TestException.php @@ -18,6 +18,9 @@ class TestException extends CriticalError { use DebugTraceableTrait; + /** + * @return static + */ public static function forInvalidMockClass(string $name) { return new static(lang('Test.invalidMockClass', [$name]));