Skip to content

Commit 28f4a88

Browse files
committed
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. ------ ------------------------------------------------------------------
1 parent f6435c3 commit 28f4a88

File tree

3 files changed

+16
-18
lines changed

3 files changed

+16
-18
lines changed

phpstan-baseline.neon.dist

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,6 @@ parameters:
2525
count: 1
2626
path: system/Cache/Handlers/RedisHandler.php
2727

28-
-
29-
message: "#^Call to an undefined method CodeIgniter\\\\HTTP\\\\Request\\:\\:getPost\\(\\)\\.$#"
30-
count: 1
31-
path: system/CodeIgniter.php
32-
33-
-
34-
message: "#^Call to an undefined method CodeIgniter\\\\HTTP\\\\Request\\:\\:setLocale\\(\\)\\.$#"
35-
count: 1
36-
path: system/CodeIgniter.php
37-
3828
-
3929
message: "#^Property CodeIgniter\\\\Database\\\\BaseBuilder\\:\\:\\$db \\(CodeIgniter\\\\Database\\\\BaseConnection\\) in empty\\(\\) is not falsy\\.$#"
4030
count: 1

system/CodeIgniter.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ class CodeIgniter
8585
/**
8686
* Current request.
8787
*
88-
* @var CLIRequest|IncomingRequest|Request|null
88+
* @var CLIRequest|IncomingRequest|null
8989
*/
9090
protected $request;
9191

@@ -471,7 +471,7 @@ protected function handleRequest(?RouteCollectionInterface $routes, Cache $cache
471471
return $possibleResponse;
472472
}
473473

474-
if ($possibleResponse instanceof Request) {
474+
if ($possibleResponse instanceof IncomingRequest || $possibleResponse instanceof CLIRequest) {
475475
$this->request = $possibleResponse;
476476
}
477477
}
@@ -611,9 +611,11 @@ protected function startBenchmark()
611611
* Sets a Request object to be used for this request.
612612
* Used when running certain tests.
613613
*
614+
* @param CLIRequest|IncomingRequest $request
615+
*
614616
* @return $this
615617
*/
616-
public function setRequest(Request $request)
618+
public function setRequest($request)
617619
{
618620
$this->request = $request;
619621

system/Test/FeatureTestCase.php

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace CodeIgniter\Test;
1313

1414
use CodeIgniter\Events\Events;
15+
use CodeIgniter\HTTP\CLIRequest;
1516
use CodeIgniter\HTTP\Exceptions\RedirectException;
1617
use CodeIgniter\HTTP\IncomingRequest;
1718
use CodeIgniter\HTTP\Request;
@@ -328,11 +329,13 @@ protected function setupHeaders(IncomingRequest $request)
328329
*
329330
* Always populate the GET vars based on the URI.
330331
*
331-
* @return Request
332+
* @param CLIRequest|IncomingRequest $request
333+
*
334+
* @return CLIRequest|IncomingRequest
332335
*
333336
* @throws ReflectionException
334337
*/
335-
protected function populateGlobals(string $method, Request $request, ?array $params = null)
338+
protected function populateGlobals(string $method, $request, ?array $params = null)
336339
{
337340
// $params should set the query vars if present,
338341
// otherwise set it from the URL.
@@ -357,10 +360,13 @@ protected function populateGlobals(string $method, Request $request, ?array $par
357360
* This allows the body to be formatted in a way that the controller is going to
358361
* expect as in the case of testing a JSON or XML API.
359362
*
360-
* @param array|null $params The parameters to be formatted and put in the body. If this is empty, it will get the
361-
* what has been loaded into the request global of the request class.
363+
* @param CLIRequest|IncomingRequest $request
364+
* @param array|null $params The parameters to be formatted and put in the body. If this is empty, it will get the
365+
* what has been loaded into the request global of the request class.
366+
*
367+
* @return CLIRequest|IncomingRequest
362368
*/
363-
protected function setRequestBody(Request $request, ?array $params = null): Request
369+
protected function setRequestBody($request, ?array $params = null)
364370
{
365371
if (isset($this->requestBody) && $this->requestBody !== '') {
366372
$request->setBody($this->requestBody);

0 commit comments

Comments
 (0)