Skip to content

Allow use callable rules into Nested #770

Merged
vjik merged 10 commits into
yiisoft:masterfrom
Enjoyzz:611-issue
Jun 4, 2025
Merged

Allow use callable rules into Nested #770
vjik merged 10 commits into
yiisoft:masterfrom
Enjoyzz:611-issue

Conversation

@Enjoyzz
Copy link
Copy Markdown
Contributor

@Enjoyzz Enjoyzz commented May 30, 2025

Q A
Is bugfix?
New feature?
Breaks BC?

#611

@Enjoyzz Enjoyzz changed the title #611 Allow use callable rules into Nested Allow use callable rules into Nested May 30, 2025
@codecov
Copy link
Copy Markdown

codecov Bot commented May 30, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.18%. Comparing base (fe63447) to head (76fc357).
Report is 78 commits behind head on master.

Additional details and impacted files
@@             Coverage Diff              @@
##             master     #770      +/-   ##
============================================
+ Coverage     94.40%   96.18%   +1.78%     
- Complexity      953     1036      +83     
============================================
  Files           108      122      +14     
  Lines          3018     3276     +258     
============================================
+ Hits           2849     3151     +302     
+ Misses          169      125      -44     

☔ View full report in Codecov by Sentry.
📢 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.

@samdark samdark requested a review from Copilot May 31, 2025 07:48
Copy link
Copy Markdown

Copilot AI left a 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 extends the Nested rule to accept callables as validation rules and adds a corresponding test.

  • Allow inline callable validators in Nested
  • Update ensureArrayHasRules to recognize callables
  • Add test to cover callable rules and update changelog

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
tests/Rule/NestedTest.php Added testUseCallableRules to verify inline callables
src/Rule/Nested.php Modified ensureArrayHasRules to accept callables
CHANGELOG.md Documented support for callable rules in Nested
Comments suppressed due to low confidence (1)

tests/Rule/NestedTest.php:1514

  • The testUseCallableRules method is missing a closing } before the next test. Add the closing brace after the assertion to avoid a syntax error.
public function testWithArrayOfObjects(): void

Comment thread src/Rule/Nested.php Outdated
Enjoyzz and others added 2 commits May 31, 2025 13:48
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Comment thread src/Rule/Nested.php Outdated
Reason: To avoid modifying `RawNestedRulesArray` and `NormalizedNestedRulesArray` since changes would cause Psalm errors. Fixing these errors would require changes to `PropagateOptionsHelper`, which is used by other rules like Each that expect different input types (without callable). Since the validator would eventually convert `callable` to a `Callback` rule anyway, we can do this conversion earlier.

P.S. I tried using `RulesNormalizer::normalize()`, but encountered errors in some places - plain text in two cases and an incompatible array structure in another.
@Enjoyzz Enjoyzz requested a review from vjik June 3, 2025 10:33
Comment thread src/Rule/Nested.php Outdated
Enjoyzz and others added 2 commits June 4, 2025 17:42
Co-authored-by: Sergei Predvoditelev <sergey.predvoditelev@gmail.com>
@vjik vjik merged commit 6edb238 into yiisoft:master Jun 4, 2025
31 of 32 checks passed
@vjik
Copy link
Copy Markdown
Member

vjik commented Jun 4, 2025

Thank you!

@Enjoyzz Enjoyzz deleted the 611-issue branch June 5, 2025 05:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants