Skip to content

Commit

Permalink
refactor: remove strtoupper()/strtolower() for $request->getMethod()
Browse files Browse the repository at this point in the history
  • Loading branch information
kenjis committed Nov 10, 2023
1 parent d05a5a6 commit 25f7636
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion app/Views/errors/html/error_exception.php
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@
</tr>
<tr>
<td>HTTP Method</td>
<td><?= esc(strtoupper($request->getMethod())) ?></td>
<td><?= esc($request->getMethod()) ?></td>
</tr>
<tr>
<td>IP Address</td>
Expand Down
2 changes: 1 addition & 1 deletion system/Debug/Exceptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public function exceptionHandler(Throwable $exception)

if ($this->config->log === true && ! in_array($statusCode, $this->config->ignoreCodes, true)) {
$uri = $this->request->getPath() === '' ? '/' : $this->request->getPath();
$routeInfo = '[Method: ' . strtoupper($this->request->getMethod()) . ', Route: ' . $uri . ']';
$routeInfo = '[Method: ' . $this->request->getMethod() . ', Route: ' . $uri . ']';

log_message('critical', "{message}\n{routeInfo}\nin {exFile} on line {exLine}.\n{trace}", [
'message' => $exception->getMessage(),
Expand Down
2 changes: 1 addition & 1 deletion system/Debug/Toolbar.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public function run(float $startTime, float $totalTime, RequestInterface $reques
$data = [];
// Data items used within the view.
$data['url'] = current_url();
$data['method'] = strtoupper($request->getMethod());
$data['method'] = $request->getMethod();
$data['isAJAX'] = $request->isAJAX();
$data['startTime'] = $startTime;
$data['totalTime'] = $totalTime * 1000;
Expand Down
2 changes: 1 addition & 1 deletion system/Security/Security.php
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ public function getCSRFTokenName(): string
public function verify(RequestInterface $request)
{
// Protects POST, PUT, DELETE, PATCH
$method = strtoupper($request->getMethod());
$method = $request->getMethod();
$methodsToProtect = ['POST', 'PUT', 'DELETE', 'PATCH'];
if (! in_array($method, $methodsToProtect, true)) {
return $this;
Expand Down
2 changes: 1 addition & 1 deletion system/Validation/Validation.php
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ public function withRequest(RequestInterface $request): ValidationInterface
return $this;
}

if (in_array(strtolower($request->getMethod()), ['put', 'patch', 'delete'], true)
if (in_array($request->getMethod(), ['PUT', 'PATCH', 'DELETE'], true)
&& strpos($request->getHeaderLine('Content-Type'), 'multipart/form-data') === false
) {
$this->data = $request->getRawInput();
Expand Down
4 changes: 2 additions & 2 deletions tests/system/HTTP/OutgoingRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ public function testWithMethod(): void

$newRequest = $request->withMethod('POST');

$this->assertSame('GET', strtoupper($request->getMethod()));
$this->assertSame('POST', strtoupper($newRequest->getMethod()));
$this->assertSame('GET', $request->getMethod());
$this->assertSame('POST', $newRequest->getMethod());
}

public function testWithUri(): void
Expand Down

0 comments on commit 25f7636

Please sign in to comment.