Enhance request handling with query parameters and HTTP method access.#51
Enhance request handling with query parameters and HTTP method access.#51gustavofreze merged 1 commit intomainfrom
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 73620650b4
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
Pull request overview
This pull request enhances the HTTP Request handling capabilities by adding three major features: HTTP method access, query parameter support, and full URI access. It also improves body handling by supporting PSR-7 parsed body for non-JSON payloads like form data.
Changes:
- Added
Request::method()to retrieve HTTP method as a typedMethodenum - Added
Uri::toString()to access the complete request URI as a string - Added
Uri::queryParameters()with typed access to query string parameters through a newQueryParametersclass - Enhanced
Body::from()to fall back togetParsedBody()when the stream is empty, supporting form-encoded and multipart requests - Updated all existing tests to mock
getMethod()onServerRequestInterface(required for the newmethod()API)
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| src/Request.php | Added method() function to return typed HTTP method enum |
| src/Internal/Request/Uri.php | Added toString() and queryParameters() methods, updated class docblock |
| src/Internal/Request/QueryParameters.php | New class providing typed access to query parameters, follows same pattern as Body |
| src/Internal/Request/Body.php | Enhanced to support parsed body fallback when stream is empty |
| src/Internal/Request/Decoder.php | Formatting change for multi-line constructor call |
| tests/RequestTest.php | Added comprehensive tests for new features and updated all existing mocks |
| README.md | Updated documentation with examples for new query parameters, URI, and method access features |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if ($streamFactory->isEmptyContent()) { | ||
| return new Body(data: []); | ||
| if (!$streamFactory->isEmptyContent()) { | ||
| return new Body(data: json_decode($streamFactory->content(), true)); |
There was a problem hiding this comment.
The json_decode on line 22 can return null if the JSON is invalid or a non-array value if the JSON doesn't represent an array. This would cause a type error when constructing Body, which expects an array parameter. Consider adding a check to ensure json_decode returns an array before passing it to the constructor, falling through to the empty array case otherwise.
| return new Body(data: json_decode($streamFactory->content(), true)); | |
| $decoded = json_decode($streamFactory->content(), true); | |
| if (is_array($decoded)) { | |
| return new Body(data: $decoded); | |
| } |
| public function method(): Method | ||
| { | ||
| return Method::from(value: $this->request->getMethod()); | ||
| } |
There was a problem hiding this comment.
The Method::from() call will throw a ValueError if the HTTP method string returned by getMethod() is not one of the standard HTTP methods defined in the Method enum (GET, PUT, POST, HEAD, PATCH, TRACE, DELETE, OPTIONS, CONNECT). While this is acceptable for most cases, some applications may need to handle custom HTTP methods like PROPFIND, MKCOL, or other WebDAV methods. Consider documenting this behavior or adding a test that validates this throws an exception for non-standard methods to make the behavior explicit.
No description provided.