Extended validators to allow array values, dependent field validations and added new rules
Hi,
I am planning to use the library on one of my projects. Thought I'd share some changes here as well to help out the community.
- Added support for array of values in rule parameters
- The current ParameterizedRuleInterface is restrictive in terms of having to specify exact number of values which a rule would receive
- The new ArrayParameterizedRuleInterface aims to relax the constraints and allow rules to make use of multiple parameter values
- Added new rules like
inandrequired_ifusing the above interface
- Added support for dependent field validations
- The
passes()function now receives the current validation row which allows for dependent field validation checks - Added new rule
required_ifwhich is based on dependent field validation
- The
- Added new rules
- alpha
- alpha_num
- in:foo,bar,baz
- integer
- numeric
- required
- required_if:field,value1,value2
- min:min_val
- max:max_val
- Following rules now silently pass if the field value is empty. Since we now have a explicit
requiredrule, we can easily ignore empty cells unless required by user explicitlyalpha,alpha_num,in,integer,numericandurlwill now return true for null / empty string values
- Modified between rule to work for both strings and numbers, min and max rules will also work for both strings and numbers
- Added test cases for new rules, updated existing ones
- Updated documentation with new rules
Let me know if any change is required.
Codecov Report
Merging #22 (0045669) into master (34afb02) will not change coverage. The diff coverage is
100.00%.
@@ Coverage Diff @@
## master #22 +/- ##
===========================================
Coverage 100.00% 100.00%
- Complexity 94 141 +47
===========================================
Files 9 20 +11
Lines 230 320 +90
===========================================
+ Hits 230 320 +90
| Impacted Files | Coverage Δ | |
|---|---|---|
| src/Helpers/FormatsMessages.php | 100.00% <100.00%> (ø) |
|
| src/Rules/Alpha.php | 100.00% <100.00%> (ø) |
|
| src/Rules/AlphaNum.php | 100.00% <100.00%> (ø) |
|
| src/Rules/AsciiOnly.php | 100.00% <100.00%> (ø) |
|
| src/Rules/Between.php | 100.00% <100.00%> (ø) |
|
| src/Rules/ClosureValidationRule.php | 100.00% <100.00%> (ø) |
|
| src/Rules/In.php | 100.00% <100.00%> (ø) |
|
| src/Rules/Integer.php | 100.00% <100.00%> (ø) |
|
| src/Rules/Max.php | 100.00% <100.00%> (ø) |
|
| src/Rules/MaxLength.php | 100.00% <100.00%> (ø) |
|
| ... and 7 more |
Continue to review full report at Codecov.
Legend - Click here to learn more
Δ = absolute <relative> (impact),ø = not affected,? = missing dataPowered by Codecov. Last update 34afb02...0045669. Read the comment docs.
Hi, @hoshomoh, can you help me with this. Checks still haven't completed it seems.
This is quite the change. I will take some time this coming weekend to review. Great initiative.
Made a few changes recently
- Added an optional trimming function to trim row values if needed
- Reverted Min, Max and Between to only work for Numbers as this would've caused issues since more information was needed to figure out whether we should check for length or the exact value of the field. (Ideally to make these generalised we would have to check if the attribute already has a number or integer validation then validate for value and if not then validate for length)
- Since I removed the Length checks from above rules added MinLength and MaxLength validators