Repository navigation
Fix #752: Allow access to sibling properties in nested context - #791
WarLikeLaux wants to merge 16 commits into
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #791 +/- ##
=========================================
Coverage 97.14% 97.15%
- Complexity 1154 1159 +5
=========================================
Files 124 124
Lines 3542 3551 +9
=========================================
+ Hits 3441 3450 +9
Misses 101 101 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
Fixes nested validation context scoping so when callbacks in nested rules can access sibling properties (e.g., isEnabled when validating content) via ValidationContext::getDataSet().
Changes:
- Update
NestedHandlerto pass the full relevant scope data intocontext->validate()for nested property validation. - Add regression tests covering sibling access in
whencallbacks (including insideEach+Nestedcombinations) and a missing-intermediate-key dotted path case. - Add a changelog entry documenting the bugfix.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
src/Rule/NestedHandler.php |
Adjusts nested validation to validate against the parent scope dataset so sibling properties are available in context. |
tests/Rule/Nested/NestedTest.php |
Adds tests proving sibling access works in when callbacks across nested structures. |
CHANGELOG.md |
Documents the bugfix in the upcoming release notes. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Alexander Makarov <sam@rmcreative.ru>
|
@coderabbitai full review |
✅ Actions performedFull review triggered. |
📝 WalkthroughWalkthroughThe PR enables sibling property access in nested validation contexts. ChangesSibling property access in nested validation
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
@coderabbitai full review |
✅ Actions performedFull review triggered. |
|
@coderabbitai full review |
✅ Actions performedFull review triggered. |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/Rule/NestedHandler.php`:
- Around line 98-109: The code can pass a scalar as the scope to
context->validate when an intermediate path segment exists but is not an array
(e.g. ['push'=>'on'] with path push.content); after the for-loop that walks
$valuePathList in NestedHandler.php, ensure $scopeData is an array and if not
set $scopeData = [] so context->validate always receives an array (empty-scope
fallback) instead of a scalar; locate the variables $scopeData, $valuePathList
and the call to $context->validate and add the normalization check just before
the validate call.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: a34e8aa5-ff03-43bc-8834-3d217bc1b576
📒 Files selected for processing (3)
CHANGELOG.mdsrc/Rule/NestedHandler.phptests/Rule/Nested/NestedTest.php
| ## 2.6.1 under development | ||
|
|
||
| - no changes in this release. | ||
| - Bug #752: Allow access to sibling properties in nested validation context (@WarLikeLaux) |
There was a problem hiding this comment.
The change isn't limited to when: inside Nested the data set is now the whole parent array, so targetProperty of compare rules resolves siblings too (e.g. Nested(['p2' => new Equal(targetProperty: 'p')]) used to compare against null), and custom rules reading $context->getDataSet() see siblings. Worth saying so.
| - Bug #752: Allow access to sibling properties in nested validation context (@WarLikeLaux) | |
| - Bug #752: Allow access to sibling properties in nested validation context, e.g. in `when` callbacks and `targetProperty` of compare rules (@WarLikeLaux) |
Reviewer's GuideImplementationUpdate
DocumentationExplain sibling access in nested validation for callbacks, comparison rules, and custom rules, and document the limitations for numeric paths.
Record the sibling-access fix in the changelog.
TestsCover sibling access across nested and
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
samdark
left a comment
There was a problem hiding this comment.
Please update the Nested and conditional validation guides to explain sibling access for comparisons and custom rules on named leaves. Explain that numeric leaves validate the selected value and do not expose siblings from the containing list.
What does this PR do?
Pass full scope data (with sibling properties) to
context->validate()inNestedHandler, sowhencallbacks can access siblings via$context->getDataSet()->getPropertyValue().Coverage
Tests: 89 → 93. Line coverage: 66/66 (100%) → 73/73 (100%). MSI: 96% (55/57) → 95% (65/68).
Summary by Sourcery
Pass the containing property scope into nested validation so rules can resolve sibling properties without changing existing numeric-path behavior.
Bug Fixes:
Enhancements:
Documentation:
Tests:
Chores:
Summary by CodeRabbit
Bug Fixes