diff --git a/rector.php b/rector.php index 797387ba4aba..0473a5d8cfdb 100644 --- a/rector.php +++ b/rector.php @@ -28,6 +28,7 @@ use Rector\CodingStyle\Rector\ClassMethod\MakeInheritedMethodVisibilitySameAsParentRector; use Rector\CodingStyle\Rector\FuncCall\CountArrayToEmptyArrayComparisonRector; use Rector\Config\RectorConfig; +use Rector\DeadCode\Rector\ClassMethod\RemoveUnusedConstructorParamRector; use Rector\DeadCode\Rector\ClassMethod\RemoveUnusedPrivateMethodRector; use Rector\DeadCode\Rector\If_\UnwrapFutureCompatibleIfPhpVersionRector; use Rector\DeadCode\Rector\MethodCall\RemoveEmptyMethodCallRector; @@ -89,6 +90,11 @@ __DIR__ . '/tests/system/Test/ReflectionHelperTest.php', ], + RemoveUnusedConstructorParamRector::class => [ + // there are deprecated parameters + __DIR__ . '/system/Debug/Exceptions.php', + ], + // call on purpose for nothing happen check RemoveEmptyMethodCallRector::class => [ __DIR__ . '/tests', diff --git a/system/Config/Services.php b/system/Config/Services.php index a2d13c40e80c..2358e87bb1a5 100644 --- a/system/Config/Services.php +++ b/system/Config/Services.php @@ -250,6 +250,8 @@ public static function encrypter(?EncryptionConfig $config = null, $getShared = * - register_shutdown_function * * @return Exceptions + * + * @deprecated The parameter $request and $response are deprecated. */ public static function exceptions( ?ExceptionsConfig $config = null, @@ -262,7 +264,9 @@ public static function exceptions( } $config ??= config('Exceptions'); - $request ??= AppServices::request(); + /** @var ExceptionsConfig $config */ + + // @TODO remove instantiation of Response in the future. $response ??= AppServices::response(); return new Exceptions($config, $request, $response); diff --git a/system/Debug/Exceptions.php b/system/Debug/Exceptions.php index 6dc098d4af10..d4e80f28f2e9 100644 --- a/system/Debug/Exceptions.php +++ b/system/Debug/Exceptions.php @@ -21,6 +21,7 @@ use CodeIgniter\HTTP\ResponseInterface; use Config\Exceptions as ExceptionsConfig; use Config\Paths; +use Config\Services; use ErrorException; use Psr\Log\LogLevel; use Throwable; @@ -71,15 +72,15 @@ class Exceptions private ?Throwable $exceptionCaughtByExceptionHandler = null; /** - * @param CLIRequest|IncomingRequest $request + * @param CLIRequest|IncomingRequest|null $request + * + * @deprecated The parameter $request and $response are deprecated. No longer used. */ - public function __construct(ExceptionsConfig $config, $request, ResponseInterface $response) + public function __construct(ExceptionsConfig $config, $request, ResponseInterface $response) /** @phpstan-ignore-line */ { $this->ob_level = ob_get_level(); $this->viewPath = rtrim($config->errorViewPath, '\\/ ') . DIRECTORY_SEPARATOR; $this->config = $config; - $this->request = $request; - $this->response = $response; // workaround for upgraded users // This causes "Deprecated: Creation of dynamic property" in PHP 8.2. @@ -119,6 +120,9 @@ public function exceptionHandler(Throwable $exception) [$statusCode, $exitCode] = $this->determineCodes($exception); + $this->request = Services::request(); + $this->response = Services::response(); + if ($this->config->log === true && ! in_array($statusCode, $this->config->ignoreCodes, true)) { log_message('critical', "{message}\nin {exFile} on line {exLine}.\n{trace}", [ 'message' => $exception->getMessage(), diff --git a/tests/system/Helpers/FormHelperTest.php b/tests/system/Helpers/FormHelperTest.php index 9a525adf7ad2..b45329c8663c 100644 --- a/tests/system/Helpers/FormHelperTest.php +++ b/tests/system/Helpers/FormHelperTest.php @@ -39,7 +39,6 @@ private function setRequest(): void Services::injectMock('uri', $uri); $config = new App(); - $config->baseURL = ''; $config->indexPage = 'index.php'; $request = Services::request($config);