Skip to content

Fix #752: Allow access to sibling properties in nested context - #791

Open
WarLikeLaux wants to merge 16 commits into
yiisoft:masterfrom
WarLikeLaux:fix-nested-context-sibling-access
Open

WarLikeLaux wants to merge 16 commits into
yiisoft:masterfrom
WarLikeLaux:fix-nested-context-sibling-access

Conversation

@WarLikeLaux

@WarLikeLaux WarLikeLaux commented Mar 21, 2026 •

Copy link
Copy Markdown
Contributor
Q A
Is bugfix? ✔️
New feature? ❌
Tests added? ✔️
Breaks BC? ❌
Fixed issues #752

What does this PR do?

Pass full scope data (with sibling properties) to context->validate() in NestedHandler, so when callbacks 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:

  • Allow nested validation contexts to access sibling properties for conditional callbacks and comparison rules.

Enhancements:

  • Clarify nested validation behavior for sibling access, numeric paths, custom rules, and comparison rules.

Documentation:

  • Document sibling-property access in nested validation, including conditional, custom, and comparison rules and numeric-key limitations.

Tests:

  • Add coverage for sibling access across nested and repeated structures, comparison targets, numeric paths, and invalid intermediate paths.

Chores:

  • Record the sibling-property access fix in the changelog.

Summary by CodeRabbit

Bug Fixes

  • Fixed an issue preventing validation rules from accessing sibling properties within nested validation contexts.

Review Change Stack

@codecov

codecov Bot commented Mar 21, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.15%. Comparing base (d4c11c2) to head (19d1280).
⚠️ Report is 2 commits behind head on master.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 NestedHandler to pass the full relevant scope data into context->validate() for nested property validation.
  • Add regression tests covering sibling access in when callbacks (including inside Each + Nested combinations) 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.

Comment thread CHANGELOG.md Resolved
Comment thread src/Rule/NestedHandler.php Resolved
Comment thread CHANGELOG.md Resolved
@WarLikeLaux WarLikeLaux changed the title Allow access to sibling properties in nested context (#752) Fix #752: Allow access to sibling properties in nested context May 30, 2026
@WarLikeLaux
WarLikeLaux requested a review from samdark May 30, 2026 13:10
@WarLikeLaux

Copy link
Copy Markdown
Contributor Author

@coderabbitai full review

@coderabbitai

coderabbitai Bot commented May 30, 2026

Copy link
Copy Markdown
✅ Actions performed

Full review triggered.

@coderabbitai

coderabbitai Bot commented May 30, 2026 •

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

The PR enables sibling property access in nested validation contexts. NestedHandler reworks how it validates non-integer property paths by parsing them into segments, walking through intermediate keys to build a scoped data structure, and validating rules against that scope. Tests verify sibling-driven conditional skipping and missing key handling. The changelog documents the fix for Bug #752.

Changes

Sibling property access in nested validation

Layer / File(s) Summary
NestedHandler sibling-aware validation logic
src/Rule/NestedHandler.php
array_key_exists and count imports are added. Non-integer property path validation is refactored to parse the path into segments, walk through intermediate segments to build a scopeData subtree (or empty array if traversal fails), and validate rules against that computed scope instead of wrapping a single fetched value.
Test cases for sibling access and missing keys
tests/Rule/Nested/NestedTest.php
New "validation passed" entries test sibling-driven rule skipping via when callbacks in direct and nested Each contexts. New "validation failed" entries confirm when callbacks can read sibling fields and control nested rules, and that missing intermediate keys in dotted paths produce errors at the full path.
Changelog entry for bug fix #752
CHANGELOG.md
Bug #752 is documented under the "2.5.2 under development" section, describing the change that enables sibling property access in nested validation contexts.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 A nested hop through sibling lands,
Where paths now follow walkers' commands,
Each segment parsed with careful care,
Scope data built and validated fair!
Siblings whisper through the when,
And tests ensure it works again! 🌿

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Fix #752: Allow access to sibling properties in nested context' directly and clearly summarizes the main change: enabling access to sibling properties in nested validation contexts.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@WarLikeLaux

Copy link
Copy Markdown
Contributor Author

@coderabbitai full review

@coderabbitai

coderabbitai Bot commented May 30, 2026

Copy link
Copy Markdown
✅ Actions performed

Full review triggered.

@WarLikeLaux

Copy link
Copy Markdown
Contributor Author

@coderabbitai full review

@coderabbitai

coderabbitai Bot commented May 30, 2026

Copy link
Copy Markdown
✅ Actions performed

Full review triggered.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 2779afc and 0cb3cc2.

📒 Files selected for processing (3)
  • CHANGELOG.md
  • src/Rule/NestedHandler.php
  • tests/Rule/Nested/NestedTest.php

Comment thread src/Rule/NestedHandler.php Resolved
Comment thread src/Rule/NestedHandler.php Resolved
Comment thread tests/Rule/Nested/NestedTest.php Resolved
Comment thread CHANGELOG.md Outdated
## 2.6.1 under development

- no changes in this release.
- Bug #752: Allow access to sibling properties in nested validation context (@WarLikeLaux)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
- 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)

@sourcery-ai

sourcery-ai Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

Implementation

Update NestedHandler to validate named properties against their containing scope so rules can access siblings, while retaining direct-value validation for numeric paths and preserving error paths.

  • src/Rule/NestedHandler.php L72-76, L90-99, L126-147 (+4 small edits)

Documentation

Explain sibling access in nested validation for callbacks, comparison rules, and custom rules, and document the limitations for numeric paths.

  • docs/guide/en/built-in-rules-nested.md L391-399, L434-480, L556-557
  • docs/guide/en/conditional-validation.md L346-354, L360

Record the sibling-access fix in the changelog.

  • CHANGELOG.md L5-6

Tests

Cover sibling access across nested and Each validation, comparison targets, and behavior for numeric paths and missing or scalar intermediate values.

  • tests/Rule/Nested/NestedTest.php L1064-1124, L1349-1412, L1442-1501 (+1 small edits)

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sourcery assessment

Approved.

@vjik vjik added the status:code review The pull request needs review. label Nov 20, 2026
@vjik
vjik requested review from a team and samdark November 20, 2026 10:22

@samdark samdark left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@vjik
vjik requested a review from samdark November 21, 2026 13:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status:code review The pull request needs review.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants