feat(#115): add cross-field validation with #[Validate] attribute#134
Merged
Conversation
- Add overridable validate(array $inputs): array on WebService (service-wide)
- Add #[Validate('methodName')] attribute for method-specific validation
- Both run: service-wide first, then method-specific, errors merged
- Returns 422 with error details if validation fails
- Missing validator method throws InvalidArgumentException (caught as 500)
- Uses reflection to invoke private validator methods
- Update README with cross-field validation documentation
- 10 new tests covering all paths
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## dev #134 +/- ##
============================================
+ Coverage 93.69% 93.75% +0.05%
- Complexity 1308 1317 +9
============================================
Files 39 39
Lines 3188 3218 +30
============================================
+ Hits 2987 3017 +30
Misses 201 201
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Summary
Add cross-field validation support via an overridable
validate()method and a#[Validate]attribute for method-specific validators.Motivation
Individual parameter validation cannot express rules that depend on multiple fields together (e.g., "passwords must match", "end date after start date"). Currently developers must do these checks inside
processRequest()and manually send error responses. Fixes #115.Changes
WebService::validate(array $inputs): array— service-wide hook, returns empty array by default#[Validate('methodName')]attribute for method-specific cross-field validation{"message": "Validation failed", "type": "error", "more-info": {"errors": {...}}}if validation failsInvalidArgumentException(caught as 500)UI Changes
N/A
How to Test / Verify
10 new tests, 36 assertions. Full suite: 574 tests pass.
Breaking Changes and Migration Steps
None.
validate()returns empty array by default — existing services are unaffected.Checklist
Related issues
Closes #115