Skip to content

Commit 8540948

Browse files
committed
fix: make fetchFromArray protected and avoid short ternary
- fetchFromArray() must be protected so IncomingRequest (a subclass) can call it. - Replace the short ternary in getRequestData() with explicit checks to satisfy the static analysis rules. - Drop the cookie assertion from the test since request_order defaults to GP (no cookies).
1 parent 9ec81ae commit 8540948

3 files changed

Lines changed: 9 additions & 5 deletions

File tree

‎system/HTTP/RequestTrait.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ public function fetchGlobal(string $name, $index = null, ?int $filter = null, $f
305305
*
306306
* @return mixed
307307
*/
308-
private function fetchFromArray(array $data, $index = null, ?int $filter = null, $flags = null)
308+
protected function fetchFromArray(array $data, $index = null, ?int $filter = null, $flags = null)
309309
{
310310
// Null filters cause null values to return.
311311
$filter ??= FILTER_UNSAFE_RAW;

‎system/Superglobals.php‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,13 @@ public function setRequestArray(array $array): self
401401
*/
402402
public function getRequestData(): array
403403
{
404-
$requestOrder = ini_get('request_order') ?: ini_get('variables_order') ?: 'GP';
404+
$requestOrder = ini_get('request_order');
405+
if ($requestOrder === false || $requestOrder === '') {
406+
$requestOrder = ini_get('variables_order');
407+
}
408+
if ($requestOrder === false || $requestOrder === '') {
409+
$requestOrder = 'GP';
410+
}
405411

406412
$request = [];
407413

‎tests/system/SuperglobalsTest.php‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -302,17 +302,15 @@ public function testRequestSetArray(): void
302302
$this->assertSame($data, $_REQUEST);
303303
}
304304

305-
public function testGetRequestDataMergesGetPostCookie(): void
305+
public function testGetRequestDataMergesGetAndPost(): void
306306
{
307307
$this->superglobals->setGetArray(['get_key' => 'get_value']);
308308
$this->superglobals->setPostArray(['post_key' => 'post_value']);
309-
$this->superglobals->setCookieArray(['cookie_key' => 'cookie_value']);
310309

311310
$data = $this->superglobals->getRequestData();
312311

313312
$this->assertSame('get_value', $data['get_key']);
314313
$this->assertSame('post_value', $data['post_key']);
315-
$this->assertSame('cookie_value', $data['cookie_key']);
316314
}
317315

318316
public function testGetRequestDataReflectsGetChanges(): void

0 commit comments

Comments
 (0)