fix(Validation): correct required_without logic and prevent array key warnings#10328
Open
gr8man wants to merge 3 commits into
Open
fix(Validation): correct required_without logic and prevent array key warnings#10328gr8man wants to merge 3 commits into
gr8man wants to merge 3 commits into
Conversation
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.
Description
This PR fixes two bugs in the
required_withoutvalidation rule when used with array dot notation.required_withoutrule (e.g.,required_without[a.*.b,a.*.c]), theforeachloop inside the method would prematurely returntrueas soon as it found the first present field. This caused the rule to completely ignore any subsequent fields in the array, leading to incorrect validation passes even if the subsequent fields were missing. This has been fixed by continuing the loop to check all declared fields.dot_array_searchreturnednullor a non-array, trying to access[$fieldKey]directly resulted in anUndefined array keywarning. Added the null coalescing operator (?? null) and a safe check withempty()to prevent PHP warnings when the array key is not set.Added
testRequireWithoutMultipleWithAsterisktoValidationTest.phpto prove the bug was resolved.Checklist: