Skip to content

Commit

Permalink
fix: [BC] fix wrong types for Requests
Browse files Browse the repository at this point in the history
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.
 ------ ------------------------------------------------------------------
  • Loading branch information
kenjis committed Jul 3, 2023
1 parent f6435c3 commit 28f4a88
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 18 deletions.
10 changes: 0 additions & 10 deletions phpstan-baseline.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 5 additions & 3 deletions system/CodeIgniter.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class CodeIgniter
/**
* Current request.
*
* @var CLIRequest|IncomingRequest|Request|null
* @var CLIRequest|IncomingRequest|null
*/
protected $request;

Expand Down Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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;

Expand Down
16 changes: 11 additions & 5 deletions system/Test/FeatureTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
Expand All @@ -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);
Expand Down

0 comments on commit 28f4a88

Please sign in to comment.