Skip to content

Commit 40529b9

Browse files
committed
Add isSpoofable to Method enum
1 parent bffe5df commit 40529b9

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

packages/http/src/Mappers/PsrRequestToGenericRequestMapper.php

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -98,14 +98,8 @@ private function requestMethod(PsrRequest $request, array $data): Method
9898
return $originalMethod;
9999
}
100100

101-
$allowedMethods = [
102-
Method::PUT,
103-
Method::PATCH,
104-
Method::DELETE,
105-
];
106-
107-
return ! in_array($spoofedMethod, $allowedMethods, strict: true)
108-
? $originalMethod
109-
: $spoofedMethod;
101+
return $spoofedMethod->isSpoofable()
102+
? $spoofedMethod
103+
: $originalMethod;
110104
}
111105
}

packages/http/src/Method.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,12 @@ enum Method: string
1515
case OPTIONS = 'OPTIONS';
1616
case TRACE = 'TRACE';
1717
case PATCH = 'PATCH';
18+
19+
public function isSpoofable(): bool
20+
{
21+
return match ($this) {
22+
Method::PUT, Method::PATCH, Method::DELETE => true,
23+
default => false,
24+
};
25+
}
1826
}

0 commit comments

Comments
 (0)