From 28f4a88166c7a6d455a9af1c38b65823a7a7bcbb Mon Sep 17 00:00:00 2001 From: kenjis Date: Fri, 30 Jun 2023 20:04:57 +0900 Subject: [PATCH] fix: [BC] fix wrong types for Requests Fixes the following errors: ------ ------------------------------------------------------------------ Line system/CodeIgniter.php ------ ------------------------------------------------------------------ 529 Parameter #1 $request of method CodeIgniter\Cache\PageCache::cachePage() expects CodeIgniter\HTTP\CLIRequest|CodeIgniter\HTTP\IncomingRequest, CodeIgniter\HTTP\Request|null given. 685 Parameter #1 $request of method CodeIgniter\Cache\PageCache::getCachedResponse() expects CodeIgniter\HTTP\CLIRequest|CodeIgniter\HTTP\IncomingRequest, CodeIgniter\HTTP\Request|null given. ------ ------------------------------------------------------------------ --- phpstan-baseline.neon.dist | 10 ---------- system/CodeIgniter.php | 8 +++++--- system/Test/FeatureTestCase.php | 16 +++++++++++----- 3 files changed, 16 insertions(+), 18 deletions(-) diff --git a/phpstan-baseline.neon.dist b/phpstan-baseline.neon.dist index 2d60b2b599d2..e1ecece1f5f0 100644 --- a/phpstan-baseline.neon.dist +++ b/phpstan-baseline.neon.dist @@ -25,16 +25,6 @@ parameters: count: 1 path: system/Cache/Handlers/RedisHandler.php - - - message: "#^Call to an undefined method CodeIgniter\\\\HTTP\\\\Request\\:\\:getPost\\(\\)\\.$#" - count: 1 - path: system/CodeIgniter.php - - - - message: "#^Call to an undefined method CodeIgniter\\\\HTTP\\\\Request\\:\\:setLocale\\(\\)\\.$#" - count: 1 - path: system/CodeIgniter.php - - message: "#^Property CodeIgniter\\\\Database\\\\BaseBuilder\\:\\:\\$db \\(CodeIgniter\\\\Database\\\\BaseConnection\\) in empty\\(\\) is not falsy\\.$#" count: 1 diff --git a/system/CodeIgniter.php b/system/CodeIgniter.php index b8625b281978..1d4ccd12fed0 100644 --- a/system/CodeIgniter.php +++ b/system/CodeIgniter.php @@ -85,7 +85,7 @@ class CodeIgniter /** * Current request. * - * @var CLIRequest|IncomingRequest|Request|null + * @var CLIRequest|IncomingRequest|null */ protected $request; @@ -471,7 +471,7 @@ protected function handleRequest(?RouteCollectionInterface $routes, Cache $cache return $possibleResponse; } - if ($possibleResponse instanceof Request) { + if ($possibleResponse instanceof IncomingRequest || $possibleResponse instanceof CLIRequest) { $this->request = $possibleResponse; } } @@ -611,9 +611,11 @@ protected function startBenchmark() * Sets a Request object to be used for this request. * Used when running certain tests. * + * @param CLIRequest|IncomingRequest $request + * * @return $this */ - public function setRequest(Request $request) + public function setRequest($request) { $this->request = $request; diff --git a/system/Test/FeatureTestCase.php b/system/Test/FeatureTestCase.php index 7163d3e85717..371e302c59ae 100644 --- a/system/Test/FeatureTestCase.php +++ b/system/Test/FeatureTestCase.php @@ -12,6 +12,7 @@ namespace CodeIgniter\Test; use CodeIgniter\Events\Events; +use CodeIgniter\HTTP\CLIRequest; use CodeIgniter\HTTP\Exceptions\RedirectException; use CodeIgniter\HTTP\IncomingRequest; use CodeIgniter\HTTP\Request; @@ -328,11 +329,13 @@ protected function setupHeaders(IncomingRequest $request) * * Always populate the GET vars based on the URI. * - * @return Request + * @param CLIRequest|IncomingRequest $request + * + * @return CLIRequest|IncomingRequest * * @throws ReflectionException */ - protected function populateGlobals(string $method, Request $request, ?array $params = null) + protected function populateGlobals(string $method, $request, ?array $params = null) { // $params should set the query vars if present, // otherwise set it from the URL. @@ -357,10 +360,13 @@ protected function populateGlobals(string $method, Request $request, ?array $par * This allows the body to be formatted in a way that the controller is going to * expect as in the case of testing a JSON or XML API. * - * @param array|null $params The parameters to be formatted and put in the body. If this is empty, it will get the - * what has been loaded into the request global of the request class. + * @param CLIRequest|IncomingRequest $request + * @param array|null $params The parameters to be formatted and put in the body. If this is empty, it will get the + * what has been loaded into the request global of the request class. + * + * @return CLIRequest|IncomingRequest */ - protected function setRequestBody(Request $request, ?array $params = null): Request + protected function setRequestBody($request, ?array $params = null) { if (isset($this->requestBody) && $this->requestBody !== '') { $request->setBody($this->requestBody);