Fix misplaced Outer/Inner names when using named() on Each#1640
Fix misplaced Outer/Inner names when using named() on Each#1640alganet merged 1 commit intoRespect:mainfrom
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1640 +/- ##
============================================
+ Coverage 98.03% 98.14% +0.11%
- Complexity 961 963 +2
============================================
Files 197 197
Lines 2234 2213 -21
============================================
- Hits 2190 2172 -18
+ Misses 44 41 -3 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
2b24ccd to
e8ea6fb
Compare
There was a problem hiding this comment.
Pull request overview
This PR fixes a bug where the Each validator was inverting Outer and Inner names when using named(), and also refactors the Result class for better maintainability.
Changes:
- Fixed
Eachvalidator to correctly apply Outer names to the parent result and Inner names to child results - Refactored
Resultclass by introducingmapChildrenandmapAdjacenthelper methods - Enhanced message formatting to show named children with their names (e.g.,
.0 (<- Inner)) while avoiding redundancy in nested displays
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| tests/feature/Validators/EachTest.php | Updated test expectations to match corrected naming behavior where Outer names apply to parent "Each item in..." messages and Inner names apply to individual child items |
| src/Validators/Each.php | Added withPrecedentName(false) to child results and removed incorrect withNameFrom call to fix name inversion |
| src/Validators/Core/FilteredNonEmptyArray.php | Removed incorrect withNameFrom calls that were propagating child names to parent error results |
| src/Result.php | Refactored with new withPrecedentName method, streamlined name/path handling, and added mapChildren/mapAdjacent helpers to eliminate redundant array_map calls |
| src/Message/Formatter/NestedArrayFormatter.php | Enhanced to conditionally remove redundant names from children when they match the parent name in nested displays |
| src/Validators/Key.php | Code formatting improvement (line break added for readability) |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
henriquemoody
left a comment
There was a problem hiding this comment.
Awesome work, and great catch! I think we should get to an agreement regarding the withInput() before merging this one, though.
e8ea6fb to
be4ebd8
Compare
henriquemoody
left a comment
There was a problem hiding this comment.
I have only a nitpick comment, but I'm approving
The Each validator was using "Outer" names (the name applied to the parent) in child results and vice-versa. This commit fixes it, and also streamlines the Result class, introducing helper `mapChildren` and `mapAdjacent` methods and removing unecessary recursive array_maps. Named children now also display their names, allowing users to create more meaningful messages that do not spam nested `.0`...`.0`...etc numeric keys which could be confusing. If the user does not name them, the previous behavior is kept.
be4ebd8 to
04fe1d0
Compare
The Each validator was using "Outer" names (the name applied to the parent) in child results and vice-versa.
This commit fixes it, and also streamlines the Result class, introducing helper
mapChildrenandmapAdjacentmethods and removing unecessary recursive array_maps.Named children now also display their names, allowing users to create more meaningful messages that do not spam nested
.0....0...etc numeric keys which could be confusing. If the user does not name them, the previous behavior is kept.This fixes #1639