-
Notifications
You must be signed in to change notification settings - Fork 85
Optimize and align validate_object methods across handlers #2278
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Performance improvements: - Replace array_diff() + array_keys() with isset() checks (faster, no temporary arrays) - Simplify object validation from empty() || !is_array() to !isset() || !is_array() - Remove unnecessary is_wp_error() checks (request is always WP_REST_Request) Code quality improvements: - Rename $json_params to $activity for better readability - Align validation patterns across all handlers for consistency - Improve docblock formatting in REST controllers All existing tests pass.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR optimizes and standardizes the validate_object
methods across ActivityPub handlers to improve performance and code consistency.
- Replaces inefficient
array_diff()
+array_keys()
operations with directisset()
checks for better performance - Removes unnecessary
is_wp_error()
checks since the request parameter is alwaysWP_REST_Request
in practice - Renames
$json_params
to$activity
for improved readability and consistency across handlers
Reviewed Changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated no comments.
Show a summary per file
File | Description |
---|---|
includes/handler/class-accept.php | Optimizes validation logic with isset() checks and removes WP_Error handling |
includes/handler/class-create.php | Streamlines object validation and removes unnecessary WP_Error check |
includes/handler/class-quote-request.php | Simplifies required field validation and removes WP_Error handling |
includes/handler/class-reject.php | Optimizes validation with direct isset() checks |
includes/handler/class-undo.php | Replaces array operations with isset() and adds object type validation |
includes/rest/class-inbox-controller.php | Updates PHPDoc to correctly specify WP_REST_Request type |
includes/rest/class-actors-inbox-controller.php | Updates PHPDoc to correctly specify WP_REST_Request type |
tests/includes/handler/class-test-quote-request.php | Removes obsolete test for WP_Error scenario that can no longer occur |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
'actor', | ||
'object', | ||
); | ||
if ( ! \is_array( $activity['object'] ) ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we first merge #2284 and then have your changes afterwards? My PR adds support for URI-Objects at least for Like
s and Announce
s.
The signature verification returns a
validate_object verification?
|
Ok, |
We could move it to FWIW, I don't think it's a big deal, eventually a request has to pass all of these tests anyway. |
Then let's keep it as is! |
I think it is fine to merge (when the conflicts are resolved), I will update the validation callback through #2295 then. |
…8n in advanced settings (#2290)
Deleted the test_validate_object_with_wp_error method from the quote request test class, possibly because the scenario is no longer relevant or covered elsewhere.
Also fixes a potential fatal error for
Undo
activities from brid.gy.Proposed changes:
validate_object
methods in Accept, Create, Reject, Undo, and Quote_Request handlers for better performancearray_diff()
+array_keys()
operations with directisset()
checksempty() || !is_array()
to!isset() || !is_array()
is_wp_error()
checks (request parameter is alwaysWP_REST_Request
in actual usage)$json_params
to$activity
for improved code readabilityOther information:
All existing tests pass. Removed one obsolete test that was checking for an impossible scenario (WP_Error as request object).
Testing instructions:
npm run env-test
to verify all PHP tests passChangelog entry