Skip to content

Commit 0874e26

Browse files
committed
Code Review changes
1 parent bf2bc63 commit 0874e26

File tree

3 files changed

+8
-13
lines changed

3 files changed

+8
-13
lines changed

packages/http/src/Mappers/PsrRequestToGenericRequestMapper.php

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -93,13 +93,6 @@ private function requestMethod(PsrRequest $request, array $data): Method
9393
return $originalMethod;
9494
}
9595

96-
$spoofedMethod = Method::tryFrom(strtoupper($data['_method']));
97-
if ($spoofedMethod === null) {
98-
return $originalMethod;
99-
}
100-
101-
return $spoofedMethod->isSpoofable()
102-
? $spoofedMethod
103-
: $originalMethod;
96+
return Method::trySpoofingFrom($data['_method']) ?? $originalMethod;
10497
}
10598
}

packages/http/src/Method.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,13 @@ enum Method: string
1616
case TRACE = 'TRACE';
1717
case PATCH = 'PATCH';
1818

19-
public function isSpoofable(): bool
19+
public static function trySpoofingFrom(string $method): ?Method
2020
{
21-
return match ($this) {
22-
Method::PUT, Method::PATCH, Method::DELETE => true,
23-
default => false,
21+
$method = Method::tryFrom(strtoupper($method));
22+
23+
return match ($method) {
24+
self::DELETE, self::PATCH, self::PUT => $method,
25+
default => null,
2426
};
2527
}
2628
}

packages/view/src/Components/x-form.view.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
$method = $method->value;
1515
}
1616

17-
$needsSpoofing = in_array(strtoupper($method), ['PUT', 'PATCH', 'DELETE'], true);
17+
$needsSpoofing = Method::trySpoofingFrom($method) !== null;
1818
$formMethod = $needsSpoofing ? 'POST' : $method;
1919
?>
2020

0 commit comments

Comments
 (0)