From 2f72086ac3dc7acc60a68ac86bb0d57779828de7 Mon Sep 17 00:00:00 2001 From: kenjis Date: Sat, 27 Jan 2024 18:41:45 +0900 Subject: [PATCH 01/32] feat: add base RuntimeException and LogicException --- system/Exceptions/LogicException.php | 21 +++++++++++++++++++++ system/Exceptions/RuntimeException.php | 21 +++++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 system/Exceptions/LogicException.php create mode 100644 system/Exceptions/RuntimeException.php diff --git a/system/Exceptions/LogicException.php b/system/Exceptions/LogicException.php new file mode 100644 index 000000000000..2fe46792efcc --- /dev/null +++ b/system/Exceptions/LogicException.php @@ -0,0 +1,21 @@ + + * + * For the full copyright and license information, please view + * the LICENSE file that was distributed with this source code. + */ + +namespace CodeIgniter\Exceptions; + +/** + * Exception that represents error in the program logic. + */ +class LogicException extends \LogicException implements ExceptionInterface +{ +} diff --git a/system/Exceptions/RuntimeException.php b/system/Exceptions/RuntimeException.php new file mode 100644 index 000000000000..c35d55ba9e45 --- /dev/null +++ b/system/Exceptions/RuntimeException.php @@ -0,0 +1,21 @@ + + * + * For the full copyright and license information, please view + * the LICENSE file that was distributed with this source code. + */ + +namespace CodeIgniter\Exceptions; + +/** + * Exception thrown if an error which can only be found on runtime occurs. + */ +class RuntimeException extends \RuntimeException implements ExceptionInterface +{ +} From 50c43a3110e63727b8bb7448399f177069de0753 Mon Sep 17 00:00:00 2001 From: kenjis Date: Sat, 27 Jan 2024 18:42:54 +0900 Subject: [PATCH 02/32] feat: add BadMethodCallException,BadFunctionCallException,InvalidArgumentException --- .../Exceptions/BadFunctionCallException.php | 22 +++++++++++++++++++ system/Exceptions/BadMethodCallException.php | 22 +++++++++++++++++++ .../Exceptions/InvalidArgumentException.php | 21 ++++++++++++++++++ 3 files changed, 65 insertions(+) create mode 100644 system/Exceptions/BadFunctionCallException.php create mode 100644 system/Exceptions/BadMethodCallException.php create mode 100644 system/Exceptions/InvalidArgumentException.php diff --git a/system/Exceptions/BadFunctionCallException.php b/system/Exceptions/BadFunctionCallException.php new file mode 100644 index 000000000000..84d9798dc0c4 --- /dev/null +++ b/system/Exceptions/BadFunctionCallException.php @@ -0,0 +1,22 @@ + + * + * For the full copyright and license information, please view + * the LICENSE file that was distributed with this source code. + */ + +namespace CodeIgniter\Exceptions; + +/** + * Exception thrown if a function is called in the wrong way, or the function + * does not exist. + */ +class BadFunctionCallException extends \BadFunctionCallException implements ExceptionInterface +{ +} diff --git a/system/Exceptions/BadMethodCallException.php b/system/Exceptions/BadMethodCallException.php new file mode 100644 index 000000000000..977e8ae721e2 --- /dev/null +++ b/system/Exceptions/BadMethodCallException.php @@ -0,0 +1,22 @@ + + * + * For the full copyright and license information, please view + * the LICENSE file that was distributed with this source code. + */ + +namespace CodeIgniter\Exceptions; + +/** + * Exception thrown if a method is called in the wrong way, or the method + * does not exist. + */ +class BadMethodCallException extends \BadMethodCallException implements ExceptionInterface +{ +} diff --git a/system/Exceptions/InvalidArgumentException.php b/system/Exceptions/InvalidArgumentException.php new file mode 100644 index 000000000000..4790249e3f78 --- /dev/null +++ b/system/Exceptions/InvalidArgumentException.php @@ -0,0 +1,21 @@ + + * + * For the full copyright and license information, please view + * the LICENSE file that was distributed with this source code. + */ + +namespace CodeIgniter\Exceptions; + +/** + * Exception thrown if an argument is not of the expected type. + */ +class InvalidArgumentException extends \InvalidArgumentException implements ExceptionInterface +{ +} From 085eb2d76c85fa880870c507c81acf87e2bbb506 Mon Sep 17 00:00:00 2001 From: kenjis Date: Sat, 27 Jan 2024 18:46:17 +0900 Subject: [PATCH 03/32] refactor: FrameworkException extends RuntimeException --- system/Exceptions/FrameworkException.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/system/Exceptions/FrameworkException.php b/system/Exceptions/FrameworkException.php index 1fe47be49a6b..0141b139de62 100644 --- a/system/Exceptions/FrameworkException.php +++ b/system/Exceptions/FrameworkException.php @@ -13,15 +13,13 @@ namespace CodeIgniter\Exceptions; -use RuntimeException; - /** * Class FrameworkException * * A collection of exceptions thrown by the framework * that can only be determined at run time. */ -class FrameworkException extends RuntimeException implements ExceptionInterface +class FrameworkException extends RuntimeException { use DebugTraceableTrait; From 5178dd171d4ee9ce43e024d684d5a10ddce63d36 Mon Sep 17 00:00:00 2001 From: kenjis Date: Sat, 27 Jan 2024 18:50:22 +0900 Subject: [PATCH 04/32] feat: extends ExceptionInterface --- system/Exceptions/HTTPExceptionInterface.php | 2 +- system/Exceptions/HasExitCodeInterface.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/system/Exceptions/HTTPExceptionInterface.php b/system/Exceptions/HTTPExceptionInterface.php index 1974d63af6e5..b26f121fb9a6 100644 --- a/system/Exceptions/HTTPExceptionInterface.php +++ b/system/Exceptions/HTTPExceptionInterface.php @@ -16,6 +16,6 @@ /** * Interface for Exceptions that has exception code as HTTP status code. */ -interface HTTPExceptionInterface +interface HTTPExceptionInterface extends ExceptionInterface { } diff --git a/system/Exceptions/HasExitCodeInterface.php b/system/Exceptions/HasExitCodeInterface.php index 1557c82ad681..48d32655714c 100644 --- a/system/Exceptions/HasExitCodeInterface.php +++ b/system/Exceptions/HasExitCodeInterface.php @@ -16,7 +16,7 @@ /** * Interface for Exceptions that has exception code as exit code. */ -interface HasExitCodeInterface +interface HasExitCodeInterface extends ExceptionInterface { /** * Returns exit status code. From 9d2c903f7f42a45fcb74e71eab662c11e6b1c17f Mon Sep 17 00:00:00 2001 From: kenjis Date: Sat, 27 Jan 2024 19:06:44 +0900 Subject: [PATCH 05/32] refactor: change parent class --- system/CLI/Exceptions/CLIException.php | 2 +- system/Exceptions/DownloadException.php | 4 +--- system/Files/Exceptions/FileException.php | 5 ++--- system/Files/Exceptions/FileNotFoundException.php | 5 ++--- system/Format/Exceptions/FormatException.php | 5 ++--- system/Router/Exceptions/MethodNotFoundException.php | 2 +- 6 files changed, 9 insertions(+), 14 deletions(-) diff --git a/system/CLI/Exceptions/CLIException.php b/system/CLI/Exceptions/CLIException.php index fae92c001d75..304b2ea4f444 100644 --- a/system/CLI/Exceptions/CLIException.php +++ b/system/CLI/Exceptions/CLIException.php @@ -14,7 +14,7 @@ namespace CodeIgniter\CLI\Exceptions; use CodeIgniter\Exceptions\DebugTraceableTrait; -use RuntimeException; +use CodeIgniter\Exceptions\RuntimeException; /** * CLIException diff --git a/system/Exceptions/DownloadException.php b/system/Exceptions/DownloadException.php index df78127d6d64..d4b224fdee4d 100644 --- a/system/Exceptions/DownloadException.php +++ b/system/Exceptions/DownloadException.php @@ -13,12 +13,10 @@ namespace CodeIgniter\Exceptions; -use RuntimeException; - /** * Class DownloadException */ -class DownloadException extends RuntimeException implements ExceptionInterface +class DownloadException extends RuntimeException { use DebugTraceableTrait; diff --git a/system/Files/Exceptions/FileException.php b/system/Files/Exceptions/FileException.php index 5feb97929ead..8634b211afa4 100644 --- a/system/Files/Exceptions/FileException.php +++ b/system/Files/Exceptions/FileException.php @@ -14,10 +14,9 @@ namespace CodeIgniter\Files\Exceptions; use CodeIgniter\Exceptions\DebugTraceableTrait; -use CodeIgniter\Exceptions\ExceptionInterface; -use RuntimeException; +use CodeIgniter\Exceptions\RuntimeException; -class FileException extends RuntimeException implements ExceptionInterface +class FileException extends RuntimeException { use DebugTraceableTrait; diff --git a/system/Files/Exceptions/FileNotFoundException.php b/system/Files/Exceptions/FileNotFoundException.php index 86b22625aa9e..46c2c1c6cfd5 100644 --- a/system/Files/Exceptions/FileNotFoundException.php +++ b/system/Files/Exceptions/FileNotFoundException.php @@ -14,10 +14,9 @@ namespace CodeIgniter\Files\Exceptions; use CodeIgniter\Exceptions\DebugTraceableTrait; -use CodeIgniter\Exceptions\ExceptionInterface; -use RuntimeException; +use CodeIgniter\Exceptions\RuntimeException; -class FileNotFoundException extends RuntimeException implements ExceptionInterface +class FileNotFoundException extends RuntimeException { use DebugTraceableTrait; diff --git a/system/Format/Exceptions/FormatException.php b/system/Format/Exceptions/FormatException.php index 5a8c2d2cfedb..46daad558c50 100644 --- a/system/Format/Exceptions/FormatException.php +++ b/system/Format/Exceptions/FormatException.php @@ -14,13 +14,12 @@ namespace CodeIgniter\Format\Exceptions; use CodeIgniter\Exceptions\DebugTraceableTrait; -use CodeIgniter\Exceptions\ExceptionInterface; -use RuntimeException; +use CodeIgniter\Exceptions\RuntimeException; /** * FormatException */ -class FormatException extends RuntimeException implements ExceptionInterface +class FormatException extends RuntimeException { use DebugTraceableTrait; diff --git a/system/Router/Exceptions/MethodNotFoundException.php b/system/Router/Exceptions/MethodNotFoundException.php index 6e82fb09583c..19e62eb02c6d 100644 --- a/system/Router/Exceptions/MethodNotFoundException.php +++ b/system/Router/Exceptions/MethodNotFoundException.php @@ -13,7 +13,7 @@ namespace CodeIgniter\Router\Exceptions; -use RuntimeException; +use CodeIgniter\Exceptions\RuntimeException; /** * @internal From 8e5e2078f56ea044cc33d589d8c8cd6288d66730 Mon Sep 17 00:00:00 2001 From: kenjis Date: Sat, 27 Jan 2024 19:19:52 +0900 Subject: [PATCH 06/32] refactor: remove unneeded `implements ExceptionInterface` --- system/Filters/Exceptions/FilterException.php | 3 +-- system/Honeypot/Exceptions/HoneypotException.php | 3 +-- system/Images/Exceptions/ImageException.php | 3 +-- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/system/Filters/Exceptions/FilterException.php b/system/Filters/Exceptions/FilterException.php index 1226ba318429..3a4d914e3cc3 100644 --- a/system/Filters/Exceptions/FilterException.php +++ b/system/Filters/Exceptions/FilterException.php @@ -14,12 +14,11 @@ namespace CodeIgniter\Filters\Exceptions; use CodeIgniter\Exceptions\ConfigException; -use CodeIgniter\Exceptions\ExceptionInterface; /** * FilterException */ -class FilterException extends ConfigException implements ExceptionInterface +class FilterException extends ConfigException { /** * Thrown when the provided alias is not within diff --git a/system/Honeypot/Exceptions/HoneypotException.php b/system/Honeypot/Exceptions/HoneypotException.php index ce743b8651b3..7ff493e4edf8 100644 --- a/system/Honeypot/Exceptions/HoneypotException.php +++ b/system/Honeypot/Exceptions/HoneypotException.php @@ -14,9 +14,8 @@ namespace CodeIgniter\Honeypot\Exceptions; use CodeIgniter\Exceptions\ConfigException; -use CodeIgniter\Exceptions\ExceptionInterface; -class HoneypotException extends ConfigException implements ExceptionInterface +class HoneypotException extends ConfigException { /** * Thrown when the template value of config is empty. diff --git a/system/Images/Exceptions/ImageException.php b/system/Images/Exceptions/ImageException.php index 93491bfa9e1b..91bf416d20ac 100644 --- a/system/Images/Exceptions/ImageException.php +++ b/system/Images/Exceptions/ImageException.php @@ -13,10 +13,9 @@ namespace CodeIgniter\Images\Exceptions; -use CodeIgniter\Exceptions\ExceptionInterface; use CodeIgniter\Exceptions\FrameworkException; -class ImageException extends FrameworkException implements ExceptionInterface +class ImageException extends FrameworkException { /** * Thrown when the image is not found. From 2087c55a627390cead195630b84baa303bf08835 Mon Sep 17 00:00:00 2001 From: kenjis Date: Sat, 27 Jan 2024 19:20:37 +0900 Subject: [PATCH 07/32] fix: parent exception classes --- system/Database/Exceptions/DatabaseException.php | 4 ++-- system/Exceptions/ConfigException.php | 2 +- system/Exceptions/CriticalError.php | 4 +--- system/Exceptions/PageNotFoundException.php | 3 +-- system/Exceptions/TestException.php | 2 +- system/HTTP/Exceptions/RedirectException.php | 4 ++-- 6 files changed, 8 insertions(+), 11 deletions(-) diff --git a/system/Database/Exceptions/DatabaseException.php b/system/Database/Exceptions/DatabaseException.php index cdb8e22832ec..244d45d09894 100644 --- a/system/Database/Exceptions/DatabaseException.php +++ b/system/Database/Exceptions/DatabaseException.php @@ -14,9 +14,9 @@ namespace CodeIgniter\Database\Exceptions; use CodeIgniter\Exceptions\HasExitCodeInterface; -use Error; +use CodeIgniter\Exceptions\RuntimeException; -class DatabaseException extends Error implements ExceptionInterface, HasExitCodeInterface +class DatabaseException extends RuntimeException implements HasExitCodeInterface { public function getExitCode(): int { diff --git a/system/Exceptions/ConfigException.php b/system/Exceptions/ConfigException.php index d8849b809c68..d8d27d094230 100644 --- a/system/Exceptions/ConfigException.php +++ b/system/Exceptions/ConfigException.php @@ -16,7 +16,7 @@ /** * Exception for automatic logging. */ -class ConfigException extends CriticalError implements HasExitCodeInterface +class ConfigException extends RuntimeException implements HasExitCodeInterface { use DebugTraceableTrait; diff --git a/system/Exceptions/CriticalError.php b/system/Exceptions/CriticalError.php index 756393d5d95d..d3f6803b7925 100644 --- a/system/Exceptions/CriticalError.php +++ b/system/Exceptions/CriticalError.php @@ -13,11 +13,9 @@ namespace CodeIgniter\Exceptions; -use Error; - /** * Error: Critical conditions, like component unavailable, etc. */ -class CriticalError extends Error +class CriticalError extends RuntimeException { } diff --git a/system/Exceptions/PageNotFoundException.php b/system/Exceptions/PageNotFoundException.php index b1af079e3a54..ba9b98c49350 100644 --- a/system/Exceptions/PageNotFoundException.php +++ b/system/Exceptions/PageNotFoundException.php @@ -14,9 +14,8 @@ namespace CodeIgniter\Exceptions; use Config\Services; -use OutOfBoundsException; -class PageNotFoundException extends OutOfBoundsException implements ExceptionInterface, HTTPExceptionInterface +class PageNotFoundException extends RuntimeException implements HTTPExceptionInterface { use DebugTraceableTrait; diff --git a/system/Exceptions/TestException.php b/system/Exceptions/TestException.php index f533dc279335..fd70709a6cb2 100644 --- a/system/Exceptions/TestException.php +++ b/system/Exceptions/TestException.php @@ -16,7 +16,7 @@ /** * Exception for automatic logging. */ -class TestException extends CriticalError +class TestException extends LogicException { use DebugTraceableTrait; diff --git a/system/HTTP/Exceptions/RedirectException.php b/system/HTTP/Exceptions/RedirectException.php index 5f2dcd05e3b7..318ffed42227 100644 --- a/system/HTTP/Exceptions/RedirectException.php +++ b/system/HTTP/Exceptions/RedirectException.php @@ -14,9 +14,9 @@ namespace CodeIgniter\HTTP\Exceptions; use CodeIgniter\Exceptions\HTTPExceptionInterface; +use CodeIgniter\Exceptions\RuntimeException; use CodeIgniter\HTTP\ResponsableInterface; use CodeIgniter\HTTP\ResponseInterface; -use Exception; use InvalidArgumentException; use LogicException; use Throwable; @@ -24,7 +24,7 @@ /** * RedirectException */ -class RedirectException extends Exception implements ResponsableInterface, HTTPExceptionInterface +class RedirectException extends RuntimeException implements ResponsableInterface, HTTPExceptionInterface { /** * HTTP status code for redirects From 3540f97e9e935ab84bf9ccb7019bb34b4b9f609c Mon Sep 17 00:00:00 2001 From: kenjis Date: Sat, 27 Jan 2024 20:23:13 +0900 Subject: [PATCH 08/32] refactor: use CodeIgniter\Exceptions\RuntimeException --- system/Autoloader/Autoloader.php | 2 +- system/Cache/Exceptions/CacheException.php | 2 +- system/Config/BaseConfig.php | 2 +- system/Database/Exceptions/DataException.php | 2 +- system/Database/Forge.php | 2 +- system/Database/MigrationRunner.php | 2 +- system/Debug/Timer.php | 2 +- system/Encryption/Exceptions/EncryptionException.php | 2 +- system/HTTP/CLIRequest.php | 2 +- system/HTTP/Files/UploadedFile.php | 2 ++ system/HTTP/Files/UploadedFileInterface.php | 2 +- system/Log/Logger.php | 2 +- system/Publisher/ContentReplacer.php | 2 +- system/Publisher/Publisher.php | 2 +- system/Test/Fabricator.php | 2 +- system/Test/FilterTestTrait.php | 2 +- system/View/View.php | 2 +- 17 files changed, 18 insertions(+), 16 deletions(-) diff --git a/system/Autoloader/Autoloader.php b/system/Autoloader/Autoloader.php index 78d31eae0d7f..3aef07ae635f 100644 --- a/system/Autoloader/Autoloader.php +++ b/system/Autoloader/Autoloader.php @@ -14,6 +14,7 @@ namespace CodeIgniter\Autoloader; use CodeIgniter\Exceptions\ConfigException; +use CodeIgniter\Exceptions\RuntimeException; use Composer\Autoload\ClassLoader; use Composer\InstalledVersions; use Config\Autoload; @@ -24,7 +25,6 @@ use Kint; use Kint\Renderer\CliRenderer; use Kint\Renderer\RichRenderer; -use RuntimeException; /** * An autoloader that uses both PSR4 autoloading, and traditional classmaps. diff --git a/system/Cache/Exceptions/CacheException.php b/system/Cache/Exceptions/CacheException.php index 852e6302ced1..774daa9965b2 100644 --- a/system/Cache/Exceptions/CacheException.php +++ b/system/Cache/Exceptions/CacheException.php @@ -15,7 +15,7 @@ use CodeIgniter\Exceptions\DebugTraceableTrait; use CodeIgniter\Exceptions\ExceptionInterface; -use RuntimeException; +use CodeIgniter\Exceptions\RuntimeException; /** * CacheException diff --git a/system/Config/BaseConfig.php b/system/Config/BaseConfig.php index 8a82cbf7ce64..8f579ffc88f3 100644 --- a/system/Config/BaseConfig.php +++ b/system/Config/BaseConfig.php @@ -11,11 +11,11 @@ namespace CodeIgniter\Config; +use CodeIgniter\Exceptions\RuntimeException; use Config\Encryption; use Config\Modules; use ReflectionClass; use ReflectionException; -use RuntimeException; /** * Class BaseConfig diff --git a/system/Database/Exceptions/DataException.php b/system/Database/Exceptions/DataException.php index 18a54171cc29..a7ccd8c6f5c3 100644 --- a/system/Database/Exceptions/DataException.php +++ b/system/Database/Exceptions/DataException.php @@ -14,7 +14,7 @@ namespace CodeIgniter\Database\Exceptions; use CodeIgniter\Exceptions\DebugTraceableTrait; -use RuntimeException; +use CodeIgniter\Exceptions\RuntimeException; class DataException extends RuntimeException implements ExceptionInterface { diff --git a/system/Database/Forge.php b/system/Database/Forge.php index 797b685e861c..ca0428d9f7b3 100644 --- a/system/Database/Forge.php +++ b/system/Database/Forge.php @@ -14,8 +14,8 @@ namespace CodeIgniter\Database; use CodeIgniter\Database\Exceptions\DatabaseException; +use CodeIgniter\Exceptions\RuntimeException; use InvalidArgumentException; -use RuntimeException; use Throwable; /** diff --git a/system/Database/MigrationRunner.php b/system/Database/MigrationRunner.php index 719d45c15592..bf890ff24305 100644 --- a/system/Database/MigrationRunner.php +++ b/system/Database/MigrationRunner.php @@ -16,11 +16,11 @@ use CodeIgniter\CLI\CLI; use CodeIgniter\Events\Events; use CodeIgniter\Exceptions\ConfigException; +use CodeIgniter\Exceptions\RuntimeException; use CodeIgniter\I18n\Time; use Config\Database; use Config\Migrations as MigrationsConfig; use Config\Services; -use RuntimeException; use stdClass; /** diff --git a/system/Debug/Timer.php b/system/Debug/Timer.php index 0f2abdbea509..37e9901977e7 100644 --- a/system/Debug/Timer.php +++ b/system/Debug/Timer.php @@ -13,7 +13,7 @@ namespace CodeIgniter\Debug; -use RuntimeException; +use CodeIgniter\Exceptions\RuntimeException; /** * Class Timer diff --git a/system/Encryption/Exceptions/EncryptionException.php b/system/Encryption/Exceptions/EncryptionException.php index c2220bb88cb4..e18899467bd5 100644 --- a/system/Encryption/Exceptions/EncryptionException.php +++ b/system/Encryption/Exceptions/EncryptionException.php @@ -15,7 +15,7 @@ use CodeIgniter\Exceptions\DebugTraceableTrait; use CodeIgniter\Exceptions\ExceptionInterface; -use RuntimeException; +use CodeIgniter\Exceptions\RuntimeException; /** * Encryption exception diff --git a/system/HTTP/CLIRequest.php b/system/HTTP/CLIRequest.php index 0b2c57377e65..723c72b1ce98 100644 --- a/system/HTTP/CLIRequest.php +++ b/system/HTTP/CLIRequest.php @@ -13,9 +13,9 @@ namespace CodeIgniter\HTTP; +use CodeIgniter\Exceptions\RuntimeException; use Config\App; use Locale; -use RuntimeException; /** * Represents a request from the command-line. Provides additional diff --git a/system/HTTP/Files/UploadedFile.php b/system/HTTP/Files/UploadedFile.php index 78643aa7166e..da029d7739ca 100644 --- a/system/HTTP/Files/UploadedFile.php +++ b/system/HTTP/Files/UploadedFile.php @@ -13,10 +13,12 @@ namespace CodeIgniter\HTTP\Files; +use CodeIgniter\Exceptions\RuntimeException; use CodeIgniter\Files\File; use CodeIgniter\HTTP\Exceptions\HTTPException; use Config\Mimes; use Exception; +use InvalidArgumentException; /** * Value object representing a single file uploaded through an diff --git a/system/HTTP/Files/UploadedFileInterface.php b/system/HTTP/Files/UploadedFileInterface.php index 12cc25a0d050..167b0aa2f4d6 100644 --- a/system/HTTP/Files/UploadedFileInterface.php +++ b/system/HTTP/Files/UploadedFileInterface.php @@ -13,8 +13,8 @@ namespace CodeIgniter\HTTP\Files; +use CodeIgniter\Exceptions\RuntimeException; use InvalidArgumentException; -use RuntimeException; /** * Value object representing a single file uploaded through an diff --git a/system/Log/Logger.php b/system/Log/Logger.php index 369db8ffb36d..6762e3380ecf 100644 --- a/system/Log/Logger.php +++ b/system/Log/Logger.php @@ -13,10 +13,10 @@ namespace CodeIgniter\Log; +use CodeIgniter\Exceptions\RuntimeException; use CodeIgniter\Log\Exceptions\LogException; use CodeIgniter\Log\Handlers\HandlerInterface; use Psr\Log\LoggerInterface; -use RuntimeException; use Stringable; use Throwable; diff --git a/system/Publisher/ContentReplacer.php b/system/Publisher/ContentReplacer.php index 72dd8ace43b8..6e8c01fa2e41 100644 --- a/system/Publisher/ContentReplacer.php +++ b/system/Publisher/ContentReplacer.php @@ -13,7 +13,7 @@ namespace CodeIgniter\Publisher; -use RuntimeException; +use CodeIgniter\Exceptions\RuntimeException; /** * Replace Text Content diff --git a/system/Publisher/Publisher.php b/system/Publisher/Publisher.php index 90c966623b2a..bf81f6079b60 100644 --- a/system/Publisher/Publisher.php +++ b/system/Publisher/Publisher.php @@ -14,11 +14,11 @@ namespace CodeIgniter\Publisher; use CodeIgniter\Autoloader\FileLocatorInterface; +use CodeIgniter\Exceptions\RuntimeException; use CodeIgniter\Files\FileCollection; use CodeIgniter\HTTP\URI; use CodeIgniter\Publisher\Exceptions\PublisherException; use Config\Publisher as PublisherConfig; -use RuntimeException; use Throwable; /** diff --git a/system/Test/Fabricator.php b/system/Test/Fabricator.php index 8da0c60fc089..1f61efef5c62 100644 --- a/system/Test/Fabricator.php +++ b/system/Test/Fabricator.php @@ -15,13 +15,13 @@ use Closure; use CodeIgniter\Exceptions\FrameworkException; +use CodeIgniter\Exceptions\RuntimeException; use CodeIgniter\I18n\Time; use CodeIgniter\Model; use Config\App; use Faker\Factory; use Faker\Generator; use InvalidArgumentException; -use RuntimeException; /** * Fabricator diff --git a/system/Test/FilterTestTrait.php b/system/Test/FilterTestTrait.php index 93f273a39f1f..608e847413f3 100644 --- a/system/Test/FilterTestTrait.php +++ b/system/Test/FilterTestTrait.php @@ -14,6 +14,7 @@ namespace CodeIgniter\Test; use Closure; +use CodeIgniter\Exceptions\RuntimeException; use CodeIgniter\Filters\Exceptions\FilterException; use CodeIgniter\Filters\FilterInterface; use CodeIgniter\Filters\Filters; @@ -22,7 +23,6 @@ use CodeIgniter\Router\RouteCollection; use Config\Filters as FiltersConfig; use InvalidArgumentException; -use RuntimeException; /** * Filter Test Trait diff --git a/system/View/View.php b/system/View/View.php index cda3d64f6088..160f1c179278 100644 --- a/system/View/View.php +++ b/system/View/View.php @@ -15,12 +15,12 @@ use CodeIgniter\Autoloader\FileLocatorInterface; use CodeIgniter\Debug\Toolbar\Collectors\Views; +use CodeIgniter\Exceptions\RuntimeException; use CodeIgniter\Filters\DebugToolbar; use CodeIgniter\View\Exceptions\ViewException; use Config\Toolbar; use Config\View as ViewConfig; use Psr\Log\LoggerInterface; -use RuntimeException; /** * Class View From 049fb2be4d18fe835a6e097fb435b2714ca84fa6 Mon Sep 17 00:00:00 2001 From: kenjis Date: Sat, 27 Jan 2024 20:32:01 +0900 Subject: [PATCH 09/32] refactor: use CodeIgniter\Exceptions\InvalidArgumentException --- system/Autoloader/Autoloader.php | 2 +- system/BaseModel.php | 2 +- system/CLI/CLI.php | 2 +- system/Cache/Handlers/BaseHandler.php | 2 +- system/Commands/Database/ShowTableInfo.php | 2 +- system/Config/DotEnv.php | 2 +- system/Config/Factories.php | 2 +- system/Cookie/Cookie.php | 2 +- system/Database/BaseBuilder.php | 2 +- system/Database/Config.php | 2 +- system/Database/Database.php | 2 +- system/Database/Forge.php | 2 +- system/Database/Postgre/Builder.php | 2 +- system/Database/SQLite3/Builder.php | 2 +- system/Database/Seeder.php | 2 +- system/Files/FileCollection.php | 2 +- system/HTTP/CURLRequest.php | 2 +- system/HTTP/Exceptions/RedirectException.php | 2 +- system/HTTP/Files/UploadedFile.php | 2 +- system/HTTP/Files/UploadedFileInterface.php | 2 +- system/HTTP/IncomingRequest.php | 2 +- system/HTTP/Message.php | 2 +- system/HTTP/MessageTrait.php | 2 +- system/HTTP/OutgoingRequestInterface.php | 2 +- system/HTTP/ResponseInterface.php | 2 +- system/HTTP/ResponseTrait.php | 2 +- system/HTTP/URI.php | 2 +- system/Helpers/Array/ArrayHelper.php | 2 +- system/Images/Handlers/BaseHandler.php | 2 +- system/Router/RouteCollection.php | 2 +- system/Security/Security.php | 2 +- system/Test/ControllerTestTrait.php | 2 +- system/Test/DOMParser.php | 2 +- system/Test/FilterTestTrait.php | 2 +- system/Test/Mock/MockInputOutput.php | 2 +- system/Validation/FileRules.php | 2 +- system/Validation/Rules.php | 2 +- system/Validation/Validation.php | 2 +- 38 files changed, 38 insertions(+), 38 deletions(-) diff --git a/system/Autoloader/Autoloader.php b/system/Autoloader/Autoloader.php index 3aef07ae635f..567d590fdae3 100644 --- a/system/Autoloader/Autoloader.php +++ b/system/Autoloader/Autoloader.php @@ -14,6 +14,7 @@ namespace CodeIgniter\Autoloader; use CodeIgniter\Exceptions\ConfigException; +use CodeIgniter\Exceptions\InvalidArgumentException; use CodeIgniter\Exceptions\RuntimeException; use Composer\Autoload\ClassLoader; use Composer\InstalledVersions; @@ -21,7 +22,6 @@ use Config\Kint as KintConfig; use Config\Modules; use Config\Services; -use InvalidArgumentException; use Kint; use Kint\Renderer\CliRenderer; use Kint\Renderer\RichRenderer; diff --git a/system/BaseModel.php b/system/BaseModel.php index 9b8bb70ed482..eee042f6c38f 100644 --- a/system/BaseModel.php +++ b/system/BaseModel.php @@ -21,13 +21,13 @@ use CodeIgniter\Database\Query; use CodeIgniter\DataConverter\DataConverter; use CodeIgniter\Entity\Entity; +use CodeIgniter\Exceptions\InvalidArgumentException; use CodeIgniter\Exceptions\ModelException; use CodeIgniter\I18n\Time; use CodeIgniter\Pager\Pager; use CodeIgniter\Validation\ValidationInterface; use Config\Feature; use Config\Services; -use InvalidArgumentException; use ReflectionClass; use ReflectionException; use ReflectionProperty; diff --git a/system/CLI/CLI.php b/system/CLI/CLI.php index 865241b75cbf..dc9c9a971bb7 100644 --- a/system/CLI/CLI.php +++ b/system/CLI/CLI.php @@ -14,8 +14,8 @@ namespace CodeIgniter\CLI; use CodeIgniter\CLI\Exceptions\CLIException; +use CodeIgniter\Exceptions\InvalidArgumentException; use Config\Services; -use InvalidArgumentException; use Throwable; /** diff --git a/system/Cache/Handlers/BaseHandler.php b/system/Cache/Handlers/BaseHandler.php index 43d316f87b0d..b2c9778b4997 100644 --- a/system/Cache/Handlers/BaseHandler.php +++ b/system/Cache/Handlers/BaseHandler.php @@ -15,9 +15,9 @@ use Closure; use CodeIgniter\Cache\CacheInterface; +use CodeIgniter\Exceptions\InvalidArgumentException; use Config\Cache; use Exception; -use InvalidArgumentException; /** * Base class for cache handling diff --git a/system/Commands/Database/ShowTableInfo.php b/system/Commands/Database/ShowTableInfo.php index 05dcfe4d67a3..3e88e035980c 100644 --- a/system/Commands/Database/ShowTableInfo.php +++ b/system/Commands/Database/ShowTableInfo.php @@ -16,8 +16,8 @@ use CodeIgniter\CLI\BaseCommand; use CodeIgniter\CLI\CLI; use CodeIgniter\Database\BaseConnection; +use CodeIgniter\Exceptions\InvalidArgumentException; use Config\Database; -use InvalidArgumentException; /** * Get table data if it exists in the database. diff --git a/system/Config/DotEnv.php b/system/Config/DotEnv.php index db7152fd09d5..eb3e6c5e3c9d 100644 --- a/system/Config/DotEnv.php +++ b/system/Config/DotEnv.php @@ -13,7 +13,7 @@ namespace CodeIgniter\Config; -use InvalidArgumentException; +use CodeIgniter\Exceptions\InvalidArgumentException; /** * Environment-specific configuration diff --git a/system/Config/Factories.php b/system/Config/Factories.php index d98664a24a7b..dfd1c38b4f9a 100644 --- a/system/Config/Factories.php +++ b/system/Config/Factories.php @@ -14,8 +14,8 @@ namespace CodeIgniter\Config; use CodeIgniter\Database\ConnectionInterface; +use CodeIgniter\Exceptions\InvalidArgumentException; use CodeIgniter\Model; -use InvalidArgumentException; /** * Factories for creating instances. diff --git a/system/Cookie/Cookie.php b/system/Cookie/Cookie.php index 78dc44258eb9..48e1ad7c2fbe 100644 --- a/system/Cookie/Cookie.php +++ b/system/Cookie/Cookie.php @@ -15,10 +15,10 @@ use ArrayAccess; use CodeIgniter\Cookie\Exceptions\CookieException; +use CodeIgniter\Exceptions\InvalidArgumentException; use CodeIgniter\I18n\Time; use Config\Cookie as CookieConfig; use DateTimeInterface; -use InvalidArgumentException; use LogicException; use ReturnTypeWillChange; diff --git a/system/Database/BaseBuilder.php b/system/Database/BaseBuilder.php index f9ca1efd4144..79cffb9c5171 100644 --- a/system/Database/BaseBuilder.php +++ b/system/Database/BaseBuilder.php @@ -16,9 +16,9 @@ use Closure; use CodeIgniter\Database\Exceptions\DatabaseException; use CodeIgniter\Database\Exceptions\DataException; +use CodeIgniter\Exceptions\InvalidArgumentException; use CodeIgniter\Traits\ConditionalTrait; use Config\Feature; -use InvalidArgumentException; /** * Class BaseBuilder diff --git a/system/Database/Config.php b/system/Database/Config.php index 03a0dd15743b..00d1b192cae3 100644 --- a/system/Database/Config.php +++ b/system/Database/Config.php @@ -14,8 +14,8 @@ namespace CodeIgniter\Database; use CodeIgniter\Config\BaseConfig; +use CodeIgniter\Exceptions\InvalidArgumentException; use Config\Database as DbConfig; -use InvalidArgumentException; /** * Class Config diff --git a/system/Database/Database.php b/system/Database/Database.php index c2bc66d30d11..649d347ff045 100644 --- a/system/Database/Database.php +++ b/system/Database/Database.php @@ -13,7 +13,7 @@ namespace CodeIgniter\Database; -use InvalidArgumentException; +use CodeIgniter\Exceptions\InvalidArgumentException; /** * Database Connection Factory diff --git a/system/Database/Forge.php b/system/Database/Forge.php index ca0428d9f7b3..1aa313358885 100644 --- a/system/Database/Forge.php +++ b/system/Database/Forge.php @@ -14,8 +14,8 @@ namespace CodeIgniter\Database; use CodeIgniter\Database\Exceptions\DatabaseException; +use CodeIgniter\Exceptions\InvalidArgumentException; use CodeIgniter\Exceptions\RuntimeException; -use InvalidArgumentException; use Throwable; /** diff --git a/system/Database/Postgre/Builder.php b/system/Database/Postgre/Builder.php index 857760930275..10c87be53dd1 100644 --- a/system/Database/Postgre/Builder.php +++ b/system/Database/Postgre/Builder.php @@ -16,7 +16,7 @@ use CodeIgniter\Database\BaseBuilder; use CodeIgniter\Database\Exceptions\DatabaseException; use CodeIgniter\Database\RawSql; -use InvalidArgumentException; +use CodeIgniter\Exceptions\InvalidArgumentException; /** * Builder for Postgre diff --git a/system/Database/SQLite3/Builder.php b/system/Database/SQLite3/Builder.php index a59270bbc0de..87bc4d73a885 100644 --- a/system/Database/SQLite3/Builder.php +++ b/system/Database/SQLite3/Builder.php @@ -16,7 +16,7 @@ use CodeIgniter\Database\BaseBuilder; use CodeIgniter\Database\Exceptions\DatabaseException; use CodeIgniter\Database\RawSql; -use InvalidArgumentException; +use CodeIgniter\Exceptions\InvalidArgumentException; /** * Builder for SQLite3 diff --git a/system/Database/Seeder.php b/system/Database/Seeder.php index be7cfcdf8a8c..ee6f6d1081b1 100644 --- a/system/Database/Seeder.php +++ b/system/Database/Seeder.php @@ -14,10 +14,10 @@ namespace CodeIgniter\Database; use CodeIgniter\CLI\CLI; +use CodeIgniter\Exceptions\InvalidArgumentException; use Config\Database; use Faker\Factory; use Faker\Generator; -use InvalidArgumentException; /** * Class Seeder diff --git a/system/Files/FileCollection.php b/system/Files/FileCollection.php index b9456dcc15ba..8b13efa2a570 100644 --- a/system/Files/FileCollection.php +++ b/system/Files/FileCollection.php @@ -13,11 +13,11 @@ namespace CodeIgniter\Files; +use CodeIgniter\Exceptions\InvalidArgumentException; use CodeIgniter\Files\Exceptions\FileException; use CodeIgniter\Files\Exceptions\FileNotFoundException; use Countable; use Generator; -use InvalidArgumentException; use IteratorAggregate; /** diff --git a/system/HTTP/CURLRequest.php b/system/HTTP/CURLRequest.php index 4b1c9c625399..0bb5ad3ea6b1 100644 --- a/system/HTTP/CURLRequest.php +++ b/system/HTTP/CURLRequest.php @@ -13,10 +13,10 @@ namespace CodeIgniter\HTTP; +use CodeIgniter\Exceptions\InvalidArgumentException; use CodeIgniter\HTTP\Exceptions\HTTPException; use Config\App; use Config\CURLRequest as ConfigCURLRequest; -use InvalidArgumentException; /** * A lightweight HTTP client for sending synchronous HTTP requests via cURL. diff --git a/system/HTTP/Exceptions/RedirectException.php b/system/HTTP/Exceptions/RedirectException.php index 318ffed42227..8d416fa4a5ee 100644 --- a/system/HTTP/Exceptions/RedirectException.php +++ b/system/HTTP/Exceptions/RedirectException.php @@ -14,10 +14,10 @@ namespace CodeIgniter\HTTP\Exceptions; use CodeIgniter\Exceptions\HTTPExceptionInterface; +use CodeIgniter\Exceptions\InvalidArgumentException; use CodeIgniter\Exceptions\RuntimeException; use CodeIgniter\HTTP\ResponsableInterface; use CodeIgniter\HTTP\ResponseInterface; -use InvalidArgumentException; use LogicException; use Throwable; diff --git a/system/HTTP/Files/UploadedFile.php b/system/HTTP/Files/UploadedFile.php index da029d7739ca..fe19f0df0527 100644 --- a/system/HTTP/Files/UploadedFile.php +++ b/system/HTTP/Files/UploadedFile.php @@ -13,12 +13,12 @@ namespace CodeIgniter\HTTP\Files; +use CodeIgniter\Exceptions\InvalidArgumentException; use CodeIgniter\Exceptions\RuntimeException; use CodeIgniter\Files\File; use CodeIgniter\HTTP\Exceptions\HTTPException; use Config\Mimes; use Exception; -use InvalidArgumentException; /** * Value object representing a single file uploaded through an diff --git a/system/HTTP/Files/UploadedFileInterface.php b/system/HTTP/Files/UploadedFileInterface.php index 167b0aa2f4d6..6e849d04a76b 100644 --- a/system/HTTP/Files/UploadedFileInterface.php +++ b/system/HTTP/Files/UploadedFileInterface.php @@ -13,8 +13,8 @@ namespace CodeIgniter\HTTP\Files; +use CodeIgniter\Exceptions\InvalidArgumentException; use CodeIgniter\Exceptions\RuntimeException; -use InvalidArgumentException; /** * Value object representing a single file uploaded through an diff --git a/system/HTTP/IncomingRequest.php b/system/HTTP/IncomingRequest.php index ec13e40f6ff5..b5cec37232a9 100755 --- a/system/HTTP/IncomingRequest.php +++ b/system/HTTP/IncomingRequest.php @@ -13,12 +13,12 @@ namespace CodeIgniter\HTTP; +use CodeIgniter\Exceptions\InvalidArgumentException; use CodeIgniter\HTTP\Exceptions\HTTPException; use CodeIgniter\HTTP\Files\FileCollection; use CodeIgniter\HTTP\Files\UploadedFile; use Config\App; use Config\Services; -use InvalidArgumentException; use Locale; use stdClass; diff --git a/system/HTTP/Message.php b/system/HTTP/Message.php index 71c4429f28ee..d83fcbb83230 100644 --- a/system/HTTP/Message.php +++ b/system/HTTP/Message.php @@ -13,7 +13,7 @@ namespace CodeIgniter\HTTP; -use InvalidArgumentException; +use CodeIgniter\Exceptions\InvalidArgumentException; /** * An HTTP message diff --git a/system/HTTP/MessageTrait.php b/system/HTTP/MessageTrait.php index 2f6e57a90c57..fc4af710c147 100644 --- a/system/HTTP/MessageTrait.php +++ b/system/HTTP/MessageTrait.php @@ -13,8 +13,8 @@ namespace CodeIgniter\HTTP; +use CodeIgniter\Exceptions\InvalidArgumentException; use CodeIgniter\HTTP\Exceptions\HTTPException; -use InvalidArgumentException; /** * Message Trait diff --git a/system/HTTP/OutgoingRequestInterface.php b/system/HTTP/OutgoingRequestInterface.php index da9e36206c37..8e314a5be03e 100644 --- a/system/HTTP/OutgoingRequestInterface.php +++ b/system/HTTP/OutgoingRequestInterface.php @@ -13,7 +13,7 @@ namespace CodeIgniter\HTTP; -use InvalidArgumentException; +use CodeIgniter\Exceptions\InvalidArgumentException; /** * Representation of an outgoing, client-side request. diff --git a/system/HTTP/ResponseInterface.php b/system/HTTP/ResponseInterface.php index 68ec5c3fce7f..0f23f1354953 100644 --- a/system/HTTP/ResponseInterface.php +++ b/system/HTTP/ResponseInterface.php @@ -15,10 +15,10 @@ use CodeIgniter\Cookie\Cookie; use CodeIgniter\Cookie\CookieStore; +use CodeIgniter\Exceptions\InvalidArgumentException; use CodeIgniter\HTTP\Exceptions\HTTPException; use CodeIgniter\Pager\PagerInterface; use DateTime; -use InvalidArgumentException; /** * Representation of an outgoing, server-side response. diff --git a/system/HTTP/ResponseTrait.php b/system/HTTP/ResponseTrait.php index 45f07d186170..726e85bae5a4 100644 --- a/system/HTTP/ResponseTrait.php +++ b/system/HTTP/ResponseTrait.php @@ -16,6 +16,7 @@ use CodeIgniter\Cookie\Cookie; use CodeIgniter\Cookie\CookieStore; use CodeIgniter\Cookie\Exceptions\CookieException; +use CodeIgniter\Exceptions\InvalidArgumentException; use CodeIgniter\HTTP\Exceptions\HTTPException; use CodeIgniter\I18n\Time; use CodeIgniter\Pager\PagerInterface; @@ -23,7 +24,6 @@ use Config\Cookie as CookieConfig; use DateTime; use DateTimeZone; -use InvalidArgumentException; /** * Response Trait diff --git a/system/HTTP/URI.php b/system/HTTP/URI.php index efa99cf778a8..75c677345482 100644 --- a/system/HTTP/URI.php +++ b/system/HTTP/URI.php @@ -14,9 +14,9 @@ namespace CodeIgniter\HTTP; use BadMethodCallException; +use CodeIgniter\Exceptions\InvalidArgumentException; use CodeIgniter\HTTP\Exceptions\HTTPException; use Config\App; -use InvalidArgumentException; use Stringable; /** diff --git a/system/Helpers/Array/ArrayHelper.php b/system/Helpers/Array/ArrayHelper.php index 76b8e8aedfbe..b9c356d381c1 100644 --- a/system/Helpers/Array/ArrayHelper.php +++ b/system/Helpers/Array/ArrayHelper.php @@ -13,7 +13,7 @@ namespace CodeIgniter\Helpers\Array; -use InvalidArgumentException; +use CodeIgniter\Exceptions\InvalidArgumentException; /** * @interal This is internal implementation for the framework. diff --git a/system/Images/Handlers/BaseHandler.php b/system/Images/Handlers/BaseHandler.php index eb704b564670..a6607e04d160 100644 --- a/system/Images/Handlers/BaseHandler.php +++ b/system/Images/Handlers/BaseHandler.php @@ -13,11 +13,11 @@ namespace CodeIgniter\Images\Handlers; +use CodeIgniter\Exceptions\InvalidArgumentException; use CodeIgniter\Images\Exceptions\ImageException; use CodeIgniter\Images\Image; use CodeIgniter\Images\ImageHandlerInterface; use Config\Images; -use InvalidArgumentException; /** * Base image handling implementation diff --git a/system/Router/RouteCollection.php b/system/Router/RouteCollection.php index 3198d342aa9d..faf2af99b046 100644 --- a/system/Router/RouteCollection.php +++ b/system/Router/RouteCollection.php @@ -15,6 +15,7 @@ use Closure; use CodeIgniter\Autoloader\FileLocatorInterface; +use CodeIgniter\Exceptions\InvalidArgumentException; use CodeIgniter\HTTP\Method; use CodeIgniter\HTTP\ResponseInterface; use CodeIgniter\Router\Exceptions\RouterException; @@ -22,7 +23,6 @@ use Config\Modules; use Config\Routing; use Config\Services; -use InvalidArgumentException; /** * @todo Implement nested resource routing (See CakePHP) diff --git a/system/Security/Security.php b/system/Security/Security.php index 077b3b9cdbb0..54e3839845a8 100644 --- a/system/Security/Security.php +++ b/system/Security/Security.php @@ -14,6 +14,7 @@ namespace CodeIgniter\Security; use CodeIgniter\Cookie\Cookie; +use CodeIgniter\Exceptions\InvalidArgumentException; use CodeIgniter\HTTP\IncomingRequest; use CodeIgniter\HTTP\Method; use CodeIgniter\HTTP\Request; @@ -24,7 +25,6 @@ use Config\Cookie as CookieConfig; use Config\Security as SecurityConfig; use ErrorException; -use InvalidArgumentException; use LogicException; /** diff --git a/system/Test/ControllerTestTrait.php b/system/Test/ControllerTestTrait.php index ab1a1aef3907..7417e7307a08 100644 --- a/system/Test/ControllerTestTrait.php +++ b/system/Test/ControllerTestTrait.php @@ -12,13 +12,13 @@ namespace CodeIgniter\Test; use CodeIgniter\Controller; +use CodeIgniter\Exceptions\InvalidArgumentException; use CodeIgniter\HTTP\Exceptions\HTTPException; use CodeIgniter\HTTP\IncomingRequest; use CodeIgniter\HTTP\ResponseInterface; use CodeIgniter\HTTP\URI; use Config\App; use Config\Services; -use InvalidArgumentException; use Psr\Log\LoggerInterface; use Throwable; diff --git a/system/Test/DOMParser.php b/system/Test/DOMParser.php index fe9ee1d58b2a..ae4d4e4ee2b4 100644 --- a/system/Test/DOMParser.php +++ b/system/Test/DOMParser.php @@ -14,10 +14,10 @@ namespace CodeIgniter\Test; use BadMethodCallException; +use CodeIgniter\Exceptions\InvalidArgumentException; use DOMDocument; use DOMNodeList; use DOMXPath; -use InvalidArgumentException; /** * Load a response into a DOMDocument for testing assertions based on that diff --git a/system/Test/FilterTestTrait.php b/system/Test/FilterTestTrait.php index 608e847413f3..6c0a5d4670c0 100644 --- a/system/Test/FilterTestTrait.php +++ b/system/Test/FilterTestTrait.php @@ -14,6 +14,7 @@ namespace CodeIgniter\Test; use Closure; +use CodeIgniter\Exceptions\InvalidArgumentException; use CodeIgniter\Exceptions\RuntimeException; use CodeIgniter\Filters\Exceptions\FilterException; use CodeIgniter\Filters\FilterInterface; @@ -22,7 +23,6 @@ use CodeIgniter\HTTP\ResponseInterface; use CodeIgniter\Router\RouteCollection; use Config\Filters as FiltersConfig; -use InvalidArgumentException; /** * Filter Test Trait diff --git a/system/Test/Mock/MockInputOutput.php b/system/Test/Mock/MockInputOutput.php index 750f142a00e7..ff7044e07ba5 100644 --- a/system/Test/Mock/MockInputOutput.php +++ b/system/Test/Mock/MockInputOutput.php @@ -14,9 +14,9 @@ namespace CodeIgniter\Test\Mock; use CodeIgniter\CLI\InputOutput; +use CodeIgniter\Exceptions\InvalidArgumentException; use CodeIgniter\Test\Filters\CITestStreamFilter; use CodeIgniter\Test\PhpStreamWrapper; -use InvalidArgumentException; use LogicException; final class MockInputOutput extends InputOutput diff --git a/system/Validation/FileRules.php b/system/Validation/FileRules.php index dd8c4290e11d..2171858c1582 100644 --- a/system/Validation/FileRules.php +++ b/system/Validation/FileRules.php @@ -13,11 +13,11 @@ namespace CodeIgniter\Validation; +use CodeIgniter\Exceptions\InvalidArgumentException; use CodeIgniter\HTTP\CLIRequest; use CodeIgniter\HTTP\IncomingRequest; use CodeIgniter\HTTP\RequestInterface; use Config\Mimes; -use InvalidArgumentException; /** * File validation rules diff --git a/system/Validation/Rules.php b/system/Validation/Rules.php index 272b2dcf61fe..aa031e216271 100644 --- a/system/Validation/Rules.php +++ b/system/Validation/Rules.php @@ -13,9 +13,9 @@ namespace CodeIgniter\Validation; +use CodeIgniter\Exceptions\InvalidArgumentException; use CodeIgniter\Helpers\Array\ArrayHelper; use Config\Database; -use InvalidArgumentException; /** * Validation Rules. diff --git a/system/Validation/Validation.php b/system/Validation/Validation.php index eb87ef3fa776..82fc749f9cf3 100644 --- a/system/Validation/Validation.php +++ b/system/Validation/Validation.php @@ -15,6 +15,7 @@ use Closure; use CodeIgniter\Database\BaseConnection; +use CodeIgniter\Exceptions\InvalidArgumentException; use CodeIgniter\HTTP\Exceptions\HTTPException; use CodeIgniter\HTTP\IncomingRequest; use CodeIgniter\HTTP\Method; @@ -23,7 +24,6 @@ use CodeIgniter\View\RendererInterface; use Config\Services; use Config\Validation as ValidationConfig; -use InvalidArgumentException; use LogicException; use TypeError; From 4b8a50e6939d503e01147c8d612b9ad5572425f8 Mon Sep 17 00:00:00 2001 From: kenjis Date: Sat, 27 Jan 2024 20:32:26 +0900 Subject: [PATCH 10/32] refactor: use CodeIgniter\Exceptions\LogicException --- system/CodeIgniter.php | 2 +- system/Cookie/Cookie.php | 2 +- system/Database/MySQLi/Connection.php | 2 +- system/HTTP/Exceptions/RedirectException.php | 2 +- system/Security/Security.php | 2 +- system/Test/ConfigFromArrayTrait.php | 2 +- system/Test/Mock/MockInputOutput.php | 2 +- system/Validation/Validation.php | 2 +- system/View/Cells/Cell.php | 2 +- 9 files changed, 9 insertions(+), 9 deletions(-) diff --git a/system/CodeIgniter.php b/system/CodeIgniter.php index 1758228076ab..1ea1d0e2f610 100644 --- a/system/CodeIgniter.php +++ b/system/CodeIgniter.php @@ -16,6 +16,7 @@ use CodeIgniter\Debug\Timer; use CodeIgniter\Events\Events; use CodeIgniter\Exceptions\FrameworkException; +use CodeIgniter\Exceptions\LogicException; use CodeIgniter\Exceptions\PageNotFoundException; use CodeIgniter\Filters\Filters; use CodeIgniter\HTTP\CLIRequest; @@ -41,7 +42,6 @@ use Kint\Renderer\CliRenderer; use Kint\Renderer\RichRenderer; use Locale; -use LogicException; use Throwable; /** diff --git a/system/Cookie/Cookie.php b/system/Cookie/Cookie.php index 48e1ad7c2fbe..7da90654ed9b 100644 --- a/system/Cookie/Cookie.php +++ b/system/Cookie/Cookie.php @@ -16,10 +16,10 @@ use ArrayAccess; use CodeIgniter\Cookie\Exceptions\CookieException; use CodeIgniter\Exceptions\InvalidArgumentException; +use CodeIgniter\Exceptions\LogicException; use CodeIgniter\I18n\Time; use Config\Cookie as CookieConfig; use DateTimeInterface; -use LogicException; use ReturnTypeWillChange; /** diff --git a/system/Database/MySQLi/Connection.php b/system/Database/MySQLi/Connection.php index b25f2e1af390..e8db25c76640 100644 --- a/system/Database/MySQLi/Connection.php +++ b/system/Database/MySQLi/Connection.php @@ -15,7 +15,7 @@ use CodeIgniter\Database\BaseConnection; use CodeIgniter\Database\Exceptions\DatabaseException; -use LogicException; +use CodeIgniter\Exceptions\LogicException; use mysqli; use mysqli_result; use mysqli_sql_exception; diff --git a/system/HTTP/Exceptions/RedirectException.php b/system/HTTP/Exceptions/RedirectException.php index 8d416fa4a5ee..a13bc933a095 100644 --- a/system/HTTP/Exceptions/RedirectException.php +++ b/system/HTTP/Exceptions/RedirectException.php @@ -15,10 +15,10 @@ use CodeIgniter\Exceptions\HTTPExceptionInterface; use CodeIgniter\Exceptions\InvalidArgumentException; +use CodeIgniter\Exceptions\LogicException; use CodeIgniter\Exceptions\RuntimeException; use CodeIgniter\HTTP\ResponsableInterface; use CodeIgniter\HTTP\ResponseInterface; -use LogicException; use Throwable; /** diff --git a/system/Security/Security.php b/system/Security/Security.php index 54e3839845a8..03e8b8da9e2c 100644 --- a/system/Security/Security.php +++ b/system/Security/Security.php @@ -15,6 +15,7 @@ use CodeIgniter\Cookie\Cookie; use CodeIgniter\Exceptions\InvalidArgumentException; +use CodeIgniter\Exceptions\LogicException; use CodeIgniter\HTTP\IncomingRequest; use CodeIgniter\HTTP\Method; use CodeIgniter\HTTP\Request; @@ -25,7 +26,6 @@ use Config\Cookie as CookieConfig; use Config\Security as SecurityConfig; use ErrorException; -use LogicException; /** * Class Security diff --git a/system/Test/ConfigFromArrayTrait.php b/system/Test/ConfigFromArrayTrait.php index 3652fa1074a1..9dd2ac0c4de7 100644 --- a/system/Test/ConfigFromArrayTrait.php +++ b/system/Test/ConfigFromArrayTrait.php @@ -13,7 +13,7 @@ namespace CodeIgniter\Test; -use LogicException; +use CodeIgniter\Exceptions\LogicException; trait ConfigFromArrayTrait { diff --git a/system/Test/Mock/MockInputOutput.php b/system/Test/Mock/MockInputOutput.php index ff7044e07ba5..fb76781a177e 100644 --- a/system/Test/Mock/MockInputOutput.php +++ b/system/Test/Mock/MockInputOutput.php @@ -15,9 +15,9 @@ use CodeIgniter\CLI\InputOutput; use CodeIgniter\Exceptions\InvalidArgumentException; +use CodeIgniter\Exceptions\LogicException; use CodeIgniter\Test\Filters\CITestStreamFilter; use CodeIgniter\Test\PhpStreamWrapper; -use LogicException; final class MockInputOutput extends InputOutput { diff --git a/system/Validation/Validation.php b/system/Validation/Validation.php index 82fc749f9cf3..d01262640709 100644 --- a/system/Validation/Validation.php +++ b/system/Validation/Validation.php @@ -16,6 +16,7 @@ use Closure; use CodeIgniter\Database\BaseConnection; use CodeIgniter\Exceptions\InvalidArgumentException; +use CodeIgniter\Exceptions\LogicException; use CodeIgniter\HTTP\Exceptions\HTTPException; use CodeIgniter\HTTP\IncomingRequest; use CodeIgniter\HTTP\Method; @@ -24,7 +25,6 @@ use CodeIgniter\View\RendererInterface; use Config\Services; use Config\Validation as ValidationConfig; -use LogicException; use TypeError; /** diff --git a/system/View/Cells/Cell.php b/system/View/Cells/Cell.php index ddf7ef4ccf63..e60493804002 100644 --- a/system/View/Cells/Cell.php +++ b/system/View/Cells/Cell.php @@ -13,8 +13,8 @@ namespace CodeIgniter\View\Cells; +use CodeIgniter\Exceptions\LogicException; use CodeIgniter\Traits\PropertiesTrait; -use LogicException; use ReflectionClass; use Stringable; From 13106b84c19e129b551893e296527be7954e32bc Mon Sep 17 00:00:00 2001 From: kenjis Date: Sat, 27 Jan 2024 20:34:45 +0900 Subject: [PATCH 11/32] refactor: use CodeIgniter\Exceptions\BadMethodCallException --- system/Database/BasePreparedQuery.php | 2 +- system/Database/MySQLi/PreparedQuery.php | 2 +- system/Database/OCI8/PreparedQuery.php | 2 +- system/Database/Postgre/PreparedQuery.php | 2 +- system/Database/PreparedQueryInterface.php | 2 +- system/Database/SQLSRV/PreparedQuery.php | 2 +- system/Database/SQLite3/PreparedQuery.php | 2 +- system/HTTP/SiteURI.php | 2 +- system/HTTP/URI.php | 2 +- system/Model.php | 2 +- system/Test/DOMParser.php | 2 +- system/Test/Mock/MockTable.php | 2 +- 12 files changed, 12 insertions(+), 12 deletions(-) diff --git a/system/Database/BasePreparedQuery.php b/system/Database/BasePreparedQuery.php index 8c4f252cfb7e..95e7c0df0c47 100644 --- a/system/Database/BasePreparedQuery.php +++ b/system/Database/BasePreparedQuery.php @@ -14,9 +14,9 @@ namespace CodeIgniter\Database; use ArgumentCountError; -use BadMethodCallException; use CodeIgniter\Database\Exceptions\DatabaseException; use CodeIgniter\Events\Events; +use CodeIgniter\Exceptions\BadMethodCallException; use ErrorException; /** diff --git a/system/Database/MySQLi/PreparedQuery.php b/system/Database/MySQLi/PreparedQuery.php index e9a6c6d10e30..2ff2f6638259 100644 --- a/system/Database/MySQLi/PreparedQuery.php +++ b/system/Database/MySQLi/PreparedQuery.php @@ -13,9 +13,9 @@ namespace CodeIgniter\Database\MySQLi; -use BadMethodCallException; use CodeIgniter\Database\BasePreparedQuery; use CodeIgniter\Database\Exceptions\DatabaseException; +use CodeIgniter\Exceptions\BadMethodCallException; use mysqli; use mysqli_result; use mysqli_sql_exception; diff --git a/system/Database/OCI8/PreparedQuery.php b/system/Database/OCI8/PreparedQuery.php index c267f8061377..a6b6c73c0348 100644 --- a/system/Database/OCI8/PreparedQuery.php +++ b/system/Database/OCI8/PreparedQuery.php @@ -13,9 +13,9 @@ namespace CodeIgniter\Database\OCI8; -use BadMethodCallException; use CodeIgniter\Database\BasePreparedQuery; use CodeIgniter\Database\Exceptions\DatabaseException; +use CodeIgniter\Exceptions\BadMethodCallException; /** * Prepared query for OCI8 diff --git a/system/Database/Postgre/PreparedQuery.php b/system/Database/Postgre/PreparedQuery.php index 832108675ab9..06e7ffbb1f4e 100644 --- a/system/Database/Postgre/PreparedQuery.php +++ b/system/Database/Postgre/PreparedQuery.php @@ -13,9 +13,9 @@ namespace CodeIgniter\Database\Postgre; -use BadMethodCallException; use CodeIgniter\Database\BasePreparedQuery; use CodeIgniter\Database\Exceptions\DatabaseException; +use CodeIgniter\Exceptions\BadMethodCallException; use Exception; use PgSql\Connection as PgSqlConnection; use PgSql\Result as PgSqlResult; diff --git a/system/Database/PreparedQueryInterface.php b/system/Database/PreparedQueryInterface.php index d9e11cd520d6..6ac69904e7f9 100644 --- a/system/Database/PreparedQueryInterface.php +++ b/system/Database/PreparedQueryInterface.php @@ -13,7 +13,7 @@ namespace CodeIgniter\Database; -use BadMethodCallException; +use CodeIgniter\Exceptions\BadMethodCallException; /** * @template TConnection diff --git a/system/Database/SQLSRV/PreparedQuery.php b/system/Database/SQLSRV/PreparedQuery.php index f3a4a14c2bc6..1f9dad6217e8 100755 --- a/system/Database/SQLSRV/PreparedQuery.php +++ b/system/Database/SQLSRV/PreparedQuery.php @@ -13,9 +13,9 @@ namespace CodeIgniter\Database\SQLSRV; -use BadMethodCallException; use CodeIgniter\Database\BasePreparedQuery; use CodeIgniter\Database\Exceptions\DatabaseException; +use CodeIgniter\Exceptions\BadMethodCallException; /** * Prepared query for Postgre diff --git a/system/Database/SQLite3/PreparedQuery.php b/system/Database/SQLite3/PreparedQuery.php index 21dc4c2fdeff..654afa1ce36e 100644 --- a/system/Database/SQLite3/PreparedQuery.php +++ b/system/Database/SQLite3/PreparedQuery.php @@ -13,9 +13,9 @@ namespace CodeIgniter\Database\SQLite3; -use BadMethodCallException; use CodeIgniter\Database\BasePreparedQuery; use CodeIgniter\Database\Exceptions\DatabaseException; +use CodeIgniter\Exceptions\BadMethodCallException; use Exception; use SQLite3; use SQLite3Result; diff --git a/system/HTTP/SiteURI.php b/system/HTTP/SiteURI.php index def61b65e17b..20bec2972122 100644 --- a/system/HTTP/SiteURI.php +++ b/system/HTTP/SiteURI.php @@ -13,7 +13,7 @@ namespace CodeIgniter\HTTP; -use BadMethodCallException; +use CodeIgniter\Exceptions\BadMethodCallException; use CodeIgniter\Exceptions\ConfigException; use CodeIgniter\HTTP\Exceptions\HTTPException; use Config\App; diff --git a/system/HTTP/URI.php b/system/HTTP/URI.php index 75c677345482..e3062d30dd7c 100644 --- a/system/HTTP/URI.php +++ b/system/HTTP/URI.php @@ -13,7 +13,7 @@ namespace CodeIgniter\HTTP; -use BadMethodCallException; +use CodeIgniter\Exceptions\BadMethodCallException; use CodeIgniter\Exceptions\InvalidArgumentException; use CodeIgniter\HTTP\Exceptions\HTTPException; use Config\App; diff --git a/system/Model.php b/system/Model.php index b3ecfc653943..ee165c68371c 100644 --- a/system/Model.php +++ b/system/Model.php @@ -13,7 +13,6 @@ namespace CodeIgniter; -use BadMethodCallException; use Closure; use CodeIgniter\Database\BaseBuilder; use CodeIgniter\Database\BaseConnection; @@ -23,6 +22,7 @@ use CodeIgniter\Database\Exceptions\DataException; use CodeIgniter\Database\Query; use CodeIgniter\Entity\Entity; +use CodeIgniter\Exceptions\BadMethodCallException; use CodeIgniter\Exceptions\ModelException; use CodeIgniter\Validation\ValidationInterface; use Config\Database; diff --git a/system/Test/DOMParser.php b/system/Test/DOMParser.php index ae4d4e4ee2b4..f46ce1d65206 100644 --- a/system/Test/DOMParser.php +++ b/system/Test/DOMParser.php @@ -13,7 +13,7 @@ namespace CodeIgniter\Test; -use BadMethodCallException; +use CodeIgniter\Exceptions\BadMethodCallException; use CodeIgniter\Exceptions\InvalidArgumentException; use DOMDocument; use DOMNodeList; diff --git a/system/Test/Mock/MockTable.php b/system/Test/Mock/MockTable.php index 1976aaed7be1..a7edc359e4f8 100644 --- a/system/Test/Mock/MockTable.php +++ b/system/Test/Mock/MockTable.php @@ -13,7 +13,7 @@ namespace CodeIgniter\Test\Mock; -use BadMethodCallException; +use CodeIgniter\Exceptions\BadMethodCallException; use CodeIgniter\View\Table; class MockTable extends Table From 82eaa32d65a094cbeed0b72e41117e1da025d109 Mon Sep 17 00:00:00 2001 From: kenjis Date: Sat, 27 Jan 2024 21:16:27 +0900 Subject: [PATCH 12/32] refactor: use CodeIgniter\Exceptions\BadFunctionCallException --- system/Helpers/number_helper.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/system/Helpers/number_helper.php b/system/Helpers/number_helper.php index 96468ddcdea3..a0d0496452c3 100644 --- a/system/Helpers/number_helper.php +++ b/system/Helpers/number_helper.php @@ -11,6 +11,8 @@ * the LICENSE file that was distributed with this source code. */ +use CodeIgniter\Exceptions\BadFunctionCallException; + // CodeIgniter Number Helpers if (! function_exists('number_to_size')) { From 3fa8a261779fdac2f9cabf5bdee8265510dfa74e Mon Sep 17 00:00:00 2001 From: kenjis Date: Sat, 27 Jan 2024 22:41:02 +0900 Subject: [PATCH 13/32] fix: replace \Exception with RuntimeException --- system/Cache/ResponseCache.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/system/Cache/ResponseCache.php b/system/Cache/ResponseCache.php index 388931813c7c..35c2617c8cb5 100644 --- a/system/Cache/ResponseCache.php +++ b/system/Cache/ResponseCache.php @@ -13,12 +13,12 @@ namespace CodeIgniter\Cache; +use CodeIgniter\Exceptions\RuntimeException; use CodeIgniter\HTTP\CLIRequest; use CodeIgniter\HTTP\Header; use CodeIgniter\HTTP\IncomingRequest; use CodeIgniter\HTTP\ResponseInterface; use Config\Cache as CacheConfig; -use Exception; /** * Web Page Caching @@ -131,7 +131,7 @@ public function get($request, ResponseInterface $response): ?ResponseInterface || ! isset($cachedResponse['output']) || ! isset($cachedResponse['headers']) ) { - throw new Exception('Error unserializing page cache'); + throw new RuntimeException('Error unserializing page cache'); } $headers = $cachedResponse['headers']; From 3a35769b197bf8104a252c30afbd3149593dcc56 Mon Sep 17 00:00:00 2001 From: kenjis Date: Sat, 27 Jan 2024 22:42:41 +0900 Subject: [PATCH 14/32] fix: replace \Exception with BadMethodCallException --- system/Cache/Handlers/BaseHandler.php | 3 ++- system/Cache/Handlers/MemcachedHandler.php | 3 ++- system/Cache/Handlers/WincacheHandler.php | 4 ++-- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/system/Cache/Handlers/BaseHandler.php b/system/Cache/Handlers/BaseHandler.php index b2c9778b4997..9c98bedc7693 100644 --- a/system/Cache/Handlers/BaseHandler.php +++ b/system/Cache/Handlers/BaseHandler.php @@ -15,6 +15,7 @@ use Closure; use CodeIgniter\Cache\CacheInterface; +use CodeIgniter\Exceptions\BadMethodCallException; use CodeIgniter\Exceptions\InvalidArgumentException; use Config\Cache; use Exception; @@ -108,6 +109,6 @@ public function remember(string $key, int $ttl, Closure $callback) */ public function deleteMatching(string $pattern) { - throw new Exception('The deleteMatching method is not implemented.'); + throw new BadMethodCallException('The deleteMatching method is not implemented.'); } } diff --git a/system/Cache/Handlers/MemcachedHandler.php b/system/Cache/Handlers/MemcachedHandler.php index e1048004077a..a0d487126cf4 100644 --- a/system/Cache/Handlers/MemcachedHandler.php +++ b/system/Cache/Handlers/MemcachedHandler.php @@ -13,6 +13,7 @@ namespace CodeIgniter\Cache\Handlers; +use CodeIgniter\Exceptions\BadMethodCallException; use CodeIgniter\Exceptions\CriticalError; use CodeIgniter\I18n\Time; use Config\Cache; @@ -197,7 +198,7 @@ public function delete(string $key) */ public function deleteMatching(string $pattern) { - throw new Exception('The deleteMatching method is not implemented for Memcached. You must select File, Redis or Predis handlers to use it.'); + throw new BadMethodCallException('The deleteMatching method is not implemented for Memcached. You must select File, Redis or Predis handlers to use it.'); } /** diff --git a/system/Cache/Handlers/WincacheHandler.php b/system/Cache/Handlers/WincacheHandler.php index 0ddee50a7fde..d4d97701b135 100644 --- a/system/Cache/Handlers/WincacheHandler.php +++ b/system/Cache/Handlers/WincacheHandler.php @@ -13,9 +13,9 @@ namespace CodeIgniter\Cache\Handlers; +use CodeIgniter\Exceptions\BadMethodCallException; use CodeIgniter\I18n\Time; use Config\Cache; -use Exception; /** * Cache handler for WinCache from Microsoft & IIS. @@ -80,7 +80,7 @@ public function delete(string $key) */ public function deleteMatching(string $pattern) { - throw new Exception('The deleteMatching method is not implemented for Wincache. You must select File, Redis or Predis handlers to use it.'); + throw new BadMethodCallException('The deleteMatching method is not implemented for Wincache. You must select File, Redis or Predis handlers to use it.'); } /** From d33d3c7fd6eae429d5c44ca17b3f0123be0dae5c Mon Sep 17 00:00:00 2001 From: kenjis Date: Sat, 27 Jan 2024 22:43:09 +0900 Subject: [PATCH 15/32] fix: replace \TypeError with InvalidArgumentException --- system/Validation/Validation.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/system/Validation/Validation.php b/system/Validation/Validation.php index d01262640709..3cdf2f2ee22d 100644 --- a/system/Validation/Validation.php +++ b/system/Validation/Validation.php @@ -25,7 +25,6 @@ use CodeIgniter\View\RendererInterface; use Config\Services; use Config\Validation as ValidationConfig; -use TypeError; /** * Validator @@ -540,12 +539,12 @@ public function withRequest(RequestInterface $request): ValidationInterface * * @return $this * - * @throws TypeError + * @throws InvalidArgumentException */ public function setRule(string $field, ?string $label, $rules, array $errors = []) { if (! is_array($rules) && ! is_string($rules)) { - throw new TypeError('$rules must be of type string|array'); + throw new InvalidArgumentException('$rules must be of type string|array'); } $ruleSet = [ From 08fea02f2c82732d2ed31085fc28b4220c8a9df0 Mon Sep 17 00:00:00 2001 From: kenjis Date: Sun, 28 Jan 2024 09:54:00 +0900 Subject: [PATCH 16/32] docs: fix class Doc comments --- system/Exceptions/ConfigException.php | 3 ++- system/Exceptions/TestException.php | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/system/Exceptions/ConfigException.php b/system/Exceptions/ConfigException.php index d8d27d094230..b30818124901 100644 --- a/system/Exceptions/ConfigException.php +++ b/system/Exceptions/ConfigException.php @@ -14,7 +14,8 @@ namespace CodeIgniter\Exceptions; /** - * Exception for automatic logging. + * Exception thrown if the value of the Config class is invalid or the type is + * incorrect. */ class ConfigException extends RuntimeException implements HasExitCodeInterface { diff --git a/system/Exceptions/TestException.php b/system/Exceptions/TestException.php index fd70709a6cb2..4487ae1e1815 100644 --- a/system/Exceptions/TestException.php +++ b/system/Exceptions/TestException.php @@ -14,7 +14,7 @@ namespace CodeIgniter\Exceptions; /** - * Exception for automatic logging. + * Exception thrown when there is an error with the test code. */ class TestException extends LogicException { From 616e0f5964409ec9820f6126aa04972c8efe5079 Mon Sep 17 00:00:00 2001 From: kenjis Date: Sun, 28 Jan 2024 10:15:25 +0900 Subject: [PATCH 17/32] test: update expectException() --- tests/system/Validation/ValidationTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/system/Validation/ValidationTest.php b/tests/system/Validation/ValidationTest.php index b5493a682c8e..64c42a088681 100644 --- a/tests/system/Validation/ValidationTest.php +++ b/tests/system/Validation/ValidationTest.php @@ -13,6 +13,7 @@ namespace CodeIgniter\Validation; +use CodeIgniter\Exceptions\InvalidArgumentException; use CodeIgniter\HTTP\Exceptions\HTTPException; use CodeIgniter\HTTP\IncomingRequest; use CodeIgniter\HTTP\SiteURI; @@ -26,7 +27,6 @@ use PHPUnit\Framework\ExpectationFailedException; use Tests\Support\Validation\TestRules; use Throwable; -use TypeError; /** * @internal @@ -197,7 +197,7 @@ public function testSetRuleOverwritesRuleReverse(): void public function testSetRuleRulesFormat(bool $expected, $rules): void { if (! $expected) { - $this->expectException(TypeError::class); + $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage('$rules must be of type string|array'); } From 832c77ff1aa46e86901faef779462b3bbb7dc414 Mon Sep 17 00:00:00 2001 From: kenjis Date: Sun, 28 Jan 2024 10:45:00 +0900 Subject: [PATCH 18/32] refactor: remove unneeded `implements ExceptionInterface` --- system/Cache/Exceptions/CacheException.php | 3 +-- system/Encryption/Exceptions/EncryptionException.php | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/system/Cache/Exceptions/CacheException.php b/system/Cache/Exceptions/CacheException.php index 774daa9965b2..650dad64d649 100644 --- a/system/Cache/Exceptions/CacheException.php +++ b/system/Cache/Exceptions/CacheException.php @@ -14,13 +14,12 @@ namespace CodeIgniter\Cache\Exceptions; use CodeIgniter\Exceptions\DebugTraceableTrait; -use CodeIgniter\Exceptions\ExceptionInterface; use CodeIgniter\Exceptions\RuntimeException; /** * CacheException */ -class CacheException extends RuntimeException implements ExceptionInterface +class CacheException extends RuntimeException { use DebugTraceableTrait; diff --git a/system/Encryption/Exceptions/EncryptionException.php b/system/Encryption/Exceptions/EncryptionException.php index e18899467bd5..9a0935d7d91d 100644 --- a/system/Encryption/Exceptions/EncryptionException.php +++ b/system/Encryption/Exceptions/EncryptionException.php @@ -14,13 +14,12 @@ namespace CodeIgniter\Encryption\Exceptions; use CodeIgniter\Exceptions\DebugTraceableTrait; -use CodeIgniter\Exceptions\ExceptionInterface; use CodeIgniter\Exceptions\RuntimeException; /** * Encryption exception */ -class EncryptionException extends RuntimeException implements ExceptionInterface +class EncryptionException extends RuntimeException { use DebugTraceableTrait; From b91b905a6e101a829137adb8c7593558ff56a7af Mon Sep 17 00:00:00 2001 From: kenjis Date: Sun, 28 Jan 2024 10:45:36 +0900 Subject: [PATCH 19/32] feat: add domain-level ExceptionInterface If there are more than one Exception class in the domain, provide a domain-level interface for capture of all exceptions. --- .../Files/Exceptions/ExceptionInterface.php | 24 +++++++++++++++++++ system/HTTP/Exceptions/ExceptionInterface.php | 24 +++++++++++++++++++ .../Router/Exceptions/ExceptionInterface.php | 24 +++++++++++++++++++ 3 files changed, 72 insertions(+) create mode 100644 system/Files/Exceptions/ExceptionInterface.php create mode 100644 system/HTTP/Exceptions/ExceptionInterface.php create mode 100644 system/Router/Exceptions/ExceptionInterface.php diff --git a/system/Files/Exceptions/ExceptionInterface.php b/system/Files/Exceptions/ExceptionInterface.php new file mode 100644 index 000000000000..346ff1624e12 --- /dev/null +++ b/system/Files/Exceptions/ExceptionInterface.php @@ -0,0 +1,24 @@ + + * + * For the full copyright and license information, please view + * the LICENSE file that was distributed with this source code. + */ + +namespace CodeIgniter\Files\Exceptions; + +/** + * Provides a domain-level interface for broad capture + * of all Files-related exceptions. + * + * catch (\CodeIgniter\Files\Exceptions\ExceptionInterface) { ... } + */ +interface ExceptionInterface extends \CodeIgniter\Exceptions\ExceptionInterface +{ +} diff --git a/system/HTTP/Exceptions/ExceptionInterface.php b/system/HTTP/Exceptions/ExceptionInterface.php new file mode 100644 index 000000000000..984a94972364 --- /dev/null +++ b/system/HTTP/Exceptions/ExceptionInterface.php @@ -0,0 +1,24 @@ + + * + * For the full copyright and license information, please view + * the LICENSE file that was distributed with this source code. + */ + +namespace CodeIgniter\HTTP\Exceptions; + +/** + * Provides a domain-level interface for broad capture + * of all HTTP-related exceptions. + * + * catch (\CodeIgniter\HTTP\Exceptions\ExceptionInterface) { ... } + */ +interface ExceptionInterface extends \CodeIgniter\Exceptions\ExceptionInterface +{ +} diff --git a/system/Router/Exceptions/ExceptionInterface.php b/system/Router/Exceptions/ExceptionInterface.php new file mode 100644 index 000000000000..49ed7cc11a78 --- /dev/null +++ b/system/Router/Exceptions/ExceptionInterface.php @@ -0,0 +1,24 @@ + + * + * For the full copyright and license information, please view + * the LICENSE file that was distributed with this source code. + */ + +namespace CodeIgniter\Router\Exceptions; + +/** + * Provides a domain-level interface for broad capture + * of all Router-related exceptions. + * + * catch (\CodeIgniter\Router\Exceptions\ExceptionInterface) { ... } + */ +interface ExceptionInterface extends \CodeIgniter\Exceptions\ExceptionInterface +{ +} From cff68f1c81846fef9eaee4d4cd1e2988c86d0d41 Mon Sep 17 00:00:00 2001 From: kenjis Date: Sun, 28 Jan 2024 10:48:56 +0900 Subject: [PATCH 20/32] feat: implements domain-level ExceptionInterface --- system/Database/Exceptions/DatabaseException.php | 2 +- system/Files/Exceptions/FileException.php | 2 +- system/Files/Exceptions/FileNotFoundException.php | 2 +- system/HTTP/Exceptions/HTTPException.php | 2 +- system/HTTP/Exceptions/RedirectException.php | 2 +- system/Router/Exceptions/MethodNotFoundException.php | 2 +- system/Router/Exceptions/RouterException.php | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/system/Database/Exceptions/DatabaseException.php b/system/Database/Exceptions/DatabaseException.php index 244d45d09894..77b170e0b407 100644 --- a/system/Database/Exceptions/DatabaseException.php +++ b/system/Database/Exceptions/DatabaseException.php @@ -16,7 +16,7 @@ use CodeIgniter\Exceptions\HasExitCodeInterface; use CodeIgniter\Exceptions\RuntimeException; -class DatabaseException extends RuntimeException implements HasExitCodeInterface +class DatabaseException extends RuntimeException implements ExceptionInterface, HasExitCodeInterface { public function getExitCode(): int { diff --git a/system/Files/Exceptions/FileException.php b/system/Files/Exceptions/FileException.php index 8634b211afa4..3202978c3af6 100644 --- a/system/Files/Exceptions/FileException.php +++ b/system/Files/Exceptions/FileException.php @@ -16,7 +16,7 @@ use CodeIgniter\Exceptions\DebugTraceableTrait; use CodeIgniter\Exceptions\RuntimeException; -class FileException extends RuntimeException +class FileException extends RuntimeException implements ExceptionInterface { use DebugTraceableTrait; diff --git a/system/Files/Exceptions/FileNotFoundException.php b/system/Files/Exceptions/FileNotFoundException.php index 46c2c1c6cfd5..4c043f9ab02c 100644 --- a/system/Files/Exceptions/FileNotFoundException.php +++ b/system/Files/Exceptions/FileNotFoundException.php @@ -16,7 +16,7 @@ use CodeIgniter\Exceptions\DebugTraceableTrait; use CodeIgniter\Exceptions\RuntimeException; -class FileNotFoundException extends RuntimeException +class FileNotFoundException extends RuntimeException implements ExceptionInterface { use DebugTraceableTrait; diff --git a/system/HTTP/Exceptions/HTTPException.php b/system/HTTP/Exceptions/HTTPException.php index 946af3d9fb15..146a565b8c77 100644 --- a/system/HTTP/Exceptions/HTTPException.php +++ b/system/HTTP/Exceptions/HTTPException.php @@ -18,7 +18,7 @@ /** * Things that can go wrong with HTTP */ -class HTTPException extends FrameworkException +class HTTPException extends FrameworkException implements ExceptionInterface { /** * For CurlRequest diff --git a/system/HTTP/Exceptions/RedirectException.php b/system/HTTP/Exceptions/RedirectException.php index a13bc933a095..0ee895fbb688 100644 --- a/system/HTTP/Exceptions/RedirectException.php +++ b/system/HTTP/Exceptions/RedirectException.php @@ -24,7 +24,7 @@ /** * RedirectException */ -class RedirectException extends RuntimeException implements ResponsableInterface, HTTPExceptionInterface +class RedirectException extends RuntimeException implements ExceptionInterface, ResponsableInterface, HTTPExceptionInterface { /** * HTTP status code for redirects diff --git a/system/Router/Exceptions/MethodNotFoundException.php b/system/Router/Exceptions/MethodNotFoundException.php index 19e62eb02c6d..2dabad79b6a1 100644 --- a/system/Router/Exceptions/MethodNotFoundException.php +++ b/system/Router/Exceptions/MethodNotFoundException.php @@ -18,6 +18,6 @@ /** * @internal */ -final class MethodNotFoundException extends RuntimeException +final class MethodNotFoundException extends RuntimeException implements ExceptionInterface { } diff --git a/system/Router/Exceptions/RouterException.php b/system/Router/Exceptions/RouterException.php index fe21b53d32b7..378647289a72 100644 --- a/system/Router/Exceptions/RouterException.php +++ b/system/Router/Exceptions/RouterException.php @@ -18,7 +18,7 @@ /** * RouterException */ -class RouterException extends FrameworkException +class RouterException extends FrameworkException implements ExceptionInterface { /** * Thrown when the actual parameter type does not match From fa0fea5610e9113ad020bdb3ce3cc6738be0eec8 Mon Sep 17 00:00:00 2001 From: kenjis Date: Mon, 29 Jan 2024 14:57:02 +0900 Subject: [PATCH 21/32] refactor: use CodeIgniter\Exceptions\InvalidArgumentException --- system/Helpers/text_helper.php | 1 + 1 file changed, 1 insertion(+) diff --git a/system/Helpers/text_helper.php b/system/Helpers/text_helper.php index 7f5fb2cf2d3f..8ce3677b0eee 100755 --- a/system/Helpers/text_helper.php +++ b/system/Helpers/text_helper.php @@ -11,6 +11,7 @@ * the LICENSE file that was distributed with this source code. */ +use CodeIgniter\Exceptions\InvalidArgumentException; use Config\ForeignCharacters; // CodeIgniter Text Helpers From 8e75308f86373b22c9f5b9c061a4fc705f775c8b Mon Sep 17 00:00:00 2001 From: kenjis Date: Mon, 29 Jan 2024 15:00:02 +0900 Subject: [PATCH 22/32] test: use odeIgniter\Exceptions\RuntimeException --- system/HTTP/Files/UploadedFile.php | 2 -- tests/_support/Autoloader/FatalLocator.php | 2 +- tests/_support/Commands/AppInfo.php | 2 +- tests/_support/Config/Services.php | 2 +- tests/_support/Controllers/Popcorn.php | 2 +- tests/system/Autoloader/AutoloaderTest.php | 2 +- tests/system/CLI/CLITest.php | 2 +- tests/system/CommonFunctionsTest.php | 2 +- tests/system/CommonHelperTest.php | 2 +- tests/system/Config/BaseConfigTest.php | 2 +- tests/system/Config/ServicesTest.php | 2 +- tests/system/Database/Live/ForgeTest.php | 2 +- tests/system/Debug/ExceptionHandlerTest.php | 2 +- tests/system/Debug/ExceptionsTest.php | 2 +- tests/system/Debug/TimerTest.php | 2 +- tests/system/Format/JSONFormatterTest.php | 2 +- tests/system/View/ViewTest.php | 2 +- 17 files changed, 16 insertions(+), 18 deletions(-) diff --git a/system/HTTP/Files/UploadedFile.php b/system/HTTP/Files/UploadedFile.php index fe19f0df0527..78643aa7166e 100644 --- a/system/HTTP/Files/UploadedFile.php +++ b/system/HTTP/Files/UploadedFile.php @@ -13,8 +13,6 @@ namespace CodeIgniter\HTTP\Files; -use CodeIgniter\Exceptions\InvalidArgumentException; -use CodeIgniter\Exceptions\RuntimeException; use CodeIgniter\Files\File; use CodeIgniter\HTTP\Exceptions\HTTPException; use Config\Mimes; diff --git a/tests/_support/Autoloader/FatalLocator.php b/tests/_support/Autoloader/FatalLocator.php index 578bd02ad9ae..0b98fddc6eca 100644 --- a/tests/_support/Autoloader/FatalLocator.php +++ b/tests/_support/Autoloader/FatalLocator.php @@ -14,7 +14,7 @@ namespace Tests\Support\Autoloader; use CodeIgniter\Autoloader\FileLocator; -use RuntimeException; +use CodeIgniter\Exceptions\RuntimeException; /** * Class FatalLocator diff --git a/tests/_support/Commands/AppInfo.php b/tests/_support/Commands/AppInfo.php index ae609514ad54..767523071466 100644 --- a/tests/_support/Commands/AppInfo.php +++ b/tests/_support/Commands/AppInfo.php @@ -16,7 +16,7 @@ use CodeIgniter\CLI\BaseCommand; use CodeIgniter\CLI\CLI; use CodeIgniter\CodeIgniter; -use RuntimeException; +use CodeIgniter\Exceptions\RuntimeException; class AppInfo extends BaseCommand { diff --git a/tests/_support/Config/Services.php b/tests/_support/Config/Services.php index 809fd9bad173..712c79004a0b 100644 --- a/tests/_support/Config/Services.php +++ b/tests/_support/Config/Services.php @@ -13,11 +13,11 @@ namespace Tests\Support\Config; +use CodeIgniter\Exceptions\RuntimeException; use CodeIgniter\HTTP\SiteURIFactory; use CodeIgniter\HTTP\URI; use Config\App; use Config\Services as BaseServices; -use RuntimeException; /** * Services Class diff --git a/tests/_support/Controllers/Popcorn.php b/tests/_support/Controllers/Popcorn.php index 2223a3c3108a..f736f0dcc50f 100644 --- a/tests/_support/Controllers/Popcorn.php +++ b/tests/_support/Controllers/Popcorn.php @@ -15,7 +15,7 @@ use CodeIgniter\API\ResponseTrait; use CodeIgniter\Controller; -use RuntimeException; +use CodeIgniter\Exceptions\RuntimeException; /** * This is a testing only controller, intended to blow up in multiple diff --git a/tests/system/Autoloader/AutoloaderTest.php b/tests/system/Autoloader/AutoloaderTest.php index 647b041d5f78..094b4cfd6b38 100644 --- a/tests/system/Autoloader/AutoloaderTest.php +++ b/tests/system/Autoloader/AutoloaderTest.php @@ -16,6 +16,7 @@ use App\Controllers\Home; use Closure; use CodeIgniter\Exceptions\ConfigException; +use CodeIgniter\Exceptions\RuntimeException; use CodeIgniter\Test\CIUnitTestCase; use CodeIgniter\Test\ReflectionHelper; use Config\Autoload; @@ -25,7 +26,6 @@ use PHPUnit\Framework\Attributes\Group; use PHPUnit\Framework\Attributes\PreserveGlobalState; use PHPUnit\Framework\Attributes\RunInSeparateProcess; -use RuntimeException; use UnnamespacedClass; /** diff --git a/tests/system/CLI/CLITest.php b/tests/system/CLI/CLITest.php index fc62e5888e53..80a55ade45cf 100644 --- a/tests/system/CLI/CLITest.php +++ b/tests/system/CLI/CLITest.php @@ -13,13 +13,13 @@ namespace CodeIgniter\CLI; +use CodeIgniter\Exceptions\RuntimeException; use CodeIgniter\Test\CIUnitTestCase; use CodeIgniter\Test\PhpStreamWrapper; use CodeIgniter\Test\StreamFilterTrait; use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\Attributes\Group; use ReflectionProperty; -use RuntimeException; /** * @internal diff --git a/tests/system/CommonFunctionsTest.php b/tests/system/CommonFunctionsTest.php index 226f9f79c776..fbf3f3fe9ab2 100644 --- a/tests/system/CommonFunctionsTest.php +++ b/tests/system/CommonFunctionsTest.php @@ -15,6 +15,7 @@ use CodeIgniter\Config\BaseService; use CodeIgniter\Config\Factories; +use CodeIgniter\Exceptions\RuntimeException; use CodeIgniter\HTTP\CLIRequest; use CodeIgniter\HTTP\Exceptions\RedirectException; use CodeIgniter\HTTP\IncomingRequest; @@ -46,7 +47,6 @@ use PHPUnit\Framework\Attributes\Group; use PHPUnit\Framework\Attributes\PreserveGlobalState; use PHPUnit\Framework\Attributes\RunInSeparateProcess; -use RuntimeException; use stdClass; use Tests\Support\Models\JobModel; diff --git a/tests/system/CommonHelperTest.php b/tests/system/CommonHelperTest.php index 819b5c582d4c..0f91f1088073 100644 --- a/tests/system/CommonHelperTest.php +++ b/tests/system/CommonHelperTest.php @@ -14,12 +14,12 @@ namespace CodeIgniter; use CodeIgniter\Autoloader\FileLocator; +use CodeIgniter\Exceptions\RuntimeException; use CodeIgniter\Test\CIUnitTestCase; use Config\Services; use PHPUnit\Framework\Attributes\CoversFunction; use PHPUnit\Framework\Attributes\Group; use PHPUnit\Framework\MockObject\MockObject; -use RuntimeException; use Tests\Support\Autoloader\FatalLocator; /** diff --git a/tests/system/Config/BaseConfigTest.php b/tests/system/Config/BaseConfigTest.php index 68776b671fda..8a169801b32f 100644 --- a/tests/system/Config/BaseConfigTest.php +++ b/tests/system/Config/BaseConfigTest.php @@ -14,6 +14,7 @@ namespace CodeIgniter\Config; use CodeIgniter\Autoloader\FileLocator; +use CodeIgniter\Exceptions\RuntimeException; use CodeIgniter\Test\CIUnitTestCase; use Config\Modules; use Encryption; @@ -22,7 +23,6 @@ use PHPUnit\Framework\Attributes\RunInSeparateProcess; use PHPUnit\Framework\MockObject\MockObject; use RegistrarConfig; -use RuntimeException; use SimpleConfig; use Tests\Support\Config\BadRegistrar; use Tests\Support\Config\TestRegistrar; diff --git a/tests/system/Config/ServicesTest.php b/tests/system/Config/ServicesTest.php index 17b97dd2e259..5ab4026a5c92 100644 --- a/tests/system/Config/ServicesTest.php +++ b/tests/system/Config/ServicesTest.php @@ -20,6 +20,7 @@ use CodeIgniter\Debug\Timer; use CodeIgniter\Debug\Toolbar; use CodeIgniter\Email\Email; +use CodeIgniter\Exceptions\RuntimeException; use CodeIgniter\Filters\Filters; use CodeIgniter\Format\Format; use CodeIgniter\Honeypot\Honeypot; @@ -49,7 +50,6 @@ use PHPUnit\Framework\Attributes\Group; use PHPUnit\Framework\Attributes\PreserveGlobalState; use PHPUnit\Framework\Attributes\RunInSeparateProcess; -use RuntimeException; use Tests\Support\Config\Services; /** diff --git a/tests/system/Database/Live/ForgeTest.php b/tests/system/Database/Live/ForgeTest.php index 7fccd6b1d298..aa415a9d72a5 100644 --- a/tests/system/Database/Live/ForgeTest.php +++ b/tests/system/Database/Live/ForgeTest.php @@ -15,12 +15,12 @@ use CodeIgniter\Database\Exceptions\DatabaseException; use CodeIgniter\Database\Forge; +use CodeIgniter\Exceptions\RuntimeException; use CodeIgniter\Test\CIUnitTestCase; use CodeIgniter\Test\DatabaseTestTrait; use Config\Database; use LogicException; use PHPUnit\Framework\Attributes\Group; -use RuntimeException; use stdClass; use Tests\Support\Database\Seeds\CITestSeeder; diff --git a/tests/system/Debug/ExceptionHandlerTest.php b/tests/system/Debug/ExceptionHandlerTest.php index 85eaed74621b..0d6ba9499ec3 100644 --- a/tests/system/Debug/ExceptionHandlerTest.php +++ b/tests/system/Debug/ExceptionHandlerTest.php @@ -15,13 +15,13 @@ use App\Controllers\Home; use CodeIgniter\Exceptions\PageNotFoundException; +use CodeIgniter\Exceptions\RuntimeException; use CodeIgniter\Test\CIUnitTestCase; use CodeIgniter\Test\IniTestTrait; use CodeIgniter\Test\StreamFilterTrait; use Config\Exceptions as ExceptionsConfig; use Config\Services; use PHPUnit\Framework\Attributes\Group; -use RuntimeException; /** * @internal diff --git a/tests/system/Debug/ExceptionsTest.php b/tests/system/Debug/ExceptionsTest.php index aa3c2d8b49a6..0a760b79aa61 100644 --- a/tests/system/Debug/ExceptionsTest.php +++ b/tests/system/Debug/ExceptionsTest.php @@ -16,13 +16,13 @@ use CodeIgniter\Entity\Exceptions\CastException; use CodeIgniter\Exceptions\ConfigException; use CodeIgniter\Exceptions\PageNotFoundException; +use CodeIgniter\Exceptions\RuntimeException; use CodeIgniter\Test\CIUnitTestCase; use CodeIgniter\Test\ReflectionHelper; use Config\Exceptions as ExceptionsConfig; use ErrorException; use PHPUnit\Framework\Attributes\Group; use PHPUnit\Framework\Attributes\RequiresPhp; -use RuntimeException; /** * @internal diff --git a/tests/system/Debug/TimerTest.php b/tests/system/Debug/TimerTest.php index eb3cb243b398..d76e35583305 100644 --- a/tests/system/Debug/TimerTest.php +++ b/tests/system/Debug/TimerTest.php @@ -14,9 +14,9 @@ namespace CodeIgniter\Debug; use ArgumentCountError; +use CodeIgniter\Exceptions\RuntimeException; use CodeIgniter\Test\CIUnitTestCase; use PHPUnit\Framework\Attributes\Group; -use RuntimeException; /** * @internal diff --git a/tests/system/Format/JSONFormatterTest.php b/tests/system/Format/JSONFormatterTest.php index a479be9e8f63..7ac97091a4c7 100644 --- a/tests/system/Format/JSONFormatterTest.php +++ b/tests/system/Format/JSONFormatterTest.php @@ -13,9 +13,9 @@ namespace CodeIgniter\Format; +use CodeIgniter\Exceptions\RuntimeException; use CodeIgniter\Test\CIUnitTestCase; use PHPUnit\Framework\Attributes\Group; -use RuntimeException; /** * @internal diff --git a/tests/system/View/ViewTest.php b/tests/system/View/ViewTest.php index d1455a604f1b..98ce11245a4d 100644 --- a/tests/system/View/ViewTest.php +++ b/tests/system/View/ViewTest.php @@ -15,11 +15,11 @@ use CodeIgniter\Autoloader\FileLocator; use CodeIgniter\Config\Services; +use CodeIgniter\Exceptions\RuntimeException; use CodeIgniter\Test\CIUnitTestCase; use CodeIgniter\View\Exceptions\ViewException; use Config; use PHPUnit\Framework\Attributes\Group; -use RuntimeException; /** * @internal From 8de2d7004ff8417ae7df2edb87c7a4e182df0058 Mon Sep 17 00:00:00 2001 From: kenjis Date: Mon, 29 Jan 2024 15:02:09 +0900 Subject: [PATCH 23/32] test: use CodeIgniter\Exceptions\InvalidArgumentException --- tests/system/AutoReview/ComposerJsonTest.php | 2 +- tests/system/Autoloader/AutoloaderTest.php | 2 +- tests/system/Config/FactoriesTest.php | 2 +- tests/system/Database/Builder/InsertTest.php | 2 +- tests/system/HTTP/IncomingRequestTest.php | 2 +- tests/system/HTTP/MessageTest.php | 2 +- tests/system/Helpers/Array/ArrayHelperDotKeyExistsTest.php | 2 +- tests/system/Helpers/TextHelperTest.php | 2 +- tests/system/Helpers/URLHelper/MiscUrlTest.php | 2 +- tests/system/Models/UpdateModelTest.php | 2 +- tests/system/Validation/FileRulesTest.php | 2 +- .../system/Validation/StrictRules/DatabaseRelatedRulesTest.php | 2 +- tests/system/Validation/StrictRules/FileRulesTest.php | 2 +- 13 files changed, 13 insertions(+), 13 deletions(-) diff --git a/tests/system/AutoReview/ComposerJsonTest.php b/tests/system/AutoReview/ComposerJsonTest.php index 995ef99f4f2b..e7ca88f688c2 100644 --- a/tests/system/AutoReview/ComposerJsonTest.php +++ b/tests/system/AutoReview/ComposerJsonTest.php @@ -13,7 +13,7 @@ namespace CodeIgniter\AutoReview; -use InvalidArgumentException; +use CodeIgniter\Exceptions\InvalidArgumentException; use JsonException; use PHPUnit\Framework\Attributes\CoversNothing; use PHPUnit\Framework\Attributes\Group; diff --git a/tests/system/Autoloader/AutoloaderTest.php b/tests/system/Autoloader/AutoloaderTest.php index 094b4cfd6b38..b0dab8d8d841 100644 --- a/tests/system/Autoloader/AutoloaderTest.php +++ b/tests/system/Autoloader/AutoloaderTest.php @@ -16,13 +16,13 @@ use App\Controllers\Home; use Closure; use CodeIgniter\Exceptions\ConfigException; +use CodeIgniter\Exceptions\InvalidArgumentException; use CodeIgniter\Exceptions\RuntimeException; use CodeIgniter\Test\CIUnitTestCase; use CodeIgniter\Test\ReflectionHelper; use Config\Autoload; use Config\Modules; use Config\Services; -use InvalidArgumentException; use PHPUnit\Framework\Attributes\Group; use PHPUnit\Framework\Attributes\PreserveGlobalState; use PHPUnit\Framework\Attributes\RunInSeparateProcess; diff --git a/tests/system/Config/FactoriesTest.php b/tests/system/Config/FactoriesTest.php index 11a5e77a433e..4bebc304f4fa 100644 --- a/tests/system/Config/FactoriesTest.php +++ b/tests/system/Config/FactoriesTest.php @@ -13,10 +13,10 @@ namespace CodeIgniter\Config; +use CodeIgniter\Exceptions\InvalidArgumentException; use CodeIgniter\Test\CIUnitTestCase; use Config\App; use Config\Database; -use InvalidArgumentException; use PHPUnit\Framework\Attributes\Depends; use PHPUnit\Framework\Attributes\Group; use ReflectionClass; diff --git a/tests/system/Database/Builder/InsertTest.php b/tests/system/Database/Builder/InsertTest.php index e021472b72fc..ca778a098408 100644 --- a/tests/system/Database/Builder/InsertTest.php +++ b/tests/system/Database/Builder/InsertTest.php @@ -16,9 +16,9 @@ use CodeIgniter\Database\Exceptions\DatabaseException; use CodeIgniter\Database\Query; use CodeIgniter\Database\RawSql; +use CodeIgniter\Exceptions\InvalidArgumentException; use CodeIgniter\Test\CIUnitTestCase; use CodeIgniter\Test\Mock\MockConnection; -use InvalidArgumentException; use PHPUnit\Framework\Attributes\Group; /** diff --git a/tests/system/HTTP/IncomingRequestTest.php b/tests/system/HTTP/IncomingRequestTest.php index eb15b2c37c91..2bbe52897eb5 100644 --- a/tests/system/HTTP/IncomingRequestTest.php +++ b/tests/system/HTTP/IncomingRequestTest.php @@ -15,11 +15,11 @@ use CodeIgniter\Config\Factories; use CodeIgniter\Exceptions\ConfigException; +use CodeIgniter\Exceptions\InvalidArgumentException; use CodeIgniter\HTTP\Exceptions\HTTPException; use CodeIgniter\HTTP\Files\UploadedFile; use CodeIgniter\Test\CIUnitTestCase; use Config\App; -use InvalidArgumentException; use JsonException; use PHPUnit\Framework\Attributes\BackupGlobals; use PHPUnit\Framework\Attributes\DataProvider; diff --git a/tests/system/HTTP/MessageTest.php b/tests/system/HTTP/MessageTest.php index d16224367a6f..79bfb2dcdf6f 100644 --- a/tests/system/HTTP/MessageTest.php +++ b/tests/system/HTTP/MessageTest.php @@ -13,9 +13,9 @@ namespace CodeIgniter\HTTP; +use CodeIgniter\Exceptions\InvalidArgumentException; use CodeIgniter\HTTP\Exceptions\HTTPException; use CodeIgniter\Test\CIUnitTestCase; -use InvalidArgumentException; use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\Attributes\Group; diff --git a/tests/system/Helpers/Array/ArrayHelperDotKeyExistsTest.php b/tests/system/Helpers/Array/ArrayHelperDotKeyExistsTest.php index ea7b379d0b44..0641c41b2bd0 100644 --- a/tests/system/Helpers/Array/ArrayHelperDotKeyExistsTest.php +++ b/tests/system/Helpers/Array/ArrayHelperDotKeyExistsTest.php @@ -13,8 +13,8 @@ namespace CodeIgniter\Helpers\Array; +use CodeIgniter\Exceptions\InvalidArgumentException; use CodeIgniter\Test\CIUnitTestCase; -use InvalidArgumentException; use PHPUnit\Framework\Attributes\Group; /** diff --git a/tests/system/Helpers/TextHelperTest.php b/tests/system/Helpers/TextHelperTest.php index e3acd7bb9c50..4033e3c72e1a 100755 --- a/tests/system/Helpers/TextHelperTest.php +++ b/tests/system/Helpers/TextHelperTest.php @@ -13,8 +13,8 @@ namespace CodeIgniter\Helpers; +use CodeIgniter\Exceptions\InvalidArgumentException; use CodeIgniter\Test\CIUnitTestCase; -use InvalidArgumentException; use PHPUnit\Framework\Attributes\Group; /** diff --git a/tests/system/Helpers/URLHelper/MiscUrlTest.php b/tests/system/Helpers/URLHelper/MiscUrlTest.php index 87c6a3940208..da25199bf957 100644 --- a/tests/system/Helpers/URLHelper/MiscUrlTest.php +++ b/tests/system/Helpers/URLHelper/MiscUrlTest.php @@ -15,6 +15,7 @@ use CodeIgniter\Config\Factories; use CodeIgniter\Config\Services; +use CodeIgniter\Exceptions\InvalidArgumentException; use CodeIgniter\HTTP\IncomingRequest; use CodeIgniter\HTTP\SiteURIFactory; use CodeIgniter\HTTP\UserAgent; @@ -22,7 +23,6 @@ use CodeIgniter\Superglobals; use CodeIgniter\Test\CIUnitTestCase; use Config\App; -use InvalidArgumentException; use PHPUnit\Framework\Attributes\BackupGlobals; use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\Attributes\Group; diff --git a/tests/system/Models/UpdateModelTest.php b/tests/system/Models/UpdateModelTest.php index c7c8b9ad51d4..2f9cac3958df 100644 --- a/tests/system/Models/UpdateModelTest.php +++ b/tests/system/Models/UpdateModelTest.php @@ -16,8 +16,8 @@ use CodeIgniter\Database\Exceptions\DatabaseException; use CodeIgniter\Database\Exceptions\DataException; use CodeIgniter\Entity\Entity; +use CodeIgniter\Exceptions\InvalidArgumentException; use Config\Database; -use InvalidArgumentException; use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\Attributes\Group; use stdClass; diff --git a/tests/system/Validation/FileRulesTest.php b/tests/system/Validation/FileRulesTest.php index 6d59af537a06..ec016ee0dbeb 100644 --- a/tests/system/Validation/FileRulesTest.php +++ b/tests/system/Validation/FileRulesTest.php @@ -13,9 +13,9 @@ namespace CodeIgniter\Validation; +use CodeIgniter\Exceptions\InvalidArgumentException; use CodeIgniter\Test\CIUnitTestCase; use Config\Services; -use InvalidArgumentException; use PHPUnit\Framework\Attributes\Group; use Tests\Support\Validation\TestRules; diff --git a/tests/system/Validation/StrictRules/DatabaseRelatedRulesTest.php b/tests/system/Validation/StrictRules/DatabaseRelatedRulesTest.php index 1535d265f729..5f8472ec29f0 100644 --- a/tests/system/Validation/StrictRules/DatabaseRelatedRulesTest.php +++ b/tests/system/Validation/StrictRules/DatabaseRelatedRulesTest.php @@ -13,12 +13,12 @@ namespace CodeIgniter\Validation\StrictRules; +use CodeIgniter\Exceptions\InvalidArgumentException; use CodeIgniter\Test\CIUnitTestCase; use CodeIgniter\Test\DatabaseTestTrait; use CodeIgniter\Validation\Validation; use Config\Database; use Config\Services; -use InvalidArgumentException; use LogicException; use PHPUnit\Framework\Attributes\Group; use Tests\Support\Validation\TestRules; diff --git a/tests/system/Validation/StrictRules/FileRulesTest.php b/tests/system/Validation/StrictRules/FileRulesTest.php index 07dfc44ad8ce..ab31b5cff06b 100644 --- a/tests/system/Validation/StrictRules/FileRulesTest.php +++ b/tests/system/Validation/StrictRules/FileRulesTest.php @@ -13,10 +13,10 @@ namespace CodeIgniter\Validation\StrictRules; +use CodeIgniter\Exceptions\InvalidArgumentException; use CodeIgniter\Test\CIUnitTestCase; use CodeIgniter\Validation\Validation; use Config\Services; -use InvalidArgumentException; use PHPUnit\Framework\Attributes\Group; use Tests\Support\Validation\TestRules; From 29b8597bf7c87959771d43b4efaeb861b069cb33 Mon Sep 17 00:00:00 2001 From: kenjis Date: Mon, 29 Jan 2024 15:03:11 +0900 Subject: [PATCH 24/32] test: use CodeIgniter\Exceptions\LogicException --- tests/system/Cookie/CookieTest.php | 2 +- tests/system/Database/Live/ForgeTest.php | 2 +- tests/system/HTTP/RedirectExceptionTest.php | 2 +- tests/system/View/ControlledCellTest.php | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/system/Cookie/CookieTest.php b/tests/system/Cookie/CookieTest.php index 51016ca0061e..444812c31485 100644 --- a/tests/system/Cookie/CookieTest.php +++ b/tests/system/Cookie/CookieTest.php @@ -14,11 +14,11 @@ namespace CodeIgniter\Cookie; use CodeIgniter\Cookie\Exceptions\CookieException; +use CodeIgniter\Exceptions\LogicException; use CodeIgniter\Test\CIUnitTestCase; use Config\Cookie as CookieConfig; use DateTimeImmutable; use DateTimeZone; -use LogicException; use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\Attributes\Group; diff --git a/tests/system/Database/Live/ForgeTest.php b/tests/system/Database/Live/ForgeTest.php index aa415a9d72a5..53c6a2144819 100644 --- a/tests/system/Database/Live/ForgeTest.php +++ b/tests/system/Database/Live/ForgeTest.php @@ -15,11 +15,11 @@ use CodeIgniter\Database\Exceptions\DatabaseException; use CodeIgniter\Database\Forge; +use CodeIgniter\Exceptions\LogicException; use CodeIgniter\Exceptions\RuntimeException; use CodeIgniter\Test\CIUnitTestCase; use CodeIgniter\Test\DatabaseTestTrait; use Config\Database; -use LogicException; use PHPUnit\Framework\Attributes\Group; use stdClass; use Tests\Support\Database\Seeds\CITestSeeder; diff --git a/tests/system/HTTP/RedirectExceptionTest.php b/tests/system/HTTP/RedirectExceptionTest.php index e77c0ea060d3..b1f325199cc6 100644 --- a/tests/system/HTTP/RedirectExceptionTest.php +++ b/tests/system/HTTP/RedirectExceptionTest.php @@ -13,12 +13,12 @@ namespace CodeIgniter\HTTP; +use CodeIgniter\Exceptions\LogicException; use CodeIgniter\HTTP\Exceptions\RedirectException; use CodeIgniter\I18n\Time; use CodeIgniter\Log\Logger; use CodeIgniter\Test\Mock\MockLogger as LoggerConfig; use Config\Services; -use LogicException; use PHPUnit\Framework\Attributes\Group; use PHPUnit\Framework\TestCase; use Tests\Support\Log\Handlers\TestHandler; diff --git a/tests/system/View/ControlledCellTest.php b/tests/system/View/ControlledCellTest.php index 8448aed22ced..96e3be2e3115 100644 --- a/tests/system/View/ControlledCellTest.php +++ b/tests/system/View/ControlledCellTest.php @@ -13,9 +13,9 @@ namespace CodeIgniter\View; +use CodeIgniter\Exceptions\LogicException; use CodeIgniter\Test\CIUnitTestCase; use CodeIgniter\View\Exceptions\ViewException; -use LogicException; use PHPUnit\Framework\Attributes\Group; use Tests\Support\View\Cells\AdditionCell; use Tests\Support\View\Cells\AwesomeCell; From aae19e6b73433fd4345561cd3216a6d9a9a75508 Mon Sep 17 00:00:00 2001 From: kenjis Date: Mon, 29 Jan 2024 15:03:58 +0900 Subject: [PATCH 25/32] test: use CodeIgniter\Exceptions\BadMethodCallException --- tests/system/Database/Live/PreparedQueryTest.php | 2 +- tests/system/HTTP/SiteURITest.php | 2 +- tests/system/Models/GeneralModelTest.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/system/Database/Live/PreparedQueryTest.php b/tests/system/Database/Live/PreparedQueryTest.php index fd3b6cedb403..b44e127283c6 100644 --- a/tests/system/Database/Live/PreparedQueryTest.php +++ b/tests/system/Database/Live/PreparedQueryTest.php @@ -13,11 +13,11 @@ namespace CodeIgniter\Database\Live; -use BadMethodCallException; use CodeIgniter\Database\BasePreparedQuery; use CodeIgniter\Database\Exceptions\DatabaseException; use CodeIgniter\Database\Query; use CodeIgniter\Database\ResultInterface; +use CodeIgniter\Exceptions\BadMethodCallException; use CodeIgniter\Test\CIUnitTestCase; use CodeIgniter\Test\DatabaseTestTrait; use PHPUnit\Framework\Attributes\Group; diff --git a/tests/system/HTTP/SiteURITest.php b/tests/system/HTTP/SiteURITest.php index 644aaa795b6d..6aca302e7cc7 100644 --- a/tests/system/HTTP/SiteURITest.php +++ b/tests/system/HTTP/SiteURITest.php @@ -13,7 +13,7 @@ namespace CodeIgniter\HTTP; -use BadMethodCallException; +use CodeIgniter\Exceptions\BadMethodCallException; use CodeIgniter\Exceptions\ConfigException; use CodeIgniter\HTTP\Exceptions\HTTPException; use CodeIgniter\Test\CIUnitTestCase; diff --git a/tests/system/Models/GeneralModelTest.php b/tests/system/Models/GeneralModelTest.php index d0e50768457a..c0d3d806dbdd 100644 --- a/tests/system/Models/GeneralModelTest.php +++ b/tests/system/Models/GeneralModelTest.php @@ -13,8 +13,8 @@ namespace CodeIgniter\Models; -use BadMethodCallException; use CodeIgniter\Database\BaseConnection; +use CodeIgniter\Exceptions\BadMethodCallException; use CodeIgniter\Model; use CodeIgniter\Test\CIUnitTestCase; use PHPUnit\Framework\Attributes\Group; From ac9a7164486c7cd4fc0d14a1d70a294675df0328 Mon Sep 17 00:00:00 2001 From: kenjis Date: Mon, 29 Jan 2024 15:04:45 +0900 Subject: [PATCH 26/32] test: use narrower exceptions --- .../system/Cache/Handlers/MemcachedHandlerTest.php | 3 ++- tests/system/Cache/ResponseCacheTest.php | 4 ++-- tests/system/Log/LoggerTest.php | 6 +++--- tests/system/Test/ControllerTestTraitTest.php | 13 ++++++++----- 4 files changed, 15 insertions(+), 11 deletions(-) diff --git a/tests/system/Cache/Handlers/MemcachedHandlerTest.php b/tests/system/Cache/Handlers/MemcachedHandlerTest.php index 4aad8288401c..2e3c69895d21 100644 --- a/tests/system/Cache/Handlers/MemcachedHandlerTest.php +++ b/tests/system/Cache/Handlers/MemcachedHandlerTest.php @@ -14,6 +14,7 @@ namespace CodeIgniter\Cache\Handlers; use CodeIgniter\CLI\CLI; +use CodeIgniter\Exceptions\BadMethodCallException; use CodeIgniter\I18n\Time; use Config\Cache; use Exception; @@ -125,7 +126,7 @@ public function testDelete(): void public function testDeleteMatching(): void { // Not implemented for Memcached, should throw an exception - $this->expectException(Exception::class); + $this->expectException(BadMethodCallException::class); $this->handler->deleteMatching('key*'); } diff --git a/tests/system/Cache/ResponseCacheTest.php b/tests/system/Cache/ResponseCacheTest.php index b0b73855231a..4888c78bfbcb 100644 --- a/tests/system/Cache/ResponseCacheTest.php +++ b/tests/system/Cache/ResponseCacheTest.php @@ -13,6 +13,7 @@ namespace CodeIgniter\Cache; +use CodeIgniter\Exceptions\RuntimeException; use CodeIgniter\HTTP\CLIRequest; use CodeIgniter\HTTP\IncomingRequest; use CodeIgniter\HTTP\Response; @@ -23,7 +24,6 @@ use Config\App as AppConfig; use Config\Cache as CacheConfig; use ErrorException; -use Exception; use PHPUnit\Framework\Attributes\BackupGlobals; use PHPUnit\Framework\Attributes\Group; @@ -245,7 +245,7 @@ public function testUnserializeError(): void public function testInvalidCacheError(): void { - $this->expectException(Exception::class); + $this->expectException(RuntimeException::class); $this->expectExceptionMessage('Error unserializing page cache'); $cache = mock(CacheFactory::class); diff --git a/tests/system/Log/LoggerTest.php b/tests/system/Log/LoggerTest.php index 9464d4d286fd..09efa7be4a1d 100644 --- a/tests/system/Log/LoggerTest.php +++ b/tests/system/Log/LoggerTest.php @@ -14,11 +14,11 @@ namespace CodeIgniter\Log; use CodeIgniter\Exceptions\FrameworkException; +use CodeIgniter\Exceptions\RuntimeException; use CodeIgniter\I18n\Time; use CodeIgniter\Log\Exceptions\LogException; use CodeIgniter\Test\CIUnitTestCase; use CodeIgniter\Test\Mock\MockLogger as LoggerConfig; -use Exception; use PHPUnit\Framework\Attributes\Group; use Tests\Support\Log\Handlers\TestHandler; use TypeError; @@ -241,8 +241,8 @@ public function testLogInterpolatesExceptions(): void $expected = 'ERROR - ' . Time::now()->format('Y-m-d') . ' --> [ERROR] These are not the droids you are looking for'; try { - throw new Exception('These are not the droids you are looking for'); - } catch (Exception $e) { + throw new RuntimeException('These are not the droids you are looking for'); + } catch (RuntimeException $e) { $logger->log('error', '[ERROR] {exception}', ['exception' => $e]); } diff --git a/tests/system/Test/ControllerTestTraitTest.php b/tests/system/Test/ControllerTestTraitTest.php index 8230dd9d6248..43fdf7a23b23 100644 --- a/tests/system/Test/ControllerTestTraitTest.php +++ b/tests/system/Test/ControllerTestTraitTest.php @@ -16,11 +16,12 @@ use App\Controllers\Home; use App\Controllers\NeverHeardOfIt; use CodeIgniter\Controller; +use CodeIgniter\Exceptions\InvalidArgumentException; +use CodeIgniter\Exceptions\RuntimeException; use CodeIgniter\Log\Logger; use CodeIgniter\Test\Mock\MockLogger as LoggerConfig; use Config\App; use Config\Services; -use Exception; use PHPUnit\Framework\Attributes\Group; use PHPUnit\Framework\Attributes\PreserveGlobalState; use PHPUnit\Framework\Attributes\RunTestsInSeparateProcesses; @@ -50,7 +51,8 @@ protected function setUp(): void public function testBadController(): void { - $this->expectException('InvalidArgumentException'); + $this->expectException(InvalidArgumentException::class); + $logger = new Logger(new LoggerConfig()); $this->withURI('http://example.com') ->withLogger($logger) @@ -60,7 +62,8 @@ public function testBadController(): void public function testBadControllerMethod(): void { - $this->expectException('InvalidArgumentException'); + $this->expectException(InvalidArgumentException::class); + $logger = new Logger(new LoggerConfig()); $this->withURI('http://example.com') ->withLogger($logger) @@ -261,12 +264,12 @@ public function testUsesRequestBody(): void $this->controller = new class () extends Controller { public function throwsBody(): never { - throw new Exception($this->request->getBody()); + throw new RuntimeException($this->request->getBody()); } }; $this->controller->initController($this->request, $this->response, $this->logger); - $this->expectException(Exception::class); + $this->expectException(RuntimeException::class); $this->expectExceptionMessage('banana'); $this->withBody('banana')->execute('throwsBody'); From afe99687a8291b1bda90321ff181a134a37fe8bf Mon Sep 17 00:00:00 2001 From: kenjis Date: Mon, 29 Jan 2024 16:07:56 +0900 Subject: [PATCH 27/32] refactor: use CodeIgniter\Exceptions\InvalidArgumentException --- system/Common.php | 1 + system/Helpers/filesystem_helper.php | 2 ++ 2 files changed, 3 insertions(+) diff --git a/system/Common.php b/system/Common.php index f96e9f100f00..96f9d5bb756f 100644 --- a/system/Common.php +++ b/system/Common.php @@ -20,6 +20,7 @@ use CodeIgniter\Database\BaseConnection; use CodeIgniter\Database\ConnectionInterface; use CodeIgniter\Debug\Timer; +use CodeIgniter\Exceptions\InvalidArgumentException; use CodeIgniter\Files\Exceptions\FileNotFoundException; use CodeIgniter\HTTP\CLIRequest; use CodeIgniter\HTTP\Exceptions\HTTPException; diff --git a/system/Helpers/filesystem_helper.php b/system/Helpers/filesystem_helper.php index 2b86654c960e..1ffabc34b056 100644 --- a/system/Helpers/filesystem_helper.php +++ b/system/Helpers/filesystem_helper.php @@ -11,6 +11,8 @@ * the LICENSE file that was distributed with this source code. */ +use CodeIgniter\Exceptions\InvalidArgumentException; + // CodeIgniter File System Helpers if (! function_exists('directory_map')) { From 55128157b6f561597765eadd527c9b169025f481 Mon Sep 17 00:00:00 2001 From: kenjis Date: Mon, 29 Jan 2024 16:08:24 +0900 Subject: [PATCH 28/32] refactor: use CodeIgniter\Exceptions\RuntimeException --- system/Common.php | 1 + 1 file changed, 1 insertion(+) diff --git a/system/Common.php b/system/Common.php index 96f9d5bb756f..56cbe0cd5233 100644 --- a/system/Common.php +++ b/system/Common.php @@ -21,6 +21,7 @@ use CodeIgniter\Database\ConnectionInterface; use CodeIgniter\Debug\Timer; use CodeIgniter\Exceptions\InvalidArgumentException; +use CodeIgniter\Exceptions\RuntimeException; use CodeIgniter\Files\Exceptions\FileNotFoundException; use CodeIgniter\HTTP\CLIRequest; use CodeIgniter\HTTP\Exceptions\HTTPException; From 99e2ba3ccaa3a815b3150c2af0e3d9811808123b Mon Sep 17 00:00:00 2001 From: kenjis Date: Tue, 16 Apr 2024 11:46:45 +0900 Subject: [PATCH 29/32] refactor: use CodeIgniter\Exceptions\RuntimeException --- system/Commands/Utilities/Optimize.php | 2 +- system/HTTP/Exceptions/BadRequestException.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/system/Commands/Utilities/Optimize.php b/system/Commands/Utilities/Optimize.php index fa7612d524a6..46b24efb2da9 100644 --- a/system/Commands/Utilities/Optimize.php +++ b/system/Commands/Utilities/Optimize.php @@ -17,8 +17,8 @@ use CodeIgniter\Autoloader\FileLocatorCached; use CodeIgniter\CLI\BaseCommand; use CodeIgniter\CLI\CLI; +use CodeIgniter\Exceptions\RuntimeException; use CodeIgniter\Publisher\Publisher; -use RuntimeException; /** * Optimize for production. diff --git a/system/HTTP/Exceptions/BadRequestException.php b/system/HTTP/Exceptions/BadRequestException.php index c87f4de294e2..35933dcc1f5c 100644 --- a/system/HTTP/Exceptions/BadRequestException.php +++ b/system/HTTP/Exceptions/BadRequestException.php @@ -14,7 +14,7 @@ namespace CodeIgniter\HTTP\Exceptions; use CodeIgniter\Exceptions\HTTPExceptionInterface; -use RuntimeException; +use CodeIgniter\Exceptions\RuntimeException; /** * 400 Bad Request From 60fddfe7c31e7c41cdff0755dc9eb422834005c2 Mon Sep 17 00:00:00 2001 From: kenjis Date: Tue, 16 Apr 2024 11:47:22 +0900 Subject: [PATCH 30/32] refactor: use CodeIgniter\Exceptions\InvalidArgumentException --- system/Config/BaseService.php | 2 +- system/DataCaster/Cast/BaseCast.php | 2 +- system/DataCaster/Cast/DatetimeCast.php | 2 +- system/DataCaster/DataCaster.php | 2 +- system/Test/Fabricator.php | 5 +++-- 5 files changed, 7 insertions(+), 6 deletions(-) diff --git a/system/Config/BaseService.php b/system/Config/BaseService.php index cd770dc667ed..551261eda215 100644 --- a/system/Config/BaseService.php +++ b/system/Config/BaseService.php @@ -29,6 +29,7 @@ use CodeIgniter\Debug\Toolbar; use CodeIgniter\Email\Email; use CodeIgniter\Encryption\EncrypterInterface; +use CodeIgniter\Exceptions\InvalidArgumentException; use CodeIgniter\Filters\Filters; use CodeIgniter\Format\Format; use CodeIgniter\Honeypot\Honeypot; @@ -78,7 +79,6 @@ use Config\Toolbar as ConfigToolbar; use Config\Validation as ConfigValidation; use Config\View as ConfigView; -use InvalidArgumentException; /** * Services Configuration file. diff --git a/system/DataCaster/Cast/BaseCast.php b/system/DataCaster/Cast/BaseCast.php index c3df0efee103..2a3ca1971674 100644 --- a/system/DataCaster/Cast/BaseCast.php +++ b/system/DataCaster/Cast/BaseCast.php @@ -13,7 +13,7 @@ namespace CodeIgniter\DataCaster\Cast; -use InvalidArgumentException; +use CodeIgniter\Exceptions\InvalidArgumentException; abstract class BaseCast implements CastInterface { diff --git a/system/DataCaster/Cast/DatetimeCast.php b/system/DataCaster/Cast/DatetimeCast.php index 83e66d02217c..b6fa97f9ddda 100644 --- a/system/DataCaster/Cast/DatetimeCast.php +++ b/system/DataCaster/Cast/DatetimeCast.php @@ -14,8 +14,8 @@ namespace CodeIgniter\DataCaster\Cast; use CodeIgniter\Database\BaseConnection; +use CodeIgniter\Exceptions\InvalidArgumentException; use CodeIgniter\I18n\Time; -use InvalidArgumentException; /** * Class DatetimeCast diff --git a/system/DataCaster/DataCaster.php b/system/DataCaster/DataCaster.php index 854a0b50b32c..daeba4b0c0bc 100644 --- a/system/DataCaster/DataCaster.php +++ b/system/DataCaster/DataCaster.php @@ -26,7 +26,7 @@ use CodeIgniter\DataCaster\Cast\URICast; use CodeIgniter\Entity\Cast\CastInterface as EntityCastInterface; use CodeIgniter\Entity\Exceptions\CastException; -use InvalidArgumentException; +use CodeIgniter\Exceptions\InvalidArgumentException; final class DataCaster { diff --git a/system/Test/Fabricator.php b/system/Test/Fabricator.php index 1f61efef5c62..70f3c3adcc72 100644 --- a/system/Test/Fabricator.php +++ b/system/Test/Fabricator.php @@ -15,13 +15,14 @@ use Closure; use CodeIgniter\Exceptions\FrameworkException; +use CodeIgniter\Exceptions\InvalidArgumentException; use CodeIgniter\Exceptions\RuntimeException; use CodeIgniter\I18n\Time; use CodeIgniter\Model; use Config\App; use Faker\Factory; use Faker\Generator; -use InvalidArgumentException; +use InvalidArgumentException as BaseInvalidArgumentException; /** * Fabricator @@ -359,7 +360,7 @@ protected function guessFormatter($field): string $this->faker->getFormatter($field); return $field; - } catch (InvalidArgumentException) { + } catch (BaseInvalidArgumentException) { // No match, keep going } From f1359ddc136cead22b4b55db2162f20160c83b78 Mon Sep 17 00:00:00 2001 From: kenjis Date: Tue, 16 Apr 2024 13:44:00 +0900 Subject: [PATCH 31/32] docs: add user guide --- user_guide_src/source/changelogs/v4.6.0.rst | 64 +++++++++++++++++++ user_guide_src/source/general/errors.rst | 30 ++++++++- .../source/installation/upgrade_460.rst | 9 +++ 3 files changed, 102 insertions(+), 1 deletion(-) diff --git a/user_guide_src/source/changelogs/v4.6.0.rst b/user_guide_src/source/changelogs/v4.6.0.rst index becb1ec0688c..99d7476299f0 100644 --- a/user_guide_src/source/changelogs/v4.6.0.rst +++ b/user_guide_src/source/changelogs/v4.6.0.rst @@ -23,6 +23,26 @@ BREAKING Behavior Changes ================ +.. _v460-behavior-changes-exceptions: + +Exceptions +---------- + +The exception class has been redesigned. See :ref:`exception-design` for details. +The following breaking changes have been made accordingly: + +- ``Validation::setRule()`` now throws ``CodeIgniter\Exceptions\InvalidArgumentException`` + instead of ``TypeError``. + +- ``CriticalError`` now extends ``CodeIgniter\Exceptions\RuntimeException`` + instead of ``Error``. +- ``DatabaseException`` now extends ``CodeIgniter\Exceptions\RuntimeException`` + instead of ``Error``. +- ``ConfigException`` now extends ``CodeIgniter\Exceptions\RuntimeException`` + instead of ``CodeIgniter\Exceptions\CriticalError``. +- ``TestException`` now extends ``CodeIgniter\Exceptions\LogicException`` + instead of ``CodeIgniter\Exceptions\CriticalError``. + Interface Changes ================= @@ -46,6 +66,24 @@ Removed Deprecated Items Enhancements ************ +Exceptions +========== + +The exception class has been redesigned. See :ref:`exception-design` for details. +The following new Exception classes have been added accordingly: + +- ``CodeIgniter\Exceptions\LogicException`` +- ``CodeIgniter\Exceptions\RuntimeException`` +- ``CodeIgniter\Exceptions\BadFunctionCallException`` +- ``CodeIgniter\Exceptions\BadMethodCallException`` +- ``CodeIgniter\Exceptions\InvalidArgumentException`` + +The following new Exception interfaces have been added: + +- ``CodeIgniter\Files\Exceptions\ExceptionInterface`` +- ``CodeIgniter\HTTP\Exceptions\ExceptionInterface`` +- ``CodeIgniter\Router\Exceptions\ExceptionInterface`` + Commands ======== @@ -84,6 +122,32 @@ Message Changes Changes ******* +Exceptions +========== + +The exception classes have been redesigned. See :ref:`exception-design` for details. +The following changes have been made accordingly: + +- The ``deleteMatching()`` method in Cache Handler classes now throws + ``CodeIgniter\Exceptions\BadMethodCallException`` instead of ``Exception``. +- ``Cache\ResponseCache::get()`` now throws ``CodeIgniter\Exceptions\RuntimeException`` + instead of ``Exception``. +- Classes that threw ``RuntimeException`` have been changed to throw + ``CodeIgniter\Exceptions\RuntimeException``. +- Classes that threw ``InvalidArgumentException`` have been changed to throw + ``CodeIgniter\Exceptions\InvalidArgumentException``. +- Classes that threw ``LogicException`` have been changed to throw + ``CodeIgniter\Exceptions\LogicException``. +- Classes that threw ``BadMethodCallException`` have been changed to throw + ``CodeIgniter\Exceptions\BadMethodCallException``. +- Classes that threw ``BadFunctionCallException`` have been changed to throw + ``CodeIgniter\Exceptions\BadFunctionCallException``. + +- ``RedirectException`` now extends ``CodeIgniter\Exceptions\RuntimeException`` + instead of ``Exception``. +- ``PageNotFoundException`` now extends ``CodeIgniter\Exceptions\RuntimeException`` + instead of ``OutOfBoundsException``. + ************ Deprecations ************ diff --git a/user_guide_src/source/general/errors.rst b/user_guide_src/source/general/errors.rst index 2b6eafce8c33..3d95498a7a28 100644 --- a/user_guide_src/source/general/errors.rst +++ b/user_guide_src/source/general/errors.rst @@ -121,7 +121,35 @@ setting the environment variable ``CODEIGNITER_SCREAM_DEPRECATIONS`` to a truthy Framework Exceptions ==================== -The following framework exceptions are available: +.. _exception-design: + +Exception Design +---------------- + +Staring with v4.6.0, all Exception classes that the framework throws: + +- implement ``CodeIgniter\Exceptions\ExceptionInterface`` +- extend ``CodeIgniter\Exceptions\LogicException`` or ``CodeIgniter\Exceptions\RuntimeException`` + +.. note:: The framework only throws the above kind of exception classes, but PHP + or other libraries that are used may throw other exceptions. + +There are two base Exception classes that the framework throws: + +LogicException +-------------- + +``CodeIgniter\Exceptions\LogicException`` extends ``\LogicException``. +This exception represents error in the program logic. This kind of exception +should lead directly to a fix in your code. + +RuntimeException +---------------- + +``CodeIgniter\Exceptions\RuntimeException`` extends ``\RuntimeException``. +This exception is thrown if an error which can only be found on runtime occurs. + +The following framework exceptions are also available: PageNotFoundException --------------------- diff --git a/user_guide_src/source/installation/upgrade_460.rst b/user_guide_src/source/installation/upgrade_460.rst index 4344f7565b55..94f69a2322f9 100644 --- a/user_guide_src/source/installation/upgrade_460.rst +++ b/user_guide_src/source/installation/upgrade_460.rst @@ -20,6 +20,15 @@ Mandatory File Changes Breaking Changes **************** +Exception Changes +================= + +Some classes have changed the exception classes that are thrown. Some exception +classes have changed parent classes. +See :ref:`ChangeLog ` for details. + +If you have code that catches these exceptions, change the exception classes. + Removed Deprecated Items ======================== From e1d3516208e6ed6a58e13e8a6cae76cc8c42c388 Mon Sep 17 00:00:00 2001 From: kenjis Date: Mon, 6 May 2024 19:27:45 +0900 Subject: [PATCH 32/32] refactor: by rector --- tests/system/Cache/Handlers/MemcachedHandlerTest.php | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/system/Cache/Handlers/MemcachedHandlerTest.php b/tests/system/Cache/Handlers/MemcachedHandlerTest.php index 2e3c69895d21..991e31d1b75c 100644 --- a/tests/system/Cache/Handlers/MemcachedHandlerTest.php +++ b/tests/system/Cache/Handlers/MemcachedHandlerTest.php @@ -17,7 +17,6 @@ use CodeIgniter\Exceptions\BadMethodCallException; use CodeIgniter\I18n\Time; use Config\Cache; -use Exception; use PHPUnit\Framework\Attributes\Group; /**